This repository was archived by the owner on Sep 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscripts.js
More file actions
274 lines (254 loc) · 9.03 KB
/
scripts.js
File metadata and controls
274 lines (254 loc) · 9.03 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
var currentPMUser="";
function initWS() {
var ws = new WebSocket("ws://ws.juick.com/?hash="+hash);
ws.onopen = function(){
$('#sidepanel').addClass('online');
};
ws.onclose = function(){
$('#sidepanel').removeClass('online');
};
ws.onmessage = function(msg){
if(msg.data==' ') {
ws.send(' ');
} else {
try {
var jsonMsg=$.parseJSON(msg.data);
if(jsonMsg.rid>0) {
incomingComment(jsonMsg);
} else if(jsonMsg.mid>0) {
incomingPost(jsonMsg);
} else {
incomingPM(jsonMsg);
}
} catch(err) {
console.log(err);
}
}
};
}
function incomingPM(msg) {
try {
if(msg.user.uname===currentPMUser) {
$('#pmlist').append($("<li/>").attr("class","pm-in").text(msg.body));
$(window).scrollTop($(document).height());
} else {
var modified=false;
$.each(lastConversations,function(i,item) {
if(item.uname===msg.user.uname) {
if(item.MessagesCount>0) {
item.MessagesCount++;
} else {
item.MessagesCount=1;
}
modified=true;
}
});
if(!modified) {
lastConversations.unshift({
uname:msg.user.uname,
uid:msg.user.uid,
MessagesCount:"1"
});
}
initPMUList();
}
} catch(err) { }
}
function incomingPost(msg) {
console.log(msg);
if(groups[0].MessagesCount>0) {
groups[0].MessagesCount++;
} else {
groups[0].MessagesCount=1;
}
initGroupsList();
}
function incomingComment(msg) {
console.log(msg);
}
function initPMUList() {
var ul=$('#pmulist');
ul.empty();
$.each(lastConversations,function(i,item) {
var img=$("<img/>").attr("src","http://i.juick.com/as/"+item.uid+".png");
var a=$("<a/>").attr("href","#").attr("onclick","return showPM('"+item.uname+"')");
a.append(img).append(item.uname);
if(item.MessagesCount) {
a.append($("<div/>").attr("class","unreadcnt").text(item.MessagesCount));
}
var li=$("<li/>").append(a);
ul.append(li);
});
}
function initGroupsList() {
var ul=$('#groupslist');
ul.empty();
$.each(groups,function(i,item) {
var a=$("<a/>").attr("href","#").attr("onclick","return showGroup('"+item.gid+"')");
a.append(item.name);
if(item.MessagesCount) {
a.append($("<div/>").attr("class","unreadcnt").text(item.MessagesCount));
}
var li=$("<li/>").append(a);
ul.append(li);
});
}
function showGroup(gid) {
currentPMUser="";
groups[0].MessagesCount=0;
initGroupsList();
$.getJSON('http://api.juick.com/home?hash='+hash+'&callback=?').done(function(data) {
var ul=$('<ul/>');
ul.attr("id","msglist");
$.each(data,function(i,item) {
var tags="";
if(item.tags) {
$.each(item.tags,function(t,tag) {
tags+=" *"+tag;
});
}
var photo="";
if(item.photo) {
photo="<div class=\"msg-media\"><img src=\""+item.photo.small+"\"/></div>";
}
var li=$("<li/>").attr("class","msg").html(
"<div class=\"msg-header\">"+
"<div class=\"msg-menu\"></div>"+
"<div class=\"msg-avatar\"><a href=\"#\" onclick=\"return showUser('"+item.user.uname+"')\"><img src=\"//i.juick.com/a/"+item.user.uid+".png\"/></a></div>"+
"<div class=\"msg-uname\"><a href=\"#\" onclick=\"return showUser('"+item.user.uname+"')\">@"+item.user.uname+"</a>:"+tags+"</div>"+
"<div class=\"msg-ts\"><a href=\"#\" onclick=\"return showThread("+item.mid+")\">"+item.timestamp+"</a></div>"+
"</div>"+
"<div class=\"msg-txt\">"+item.body+"</div>"+
photo//+
// "<div class=\"msg-comment\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"Add a comment...\" onkeypress=\"postformListener(this.form,event)\"></textarea></div>"
);
ul.append(li);
});
$('#toppanel').css("display","none");
$('#bottompanel').css("display","none");
var content=$('#content');
content.attr("class","");
content.empty();
content.append(ul);
$(window).scrollTop(0);
});
return false;
}
function showMessages(param) {
currentPMUser="";
$.getJSON('http://api.juick.com/messages?hash='+hash+'&'+param+'&callback=?').done(function(data) {
var ul=$('<ul/>');
ul.attr("id","msglist");
$.each(data,function(i,item) {
var tags="";
if(item.tags) {
$.each(item.tags,function(t,tag) {
tags+=" *"+tag+"</a>";
});
}
var photo="";
if(item.photo) {
photo="<div class=\"msg-media\"><img src=\""+item.photo.small+"\"/></div>";
}
var li=$("<li/>").attr("class","msg").html(
"<div class=\"msg-header\">"+
"<div class=\"msg-menu\"></div>"+
"<div class=\"msg-avatar\"><a href=\"#\" onclick=\"return showUser('"+item.user.uname+"')\"><img src=\"//i.juick.com/a/"+item.user.uid+".png\"/></a></div>"+
"<div class=\"msg-uname\"><a href=\"#\" onclick=\"return showUser('"+item.user.uname+"')\">@"+item.user.uname+"</a>:"+tags+"</div>"+
"<div class=\"msg-ts\"><a href=\"#\" onclick=\"return showThread("+item.mid+")\">"+item.timestamp+"</a></div>"+
"</div>"+
"<div class=\"msg-txt\">"+item.body+"</div>"+
photo//+
//"<div class=\"msg-comment\"><textarea name=\"body\" rows=\"1\" class=\"reply\" placeholder=\"Add a comment...\" onkeypress=\"postformListener(this.form,event)\"></textarea></div>"
);
ul.append(li);
});
$('#toppanel').css("display","none");
$('#bottompanel').css("display","none");
var content=$('#content');
content.attr("class","");
content.empty();
content.append(ul);
$(window).scrollTop(0);
});
return false;
}
function showUser(uname) {
showMessages('uname='+uname);
return false;
}
function showPM(uname) {
var modified=false;
$.each(lastConversations,function(i,item) {
if(item.uname===uname && item.MessagesCount>0) {
item.MessagesCount=0;
modified=true;
}
});
if(modified) {
initPMUList();
}
$.getJSON('http://api.juick.com/pm?hash='+hash+'&uname='+uname+'&callback=?').done(function(data) {
var ul=$('<ul/>');
ul.attr("id","pmlist");
$.each(data,function(i,item) {
var li=$("<li/>");
if(item.user.uid==user_id) {
li.attr("class","pm-out");
} else {
li.attr("class","pm-in");
}
li.text(item.body);
ul.append(li);
});
currentPMUser=uname;
var toppanel=$('#toppanel');
toppanel.css("display","block");
toppanel.html("<h1>"+uname+"</h1>");
var bottompanel=$('#bottompanel');
bottompanel.html("<input type=\"text\" name=\"reply\" id=\"replypmtext\" onkeypress=\"sendPMformListener(this.form,event)\"/><input type=\"button\" value=\">\" id=\"replypmbutton\" onclick=\"return sendPM()\"/>");
bottompanel.css("display","block");
var content=$('#content');
content.attr("class","withtoppanel withbottompanel");
content.empty();
content.append(ul);
$(window).scrollTop($(document).height());
$('#replypmtext').focus();
});
return false;
}
function sendPMformListener(formEl,ev) {
if(ev.ctrlKey && (ev.keyCode==10 || ev.keyCode==13)) {
sendPM();
}
}
function sendPM() {
var replypmtext=$('#replypmtext');
var replypmbutton=$('#replypmbutton');
replypmtext.prop('disabled', true);
replypmbutton.prop('disabled', true);
var body=replypmtext.val();
$.ajax({
url:"http://api.juick.com/pm",
type:"POST",
data:{
hash:hash,
uname:currentPMUser,
body:body
},
success:function(data) {
replypmtext.val("");
$('#pmlist').append($("<li/>").attr("class","pm-out").text(body));
$(window).scrollTop($(document).height());
},
error:function(jqxhr,status) {
alert("Error: "+status);
},
complete:function() {
replypmtext.removeAttr("disabled");
replypmbutton.removeAttr("disabled");
replypmtext.focus();
}
});
return false;
}