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());
145 $(".mine").slideDown("fast");
146 $("#full_status").fadeIn("fast");
147 $("#currently .status-text").hide().text(limitation(text)).fadeIn("fast");
148 $("#latest_meta").hide().html("<a target=\"_blank\" href=\"status.php?id="+statusid+"\">less than 5 seconds ago</a>").fadeIn("fast");
149 $("#currently .full-text").hide().html(statusText);
150 $("#full_meta").hide().html("<a target=\"_blank\" href=\"status.php?id="+statusid+"\">less than 5 seconds ago</a>");
151 $("#full_meta a,.full-text a").click(function (e){e.stopPropagation();});
152 previewMedia(source);
157 $('#tip').removeClass('loading');
159 updateSentTip("Update failed. Please try again.",3e3,"failure");
160 $('#tweeting_button').removeClass('btn-disabled');
162 PAUSE_UPDATE = false;
164 error: function (msg){
165 $('#tip').removeClass('loading');
167 updateSentTip("Update failed. Please try again.",3e3,"failure");
168 $('#tweeting_button').removeClass('btn-disabled');
169 PAUSE_UPDATE = false;
174 function shortUrlDisplay(){
175 var stringVar = $("#textbox").val();
176 if (stringVar.length === 0){
177 updateSentTip("There's no URL in your tweet to shorten!",3e3,"failure");
180 var regexp = /http(s)?:\/\/([\w\-]+\.)+[\w\-]+(\/[\w\-\.\/?\%\!\&=\+\~\:\#\;\,]*)?/ig;
182 str = stringVar.match(regexp);
185 for (idx = 0; idx < str.length; idx++){
186 regexp2 = /(http:\/\/j.mp\/[\S]+)|(http:\/\/bit.ly\/[\S]+)|(http:\/\/goo.gl\/[\S]+)|(http:\/\/t.co\/[\S]+)/gi;
187 if (!str[idx].match(regexp2)){
188 l_urls += str[idx]+"|";
194 updateSentTip(unshorten+" URL(s) are maintained!",3e3,"failure");
197 $('#tip').addClass('loading').find('b').css('color','transparent');
198 $.post("ajax/shorturl.php",{
207 function getShortUrl(res){
208 var $textbox = $('#textbox');
209 var url_arry,s_url,l_url,part;
211 url_arry = res.split('^');
212 for (i = 0; i < url_arry.length; i++){
213 part = url_arry[i].split('|');
214 if (part.length == 2){
219 $textbox.val($textbox.val().replace(l_url,s_url)+"");
221 $('#tip').removeClass('loading');
222 updateSentTip("Successfully shortened your URLs!",3e3,"success");
228 updateSentTip("Failed to shorten URLs,please try again.",3e3,"failure");
232 function shortenTweet(){
233 var tweet = $.trim($("#textbox").val());
234 if (tweet.length === 0){
235 updateSentTip("There's nothing to shorten!",3e3,"failure");
237 $('#tip').addClass('loading');
239 url: "ajax/shortenTweet.php",
242 success: function(msg){
244 $("#textbox").val(msg);
246 $('#tip').removeClass('loading');
247 updateSentTip("Your tweet has been shortened!",5e3,"success");
249 updateSentTip("Failed to shorten your tweet.",5e3,"failure");
252 error: function(msg){
253 updateSentTip("Failed to shorten your tweet.",5e3,"failure");
259 $("#latest_status").toggle(
261 $("#currently .status-text,#latest_meta").css("display","none");
262 $("#currently .full-text,#full_meta").css("display","inline");
264 $("#currently .status-text,#latest_meta").css("display","inline");
265 $("#currently .full-text,#full_meta").css("display","none");
267 $("#full_meta a,.full-text a").click(function (e){
270 var $temp = $("#currently .status-text");
271 $temp.text(limitation($temp.text()));
272 $("#translateMy").live("click",function(){
273 var orig = $("#textbox").val();
275 var lang = $.cookie('myLangs')
279 $('#tip').addClass('loading');
280 translate(orig,'',lang,'transMyCallback');
283 var limitation = function (text){
284 if (text.length > 60){
285 text = text.substr(0,60)+" ...";
289 function ajax_reply($this){
290 var $that = $this.parent().parent().parent().parent();
291 var thread = $that.find(".ajax_form");
292 if (thread.length > 0){
293 thread.slideToggle("fast");
295 $that.addClass("loading");
297 url: $this.attr("href"),
300 success: function(msg){
301 $that.removeClass("loading");
302 if ($.trim(msg).indexOf("</li>") > 0){
303 var source = $(msg).appendTo($that);
306 updateSentTip('Get thread failed.',5e3,'failure');
309 error: function(msg){
310 updateSentTip('Get thread failed.',5e3,'failure');
311 $that.removeClass("loading");
318 function rminit($this){
319 var $that = $this.parent().parent().parent();
320 var $rm = $that.find(".right_menu");
324 var id = $that.find(".status_word").find(".user_name").text();
325 $that.addClass("loading");
327 url: 'ajax/relation.php',
329 data: "action=show&id="+id,
330 success: function(msg){
331 var html = '<ul class="right_menu round"><li><a class="rm_mention" href="#"><i></i>Mention</a></li>';
332 var r = parseInt(msg);
335 html += '<li><a class="rm_dm" href="#"><i></i>Message</a></li>';
337 html += '<li><a class="rm_unfollow" href="#"><i></i>Unfollow</a></li><li><a class="ul_block" href="#"><i></i>Block</a></li>';
340 html += '<li><a class="rm_dm" href="#"><i></i>Message</a></li>';
342 html += '<li><a class="rm_follow" href="#"><i></i>Follow</a></li><li><a class="rm_block" href="#"><i></i>Block</a></li>';
345 html += '<li><a class="rm_follow" href="#"><i></i>Follow</a></li><li><a class="rm_unblock" href="#"><i></i>UnBlock</a></li>';
348 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>';
349 $this.parent().parent().after(html);
350 $(html).fadeIn('fast');
354 updateSentTip('Loading Avatar Menu Failed,Please Retry!',3e3,"failure");
361 function rmmention($this,e){
362 var replie_id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();
363 var in_reply_id = $this.parent().parent().parent().find(".status_id").text();
364 var text = "@"+replie_id;
365 var mode = "In reply to ";
367 $("#textbox").focus().val($("#textbox").val()+text+' ');
368 $("#in_reply_to").val(in_reply_id);
369 $("#full_status,#latest_meta,#full_meta,#currently .full-text").hide();
370 $("#currently .status-text").html(mode+text);
373 function rmdm($this,e){
374 var replie_id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();
375 var text = "D "+replie_id;
377 $("#textbox").focus().val($("#textbox").val()+text+' ');;
378 $("#in_reply_to").val(e.target.parent().parent().parent().find(".status_id").text());
379 $("#full_status,#latest_meta,#full_meta,#currently .full-text").hide();
380 $("#currently .status-text").html("Reply direct message to @"+replie_id);
383 function rmfollow($this){
384 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();
385 updateSentTip("Following "+id+"...",5e3,"ing");
387 url: "ajax/relation.php",
389 data: "action=create&id="+id,
390 success: function (msg){
391 if (msg.indexOf("success") >= 0){
392 updateSentTip("You have followed "+id+"!",3e3,"success");
394 updateSentTip("Failed to follow "+id+",please try again.",3e3,"failure");
397 error: function (msg){
398 updateSentTip("Failed to follow "+id+",please try again.",3e3,"failure");
402 function rmunfollow($this){
403 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();
404 if (confirm("Are you sure to unfollow "+id+" ?")){
405 updateSentTip("Unfollowing "+id+"...",5e3,"ing");
407 url: "ajax/relation.php",
409 data: "action=destory&id="+id,
410 success: function (msg){
411 if (msg.indexOf("success") >= 0){
412 updateSentTip("You have unfollowed "+id+"!",3e3,"success");
414 updateSentTip("Failed to unfollow "+id+",please try again.",3e3,"failure");
417 error: function (msg){
418 updateSentTip("Failed to unfollow "+id+",please try again.",3e3,"failure");
423 function rmblock($this){
424 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();
425 if (confirm("Are you sure to block "+id+" ?")){
426 updateSentTip("Blocking "+id+"...",5e3,"ing");
428 url: "ajax/relation.php",
430 data: "action=block&id="+id,
431 success: function (msg){
432 if (msg.indexOf("success") >= 0){
433 updateSentTip("You have blocked "+id+"!",3e3,"success");
435 updateSentTip("Failed to block "+id+",please try again.",3e3,"failure");
438 error: function (msg){
439 updateSentTip("Failed to block "+id+",please try again.",3e3,"failure");
444 function rmunblock($this){
445 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();
446 if (confirm("Are you sure to unblock "+id+" ?")){
447 updateSentTip("Unblocking "+id+"...",5e3,"ing");
449 url: "ajax/relation.php",
451 data: "action=unblock&id="+id,
452 success: function (msg){
453 if (msg.indexOf("success") >= 0){
454 updateSentTip("You have unblocked "+id+"!",3e3,"success");
456 updateSentTip("Failed to unblock "+id+",please try again.",3e3,"failure");
459 error: function (msg){
460 updateSentTip("Failed to unblock "+id+",please try again.",3e3,"failure");
465 function rmspam($this){
466 var id = $this.parent().parent().parent().find(".status_word").find(".user_name").text();
467 if (confirm("Are you sure to report "+id+" ?")){
468 updateSentTip("Reporting "+id+" as a spammer...",5e3,"ing");
470 url: "ajax/reportSpam.php",
473 success: function (msg){
474 if (msg.indexOf("success") >= 0){
475 updateSentTip("Successfully reported!",3e3,"success");
477 updateSentTip("Failed to report "+id+",please try again.",3e3,"failure");
480 error: function (msg){
481 updateSentTip("Failed to report "+id+",please try again.",3e3,"failure");
487 function onFavor($this){
488 var status_id = $.trim($this.parent().parent().find(".status_id").text());
489 updateSentTip("Adding this tweet to your favorites...",5e3,"ing");
491 url: "ajax/addfavor.php",
493 data: "status_id="+status_id,
494 success: function (msg){
495 if (msg.indexOf("success") >= 0){
496 updateSentTip("Favorite added successfully.",3e3,"success");
497 $this.parent().parent().parent().append('<i class="faved"></i>');
498 $this.removeClass().addClass("unfav_btn").attr("title","UnFav").text("UnFav");
500 updateSentTip("Add failed. Please try again.",3e3,"failure");
503 error: function (msg){
504 updateSentTip("Add failed. Please try again.",3e3,"failure");
508 function onReplie($this,e){
509 var $word = $this.parent().parent().find(".status_word");
510 var replie_id = $word.find(".user_name").text();
511 var in_reply_id = $this.parent().parent().find(".status_id").text();
512 var text = "@"+replie_id;
513 var start = text.length+1;
514 var mode = "In reply to ";
515 if (!e.ctrlKey && !e.metaKey){
518 var self = '@'+$("#side_name").text();
520 var mentionArray = [text];
521 var mentions = $word.find('.tweet').find('a[href^="user.php"]');
522 $.each(mentions,function (){
526 mentionArray.push(t);
528 text = mentionArray.join(' ');
530 if (mentionArray.length > 1){
531 mode = "Reply to all: ";
535 mode = "Non-conversational reply to ";
539 var end = text.length;
540 $("#textbox").focus().val($("#textbox").val()+text+' ').caret(start,end);
541 $("#in_reply_to").val(in_reply_id);
542 $("#full_status,#latest_meta,#full_meta,#currently .full-text,#latest_meta").hide();
543 $("#currently .status-text").html(mode+text);
546 function onRT($this){
547 var replie_id = $this.parent().parent().find(".status_word").find(".user_name").text();
549 var status_word = $this.parent().parent().find(".status_word").clone();
550 status_word.find('.tweet a[rel=noreferrer]').each(function(){
551 $(this).text($(this).attr('href'));
553 $("#textbox").focus().val(" RT @"+replie_id+":"+status_word.text().replace(replie_id,"")).caret(0);
554 $("#full_status,#latest_meta,#full_meta,#currently .full-text,#latest_meta").hide();
555 $("#currently .status-text").html("Retweet @"+replie_id+"'s tweet with comment.");
558 function onReplieDM($this){
559 var replie_id = $this.parent().parent().find(".status_word").find(".user_name").text();
560 var text = "D "+replie_id;
562 $("#textbox").focus().val($("#textbox").val()+text+' ');
563 $("#full_status,#latest_meta,#full_meta,#currently .full-text,#latest_meta").hide();
564 $("#currently .status-text").html("Reply direct message to @"+replie_id);
567 function onNwRT($this){
568 if (confirm("Are you sure to retweet this?")){
569 var statusBody = $this.parent().parent();
570 var status_id = statusBody.find(".status_id").text();
571 var div = "#"+statusBody.parent().parent().attr('id');
572 var btnDiv = div+"Btn";
573 updateSentTip("Retweeting tweet...",5e3,"ing");
575 url: "ajax/retweet.php",
577 data: "status_id="+status_id,
578 success: function (msg){
579 if (msg.length >= 0){
580 statusBody.parent().addClass("retweet");
581 statusBody.find(".source").hide();
582 statusBody.find(".status_info").append("<span class=\"rt_source\">Retweeted by you from <a rel=\"nofollow\" href=\"http://code.google.com/p/embr/\">embr</a></span>").fadeIn("fast");
583 statusBody.find(".date").hide();
584 statusBody.find(".status_info").append("<span class=\"rt_undo\" title=\"Your followers will no longer see the tweet as retweeted by you.\"> <a href=\"#\">(Undo)</a><span class=\"rt_id\" style=\"display: none;\">"+msg+"</span></span>").fadeIn("fast");
585 updateSentTip("This tweet has been retweeted!",3e3,"success");
586 $(".rt_undo").tipsy({
590 if (msg === "duplicated"){
591 updateSentTip("You have retweeted this tweet!",3e3,"failure");
593 updateSentTip("Failed to retweet!",3e3,"failure");
597 error: function (msg){
598 updateSentTip("Retweet failed. Please try again.",3e3,"failure");
603 function UnFavor($this){
604 if (window.confirm("Are you sure to unfavor this tweet?")){
605 var $that=$this.parent().parent();
606 var status_id = $.trim($that.find(".status_id").text());
607 $that.parent().css("background-color","#FF3300");
608 updateSentTip("Unfavoring tweet...",5e3,"ing");
610 url: "ajax/delete.php",
612 data: "favor_id="+status_id,
613 success: function (msg){
614 if (msg.indexOf("success") >= 0){
615 if (location.href.indexOf('favor.php')>0){
616 $that.parent().fadeOut("fast");
618 $that.parent().find(".faved").fadeOut("fast");
619 $this.removeClass().addClass("favor_btn").attr("title","Fav").text("Fav");
621 updateSentTip("This tweet has been unfavored!",3e3,"success");
623 updateSentTip("Unfavor failed. Please try again.",3e3,"failure");
625 $that.parent().css("background-color","");
627 error: function (msg){
628 updateSentTip("Unfavor failed. Please try again.",3e3,"failure");
629 $that.parent().css("background-color","");
634 function onDelete($this){
635 if (window.confirm("Are you sure to delete this tweet?")){
636 var $this=$this.parent().parent();
637 var status_id = $.trim($this.find(".status_id").text());
638 $this.parent().css("background-color","#FF3300");
639 updateSentTip("Deleting tweet...",5e3,"ing");
641 url: "ajax/delete.php",
643 data: "status_id="+status_id,
644 success: function (msg){
645 if (msg.indexOf("success") >= 0){
646 $this.parent().fadeOut("fast");
647 updateSentTip("Your tweet has been destroyed!",3e3,"success");
649 updateSentTip("Delete failed. Please try again.",3e3,"failure");
651 $this.parent().css("background-color","");
653 error: function (msg){
654 updateSentTip("Delete failed. Please try again.",3e3,"failure");
655 $this.parent().css("background-color","");
660 function onUndoRt($this){
661 if (window.confirm("Are you sure to undo this retweet?")){
662 var status_id = $.trim($this.parent().find(".rt_id").text());
663 var statusBody = $this.parent().parent().parent();
664 statusBody.css("background-color","#FF3300");
665 updateSentTip("Undoing retweet...",5e3,"ing");
667 url: "ajax/delete.php",
669 data: "status_id="+status_id,
670 success: function (msg){
671 if (msg.indexOf("success") >= 0){
672 statusInfo = $this.parent().parent();
673 if (statusInfo.find(".rt_source").size() === 1){
674 statusInfo.find(".source").show().find(".date").show();
675 statusInfo.find(".rt_source").remove()
676 statusInfo.find(".rt_undo").remove();
677 statusBody.removeClass("retweet");
679 statusBody.fadeOut("fast");
681 updateSentTip("Your retweet has been undo!",3e3,"success");
683 updateSentTip("Undo failed. Please try again.",3e3,"failure");
685 statusBody.css("background-color","");
687 error: function (msg){
688 updateSentTip("Undo failed. Please try again.",3e3,"failure");
689 statusBody.css("background-color","");
695 function onDeleteMsg($this){
696 if (window.confirm("Are you sure to delete this message?")){
697 var $this=$this.parent().parent();
698 var message_id = $.trim($this.find(".status_id").text());
699 $this.parent().css("background-color","#FF3300");
700 updateSentTip("Deleting message...",5e3,"ing");
702 url: "ajax/delete.php",
704 data: "message_id="+message_id,
705 success: function (msg){
706 if (msg.indexOf("success") >= 0){
707 $this.parent().fadeOut("fast");
708 updateSentTip("Message deleted.",3e3,"success");
710 updateSentTip("Failed to delete this message!",3e3,"failure");
712 $this.parent().css("background-color","");
714 error: function (msg){
715 updateSentTip("Failed to delete this message!",3e3,"failure");
716 $this.parent().css("background-color","");
722 $("#statuses .trans_close").live('click',function(e){
724 $(e.target).parent().parent().parent().parent().find(".translated").remove();
726 $("#transRecover").click(function(e){
727 $("#textbox").val(ORIG_TEXT);
728 $(e.target).fadeOut('fast');
731 var translate = function(text,context,lang,callback){
733 var a = "http://www.google.com/uds/Gtranslate";
734 a += "?callback="+callback;
735 a += "&context="+context;
736 a += "&q="+encodeURIComponent(text);
737 a += "&key=notsupplied&v=1.0&nocache=1240207680396&langpair=%7C";
741 var transMyCallback = function(content,translation){
742 if(translation.translatedText !== null){
743 $('#tip').removeClass('loading');
744 $("#transArea").hide();
745 $("#textbox").val(translation.translatedText);
746 $("#transRecover").fadeIn('fast');
749 var transCallback = function(content,translation){
750 if(translation.translatedText !== null){
751 var lang = $.cookie('transLang')
755 var langTxt = $.cookie('fullLang');
756 if(langTxt === null){
757 langTxt = $('#transArea select[name=langs] option[value='+lang+']').text();
759 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;
760 html += ' to '+langTxt+')</small> : </strong></span>';
761 html += '<span class="trans_body">'+translation.translatedText+'</span></div>';
763 if(typeof INTERVAL_COOKIE !== 'undefined'){
764 li = $("#statuses ol:visible li:has(.status_id)").filter(":contains("+content+")");
765 target = li.find(".status_word").filter(":first");
767 li = $("#statuses li:has(.status_id)").filter(":contains("+content+")");
768 target = li.find(".status_word").filter(":first");
770 $(html).appendTo(target);
771 li.removeClass("loading");
776 $('body').click(function (){
777 $('ul.right_menu').fadeOut('fast');
779 $('ol.timeline').click(function(e){
780 var $this = $(e.target);
789 switch(e.target.className){
827 var tBody = $this.parent().parent();
828 if(tBody.find(".trans_body").length !== 0){
831 var id = $.trim(tBody.find('.status_id').text());
832 var text = $.trim(tBody.find('.tweet').text());
833 var lang = $.cookie('transLang');
837 tBody.parent().addClass('loading');
838 translate(text,id,lang,'transCallback');
842 var tp = $this.text().split('/');
844 if(d == 't.cn' || d == 'goo.gl' || d == 'bit.ly' || d == 'j.mp' || d == 'is.gd' || d == '163.fm') {
846 updateSentTip('Unshorting the URL...',3e3,'ing');
847 $.getJSON('http://api.longurl.org/v2/expand?url=' +encodeURIComponent($this.attr('href')) + '&format=json&callback=?', function(data) {
848 if('long-url' in data) {
849 var url = data['long-url'];
850 if (url != $this.attr('href')) {
851 var tmp = url.split("://");
853 $this.attr('href',url);
854 updateSentTip('Successfully unshort the URL!',3e3,'success');
855 if ($.cookie('showpic') === 'true') previewImg($this);
856 if ($.cookie('mediaPre') === 'true') previewFlash($this);
857 $this.data('previewed',true);
860 updateSentTip('Fail to unshort the URL! Please try again later!',3e3,'failure');
867 $('ol.timeline').on("dbclick", 'a.tweet_url', function(e){
874 var scroller = function(){
875 var $sidebar = $("#side");
876 var $window = $(window);
877 var top = $sidebar.data("top");
878 if ($window.scrollTop() > top){
892 var sidebarscroll = function (msg){
893 if($.cookie('sidebarscroll') != 'false' && location.href.indexOf('profile.php')< 0 && location.href.indexOf('setting.php') < 0){
894 var $sidebar = $("#side");
895 var $window = $(window);
896 if(!$sidebar.data("top")){
897 var offset = $sidebar.offset();
898 $sidebar.data("top",offset.top);
900 if(msg == undefined){
901 $window.scroll(scroller);
904 var top = $window.scrollTop() - $sidebar.data('top');
905 if (top <= 0) top = 0;
910 $window.unbind('scroll',scroller);
915 if($.cookie('autoscroll') != 'false' && $("#more").length > 0 && $("ol.timeline").length > 0){
916 $("ol.timeline").infinitescroll({
917 nextSelector:"#more:last",
918 navSelector:"#pagination",
919 itemSelector:"ol.timeline li",
920 callback: function(obj){
926 $("#indicator").toggle(
928 $('#sidebarTip_more').slideDown('fast');
929 $('#indicator').html('[-]');
931 $('#sidebarTip_more').slideUp('fast');
932 $('#indicator').html('[+]');
934 $("#sidebarTip [contenteditable]").live('focusout',function(){
935 var $this = $("#sidebarTip [contenteditable]");
938 {Tip_Title: $this.eq(0).text()+' ',Tip_Content:$this.eq(1).text()+' ',Tip_More:$this.eq(2).text()+' '},
940 if(msg == 'unsecured'){
941 updateSentTip('Fail to save your tip for the security issues!',3e3,'failure');
942 }else if(msg == 'error'){
943 updateSentTip('Fail to save your tip! Please try again later!',3e3,'failure');
945 updateSentTip('Successfully save your tip!',3e3,'success');
950 $("#sidebarTip #tip_reset").live('click',function(e){
952 if(window.confirm('Are you sure to restore to default tips?')){
958 updateSentTip('Successfully restore to the default tips!',3e3,'success');
961 updateSentTip('Fail to save your tip! Please try again later!',3e3,'failure');
967 $("#profileRefresh").click(function(e){
970 if (!that.hasClass('refreshing')){
971 that.addClass('refreshing');
973 url: "ajax/updateProfile.php",
976 success: function(msg){
977 if (msg.result == 'success'){
979 updateSentTip("Profile updated successfully!",3e3,"success");
982 updateSentTip("Failed to update your profile!",3e3,"failure");
985 error: function (msg){
986 updateSentTip("Failed to update your profile!",3e3,"failure");
988 complete: function(){
989 that.removeClass('refreshing');
998 $("#trends_title").toggle(
1000 $("#trends_title").removeClass().addClass("loading");
1003 $("#trends_title").removeClass();
1004 $("#trend_entries").slideUp("fast");
1007 $("#following_title").toggle(
1009 $("#following_title").removeClass().addClass("loading");
1010 sidebarscroll('pause');
1013 $("#following_title").removeClass();
1014 $("#following_list").slideUp("fast");
1017 $("#apiquota_title").toggle(
1019 $("#apiquota_title").removeClass().addClass("loading");
1020 sidebarscroll('pause');
1023 $("#apiquota_title").removeClass();
1024 $("#apiquota_list").slideUp("fast");
1028 function updateTrends(){
1029 sidebarscroll('pause');
1030 if (navigator.geolocation) {
1031 if ($.cookie('woeid') == undefined) {
1032 navigator.geolocation.getCurrentPosition(function (pos, error) {
1034 url: "ajax/updateTrends.php?lat=" + pos.coords.latitude + "&long=" + pos.coords.longitude,
1036 success: function (msg){
1037 if ($.trim(msg).indexOf("</ul>" > 0)){
1038 $("#trend_entries").html(msg);
1040 $("#trends_title").removeClass().addClass("open");
1041 $("#trend_entries").slideDown("fast");
1047 url: "ajax/updateTrends.php",
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 function updateFollowing(){
1062 url: "ajax/updateFollowing.php",
1064 success: function (msg){
1065 if ($.trim(msg).indexOf("</span>" > 0)){
1066 $("#following_list").html(msg);
1068 $("#following_title").removeClass().addClass("open");
1069 $("#following_list").slideDown("fast");
1073 function updateAPIQuota(){
1075 url: "ajax/apiQuota.php",
1077 success: function (msg){
1078 if ($.trim(msg).indexOf("</span>" > 0)){
1079 $("#apiquota_list").html(msg);
1081 $("#apiquota_title").removeClass().addClass("open");
1082 $("#apiquota_list").slideDown("fast");
1086 $(window).load(function(){
1087 var scrollTo = function (top,duration,callback){
1090 var currentTop = w.scrollTop();
1091 var offset = (currentTop - top) / (duration * FPS / 1000);
1093 var prevTop = currentTop;
1094 var t = setInterval(function (){
1095 if ((prevTop - top) * (currentTop - top) <= 0){
1097 currentTop = prevTop = top;
1099 if (callback) callback();
1101 prevTop = currentTop;
1102 w.scrollTop(currentTop -= offset);
1106 var scrollToTop = function(){
1107 scrollTo(0,200,function (){
1108 scrollTo(30,50,function (){
1113 var scrollToBottom = function(){
1114 var height = document.body.clientHeight;
1115 scrollTo(height,200,function (){
1116 scrollTo(height+30,50,function (){
1117 scrollTo(height,50);
1121 $('body').dblclick(function (){
1123 $("#textbox").focus();
1125 $('#content').dblclick(function (e){
1126 e.stopPropagation();
1128 var hkFadeIn = function(text){
1129 $("#shortcutTip").fadeIn("fast").html(text);
1131 var hkFadeOut = function(){
1132 setTimeout(function (){$("#shortcutTip").fadeOut("fast");},2000);
1135 var hotkeyHandler = function(code){
1137 case 82: // R - refresh
1138 hkFadeIn("Refresh");
1142 case 67: // C - focus textbox
1144 hkFadeIn("Compose");
1145 scrollTo(0,1,function (){
1146 $("#textbox").focus();
1150 case 66: // B - scroll to bottom
1155 case 84: // T - scroll to top
1160 case 83: // S - search
1162 $("#sidepost").animate({backgroundColor: "#FF6347"},500,function(){
1163 $("#header_search_query").focus();
1164 $("#sidepost").animate({backgroundColor: $("#side_base").css("background-color")},1000);
1170 $(document).keydown(function(e){
1171 var tag = e.target.tagName;
1172 if(tag === "BODY" || tag === "HTML"){
1173 if(!e.altKey && !e.shiftKey && !e.ctrlKey && !e.metaKey){
1174 hotkeyHandler(e.keyCode);
1178 $("#statuses .big-retweet-icon,#func_set .func_btn,#profileRefresh").tipsy({
1181 $('#symbols span').tipsy({
1182 gravity: $.fn.tipsy.autoNS
1184 $("#statuses .mine").live("mouseout",function (e){
1185 $(e.target).removeClass("mine").addClass("myTweet");
1188 //init global functions
1189 $(document).ready(function (){
1191 $("#primary_nav li a").click(function (e){
1192 $(e.target).each(function (){
1193 if ($(this).hasClass("active")){
1194 $(this).removeClass()
1197 $(this).removeClass().addClass("active").css("background","transparent url('../img/spinner.gif') no-repeat scroll 173px center")
1199 $("#avatar,#sideimg").lazyload({threshold:100,effect:"fadeIn",placeholder:"img/blank.gif"});
1202 var freshProfile = function(){
1203 $("#side_name").text($.cookie('name'));
1204 $.cookie('name',null);
1205 $("span.count").eq(0).text($.cookie('friends_count')).end()
1206 .eq(1).text($.cookie('followers_count')).end()
1207 .eq(2).text($.cookie('listed_count'));
1208 $("#update_count").text($.cookie('statuses_count'));
1209 $('#sideimg').attr("src",$.cookie('imgurl'));
1211 var markReply = function(obj){
1212 var sidename = "@"+$("#side_name").text().toLowerCase();
1213 obj.each(function (i,o){
1214 if ($(this).find("> span").find('.tweet').text().toLowerCase().indexOf(sidename) > -1){
1215 $(this).addClass("reply");