OSDN Git Service

embr
[embrj/master.git] / js / all.js
1 var INTERVAL_COOKIE = 'updatesInterval';
2 $(function () {
3                 formFunc();
4                 $("ol.timeline").click(function(e) {
5                         var $this = $(e.target);
6                         var type = $this.attr('class');
7                         switch(type) {
8                                 case 'rt_btn':
9                                         e.preventDefault();
10                                         onRT($this);
11                                         break;
12                                 case 'retw_btn':
13                                         e.preventDefault();
14                                         onNwRT($this);
15                                         break;
16                                 case 'replie_btn':
17                                         e.preventDefault();
18                                         onReplie($this,e);
19                                         break;
20                                 case 'favor_btn':
21                                         e.preventDefault();
22                                         onFavor($this);
23                                         break;
24                                 case 'unfav_btn':
25                                         e.preventDefault();
26                                         UnFavor($this);
27                                         break;
28                                 case 'delete_btn':
29                                         e.preventDefault();
30                                         onDelete($this);
31                                         break;
32                                 case 'rt_undo':
33                                         e.preventDefault();
34                                         onUndoRt($this);
35                                         break;
36                                 case 'msg_replie_btn':
37                                         e.preventDefault();
38                                         onReplieDM($this);
39                                         break;
40                                 case 'msg_delete_btn':
41                                         e.preventDefault();
42                                         onDeleteMsg($this);
43                                         break;
44                         }
45                 });
46                 markReply($("#allTimeline > li"));
47                 $("#submit_btn").click(function (e) {
48                                 updateStatus();
49                                 e.preventDefault();
50                         });
51                 document.onclick = function () {
52                         document.title = document.title.replace(/(\([0-9]+\))/g, "");
53                         $(".allHighLight").text($(".allHighLight").text().replace(/(\([0-9]+\))/g, ""));
54                         $("#statuses .new").each(function () {
55                                         $("#statuses .new").remove();
56                                 });
57                 }
58                 $("#allReplies").hide();
59                 $("#allMessage").hide();
60                 $("#allTimelineBtn").click(function () {
61                                 $("#allTimeline").show();
62                                 $("#allTimeline img").lazyload({threshold : 100, effect : "fadeIn", placeholder:'img/blank.gif'});
63                                 $("#allReplies").hide();
64                                 $("#allMessage").hide();
65                                 $("#allTimelineBtn").addClass("allHighLight");
66                                 if ($("#allRepliesBtn").hasClass("allHighLight")) $("#allRepliesBtn").removeClass("allHighLight");
67                                 else $("#allMessageBtn").removeClass("allHighLight");
68                                 $("#allTimelineBtn").text($("#allTimelineBtn").text().replace(/(\([0-9]+\))/g, ""));
69                         })
70                 $("#allRepliesBtn").click(function () {
71                                 $("#allTimeline").hide();
72                                 $("#allReplies").show();
73                                 $("#allReplies img").lazyload({threshold : 100, effect : "fadeIn",placeholder:'img/blank.gif'});
74                                 $("#allMessage").hide();
75                                 $("#allRepliesBtn").addClass("allHighLight");
76                                 if ($("#allTimelineBtn").hasClass("allHighLight")) $("#allTimelineBtn").removeClass("allHighLight");
77                                 else $("#allMessageBtn").removeClass("allHighLight");
78                                 $("#allRepliesBtn").text($("#allRepliesBtn").text().replace(/(\([0-9]+\))/g, ""));
79                         })
80                 $("#allMessageBtn").click(function () {
81                                 $("#allTimeline").hide();
82                                 $("#allReplies").hide();
83                                 $("#allMessage").show();
84                                 $("#allMessage img").lazyload({threshold : 100, effect : "fadeIn",placeholder:'img/blank.gif'});
85                                 $("#allMessageBtn").addClass("allHighLight");
86                                 if ($("#allRepliesBtn").hasClass("allHighLight")) $("#allRepliesBtn").removeClass("allHighLight");
87                                 else $("#allTimelineBtn").removeClass("allHighLight");
88                                 $("#allMessageBtn").text($("#allMessageBtn").text().replace(/(\([0-9]+\))/g, ""));
89                                 $("#allMessage span.date").timeago();
90                         })
91                 $(function () {
92                                 setUpdateInterval();
93                         });
94         });
95 var setUpdateInterval = function () {
96         if (!location.href.split("?")[1] || location.href.split("?")[1] == "p=1") {
97                 var interval = parseFloat($.cookie(INTERVAL_COOKIE));
98                 if (interval === 0.0) {
99                         return false;
100                 }
101                 interval = interval > 0 ? interval : 3;
102                 UPDATE_INTERVAL = setInterval(function () {
103                                 update();
104                         }, interval * 1000 * 60);
105         }
106 };
107
108 function update() {
109         if (PAUSE_UPDATE === true) {
110                 window.setTimeout(update, 5000);
111         } else if (PAUSE_TIMELINE === true) {
112                 return 0;
113         } else {
114                 if($.cookie("intervalChanged") === "true"){
115                         clearInterval(UPDATE_INTERVAL);
116                         $.cookie("intervalChanged", "")
117                         setUpdateInterval();
118                 }
119                 updateSentTip('Retrieving new tweets...', 5000, 'ing');
120                 updateFunc("timeline");
121                 updateFunc("replies");
122                 updateFunc("message");
123         }
124 }
125
126 function updateFunc(type, name, pw) {
127         PAUSE_TIMELINE = true;
128         var div, url, btnDiv, param;
129         switch (type) {
130         case "timeline":
131                 div = "#allTimeline";
132                 btnDiv = "#allTimelineBtn";
133                 url = "ajax/updateTimeline.php";
134                 $(div + " li.mine").removeClass("mine").addClass("myTweet");
135                 break;
136         case "replies":
137                 div = "#allReplies";
138                 btnDiv = "#allRepliesBtn";
139                 url = "ajax/updateReplies.php";
140                 break;
141         case "message":
142                 div = "#allMessage";
143                 btnDiv = "#allMessageBtn";
144                 url = "ajax/updateMessage.php";
145                 break;
146         }
147         var since_id = 0;
148         if (div === "#allTimeline") {
149                 since_id = $(div + " li:not(.myTweet):not(#ajax_statuses li):first").find("span.status_id").text();
150         } else {
151                 since_id = $(div + " li:first-child").find("span.status_id").text();
152         }
153         $.ajax({
154                 url: url,
155                 type: "GET",
156                 dataType: "text",
157                 data: "since_id=" + since_id,
158                 success: function (msg) {
159                         if ($.trim(msg).indexOf("</li>") > 0) {
160                                 var source = $(msg).prependTo(div);
161                                 if (div === "#allTimeline") {
162                                         $(div + " li.myTweet:not(:first)").removeClass("myTweet");
163                                         markReply($('#allTimeline > li'));
164                                 }
165                                 var num = 0;
166                                 var navNum = 0;
167                                 if (document.title.match(/\d+/) != null) {
168                                         num = parseInt(document.title.match(/\d+/));
169                                 }
170                                 var len = $(msg).length - 1;
171                                 document.title = "(" + (num + len) + ") " + document.title.replace(/(\([0-9]+\))/g, "");
172                                 if ($(btnDiv).text().match(/\d+/) != null) {
173                                         navNum = parseInt($(btnDiv).text().match(/\d+/));
174                                 }
175                                 $(btnDiv).text($(btnDiv).text().replace(/(\([0-9]+\))/g, "") + "(" + (navNum + len) + ")");
176                                 filterEle();
177                                 embrTweet(source);
178                                 if($("div.new").length == 1) {
179                                         $("div.new").show().slideDown("fast");
180                                 } else {
181                                         $("div.new").filter(":first").remove();
182                                         $("span.tweetcount").filter(":last").text(navNum + len);
183                                 }
184                                 $("span.big-retweet-icon").tipsy({
185                                                 gravity: 's'
186                                         });
187                                 previewMedia(source);
188                         }
189                         PAUSE_TIMELINE = false;
190                 },
191                 error: function (msg) {
192                         PAUSE_TIMELINE = false;
193                 }
194         });
195 }