-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel.js
207 lines (157 loc) · 6.35 KB
/
panel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
function parseUri (str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
};
parseUri.options = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};
var clip;
function setListBody( queue, isLoggedin ) {
$('#listbody').html('')
if( isLoggedin == false ) {
alert('Please login first')
return;
}
for( var i=0; i<queue.length;i++){
var favicon = $('<img>').addClass('itemFavIcon').attr('src',queue[i].favIcon);
var separator = $('<span>|</span>').css('margin','0 1em');
var dateLabel = $('<div>').addClass('itemDate').text(queue[i].date);
var host = $('<div>').addClass('itemHost').text( parseUri(queue[i].url).host );
var clipboard = $('<a>').addClass('itemCopy')
.text('Copy')
.attr('title',queue[i].title)
.attr('url',queue[i].url);
var tweet = $('<a>').addClass('itemTweet')
.text('Tweet')
.attr('href','https://twitter.com/share?url='+ encodeURI(queue[i].url))
.attr('target','_blank');
var name = $('<a>')
.addClass('itemTitle')
.attr('href',queue[i].url)
.text(queue[i].title)
var group = $('<span>').addClass('groupName').text( queue[i].group + '/' + queue[i].category );
var title = $('<div>')
.append(favicon)
.append(name)
.append(host)
var subtitle = $('<div>')
.append( group )
.append( separator.clone() )
.append( dateLabel )
.append( separator.clone() )
.append( clipboard )
.append( tweet );
var header = $('<div>').addClass('itemHeader')
.append( title )
.append( subtitle);
var body = $('<div>').addClass('itemBody').text( queue[i].description );
title.append( $('<button>')
.addClass('glyphicon glyphicon-trash remove')
.attr('hashcode',queue[i].hashedURL)
.click(function(e) {
var hashedURL = $(e.target).attr('hashcode');
chrome.extension.sendMessage({directive: "panel-remove-item", hashedURL: hashedURL }, function(response) {
document.location.reload(true);
});
}) );
title.append( $('<button>')
.addClass('glyphicon glyphicon-pencil')
.attr('hashcode',queue[i].hashedURL)
.click(
(function(h,b,hash){
var exitEditMode = function(h,b,c,hash,save) {
return function() {
if( save )
chrome.extension.sendMessage({directive: "panel-edit-item", hashedURL: hash, newDescription: b.text() } );
else
b.text(c);
// Back UI to Normal mode
h.find('button.hidden').css('display','inline').removeClass('hidden');
h.find('.editorButton').remove();
b.attr('contenteditable','false').css('background-color','');
}
}
return function(e) {
// Save last text
var currentText = b.text();
// Go to edit mode
b.attr('contenteditable','true').css('background-color','#fff');
h.find('button').css('display','none').addClass('hidden');
h.append( $('<button>')
.addClass('editorButton glyphicon glyphicon-ok')
.click( exitEditMode(h,b,currentText,hash,true) ) );
h.append( $('<button>')
.addClass('editorButton glyphicon glyphicon-remove')
.click( exitEditMode(h,b,currentText,hash,false) ) );
}
})(title,body,queue[i].hashedURL)
));
var item = $('<div>').addClass('item')
.append( header )
.append( body )
$('#listbody').append( item );
}
$('#emailButton').click(function(){
chrome.extension.sendMessage({directive: "panel-email-items" } );
})
$('#clearButton').click( function() {
chrome.extension.sendMessage({directive: "panel-clearButton-click"});
});
$('#groupManagerButton').click( function() {
$("#groupDialog").dialog("open");
// Fill Groups List
});
$(".itemCopy").click(function(){
var txt = '*' + $(this).attr('title') + '* (' + $(this).attr('url') + ')';
prompt ("Copy link, then click OK.", txt);
});
$("#groupDialog").dialog({autoOpen: false});
$("#groupDialog #createGroupButton").click( function() {
createNewGroup( $("#groupDialog #newGroupName").val() );
});
$("#groupDialog #joinGroupButton").click( function() {
joinGroup( $("#groupDialog #joinGroupName").val() );
});
$("#groupDialog #inviteGroupButton").click( function() {
inviteGroup( $("#groupDialog #inviteGroupName").val(), $("#groupDialog #inviteEmail").val() );
});
console.log( chromeExOAuth.hasToken() );
}
function setGroupsList( groups, isLoggedin ) {
for( var i=0; i<groups.length; i++ ) {
var option = $('<option>').text(groups[i].name);
$('#inviteGroupName').append( option );
}
}
document.addEventListener('DOMContentLoaded', function () {
chrome.extension.sendMessage({directive: "panel-open"}, function(response) {});
})
function createNewGroup(groupName) {
if( groupName != null )
chrome.extension.sendMessage({directive: "addNewGroup", groupName: groupName});
}
function joinGroup(groupName) {
if( groupName != null )
chrome.extension.sendMessage({directive: "joinToGroup", groupName: groupName});
}
function inviteGroup(groupName,email) {
if( email != null && groupName != null )
chrome.extension.sendMessage({directive: "inviteToGroup", groupName: groupName, email: email});
}