OSDN Git Service

d09f073c5c814938391ca2d6a4279e28f7cf783f
[embrj/master.git] / js / public.js
1 var UPDATE_INTERVAL;\r
2 var PAUSE_UPDATE = false;\r
3 var PAUSE_TIMELINE = false;\r
4 function register() {\r
5         window.open("signup/index.php", "registerwindow", "height=450, width=550, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=yes, status=yes")\r
6 };\r
7 function oauth() {\r
8         var wtfgfw = window.confirm("Please make sure your proxy is ready to visit Twitter.com before authenticating.");\r
9         if (wtfgfw) {\r
10                 window.location.href = "oauth.php"\r
11         }\r
12 };\r
13 function leaveWord(num) {\r
14         if(!num){\r
15                 num = 140;\r
16         }\r
17         var leave = num-$("#textbox").val().length;\r
18         if (leave < 0) {\r
19                 $("#tip").css("color","#CC0000");\r
20                 $("#tip b").css("color","#CC0000");\r
21                 $("#tip").html("<b>-" + (-leave) + "</b>");\r
22                 $("#tweeting_button").addClass('btn-disabled');\r
23         } else {\r
24                 $("#tip").css("color","#CCCCCC");\r
25                 $("#tip b").css("color","#CCCCCC");\r
26                 $("#tip").html("<b>" + leave + "</b>");\r
27                 $("#tweeting_button").removeClass('btn-disabled');\r
28         }\r
29         if(leave === 140) {\r
30                 $("#in_reply_to").val("");\r
31                 $("#tweeting_button").addClass('btn-disabled');\r
32         }\r
33 }\r
34 var formHTML = '<span id="tip"><b>140</b></span><form action="index.php" method="post">';\r
35 formHTML += '<textarea name="status" id="textbox"></textarea>';\r
36 formHTML += '<input type="hidden" id="in_reply_to" name="in_reply_to" value="0" />';\r
37 formHTML += '<input type="submit" id="submit_btn" value="update" /></form>';\r
38 function rabrTweet(objs) {\r
39         if(typeof objs === 'undefined'){\r
40                 var objs = $('#statuses .timeline .source a');\r
41         }else{\r
42                 var objs = objs.find('.source a');\r
43         }\r
44         for (i = 0; i < objs.length; i++) {\r
45                 if (/rabr/i.test($(objs[i]).text())) {\r
46                         $(objs[i]).css("color", "#33CCFF");\r
47                 }\r
48         }\r
49 }\r
50 var getConversation = function (obj) {\r
51         var url = $(obj).attr("href");\r
52         var target = $(obj).parent().parent().parent().parent();\r
53         $.ajax({\r
54                         url: url,\r
55                         type: "GET",\r
56                         dataType: "text",\r
57                         success: function(msg){\r
58                                 if ($.trim(msg).indexOf("</li>") > 0) {\r
59                                         $(msg).appendTo(target);\r
60                                 }else{\r
61                                         updateSentTip('Get thread failed.', 5000, 'failure');\r
62                                 }\r
63                                 target.removeClass("loading");\r
64                         },\r
65                         error: function(msg){\r
66                                 updateSentTip('Get thread failed.', 5000, 'failure');\r
67                                 target.removeClass("loading");\r
68                         }\r
69                 });\r
70 }\r
71 $(function () {\r
72                 $(".ajax_reply").live("click", function (e) {\r
73                                 var obj = $(this).parent().parent().parent().parent();\r
74                                 var thread = obj.find(".ajax_form");\r
75                                 if (thread.size() > 0) {\r
76                                         thread.slideToggle("fast");\r
77                                 } else {\r
78                                         obj.addClass("loading");\r
79                                         getConversation($(this));\r
80                                 }\r
81                                 e.preventDefault();\r
82                         });\r
83         });\r
84 $(function(){\r
85                 $("#statuses .trans_btn").live("click", function(){\r
86                                 var tBody = $(this).parent().parent();\r
87                                 if(tBody.find(".trans_body").size() !== 0){\r
88                                         return;\r
89                                 }\r
90                                 var id = $.trim(tBody.find('.status_id').text());\r
91                                 var text = $.trim(tBody.find('.tweet').text());\r
92                                 var lang = $.cookie('transLang');\r
93                                 if(lang === null){\r
94                                         lang = 'zh';\r
95                                 }\r
96                                 tBody.parent().addClass('loading');\r
97                                 translate(text, id, lang, 'transCallback');\r
98                         });\r
99                 $("#statuses .trans_close").live("click", function(){\r
100                                 $(this).parent().parent().parent().parent().find(".translated").remove();\r
101                         });\r
102                 $("#translateMy").live("click", function(){\r
103                                 var orig = $("#textbox").val();\r
104                                         ORIG_TEXT = orig;\r
105                                 var lang = $.cookie('myLangs')\r
106                                 if(lang === null){\r
107                                         lang = 'en';\r
108                                 }\r
109                                 $('#tip').addClass('loading');\r
110                                 translate(orig, '', lang, 'transMyCallback');\r
111                         });\r
112                 $("#transRecover").live("click", function(){\r
113                         $("#textbox").val(ORIG_TEXT);\r
114                         $("#transRecover").fadeOut('fast');\r
115                         });\r
116         });\r
117 var translate = function(text, context, lang, callback) {\r
118         var a = "http://www.google.com/uds/Gtranslate";\r
119         a += "?callback=" + callback;\r
120         a += "&context=" + context;\r
121         a += "&q=" + encodeURIComponent(text);\r
122         a += "&key=notsupplied";\r
123         a += "&v=1.0";\r
124         a += "&nocache=1240207680396";\r
125         a += "&langpair=%7C" + lang;\r
126         $.getScript(a);\r
127 };\r
128 var transMyCallback = function(content, translation){\r
129         if(translation.translatedText !== null){\r
130                 $('#tip').removeClass('loading');\r
131                 $("#transArea").hide();\r
132                 $("#textbox").val(translation.translatedText);\r
133                 $("#transRecover").fadeIn('fast');\r
134         }\r
135 };\r
136 var transCallback = function(content, translation){\r
137         if(translation.translatedText !== null){\r
138                 var lang = $.cookie('transLang')\r
139                 if(lang === null){\r
140                         lang = 'zh';\r
141                 }\r
142                 var langTxt = $.cookie('fullLang');\r
143                 if(langTxt === null){\r
144                         langTxt = $('#transArea select[name=langs] option[value=' + lang + ']').text();\r
145                 }\r
146                 var html = '<div class="translated"><a href="javascript:void(0);" title="Hide Translation" class="trans_close">(Hide)</a><span class="trans_header"><strong>Translation <small>(from ' + translation.detectedSourceLanguage;\r
147                 html += ' to ' + langTxt + ')</small> : </strong></span>';\r
148                 html += '<span class="trans_body">' + translation.translatedText + '</span></div>';\r
149                 var li, target;\r
150                 if(typeof INTERVAL_COOKIE !== 'undefined'){\r
151                         li = $("#statuses ol:visible li:has(.status_id)").filter(":contains(" + content + ")");\r
152                         target = li.find(".status_word:first");\r
153                 }else{\r
154                         li = $("#statuses li:has(.status_id)").filter(":contains(" + content + ")");\r
155                         target = li.find(".status_word:first");\r
156                 }\r
157                 $(html).appendTo(target);\r
158                 li.removeClass("loading");\r
159         }\r
160 };\r
161 $(window).load(function(){\r
162                 var scrollTo = function (top, duration, callback) {\r
163                         var w = $(window);\r
164                         var FPS = 50;\r
165                         var currentTop = w.scrollTop();\r
166                         var offset = (currentTop - top) / (duration * FPS / 1000);\r
167                         var n = 0;\r
168                         var prevTop = currentTop;\r
169                         var t = setInterval(function () {\r
170                                         if ((prevTop - top) * (currentTop - top) <= 0) {\r
171                                                 clearInterval(t);\r
172                                                 currentTop = prevTop = top;\r
173                                                 w.scrollTop(top);\r
174                                                 if (callback) callback();\r
175                                         } else {\r
176                                                 prevTop = currentTop;\r
177                                                 w.scrollTop(currentTop -= offset);\r
178                                         }\r
179                                 }, 1000 / FPS);\r
180                 }\r
181                 var scrollToTop = function(){\r
182                         scrollTo(0, 200, function () {\r
183                                         scrollTo(30, 50, function () {\r
184                                                         scrollTo(0, 50);\r
185                                                 });\r
186                                 });\r
187                 };\r
188                 var scrollToBottom = function(){\r
189                         var height = document.body.clientHeight;\r
190                         scrollTo(height, 200, function () {\r
191                                         scrollTo(height + 30, 50, function () {\r
192                                                         scrollTo(height, 50);\r
193                                                 });\r
194                                 });\r
195 \r
196                 };\r
197                 $('body').dblclick(function () {\r
198                                 scrollToTop();\r
199                                 $("#textbox").focus();\r
200                         });\r
201                 $('#content').dblclick(function (e) {\r
202                                 e.stopPropagation();\r
203                         });\r
204                 var hkFadeIn = function(text){\r
205                         $("#shortcutTip").fadeIn("fast").html(text);\r
206                 };\r
207                 var hkFadeOut = function(){\r
208                         setTimeout(function () {$("#shortcutTip").fadeOut("fast");}, 2000);\r
209                 };\r
210                 // hotkeys\r
211                 var hotkeyHandler = function(code){\r
212                         switch(code){\r
213                         case 82: // R - refresh\r
214                                 hkFadeIn("Refresh");\r
215                                 update();\r
216                                 hkFadeOut();\r
217                                 break;\r
218                         case 67: // C - focus textbox\r
219                         case 85: // U\r
220                                 hkFadeIn("Compose");\r
221                                 scrollTo(0, 1, function () {\r
222                                                 $("#textbox").focus();\r
223                                         });\r
224                                 hkFadeOut();\r
225                                 break;\r
226                         case 66: // B - scroll to bottom\r
227                                 hkFadeIn("Boom!");\r
228                                 scrollToBottom();\r
229                                 hkFadeOut();\r
230                                 break;\r
231                         case 84: // T - scroll to top\r
232                                 hkFadeIn("Whiz!");\r
233                                 scrollToTop();\r
234                                 hkFadeOut();\r
235                                 break;\r
236                         case 83: // S - search\r
237                                 hkFadeIn("Search");\r
238                                 $("#sidepost").animate({backgroundColor: "#FF6347"}, 500, function(){\r
239                                                 $("#header_search_query").focus();\r
240                                                 $("#sidepost").animate({backgroundColor: $("#side_base").css("background-color")}, 1000);\r
241                                         });\r
242                                 hkFadeOut();\r
243                                 break;\r
244                         }\r
245                 };\r
246                 $(document).keydown(function(e){\r
247                                 var tag = e.target.tagName;\r
248                                 if(tag === "BODY" || tag === "HTML"){\r
249                                         if(!e.altKey && !e.shiftKey && !e.ctrlKey && !e.metaKey){\r
250                                                 hotkeyHandler(e.keyCode);\r
251                                         }\r
252                                 }\r
253                         });\r
254         });\r
255 $(document).ready(function () {\r
256                 $("<div id='sentTip' style='display:none;' />").prependTo("#header .wrapper");\r
257         });\r
258 var updateSentTip = function(message, duration, className){\r
259         var sentTip = $("#sentTip");\r
260         var bgColor = $("body").css("background-color");\r
261         sentTip.html(message).removeClass().addClass(className);\r
262         sentTip.css({\r
263                         "border-style": "solid",\r
264                         "border-width": "1px",\r
265                         "border-color": bgColor\r
266                 });\r
267         sentTip.slideDown("fast");\r
268         window.setTimeout(function () {\r
269                         sentTip.slideUp('fast');\r
270                 }, duration);\r
271         return sentTip;\r
272 };\r
273 var formFunc = function(){\r
274         leaveWord();\r
275         $("#textbox").keyup(function () {\r
276                         leaveWord();\r
277                 }).bind("keyup", "keydown", function(event){\r
278                                 if (event.ctrlKey && event.keyCode == 13) {\r
279                                         if (PAUSE_UPDATE !== true) {\r
280                                                 updateStatus();\r
281                                         } else {\r
282                                                 return 0;\r
283                                         }\r
284                                 }\r
285                         });\r
286         };\r
287         //update button core\r
288         $(function () {\r
289                         $("#tweeting_button").click(function (e) {\r
290                                         e.preventDefault();\r
291                                         if ($("#textbox").val().length >0 ) {\r
292                                                 updateStatus();\r
293                                         }               \r
294                                 });\r
295                 });\r
296         var updateStatus = function(){\r
297                 $('#tip').addClass('loading');\r
298                 PAUSE_UPDATE = true;\r
299                 var text = $("#textbox").val();\r
300                 var wordsCount = $("#textbox").val().length;\r
301                 if (wordsCount > 140) {\r
302                         updateSentTip("Your tweet is more than 140 words!", 3000, "failure");\r
303                         return false;\r
304                 } else if (wordsCount = 0) {\r
305                         updateSentTip("Your cannot send an empty tweet!", 3000, "failure");\r
306                         return false;\r
307                 } else {\r
308                         $.ajax({\r
309                                         url: "ajax/update.php",\r
310                                         type: "POST",\r
311                                         data: {\r
312                                                 "status": text,\r
313                                                 "in_reply_to": $("#in_reply_to").val()\r
314                                         },\r
315                                         success: function (msg) {\r
316                                                 if ($.trim(msg).indexOf("</li>") > 0) {\r
317                                                         $.cookie('recover', text, {'expire': 30});\r
318                                                         $('#tip').removeClass('loading');\r
319                                                         updateSentTip("Your status has been updated!", 3000, "success");\r
320                                                         $("#textbox").val("");\r
321                                                         $("#tip").html("<b>140</b>");\r
322                                                         leaveWord();\r
323                                                         if(typeof INTERVAL_COOKIE !== "undefined"){\r
324                                                                 var source = $(msg).prependTo($("#allTimeline"));\r
325                                                                 source.hide().slideDown('fast');\r
326                                                                 var statusid = $.trim($(msg).find('.status_id').text());\r
327                                                                 var statusText = $.trim($(msg).find('.tweet').html());\r
328                                                                 rabrTweet(source);\r
329                                                                 $(".mine").slideDown("fast");\r
330                                                                 $("#full_status").fadeIn("fast");\r
331                                                                 $("#currently .status-text").hide().text(limitation(text)).fadeIn("fast");\r
332                                                                 $("#latest_meta").hide().html("<a target=\"_blank\" href=\"status.php?id=" + statusid + "\">less than 5 seconds ago</a>").fadeIn("fast");\r
333                                                                 $("#currently .full-text").hide().html(statusText);\r
334                                                                 $("#full_meta").hide().html("<a target=\"_blank\" href=\"status.php?id=" + statusid + "\">less than 5 seconds ago</a>");\r
335                                                                 $("#full_meta a, .full-text a").click(function (e) {e.stopPropagation();});\r
336                                                                 previewMedia(source);\r
337                                                                 freshProfile();\r
338                                                         }\r
339                                                 } else {\r
340                                                         $.cookie('recover', text, {'expire': 30});\r
341                                                         $('#tip').removeClass('loading');\r
342                                                         updateSentTip("Update failed. Please try again.", 3000, "failure");\r
343                                                         $('#tweeting_button').removeClass('btn-disabled');\r
344                                                 }\r
345                                                 PAUSE_UPDATE = false;\r
346                                         },\r
347                                         error: function (msg) {\r
348                                                 $.cookie('recover', text, {'expire': 30});\r
349                                                 $('#tip').removeClass('loading');\r
350                                                 updateSentTip("Update failed. Please try again.", 3000, "failure");\r
351                                                 $('#tweeting_button').removeClass('btn-disabled');\r
352                                                 PAUSE_UPDATE = false;\r
353                                         }\r
354                                 });\r
355                 }\r
356         };\r
357         function onFavor($this) {\r
358                 var status_id = $.trim($this.parent().parent().find(".status_id").text());\r
359                 updateSentTip("Adding this tweet to your favorites...", 5000, "ing");\r
360                 $.ajax({\r
361                                 url: "ajax/addfavor.php",\r
362                                 type: "POST",\r
363                                 data: "status_id=" + status_id,\r
364                                 success: function (msg) {\r
365                                         if (msg.indexOf("success") >= 0) {\r
366                                                 updateSentTip("Favorite added successfully.", 3000, "success");\r
367                                                 $this.parent().parent().parent().addClass('faved');\r
368                                         } else {\r
369                                                 updateSentTip("Add failed. Please try again.", 3000, "failure");\r
370                                         }\r
371                                 },\r
372                                 error: function (msg) {\r
373                                         updateSentTip("Add failed. Please try again.", 3000, "failure");\r
374                                 }\r
375                         });\r
376         }\r
377         function onReplie($this, e) {\r
378                 var replie_id = $this.parent().parent().find(".status_word").find(".user_name").text();\r
379                 var in_reply_id = $this.parent().parent().find(".status_id").text();\r
380                 var text = "@" + replie_id;\r
381                 var mode = "In reply to ";\r
382                 if (e.ctrlKey) {\r
383                         mode = "Reply to all: ";\r
384                         var temp = {\r
385                                 text: true\r
386                         };\r
387                         var mentionArray = [text];\r
388                         var mentions = $this.parent().parent().find('a[href^="user.php"][innerHTML^=@]');\r
389                         $.each(mentions, function () {\r
390                                         var t = $(this).text();\r
391                                         if (!(t in temp)) {\r
392                                                 temp[t] = true;\r
393                                                 mentionArray.push(t);\r
394                                         }\r
395                                         text = mentionArray.join(' ');\r
396                                 });\r
397                 }\r
398                 if (e.altKey) {\r
399                         mode = "Non-conversational reply to ";\r
400                         in_reply_id = "";\r
401                 }\r
402                 scroll(0, 0);\r
403                 $("#textbox").focus();\r
404                 $("#textbox").val($("#textbox").val() + text + ' ');\r
405                 $("#in_reply_to").val(in_reply_id);\r
406                 $("#full_status").hide();\r
407                 $("#latest_meta").html("").hide();\r
408                 $("#full_meta").hide();\r
409                 $("#currently .full-text").hide();\r
410                 $("#latest_meta").hide();\r
411                 $("#currently .status-text").html(mode + text);\r
412                 leaveWord();\r
413         }\r
414         function onRT($this) {\r
415                 var replie_id = $this.parent().parent().find(".status_word").find(".user_name").text();\r
416                 scroll(0, 0);\r
417                 $("#textbox").focus();\r
418                 $("#textbox").val("RT @" + replie_id + ":" + $this.parent().parent().find(".status_word").text().replace(replie_id, ""));\r
419                 $("#full_status").hide();\r
420                 $("#latest_meta").hide();\r
421                 $("#full_meta").hide();\r
422                 $("#currently .full-text").hide();\r
423                 $("#latest_meta").hide();\r
424                 $("#currently .status-text").html("Retweet @" + replie_id + "'s tweet with comment.");\r
425                 leaveWord();\r
426         }\r
427         function onReplieDM($this, e) {\r
428                 var replie_id = $this.parent().parent().find(".status_word").find(".user_name").text();\r
429                 var text = "D " + replie_id;\r
430                 scroll(0, 0);\r
431                 $("#textbox").focus();\r
432                 $("#textbox").val($("#textbox").val() + text + ' ');\r
433                 $("#in_reply_to").val($this.parent().parent().find(".status_id").text());\r
434                 $("#full_status").hide();\r
435                 $("#latest_meta").hide();\r
436                 $("#full_meta").hide();\r
437                 $("#currently .full-text").hide();\r
438                 $("#latest_meta").hide();\r
439                 $("#currently .status-text").html("Reply direct message to @" + replie_id);\r
440                 leaveWord();\r
441         }\r
442         function onNwRT($this) {\r
443                 var statusBody = $this.parent().parent();\r
444                 var status_id = statusBody.find(".status_id").text();\r
445                 var div = "#" + statusBody.parent().parent().attr('id');\r
446                 var btnDiv = div + "Btn";\r
447                 if (confirm("Are you sure to retweet this?")) {\r
448                         updateSentTip("Retweeting tweet...", 5000, "ing");\r
449                         $.ajax({\r
450                                         url: "ajax/retweet.php",\r
451                                         type: "post",\r
452                                         data: "status_id=" + status_id,\r
453                                         success: function (msg) {\r
454                                                 if (msg.length >= 0) {\r
455                                                         statusBody.parent().addClass("retweet");\r
456                                                         statusBody.find(".source").hide();\r
457                                                         statusBody.find(".status_info").append("<span class=\"rt_source\">Retweeted by you from <a rel=\"nofollow\" href=\"http://code.google.com/p/rabr/\">rabr</a></span>").fadeIn("fast");\r
458                                                         statusBody.find(".date").hide();\r
459                                                         statusBody.find(".status_info").append("<span class=\"rt_undo\" title=\"Your followers will no longer see the tweet as retweeted by you.\">&nbsp;<a href=\"javascript:void(0);\">(Undo)</a><span class=\"rt_id\" style=\"display: none;\">" + msg + "</span></span>").fadeIn("fast");\r
460                                                         updateSentTip("This tweet has been retweeted!", 3000, "success");\r
461                                                         $(".rt_undo").tipsy({\r
462                                                                         gravity: 's'\r
463                                                                 });\r
464                                                 } else {\r
465                                                         if (msg === "duplicated") {\r
466                                                                 updateSentTip("You have retweeted this tweet!", 3000, "failure");\r
467                                                         } else {\r
468                                                                 updateSentTip("Failed to retweet!", 3000, "failure");\r
469                                                         }\r
470                                                 }\r
471                                         },\r
472                                         error: function (msg) {\r
473                                                 updateSentTip("Retweet failed. Please try again.", 3000, "failure");\r
474                                         }\r
475                                 });\r
476                 }\r
477         }\r
478         function onDelete($this, type) {\r
479                 var status_id = $.trim($this.parent().parent().find(".status_id").text());\r
480                 $this.parent().parent().parent().css("background-color", "#FF3300");\r
481                 var confirm = window.confirm("Are you sure to delete this tweet?");\r
482                 if (confirm) {\r
483                         updateSentTip("Deleting tweet...", 5000, "ing");\r
484                         var postData = (type == "Tweet") ? "status_id=" : "favor_id=";\r
485                         $.ajax({\r
486                                         url: "ajax/delete.php",\r
487                                         type: "POST",\r
488                                         data: postData + status_id,\r
489                                         success: function (msg) {\r
490                                                 if (msg.indexOf("success") >= 0) {\r
491                                                         $this.parent().parent().parent().css("background-color", "#FF3300");\r
492                                                         $this.parent().parent().parent().fadeOut("fast");\r
493                                                         updateSentTip("Your tweet has been destroyed!", 3000, "success");\r
494                                                 } else {\r
495                                                         $this.parent().parent().parent().css("background-color", "");\r
496                                                         updateSentTip("Delete failed. Please try again.", 3000, "failure");\r
497                                                 }\r
498                                         },\r
499                                         error: function (msg) {\r
500                                                 $this.parent().parent().parent().css("background-color", "");\r
501                                                 updateSentTip("Delete failed. Please try again.", 3000, "failure");\r
502                                         }\r
503                                 });\r
504                 }\r
505                 $this.parent().parent().parent().css("background-color", "");\r
506         }\r
507         function onUndoRt($this) {\r
508                 var status_id = $.trim($this.parent().find(".rt_id").text());\r
509                 var statusBody = $this.parent().parent().parent();\r
510                 statusBody.css("background-color", "#FF3300");\r
511                 var confirm = window.confirm("Are you sure to undo this retweet?");\r
512                 if (confirm) {\r
513                         updateSentTip("Undoing retweet...", 5000, "ing");\r
514                         $.ajax({\r
515                                         url: "ajax/delete.php",\r
516                                         type: "POST",\r
517                                         data: "status_id=" + status_id,\r
518                                         success: function (msg) {\r
519                                                 if (msg.indexOf("success") >= 0) {\r
520                                                         statusBody.css("background-color", "#FF3300");\r
521                                                         statusInfo = $this.parent().parent();\r
522                                                         if (statusInfo.find(".rt_source").size() === 1) {\r
523                                                                 statusInfo.find(".source").show();\r
524                                                                 statusInfo.find(".date").show();\r
525                                                                 statusInfo.find(".rt_source").remove();\r
526                                                                 statusInfo.find(".rt_undo").remove();\r
527                                                                 statusBody.removeClass("retweet");\r
528                                                                 statusBody.css("background-color", "");\r
529                                                         } else {\r
530                                                                 statusBody.fadeOut("fast");\r
531                                                         }\r
532                                                         updateSentTip("Your retweet has been undo!", 3000, "success");\r
533                                                 } else {\r
534                                                         statusBody.css("background-color", "");\r
535                                                         updateSentTip("Undo failed. Please try again.", 3000, "failure");\r
536                                                 }\r
537                                         },\r
538                                         error: function (msg) {\r
539                                                 statusBody.css("background-color", "");\r
540                                                 updateSentTip("Undo failed. Please try again.", 3000, "failure");\r
541                                         }\r
542                                 });\r
543                 }\r
544                 statusBody.css("background-color", "");\r
545         }\r
546         function onDeleteMsg($this) {\r
547                 var message_id = $.trim($this.parent().parent().find(".status_id").text());\r
548                 $this.parent().parent().parent().css("background-color", "#FF3300");\r
549                 var confirm = window.confirm("Are you sure to delete this message?");\r
550                 if (confirm) {\r
551                         updateSentTip("Deleting message...", 5000, "ing");\r
552                         $.ajax({\r
553                                         url: "ajax/delete.php",\r
554                                         type: "POST",\r
555                                         data: "message_id=" + message_id,\r
556                                         success: function (msg) {\r
557                                                 if (msg.indexOf("success") >= 0) {\r
558                                                         $this.parent().parent().parent().css("background-color", "#FF3300");\r
559                                                         $this.parent().parent().parent().fadeOut("fast");\r
560                                                         updateSentTip("Message deleted.", 3000, "success");\r
561                                                 } else {\r
562                                                         $this.parent().parent().parent().css("background-color", "");\r
563                                                         updateSentTip("Failed to delete this message!", 3000, "failure");\r
564                                                 }\r
565                                         },\r
566                                         error: function (msg) {\r
567                                                 $this.parent().parent().parent().css("background-color", "");\r
568                                                 updateSentTip("Failed to delete this message!", 3000, "failure");\r
569                                         }\r
570                                 });\r
571                 }\r
572                 $this.parent().parent().parent().css("background-color", "");\r
573         }\r
574         function shortUrlDisplay() {\r
575                 var stringVar = "";\r
576                 stringVar = document.getElementById("textbox").value;\r
577                 if (stringVar.length === 0) {\r
578                         updateSentTip("There's no URL in your tweet to shorten!", 3000, "failure");\r
579                 } else {\r
580                         var str = '';\r
581                         var regexp = /http(s)?:\/\/([\w\-]+\.)+[\w\-]+(\/[\w\-\.\/?\%\!\&=\+\~\:\#\;\,]*)?/ig;\r
582                         var l_urls = '';\r
583                         str = stringVar.match(regexp);\r
584                         if (str !== null) {\r
585                                 for (idx = 0; idx < str.length; idx++) {\r
586                                         regexp2 = /(http:\/\/j.mp\/[\S]+)|(http:\/\/bit.ly\/[\S]+)|(http:\/\/zi.mu\/[\S]+)|(http:\/\/orz.se\/[\S]+)/gi;\r
587                                         match_short = str[idx].match(regexp2);\r
588                                         if (!match_short) {\r
589                                                 l_urls += str[idx] + "|"\r
590                                         }\r
591                                         match_short = null;\r
592                                         updateSentTip("No valid URLs!", 3000, "failure");\r
593                                 }\r
594                                 if (l_urls != "") {\r
595                                         $('#tip').addClass('loading');\r
596                                         $.post("ajax/shorturl.php", {\r
597                                                         long_urls: l_urls\r
598                                                 }, function (data) {\r
599                                                         getShortUrl(data);\r
600                                                 });\r
601                                 }\r
602                         }\r
603                 }\r
604         }\r
605         function getShortUrl(res) {\r
606                 var retstr = res;\r
607                 target_layer = 'textbox';\r
608                 var url_arry, s_url, l_url, part;\r
609                 var err_cnt = 0;\r
610                 url_arry = retstr.split('^');\r
611                 for (i = 0; i < url_arry.length; i++) {\r
612                         part = url_arry[i].split('|');\r
613                         if (part.length == 2) {\r
614                                 s_url = part[0];\r
615                                 l_url = part[1];\r
616                         }\r
617                         if (s_url.indexOf('http://zi.mu') > -1) {\r
618                                 stringVar = document.getElementById(target_layer).value;\r
619                                 stringVar = stringVar.replace(l_url, s_url);\r
620                                 document.getElementById(target_layer).value = stringVar + "";\r
621                                 leaveWord();\r
622                                 $('#tip').removeClass('loading');\r
623                                 updateSentTip("Successfully shortened your URLs!", 3000, "success");\r
624                         }\r
625                         else if (s_url.length > 0) {\r
626                                 err_cnt++;\r
627                         }\r
628                 }\r
629                 if (err_cnt < 0) {\r
630                         updateSentTip("Failed to shorten URLs, please try again.", 3000, "failure");\r
631                 }\r
632         }\r
633 \r
634         function shortenTweet() {\r
635                 var tweet = $.trim($("#textbox").val());\r
636                 if (tweet.length === 0) {\r
637                         updateSentTip("There's nothing to shorten!", 3000, "failure");\r
638                 } else {\r
639                         $('#tip').addClass('loading');\r
640                         $.ajax({\r
641                                         url: "ajax/shortenTweet.php",\r
642                                         type: "POST",\r
643                                         data: "text=" + tweet,\r
644                                         success: function(msg){\r
645                                                 if(msg !== 'error'){\r
646                                                         $("#textbox").val(msg);\r
647                                                         leaveWord();\r
648                                                         $('#tip').removeClass('loading');\r
649                                                         updateSentTip("Your tweet has been shortened!", 5000, "success");\r
650                                                 }else{\r
651                                                         updateSentTip("Failed to shorten your tweet.", 5000, "failure");\r
652                                                 }\r
653                                         },\r
654                                         error: function(msg){\r
655                                                 updateSentTip("Failed to shorten your tweet.", 5000, "failure");\r
656                                         }\r
657                                 });\r
658                         /* JSON FAILS!\r
659                          $.getJSON("http://tweetshrink.com/shrink?text=" + tweet, function(data){\r
660                          $("#textbox").val(data.text);\r
661                          leaveWord();\r
662                          updateSentTip("Reduced " + data.difference + " letters!" , 5000, "success");\r
663                  });\r
664                  */\r
665                 }\r
666         }\r
667         $(function () {\r
668                         $("#latest_status").toggle(\r
669                                 function () {\r
670                                         $("#currently .status-text, #latest_meta").css("display", "none");\r
671                                         $("#currently .full-text, #full_meta").css("display", "inline");\r
672                                 }, function () {\r
673                                         $("#currently .status-text, #latest_meta").css("display", "inline");\r
674                                         $("#currently .full-text, #full_meta").css("display", "none");\r
675                                 });\r
676                         $("#full_meta a, .full-text a").click(function (e) {\r
677                                         e.stopPropagation();\r
678                                 });\r
679                 });\r
680         var limitation = function (text) {\r
681                 if (text.length > 60) {\r
682                         text = text.substr(0, 60) + " ...";\r
683                 }\r
684                 return text;\r
685         };\r
686         $(function () {\r
687                         if (document.location.href.indexOf("index") > 0 || document.location.href.indexOf("all") > 0) {\r
688                                 var temp = $("#currently .status-text").text();\r
689                                 if (temp.length > 60) {\r
690                                         temp = temp.substr(0, 60) + " ...";\r
691                                 }\r
692                                 $("#currently .status-text").text(temp);\r
693                         }\r
694                 });\r
695         function updateTrends() {\r
696                 $.ajax({\r
697                                 url: "ajax/updateTrends.php",\r
698                                 type: "GET",\r
699                                 success: function (msg) {\r
700                                         if ($.trim(msg).indexOf("</ul>" > 0)) {\r
701                                                 $("#trend_entries").html(msg);\r
702                                         }\r
703                                         $("#trends_title").removeClass().addClass("open");\r
704                                         $("#trend_entries").slideDown("fast");\r
705                                 }\r
706                         });\r
707         }\r
708         $(function () {\r
709                         $("#trends_title").toggle(\r
710                                 function () {\r
711                                         $("#trends_title").removeClass().addClass("loading");\r
712                                         updateTrends();\r
713                                 }, function () {\r
714                                         $("#trend_entries").slideUp("fast");\r
715                                         $("#trends_title").removeClass();\r
716                                 });\r
717                 });\r
718         function updateFollowing() {\r
719                 $.ajax({\r
720                                 url: "ajax/updateFollowing.php",\r
721                                 type: "GET",\r
722                                 success: function (msg) {\r
723                                         if ($.trim(msg).indexOf("</span>" > 0)) {\r
724                                                 $("#following_list").html(msg);\r
725                                         }\r
726                                         $("#following_title").removeClass().addClass("open");\r
727                                         $("#following_list").slideDown("fast");\r
728                                 }\r
729                         });\r
730         }\r
731         $(function () {\r
732                         $("#following_title").toggle(\r
733                                 function () {\r
734                                         $("#following_title").removeClass().addClass("loading");\r
735                                         updateFollowing();\r
736                                 }, function () {\r
737                                         $("#following_list").slideUp("fast");\r
738                                         $("#following_title").removeClass();\r
739                                 });\r
740                 });\r
741         $(function () {\r
742                         $("#toolbox_title").toggle(\r
743                                 function () {\r
744                                         $("#toolbox_title").removeClass().addClass("open");\r
745                                         $("#tools_list").slideDown("fast");\r
746                                 }, function () {\r
747                                         $("#tools_list").slideUp("fast");\r
748                                         $("#toolbox_title").removeClass();\r
749                                 });\r
750                 });\r
751         $(function () {\r
752                         $(".status_author img, .rank_img img").live("click", function (e) {\r
753                                         $(".right_menu").hide();\r
754                                         $(this).parent().parent().find(".right_menu").css("display", "block");\r
755                                         e.preventDefault();\r
756                                 });\r
757                         $('body').click(function () {\r
758                                         $(".right_menu").hide();\r
759                                 });\r
760                         $('.status_author li a').click(function () {\r
761                                         $(".right_menu").hide();\r
762                                 });\r
763                         $(".rm_mention").live("click", function (e) {\r
764                                         e.preventDefault();\r
765                                         rmmention($(this), e);\r
766                                 });\r
767                         $(".rm_dm").live("click", function (e) {\r
768                                         e.preventDefault();\r
769                                         rmdm($(this), e);\r
770                                 });\r
771                         $(".rm_follow").live("click", function (e) {\r
772                                         e.preventDefault();\r
773                                         var $this = $(this);\r
774                                         var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();\r
775                                         updateSentTip("Following " + id + "...", 5000, "ing");\r
776                                         $.ajax({\r
777                                                         url: "ajax/relation.php",\r
778                                                         type: "POST",\r
779                                                         data: "action=create&id=" + id,\r
780                                                         success: function (msg) {\r
781                                                                 if (msg.indexOf("success") >= 0) {\r
782                                                                         updateSentTip("You have followed " + id + "!", 3000, "success");\r
783                                                                 } else {\r
784                                                                         updateSentTip("Failed to follow " + id + ", please try again.", 3000, "failure");\r
785                                                                 }\r
786                                                         },\r
787                                                         error: function (msg) {\r
788                                                                 updateSentTip("Failed to follow " + id + ", please try again.", 3000, "failure");\r
789                                                         }\r
790                                                 });\r
791                                 });\r
792                         $(".rm_unfollow").live("click", function (e) {\r
793                                         e.preventDefault();\r
794                                         var $this = $(this);\r
795                                         var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();\r
796                                         if (confirm("Are you sure to unfollow " + id + " ?")) {\r
797                                                 updateSentTip("Unfollowing " + id + "...", 5000, "ing");\r
798                                                 $.ajax({\r
799                                                                 url: "ajax/relation.php",\r
800                                                                 type: "POST",\r
801                                                                 data: "action=destory&id=" + id,\r
802                                                                 success: function (msg) {\r
803                                                                         if (msg.indexOf("success") >= 0) {\r
804                                                                                 updateSentTip("You have unfollowed " + id + "!", 3000, "success");\r
805                                                                         } else {\r
806                                                                                 updateSentTip("Failed to unfollow " + id + ", please try again.", 3000, "failure");\r
807                                                                         }\r
808                                                                 },\r
809                                                                 error: function (msg) {\r
810                                                                         updateSentTip("Failed to unfollow " + id + ", please try again.", 3000, "failure");\r
811                                                                 }\r
812                                                         });\r
813                                         }\r
814                                 });\r
815                         $(".rm_block").live("click", function (e) {\r
816                                         e.preventDefault();\r
817                                         var $this = $(this);\r
818                                         var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();\r
819                                         if (confirm("Are you sure to block " + id + " ?")) {\r
820                                                 updateSentTip("Blocking " + id + "...", 5000, "ing");\r
821                                                 $.ajax({\r
822                                                                 url: "ajax/relation.php",\r
823                                                                 type: "POST",\r
824                                                                 data: "action=block&id=" + id,\r
825                                                                 success: function (msg) {\r
826                                                                         if (msg.indexOf("success") >= 0) {\r
827                                                                                 updateSentTip("You have blocked " + id + "!", 3000, "success");\r
828                                                                         } else {\r
829                                                                                 updateSentTip("Failed to block " + id + ", please try again.", 3000, "failure");\r
830                                                                         }\r
831                                                                 },\r
832                                                                 error: function (msg) {\r
833                                                                         updateSentTip("Failed to block " + id + ", please try again.", 3000, "failure");\r
834                                                                 }\r
835                                                         });\r
836                                         }\r
837                                 });\r
838                 })\r
839         $(".rm_spam").live("click", function (e) {\r
840                         e.preventDefault();\r
841                         var $this = $(this);\r
842                         var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();\r
843                         if (confirm("Are you sure to report " + id + " ?")) {\r
844                                 updateSentTip("Reporting " + id + " as a spammer...", 5000, "ing");\r
845                                 $.ajax({\r
846                                                 url: "ajax/reportSpam.php",\r
847                                                 type: "POST",\r
848                                                 data: "spammer=" + id,\r
849                                                 success: function (msg) {\r
850                                                         if (msg.indexOf("success") >= 0) {\r
851                                                                 updateSentTip("Successfully reported!", 3000, "success");\r
852                                                         } else {\r
853                                                                 updateSentTip("Failed to report " + id + ", please try again.", 3000, "failure");\r
854                                                         }\r
855                                                 },\r
856                                                 error: function (msg) {\r
857                                                         updateSentTip("Failed to report " + id + ", please try again.", 3000, "failure");\r
858                                                 }\r
859                                         });\r
860                         }\r
861                 });\r
862         function rmmention($this, e) {\r
863                 var replie_id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();\r
864                 var in_reply_id = $this.parent().parent().parent().find(".status_id").text();\r
865                 var text = "@" + replie_id;\r
866                 var mode = "In reply to ";\r
867                 scroll(0, 0);\r
868                 $("#textbox").focus();\r
869                 $("#textbox").val($("#textbox").val() + text + ' ');\r
870                 $("#in_reply_to").val(in_reply_id);\r
871                 $("#full_status").hide();\r
872                 $("#latest_meta").html("").hide();\r
873                 $("#full_meta").hide();\r
874                 $("#currently .full-text").hide();\r
875                 $("#latest_meta").hide();\r
876                 $("#currently .status-text").html(mode + text);\r
877                 leaveWord();\r
878         }\r
879         function rmdm($this, e) {\r
880                 var replie_id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();\r
881                 var text = "D " + replie_id;\r
882                 scroll(0, 0);\r
883                 $("#textbox").focus();\r
884                 $("#textbox").val($("#textbox").val() + text + ' ');\r
885                 $("#in_reply_to").val($this.parent().parent().parent().find(".status_id").text());\r
886                 $("#full_status").hide();\r
887                 $("#latest_meta").hide();\r
888                 $("#full_meta").hide();\r
889                 $("#currently .full-text").hide();\r
890                 $("#latest_meta").hide();\r
891                 $("#currently .status-text").html("Reply direct message to @" + replie_id);\r
892                 leaveWord();\r
893         }\r
894         function sidebarFollow(id) {\r
895                 updateSentTip("Following " + id + "...", 5000, "ing");\r
896                 $.ajax({\r
897                                 url: "ajax/relation.php",\r
898                                 type: "POST",\r
899                                 data: "action=create&id=" + id,\r
900                                 success: function (msg) {\r
901                                         if (msg.indexOf("success") >= 0) {\r
902                                                 updateSentTip("You have followed " + id + "!", 3000, "success");\r
903                                                 $.cookie('followus', 1, {\r
904                                                                 expire: 30\r
905                                                         });\r
906                                                 $.cookie('whofollowedus', $("#sideid").html(), {\r
907                                                                 expire: 30\r
908                                                         });\r
909                                                 $("#follow_us").fadeOut("fast");\r
910                                         } else {\r
911                                                 updateSentTip("Failed to follow " + id + ", please try again.", 3000, "failure");\r
912                                         }\r
913                                 },\r
914                                 error: function (msg) {\r
915                                         updateSentTip("Failed to follow " + id + ", please try again.", 3000, "failure");\r
916                                 }\r
917                         });\r
918         };\r
919         $(function () {\r
920                         $('#fl_ds').click(function (e) {\r
921                                         e.preventDefault();\r
922                                         if (confirm("Are you sure to follow @disinfeqt?")) {\r
923                                                 sidebarFollow("disinfeqt");\r
924                                         }\r
925                                 });\r
926                         $('#fl_ys').click(function (e) {\r
927                                         e.preventDefault();\r
928                                         if (confirm("Are you sure to follow @Chris_Ys?")) {\r
929                                                 sidebarFollow("chris_ys");\r
930                                         }\r
931                                 });\r
932                 })\r
933         //sidebar shortcuts tips\r
934         $(function () {\r
935                         $("#sidebarTip").toggle(\r
936                                 function () {\r
937                                         $('#sidebarTip_more').slideDown('fast');\r
938                                         $('#indicator').html('[-]');\r
939                                 }, function () {\r
940                                         $('#sidebarTip_more').slideUp('fast');\r
941                                         $('#indicator').html('[+]');\r
942                                 });\r
943                 });\r
944         //init global functions\r
945         $(document).ready(function () {\r
946                         rabrTweet();\r
947                         $("#statuses .mine").live("mouseout", function (e) {\r
948                                         $(this).removeClass("mine").addClass("myTweet");\r
949                                 });\r
950                         $("#primary_nav li a").bind("click", function () {\r
951                                         $("#primary_nav li a").each(function (i, o) {\r
952                                                         if ($(this).hasClass("active")) {\r
953                                                                 $(this).removeClass()\r
954                                                         }\r
955                                                 });\r
956                                         $(this).removeClass().addClass("active").css("background", "transparent url('../img/spinner.gif') no-repeat scroll 173px center")\r
957                                 });\r
958                         $("#statuses .big-retweet-icon, #func_set .func_btn").tipsy({\r
959                                         gravity: 's'\r
960                                 });\r
961                         $('#symbols span').tipsy({\r
962                                         gravity: $.fn.tipsy.autoNS\r
963                                 });\r
964                         if ($.cookie('followus') == 1 && $.cookie('whofollowedus') == $("#sideid").html()) {\r
965                                 $("#follow_us").hide();\r
966                         }\r
967                         $(".timeline img").lazyload({threshold : 100, effect : "fadeIn"});\r
968                 });\r
969         var freshProfile = function(){\r
970                 $('#update_count').text($.cookie('statuses_count'));\r
971                 $('#user_stats a[href*=friends] span.count').text(parseInt($.cookie('friends_count')));\r
972                 $('#user_stats a[href*=followers] span.count').text(parseInt($.cookie('followers_count')));\r
973                 $('#user_stats a[href*=lists] span.count').text(parseInt($.cookie('listed_count')));\r
974         };\r
975         var markReply = function(obj){\r
976                 obj.each(function (i, o) {\r
977                                 if ($(this).find("> span").find('.tweet').text().toLowerCase().indexOf("@" + $("#sideid").text().toLowerCase()) > -1) {\r
978                                         $(this).addClass("reply");\r
979                                 }\r
980                         });\r
981         };