2 var PAUSE_UPDATE = false;
3 var PAUSE_TIMELINE = false;
5 function updateSentTip(message,duration,className){
6 var sentTip = $("#sentTip");
7 var bgColor = $("body").css("background-color");
8 sentTip.html(message).removeClass().addClass(className)
10 "border-style": "solid",
11 "border-width": "1px",
12 "border-color": "transparent"
14 setTimeout(function (){
15 sentTip.slideUp('fast');
19 function leaveWord(num){
23 var leave = num-$("#textbox").val().length;
24 var sent_id = $("#sent_id").val();
25 var $tb = $("#tip b");
27 leave -= sent_id.length+3;
30 $tb.text(leave).css("color","#C00");
31 $("#tweeting_button").addClass('btn-disabled');
34 $("#tweeting_button").removeClass('btn-disabled');
36 $tb.css("color","#CCC");
38 $tb.css("color","#CAA");
40 $tb.css("color","#C88");
42 $tb.css("color","#C44");
46 $("#in_reply_to").val("");
47 $("#tweeting_button").addClass('btn-disabled');
50 var formHTML = '<span id="tip"><b>140</b></span><form action="index.php" method="post"><textarea name="status" id="textbox"></textarea><input type="hidden" id="in_reply_to" name="in_reply_to" value="0" /><div id="tweeting_controls"><a class="a-btn a-btn-m btn-disabled" id="tweeting_button" tabindex="2" href="#" title="Ctrl/⌘+Enter also works!"><span>Send</span></a></div></form>';
52 var embrTweet=function(objs){
53 if(typeof objs === 'undefined'){
54 var objs = $('#statuses .timeline .source a');
56 var objs = objs.find('.source a');
58 objs.each(function (){
60 if (/embr/i.test($this.text())) $this.addClass('embr');
62 if($("span.date a").length > 0){
63 $("span.date a,#latest_meta a,#full_meta a").timeago();
65 $("span.date,#latest_meta a,#full_meta a").timeago();
68 var formFunc = function(){
70 $("#textbox").keyup(function (e){
72 $(e.target).unbind('keydown');
73 if ((e.ctrlKey || e.metaKey) && e.which == 13){
74 if (PAUSE_UPDATE !== true){
80 if($.inArray(e.which,[91,93,224,17]) > -1){
81 $(e.target).keydown(function(e){
83 if (PAUSE_UPDATE !== true){
94 $("#tweeting_button").click(function (e){
96 if ($("#textbox").val().length >0 ){
101 var updateStatus = function(){
103 var text = $("#textbox").val();
104 var sent_id = $("#sent_id").val();
106 text = "D "+sent_id+' '+text;
108 var wordsCount = text.length;
109 if (wordsCount > 140){
110 $.cookie('recover',text,{'expire': 30});
111 if(window.confirm("Your tweet is longer than 140 words! truncated? (you can restore later using restore button.)")){
112 text = text.substr(0,137)+'...' ;
115 if (wordsCount == 0 || $.trim(text).length == 0){
116 updateSentTip("Your cannot send an empty tweet!",3e3,"failure");
119 $('#tip').addClass('loading').find('b').css('color','transparent');
120 $.cookie('recover',text,{'expire': 30});
122 url: "ajax/update.php",
126 "in_reply_to": $("#in_reply_to").val()
128 success: function (msg){
129 if ($.trim(msg).indexOf("</li>") > 0){
130 $('#tip').removeClass('loading').find("b").text("140").show();
131 if ( (text.substring(0,2)).toUpperCase() == "D "){ //exclude the DMs. the exam of user_name is omitted.
132 updateSentTip("Your DM has been sent!",3e3,"success");
133 $("#sent_id,#textbox").val("");
136 updateSentTip("Your status has been updated!",3e3,"success");
137 $("#textbox").val("");
139 if(typeof INTERVAL_COOKIE !== 'undefined'){
140 var source = $(msg).prependTo($("#allTimeline"));
141 source.hide().slideDown('fast');
142 var statusid = $.trim($(msg).find('.status_id').text());
143 var statusText = $.trim($(msg).find('.tweet').html());
144 var statusDate = $.trim($(msg).find('span.date a').attr('id'));
146 $(".mine").slideDown("fast");
147 $("#full_status").fadeIn("fast");
148 $("#currently .status-text").hide().text(limitation(text)).fadeIn("fast");
149 $("#latest_meta").hide().html("<a target=\"_blank\" href=\"status.php?id="+statusid+"\" id=\""+statusDate+"\">less than 5 seconds ago</a>").fadeIn("fast");
150 $("#currently .full-text").hide().html(statusText);
151 $("#full_meta").hide().html("<a target=\"_blank\" href=\"status.php?id="+statusid+"\" id=\""+statusDate+"\">less than 5 seconds ago</a>");
152 $("#full_meta a,.full-text a").click(function (e){e.stopPropagation();});
153 previewMedia(source);
158 $('#tip').removeClass('loading');
160 updateSentTip("Update failed. Please try again.",3e3,"failure");
161 $('#tweeting_button').removeClass('btn-disabled');
163 PAUSE_UPDATE = false;
165 error: function (msg){
166 $('#tip').removeClass('loading');
168 updateSentTip("Update failed. Please try again.",3e3,"failure");
169 $('#tweeting_button').removeClass('btn-disabled');
170 PAUSE_UPDATE = false;
175 function shortUrlDisplay(){
176 var stringVar = $("#textbox").val();
177 if (stringVar.length === 0){
178 updateSentTip("There's no URL in your tweet to shorten!",3e3,"failure");
181 var regexp = /http(s)?:\/\/([\w\-]+\.)+[\w\-]+(\/[\w\-\.\/?\%\!\&=\+\~\:\#\;\,]*)?/ig;
183 str = stringVar.match(regexp);
186 for (idx = 0; idx < str.length; idx++){
187 regexp2 = /(http:\/\/j.mp\/[\S]+)|(http:\/\/bit.ly\/[\S]+)|(http:\/\/goo.gl\/[\S]+)|(http:\/\/t.co\/[\S]+)/gi;
188 if (!str[idx].match(regexp2)){
189 l_urls += str[idx]+"|";
195 updateSentTip(unshorten+" URL(s) are maintained!",3e3,"failure");
198 $('#tip').addClass('loading').find('b').css('color','transparent');
199 $.post("ajax/shorturl.php",{
208 function getShortUrl(res){
209 var $textbox = $('#textbox');
210 var url_arry,s_url,l_url,part;
212 url_arry = res.split('^');
213 for (i = 0; i < url_arry.length; i++){
214 part = url_arry[i].split('|');
215 if (part.length == 2){
220 $textbox.val($textbox.val().replace(l_url,s_url)+"");
222 $('#tip').removeClass('loading');
223 updateSentTip("Successfully shortened your URLs!",3e3,"success");
229 updateSentTip("Failed to shorten URLs,please try again.",3e3,"failure");
233 function shortenTweet(){
234 var tweet = $.trim($("#textbox").val());
235 if (tweet.length === 0){
236 updateSentTip("There's nothing to shorten!",3e3,"failure");
238 $('#tip').addClass('loading');
240 url: "ajax/shortenTweet.php",
243 success: function(msg){
245 $("#textbox").val(msg);
247 $('#tip').removeClass('loading');
248 updateSentTip("Your tweet has been shortened!",5e3,"success");
250 updateSentTip("Failed to shorten your tweet.",5e3,"failure");
253 error: function(msg){
254 updateSentTip("Failed to shorten your tweet.",5e3,"failure");
260 $("#latest_status").toggle(
262 $("#currently .status-text,#latest_meta").css("display","none");
263 $("#currently .full-text,#full_meta").css("display","inline");
265 $("#currently .status-text,#latest_meta").css("display","inline");
266 $("#currently .full-text,#full_meta").css("display","none");
268 $("#full_meta a,.full-text a").click(function (e){
271 var $temp = $("#currently .status-text");
272 $temp.text(limitation($temp.text()));
273 $("#translateMy").live("click",function(){
274 var orig = $("#textbox").val();
276 var lang = $.cookie('myLangs')
280 $('#tip').addClass('loading');
281 translate(orig,'',lang,'transMyCallback');
284 var limitation = function (text){
285 if (text.length > 60){
286 text = text.substr(0,60)+" ...";
290 function ajax_reply($this){
291 var $that = $this.parent().parent().parent().parent();
292 var thread = $that.find(".ajax_form");
293 if (thread.length > 0){
294 thread.slideToggle("fast");
296 $that.addClass("loading");
298 url: $this.attr("href"),
301 success: function(msg){
302 $that.removeClass("loading");
303 if ($.trim(msg).indexOf("</li>") > 0){
304 var source = $(msg).appendTo($that);
307 updateSentTip('Get thread failed.',5e3,'failure');
310 error: function(msg){
311 updateSentTip('Get thread failed.',5e3,'failure');
312 $that.removeClass("loading");
319 function rminit($this){
320 var $that = $this.parent().parent().parent();
321 var $rm = $that.find(".right_menu");
325 var id = $that.find(".status_word").find(".user_name").attr("id");
326 $that.addClass("loading");
328 url: 'ajax/relation.php',
330 data: "action=show&id="+id,
331 success: function(msg){
332 var html = '<ul class="right_menu round"><li><a class="rm_mention" href="#"><i></i>Mention</a></li>';
333 var r = parseInt(msg);
336 html += '<li><a class="rm_dm" href="#"><i></i>Message</a></li>';
338 html += '<li><a class="rm_unfollow" href="#"><i></i>Unfollow</a></li><li><a class="ul_block" href="#"><i></i>Block</a></li>';
341 html += '<li><a class="rm_dm" href="#"><i></i>Message</a></li>';
343 html += '<li><a class="rm_follow" href="#"><i></i>Follow</a></li><li><a class="rm_block" href="#"><i></i>Block</a></li>';
346 html += '<li><a class="rm_follow" href="#"><i></i>Follow</a></li><li><a class="rm_unblock" href="#"><i></i>UnBlock</a></li>';
349 html += '<li><a class="rm_spam" href="#"><i></i>Report Spam</a></li><li><a href="user.php?id='+id+'">View Full Profile</a></ul>';
350 $this.parent().parent().after(html);
351 $(html).fadeIn('fast');
355 updateSentTip('Loading Avatar Menu Failed,Please Retry!',3e3,"failure");
362 function rmmention($this,e){
363 var replie_id = $this.parent().parent().parent().find(".status_word").find(".user_name").attr("id");
364 var in_reply_id = $this.parent().parent().parent().find(".status_id").text();
365 var text = "@"+replie_id;
366 var mode = "In reply to ";
367 if ($("#textbox").length <= 0) {
368 $("#info_head").after('<h2>In reply to ' + replie_id + '</h2>' + formHTML);
372 $("#textbox").focus().val($("#textbox").val()+text+' ');
373 $("#in_reply_to").val(in_reply_id);
374 $("#full_status,#latest_meta,#full_meta,#currently .full-text").hide();
375 $("#currently .status-text").html(mode+text);
378 function rmdm($this,e){
379 var replie_id = $this.parent().parent().parent().find(".status_word").find(".user_name").attr("id");
380 var text = "D "+replie_id;
381 if ($("#textbox").length <= 0) {
382 $("#info_head").after('<h2>Send message to ' + replie_id + '</h2>' + formHTML);
386 $("#textbox").focus().val($("#textbox").val()+text+' ');;
387 $("#in_reply_to").val(e.target.parent().parent().parent().find(".status_id").text());
388 $("#full_status,#latest_meta,#full_meta,#currently .full-text").hide();
389 $("#currently .status-text").html("Reply direct message to @"+replie_id);
392 function rmfollow($this){
393 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").attr("id");
394 updateSentTip("Following "+id+"...",5e3,"ing");
396 url: "ajax/relation.php",
398 data: "action=create&id="+id,
399 success: function (msg){
400 if (msg.indexOf("success") >= 0){
401 updateSentTip("You have followed "+id+"!",3e3,"success");
403 updateSentTip("Failed to follow "+id+",please try again.",3e3,"failure");
406 error: function (msg){
407 updateSentTip("Failed to follow "+id+",please try again.",3e3,"failure");
411 function rmunfollow($this){
412 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").attr("id");
413 if (confirm("Are you sure to unfollow "+id+" ?")){
414 updateSentTip("Unfollowing "+id+"...",5e3,"ing");
416 url: "ajax/relation.php",
418 data: "action=destory&id="+id,
419 success: function (msg){
420 if (msg.indexOf("success") >= 0){
421 updateSentTip("You have unfollowed "+id+"!",3e3,"success");
423 updateSentTip("Failed to unfollow "+id+",please try again.",3e3,"failure");
426 error: function (msg){
427 updateSentTip("Failed to unfollow "+id+",please try again.",3e3,"failure");
432 function rmblock($this){
433 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").attr("id");
434 if (confirm("Are you sure to block "+id+" ?")){
435 updateSentTip("Blocking "+id+"...",5e3,"ing");
437 url: "ajax/relation.php",
439 data: "action=block&id="+id,
440 success: function (msg){
441 if (msg.indexOf("success") >= 0){
442 updateSentTip("You have blocked "+id+"!",3e3,"success");
444 updateSentTip("Failed to block "+id+",please try again.",3e3,"failure");
447 error: function (msg){
448 updateSentTip("Failed to block "+id+",please try again.",3e3,"failure");
453 function rmunblock($this){
454 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").attr("id");
455 if (confirm("Are you sure to unblock "+id+" ?")){
456 updateSentTip("Unblocking "+id+"...",5e3,"ing");
458 url: "ajax/relation.php",
460 data: "action=unblock&id="+id,
461 success: function (msg){
462 if (msg.indexOf("success") >= 0){
463 updateSentTip("You have unblocked "+id+"!",3e3,"success");
465 updateSentTip("Failed to unblock "+id+",please try again.",3e3,"failure");
468 error: function (msg){
469 updateSentTip("Failed to unblock "+id+",please try again.",3e3,"failure");
474 function rmspam($this){
475 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").attr("id");
476 if (confirm("Are you sure to report "+id+" ?")){
477 updateSentTip("Reporting "+id+" as a spammer...",5e3,"ing");
479 url: "ajax/reportSpam.php",
482 success: function (msg){
483 if (msg.indexOf("success") >= 0){
484 updateSentTip("Successfully reported!",3e3,"success");
486 updateSentTip("Failed to report "+id+",please try again.",3e3,"failure");
489 error: function (msg){
490 updateSentTip("Failed to report "+id+",please try again.",3e3,"failure");
496 function onFavor($this){
497 var status_id = $.trim($this.parent().parent().find(".status_id").text());
498 updateSentTip("Adding this tweet to your favorites...",5e3,"ing");
500 url: "ajax/addfavor.php",
502 data: "status_id="+status_id,
503 success: function (msg){
504 if (msg.indexOf("success") >= 0){
505 updateSentTip("Favorite added successfully.",3e3,"success");
506 $this.parent().parent().parent().append('<i class="faved"></i>');
507 $this.removeClass().addClass("unfav_btn").attr("title","UnFav").text("UnFav");
509 updateSentTip("Add failed. Please try again.",3e3,"failure");
512 error: function (msg){
513 updateSentTip("Add failed. Please try again.",3e3,"failure");
517 function onReplie($this,e){
518 var $word = $this.parent().parent().find(".status_word");
519 var replie_id = $word.find(".user_name").attr("id");
520 var in_reply_id = $this.parent().parent().find(".status_id").text();
521 var text = "@"+replie_id;
522 var start = text.length+1;
523 var mode = "In reply to ";
524 if (!e.ctrlKey && !e.metaKey){
527 var self = '@'+$("#side_name").text();
529 var mentionArray = [text];
530 var mentions = $word.find('.tweet').find('a[href^="user.php"]');
531 $.each(mentions,function (){
535 mentionArray.push(t);
537 text = mentionArray.join(' ');
539 if (mentionArray.length > 1){
540 mode = "Reply to all: ";
544 mode = "Non-conversational reply to ";
548 var end = text.length;
549 $("#textbox").focus().val($("#textbox").val()+text+' ').caret(start,end);
550 $("#in_reply_to").val(in_reply_id);
551 $("#full_status,#latest_meta,#full_meta,#currently .full-text,#latest_meta").hide();
552 $("#currently .status-text").html(mode+text);
555 function onRT($this){
556 var replie_id = $this.parent().parent().find(".status_word").find(".user_name").attr("id");
558 var status_word = $this.parent().parent().find(".status_word").clone();
559 status_word.find('.tweet a[rel=noreferrer]').each(function(){
560 var imgsrc = $(this).attr('href');
561 if (imgsrc.indexOf('img.php') > -1) {
562 imgsrc = imgsrc.substr(15);
564 $(this).text(imgsrc);
566 $("#textbox").focus().val(" RT @"+replie_id+":"+status_word.find('.tweet').text()).caret(0);
567 $("#full_status,#latest_meta,#full_meta,#currently .full-text,#latest_meta").hide();
568 $("#currently .status-text").html("Retweet @"+replie_id+"'s tweet with comment.");
571 function onReplieDM($this){
572 var replie_id = $this.parent().parent().find(".status_word").find(".user_name").attr("id");
573 var text = "D "+replie_id;
575 $("#textbox").focus().val($("#textbox").val()+text+' ');
576 $("#full_status,#latest_meta,#full_meta,#currently .full-text,#latest_meta").hide();
577 $("#currently .status-text").html("Reply direct message to @"+replie_id);
580 function onNwRT($this){
581 if (confirm("Are you sure to retweet this?")){
582 var statusBody = $this.parent().parent();
583 var status_id = statusBody.find(".status_id").text();
584 var div = "#"+statusBody.parent().parent().attr('id');
585 var btnDiv = div+"Btn";
586 updateSentTip("Retweeting tweet...",5e3,"ing");
588 url: "ajax/retweet.php",
590 data: "status_id="+status_id,
591 success: function (msg){
592 if (msg.length >= 0){
593 statusBody.parent().addClass("retweet");
594 statusBody.find(".source").hide();
595 statusBody.find(".status_info").append("<span class=\"rt_source\">Retweeted by you.").fadeIn("fast");
596 statusBody.find(".date").hide();
597 statusBody.find(".status_info").append("<span class=\"rt_undos\" title=\"Your followers will no longer see the tweet as retweeted by you.\"> <a class=\"rt_undo\" href=\"#\">(Undo)</a><span class=\"rt_id\" style=\"display: none;\">"+msg+"</span></span>").fadeIn("fast");
598 updateSentTip("This tweet has been retweeted!",3e3,"success");
599 $(".rt_undos").tipsy({
603 if (msg === "duplicated"){
604 updateSentTip("You have retweeted this tweet!",3e3,"failure");
606 updateSentTip("Failed to retweet!",3e3,"failure");
610 error: function (msg){
611 updateSentTip("Retweet failed. Please try again.",3e3,"failure");
616 function UnFavor($this){
617 if (window.confirm("Are you sure to unfavor this tweet?")){
618 var $that=$this.parent().parent();
619 var status_id = $.trim($that.find(".status_id").text());
620 $that.parent().css("background-color","#FF3300");
621 updateSentTip("Unfavoring tweet...",5e3,"ing");
623 url: "ajax/delete.php",
625 data: "favor_id="+status_id,
626 success: function (msg){
627 if (msg.indexOf("success") >= 0){
628 if (location.href.indexOf('favor.php')>0){
629 $that.parent().fadeOut("fast");
631 $that.parent().find(".faved").fadeOut("fast");
632 $this.removeClass().addClass("favor_btn").attr("title","Fav").text("Fav");
634 updateSentTip("This tweet has been unfavored!",3e3,"success");
636 updateSentTip("Unfavor failed. Please try again.",3e3,"failure");
638 $that.parent().css("background-color","");
640 error: function (msg){
641 updateSentTip("Unfavor failed. Please try again.",3e3,"failure");
642 $that.parent().css("background-color","");
647 function onDelete($this){
648 if (window.confirm("Are you sure to delete this tweet?")){
649 var $this=$this.parent().parent();
650 var status_id = $.trim($this.find(".status_id").text());
651 $this.parent().css("background-color","#FF3300");
652 updateSentTip("Deleting tweet...",5e3,"ing");
654 url: "ajax/delete.php",
656 data: "status_id="+status_id,
657 success: function (msg){
658 if (msg.indexOf("success") >= 0){
659 $this.parent().fadeOut("fast");
660 updateSentTip("Your tweet has been destroyed!",3e3,"success");
662 updateSentTip("Delete failed. Please try again.",3e3,"failure");
664 $this.parent().css("background-color","");
666 error: function (msg){
667 updateSentTip("Delete failed. Please try again.",3e3,"failure");
668 $this.parent().css("background-color","");
673 function onUndoRt($this){
674 if (window.confirm("Are you sure to undo this retweet?")){
675 var status_id = $.trim($this.parent().find(".rt_id").text());
676 var statusBody = $this.parent().parent().parent();
677 statusBody.css("background-color","#FF3300");
678 updateSentTip("Undoing retweet...",5e3,"ing");
680 url: "ajax/delete.php",
682 data: "status_id="+status_id,
683 success: function (msg){
684 if (msg.indexOf("success") >= 0){
685 statusInfo = $this.parent().parent();
686 if (statusInfo.find(".rt_source").size() === 1){
687 statusInfo.find(".source").show().find(".date").show();
688 statusInfo.find(".rt_source").remove()
689 statusInfo.find(".rt_undos").remove();
690 statusBody.removeClass("retweet");
692 statusBody.fadeOut("fast");
694 updateSentTip("Your retweet has been undo!",3e3,"success");
696 updateSentTip("Undo failed. Please try again.",3e3,"failure");
698 statusBody.css("background-color","");
700 error: function (msg){
701 updateSentTip("Undo failed. Please try again.",3e3,"failure");
702 statusBody.css("background-color","");
708 function onDeleteMsg($this){
709 if (window.confirm("Are you sure to delete this message?")){
710 var $this=$this.parent().parent();
711 var message_id = $.trim($this.find(".status_id").text());
712 $this.parent().css("background-color","#FF3300");
713 updateSentTip("Deleting message...",5e3,"ing");
715 url: "ajax/delete.php",
717 data: "message_id="+message_id,
718 success: function (msg){
719 if (msg.indexOf("success") >= 0){
720 $this.parent().fadeOut("fast");
721 updateSentTip("Message deleted.",3e3,"success");
723 updateSentTip("Failed to delete this message!",3e3,"failure");
725 $this.parent().css("background-color","");
727 error: function (msg){
728 updateSentTip("Failed to delete this message!",3e3,"failure");
729 $this.parent().css("background-color","");
735 $("#statuses .trans_close").live('click',function(e){
737 $(e.target).parent().parent().parent().parent().find(".translated").remove();
739 $("#transRecover").click(function(e){
740 $("#textbox").val(ORIG_TEXT);
741 $(e.target).fadeOut('fast');
744 var translate = function(text,context,lang,callback){
746 var a = "http://www.google.com/uds/Gtranslate";
747 a += "?callback="+callback;
748 a += "&context="+context;
749 a += "&q="+encodeURIComponent(text);
750 a += "&key=notsupplied&v=1.0&nocache=1240207680396&langpair=%7C";
754 var transMyCallback = function(content,translation){
755 if(translation.translatedText !== null){
756 $('#tip').removeClass('loading');
757 $("#transArea").hide();
758 $("#textbox").val(translation.translatedText);
759 $("#transRecover").fadeIn('fast');
762 var transCallback = function(content,translation){
763 if(translation.translatedText !== null){
764 var lang = $.cookie('transLang')
768 var langTxt = $.cookie('fullLang');
769 if(langTxt === null){
770 langTxt = $('#transArea select[name=langs] option[value='+lang+']').text();
772 var html = '<div class="translated"><a href="#" title="Hide Translation" class="trans_close">(Hide)</a><span class="trans_header"><strong>Translation <small>(from '+translation.detectedSourceLanguage;
773 html += ' to '+langTxt+')</small> : </strong></span>';
774 html += '<span class="trans_body">'+translation.translatedText+'</span></div>';
776 if(typeof INTERVAL_COOKIE !== 'undefined'){
777 li = $("#statuses ol:visible li:has(.status_id)").filter(":contains("+content+")");
778 target = li.find(".status_word").filter(":first");
780 li = $("#statuses li:has(.status_id)").filter(":contains("+content+")");
781 target = li.find(".status_word").filter(":first");
783 $(html).appendTo(target);
784 li.removeClass("loading");
789 $('body').click(function (){
790 $('ul.right_menu').fadeOut('fast');
792 $('ol.timeline').click(function(e){
793 var $this = $(e.target);
802 switch(e.target.className){
840 var tBody = $this.parent().parent();
841 if(tBody.find(".trans_body").length !== 0){
844 var id = $.trim(tBody.find('.status_id').text());
845 var text = $.trim(tBody.find('.tweet').text());
846 var lang = $.cookie('transLang');
850 tBody.parent().addClass('loading');
851 translate(text,id,lang,'transCallback');
855 var tp = $this.text().split('/');
857 if(d == 't.cn' || d == 'goo.gl' || d == 'bit.ly' || d == 'j.mp' || d == 'is.gd' || d == '163.fm') {
859 updateSentTip('Unshorting the URL...',3e3,'ing');
860 $.getJSON('ajax/expand.php?url=' +encodeURIComponent($this.attr('href')), function(data) {
861 if('expanded_url' in data) {
862 var url = data['expanded_url'];
863 if (url != $this.attr('href')) {
864 var tmp = url.split("://");
866 $this.attr('href',url);
867 updateSentTip('Successfully unshort the URL!',3e3,'success');
868 if ($.cookie('showpic') === 'true') previewImg($this);
869 if ($.cookie('mediaPre') === 'true') previewFlash($this);
870 $this.data('previewed',true);
873 updateSentTip('Fail to unshort the URL! Please try again later!',3e3,'failure');
880 $('ol.timeline').on("dbclick", 'a.tweet_url', function(e){
887 var scroller = function(){
888 var $sidebar = $("#side");
889 var $window = $(window);
890 var top = $sidebar.data("top");
891 if ($window.scrollTop() > top){
905 var sidebarscroll = function (msg){
906 if($.cookie('sidebarscroll') != 'false' && location.href.indexOf('profile.php')< 0 && location.href.indexOf('setting.php') < 0){
907 var $sidebar = $("#side");
908 var $window = $(window);
909 if(!$sidebar.data("top")){
910 var offset = $sidebar.offset();
911 $sidebar.data("top",offset.top);
913 if(msg == undefined){
914 $window.scroll(scroller);
917 var top = $window.scrollTop() - $sidebar.data('top');
918 if (top <= 0) top = 0;
923 $window.unbind('scroll',scroller);
928 if($.cookie('autoscroll') != 'false' && $("#more").length > 0 && $("ol.timeline").length > 0){
929 $("ol.timeline").infinitescroll({
930 nextSelector:"#more:last",
931 navSelector:"#pagination",
932 itemSelector:"ol.timeline li",
933 callback: function(obj){
939 $("#indicator").toggle(
941 $('#sidebarTip_more').slideDown('fast');
942 $('#indicator').html('[-]');
944 $('#sidebarTip_more').slideUp('fast');
945 $('#indicator').html('[+]');
947 $("#sidebarTip [contenteditable]").live('focusout',function(){
948 var $this = $("#sidebarTip [contenteditable]");
951 {Tip_Title: $this.eq(0).text()+' ',Tip_Content:$this.eq(1).text()+' ',Tip_More:$this.eq(2).text()+' '},
953 if(msg == 'unsecured'){
954 updateSentTip('Fail to save your tip for the security issues!',3e3,'failure');
955 }else if(msg == 'error'){
956 updateSentTip('Fail to save your tip! Please try again later!',3e3,'failure');
958 updateSentTip('Successfully save your tip!',3e3,'success');
963 $("#sidebarTip #tip_reset").live('click',function(e){
965 if(window.confirm('Are you sure to restore to default tips?')){
971 updateSentTip('Successfully restore to the default tips!',3e3,'success');
974 updateSentTip('Fail to save your tip! Please try again later!',3e3,'failure');
980 $("#profileRefresh").click(function(e){
983 if (!that.hasClass('refreshing')){
984 that.addClass('refreshing');
986 url: "ajax/updateProfile.php",
989 success: function(msg){
990 if (msg.result == 'success'){
992 updateSentTip("Profile updated successfully!",3e3,"success");
995 updateSentTip("Failed to update your profile!",3e3,"failure");
998 error: function (msg){
999 updateSentTip("Failed to update your profile!",3e3,"failure");
1001 complete: function(){
1002 that.removeClass('refreshing');
1009 // sidepost function
1011 $("#trends_title").toggle(
1013 $("#trends_title").removeClass().addClass("loading");
1016 $("#trends_title").removeClass();
1017 $("#trend_entries").slideUp("fast");
1020 $("#following_title").toggle(
1022 $("#following_title").removeClass().addClass("loading");
1023 sidebarscroll('pause');
1026 $("#following_title").removeClass();
1027 $("#following_list").slideUp("fast");
1030 $("#apiquota_title").toggle(
1032 $("#apiquota_title").removeClass().addClass("loading");
1033 sidebarscroll('pause');
1036 $("#apiquota_title").removeClass();
1037 $("#apiquota_list").slideUp("fast");
1041 function updateTrends(){
1042 sidebarscroll('pause');
1043 if (navigator.geolocation) {
1044 if ($.cookie('woeid') == undefined) {
1045 navigator.geolocation.getCurrentPosition(function (pos, error) {
1047 url: "ajax/updateTrends.php?lat=" + pos.coords.latitude + "&long=" + pos.coords.longitude,
1049 success: function (msg){
1050 if ($.trim(msg).indexOf("</ul>" > 0)){
1051 $("#trend_entries").html(msg);
1053 $("#trends_title").removeClass().addClass("open");
1054 $("#trend_entries").slideDown("fast");
1060 url: "ajax/updateTrends.php",
1062 success: function (msg){
1063 if ($.trim(msg).indexOf("</ul>" > 0)){
1064 $("#trend_entries").html(msg);
1066 $("#trends_title").removeClass().addClass("open");
1067 $("#trend_entries").slideDown("fast");
1073 function updateFollowing(){
1075 url: "ajax/updateFollowing.php",
1077 success: function (msg){
1078 if ($.trim(msg).indexOf("</span>" > 0)){
1079 $("#following_list").html(msg);
1081 $("#following_title").removeClass().addClass("open");
1082 $("#following_list").slideDown("fast");
1086 function updateAPIQuota(){
1088 url: "ajax/apiQuota.php",
1090 success: function (msg){
1091 if ($.trim(msg).indexOf("</span>" > 0)){
1092 $("#apiquota_list").html(msg);
1094 $("#apiquota_title").removeClass().addClass("open");
1095 $("#apiquota_list").slideDown("fast");
1099 $(window).load(function(){
1100 var scrollTo = function (top,duration,callback){
1103 var currentTop = w.scrollTop();
1104 var offset = (currentTop - top) / (duration * FPS / 1000);
1106 var prevTop = currentTop;
1107 var t = setInterval(function (){
1108 if ((prevTop - top) * (currentTop - top) <= 0){
1110 currentTop = prevTop = top;
1112 if (callback) callback();
1114 prevTop = currentTop;
1115 w.scrollTop(currentTop -= offset);
1119 var scrollToTop = function(){
1120 scrollTo(0,200,function (){
1121 scrollTo(30,50,function (){
1126 var scrollToBottom = function(){
1127 var height = document.body.clientHeight;
1128 scrollTo(height,200,function (){
1129 scrollTo(height+30,50,function (){
1130 scrollTo(height,50);
1134 $('body').dblclick(function (){
1136 $("#textbox").focus();
1138 $('#content').dblclick(function (e){
1139 e.stopPropagation();
1141 var hkFadeIn = function(text){
1142 $("#shortcutTip").fadeIn("fast").html(text);
1144 var hkFadeOut = function(){
1145 setTimeout(function (){$("#shortcutTip").fadeOut("fast");},2000);
1148 var hotkeyHandler = function(code){
1150 case 82: // R - refresh
1151 hkFadeIn("Refresh");
1155 case 67: // C - focus textbox
1157 hkFadeIn("Compose");
1158 scrollTo(0,1,function (){
1159 $("#textbox").focus();
1163 case 66: // B - scroll to bottom
1168 case 84: // T - scroll to top
1173 case 83: // S - search
1175 $("#sidepost").animate({backgroundColor: "#FF6347"},500,function(){
1176 $("#header_search_query").focus();
1177 $("#sidepost").animate({backgroundColor: $("#side_base").css("background-color")},1000);
1183 $(document).keydown(function(e){
1184 var tag = e.target.tagName;
1185 if(tag === "BODY" || tag === "HTML"){
1186 if(!e.altKey && !e.shiftKey && !e.ctrlKey && !e.metaKey){
1187 hotkeyHandler(e.keyCode);
1191 $("#statuses .big-retweet-icon,#func_set .func_btn,#profileRefresh").tipsy({
1194 $('#symbols span').tipsy({
1195 gravity: $.fn.tipsy.autoNS
1197 $("#statuses .mine").live("mouseout",function (e){
1198 $(e.target).removeClass("mine").addClass("myTweet");
1201 //init global functions
1202 $(document).ready(function (){
1204 $("#primary_nav li a").click(function (e){
1205 $(e.target).each(function (){
1206 if ($(this).hasClass("active")){
1207 $(this).removeClass()
1210 $(this).removeClass().addClass("active").css("background","transparent url('../img/spinner.gif') no-repeat scroll 173px center")
1212 $("#avatar,#sideimg").lazyload({threshold:100,effect:"fadeIn",placeholder:"img/blank.gif"});
1215 var freshProfile = function(){
1216 $("#side_name").text($.cookie('name'));
1217 $.cookie('name',null);
1218 $("span.count").eq(0).text($.cookie('friends_count')).end()
1219 .eq(1).text($.cookie('followers_count')).end()
1220 .eq(2).text($.cookie('listed_count'));
1221 $("#update_count").text($.cookie('statuses_count'));
1222 $('#sideimg').attr("src",$.cookie('imgurl'));
1224 var markReply = function(obj){
1225 var sidename = "@"+$("#side_name").text().toLowerCase();
1226 obj.each(function (i,o){
1227 if ($(this).find("> span").find('.tweet').text().toLowerCase().indexOf(sidename) > -1){
1228 $(this).addClass("reply");