OSDN Git Service

f0370a06d33d1a041def81c8b4f8cdfb6256e5f2
[embrj/master.git] / js / user.js
1 $(function(){\r
2         $("#allTimeline").click(function(e) {\r
3                 var $this = $(e.target);\r
4                 var type = $this.attr('class');\r
5                 switch(type) {\r
6                         case 'rt_btn':\r
7                                 e.preventDefault();\r
8                                 if ($("#textbox").length > 0) {\r
9                                         onInfoRT($this);\r
10                                 } else {\r
11                                         $("#info_head").after('<h2>What\'s happening?</h2>' + formHTML);\r
12                                         formFunc();\r
13                                         onInfoRT($this);\r
14                                 }\r
15                                 break;\r
16                         case 'retw_btn':\r
17                                 e.preventDefault();\r
18                                 onNwRT($this);\r
19                                 break;\r
20                         case 'replie_btn':\r
21                                 e.preventDefault();\r
22                                 var replie_id = $this.parent().parent().find(".status_word").find(".user_name").text();\r
23                                 if ($("#textbox").length > 0) {\r
24                                         onInfoReplie($this,e);\r
25                                 } else {\r
26                                         $("#info_head").after('<h2>In reply to ' + replie_id + '</h2>' + formHTML);\r
27                                         formFunc();\r
28                                         onInfoReplie($this,e);\r
29                                 }\r
30                                 break;\r
31                         case 'favor_btn':\r
32                                 e.preventDefault();\r
33                                 onFavor($this);\r
34                                 break;\r
35                         case 'unfav_btn':\r
36                                 e.preventDefault();\r
37                                 UnFavor($this);\r
38                                 break;\r
39                         case 'rt_undo':\r
40                                 e.preventDefault();\r
41                                 onUndoRt($this);\r
42                                 break;\r
43                 }\r
44         });\r
45 \r
46         $("#info_reply_btn").click(function(){\r
47                 var replie_id = $("#info_name").text();\r
48                 if ($("#textbox").length > 0) {\r
49                         $("#textbox").val($("#textbox").val() + "@" + replie_id + " ");\r
50                         $("#textbox").focus();\r
51                         leaveWord();\r
52                 } else {\r
53                         $("#info_head").after('<h2>In reply to ' + replie_id + '</h2>' + formHTML);\r
54                         formFunc();\r
55                         $("#textbox").val($("#textbox").val() + "@" + replie_id + " ");\r
56                         $("#textbox").focus();\r
57                         leaveWord();\r
58                 }\r
59         });\r
60         if (getCookie("infoShow") == "hide") {\r
61                 onHide();\r
62         }\r
63         $("#info_hide_btn").click(function(){\r
64                 onHide();\r
65         });\r
66 \r
67         $("#info_follow_btn").click(function(e){\r
68                 e.preventDefault();\r
69                 var $this = $(this);\r
70                 var id = $("#info_name").text();\r
71                 updateSentTip("Following " + id + "...", 5000, "ing");\r
72                 $.ajax({\r
73                         url: "ajax/relation.php",\r
74                         type: "POST",\r
75                         data: "action=create&id=" + id,\r
76                         success: function(msg) {\r
77                                 if (msg.indexOf("success") >= 0) {\r
78                                         updateSentTip("You have followed " + id + "!", 3000, "success");\r
79                                         $this.after('<a class="btn btn-red" id="info_block_btn" href="javascript:void(0)">Unfollow</a>');\r
80                                         $this.remove();\r
81                                         if($('#unblock') != null){\r
82                                                 $('#unblock').after('<a class="btn" id="block_btn" href="javascript:void(0)">Block</a>');\r
83                                                 $('#unblock').remove();\r
84                                         }\r
85                                 } else {\r
86                                         updateSentTip("Failed to follow " + id + ", please try again.", 3000, "failure");\r
87                                 }\r
88                         },\r
89                         error: function(msg) {\r
90                                 updateSentTip("Failed to follow " + id + ", please try again.", 3000, "failure");\r
91                         }\r
92                 });\r
93         });\r
94 \r
95         $("#info_block_btn").click(function(e){\r
96                 e.preventDefault();\r
97                 var $this = $(this);\r
98                 var id = $("#info_name").text();\r
99                 if (confirm("Are you sure to unfollow " + id + " ?")) {\r
100                 updateSentTip("Unfollowing " + id + "...", 5000, "ing");\r
101                 $.ajax({\r
102                         url: "ajax/relation.php",\r
103                         type: "POST",\r
104                         data: "action=destory&id=" + id,\r
105                         success: function(msg) {\r
106                                 if (msg.indexOf("success") >= 0) {\r
107                                         updateSentTip("You have unfollowed " + id + "!", 3000, "success");\r
108                                         $this.after('<a class="btn btn-green" id="info_follow_btn" href="javascript:void(0)">Follow</a>');\r
109                                         $this.remove();\r
110                                 } else {\r
111                                         updateSentTip("Failed to unfollow " + id + ", please try again.", 3000, "failure");\r
112                                 }\r
113                         },\r
114                         error: function(msg) {\r
115                                 updateSentTip("Failed to unfollow " + id + ", please try again.", 3000, "failure");\r
116                         }\r
117                 });\r
118                 }\r
119         });\r
120 \r
121         $("#block_btn").click(function(e){\r
122                 e.preventDefault();\r
123                 var $this = $(this);\r
124                 var id = $("#info_name").text();\r
125                 if (confirm("Are you sure to block " + id + " ?")) {\r
126                         updateSentTip("Blocking " + id + "...", 5000, "ing");\r
127                         $.ajax({\r
128                                 url: "ajax/relation.php",\r
129                                 type: "POST",\r
130                                 data: "action=block&id=" + id,\r
131                                 success: function(msg) {\r
132                                         if (msg.indexOf("success") >= 0) {\r
133                                                 updateSentTip("You have blocked " + id + "!", 3000, "success");\r
134                                                 $this.after('<a class="btn" id="unblock_btn" href="javascript:void(0)">Unblock</a>');\r
135                                                 $this.remove();\r
136                                                 if($('#info_block_btn') != null){\r
137                                                         $('#info_block_btn').after('<a class="btn btn-green" id="info_follow_btn" href="javascript:void(0)">Follow</a>');\r
138                                                         $('#info_block_btn').remove();\r
139                                                 }\r
140                                         } else {\r
141                                                 updateSentTip("Failed to block " + id + ", please try again.", 3000, "failure");\r
142                                         }\r
143                                 },\r
144                                 error: function(msg) {\r
145                                         updateSentTip("Failed to block " + id + ", please try again.", 3000, "failure");\r
146                                 }\r
147                         });\r
148                 }\r
149         });\r
150 \r
151         $("#unblock_btn").click(function(e){\r
152                 e.preventDefault();\r
153                 var $this = $(this);\r
154                 var id = $("#info_name").text();\r
155                 if (confirm("Are you sure to unblock " + id + " ?")) {\r
156                         updateSentTip("Unblocking...", 5000, "ing");\r
157                         $.ajax({\r
158                                 url: "ajax/relation.php",\r
159                                 type: "POST",\r
160                                 data: "action=unblock&id=" + id,\r
161                                 success: function(msg) {\r
162                                         if (msg.indexOf("success") >= 0) {\r
163                                                 updateSentTip("Unblocked.", 3000, "success");\r
164                                                 $this.after('<a class="btn" id="block_btn" href="javascript:void(0)">Block</a>');\r
165                                                 $this.remove();\r
166                                         } else {\r
167                                                 updateSentTip("Failed to unblock, please try again.", 3000, "failure");\r
168                                         }\r
169                                 },\r
170                                 error: function(msg) {\r
171                                         updateSentTip("Failed to unblock, please try again.", 3000, "failure");\r
172                                 }\r
173                         });\r
174                 }\r
175         });\r
176         \r
177         $("#report_btn").click(function(e){\r
178                 e.preventDefault();\r
179                 var $this = $(this);\r
180                 var id = $("#info_name").text();\r
181                 if (confirm("Are you sure to report " + id + " for spam?")) {\r
182                         updateSentTip("Reporting " + id + " for spam...", 5000, "ing");\r
183                         $.ajax({\r
184                                 url: "ajax/relation.php",\r
185                                 type: "POST",\r
186                                 data: "action=report&id=" + id,\r
187                                 success: function(msg) {\r
188                                         if (msg.indexOf("success") >= 0) {\r
189                                                 updateSentTip("You have reported " + id + " for spam!", 3000, "success");\r
190                                                 /*\r
191                                                 $this.after('<a class="btn" id="unblock_btn" href="javascript:void(0)">Unblock</a>');\r
192                                                 $this.remove();\r
193                                                 \r
194                                                 if($('#info_block_btn') != null){\r
195                                                         $('#info_block_btn').after('<a class="btn btn-green" id="info_follow_btn" href="javascript:void(0)">Follow</a>');\r
196                                                         $('#info_block_btn').remove();\r
197                                                 }\r
198                                                 */\r
199                                         } else {\r
200                                                 updateSentTip("Failed to report " + id + " for spam, please try again.", 3000, "failure");\r
201                                         }\r
202                                 },\r
203                                 error: function(msg) {\r
204                                         updateSentTip("Failed to report " + id + " for spam, please try again.", 3000, "failure");\r
205                                 }\r
206                         });\r
207                 }\r
208         });\r
209         $("#tweeting_button").click(function (e) {\r
210                 e.preventDefault();\r
211                 if ($("#textbox").val().length >0 ) {\r
212                         updateStatus();\r
213                 }               \r
214         });\r
215         \r
216 });\r
217 \r
218 function onInfoReplie($this) {\r
219         var replie_id = $("#info_name").text();\r
220         $("#textbox").val("@" + replie_id + " ");\r
221         $("#textbox").focus();\r
222         $("#in_reply_to").val($this.parent().parent().find(".status_id").text());\r
223         leaveWord();\r
224 }\r
225 \r
226 function onInfoRT($this) {\r
227         var replie_id = $("#info_name").text();\r
228         var status_word = $this.parent().parent().find(".status_word").clone();\r
229         status_word.find('.tweet a[rel=noreferrer]').each(function(){\r
230                 $(this).text($(this).attr('href'));\r
231         });\r
232         $("#textbox").focus().val(" RT @" + replie_id + ":" + status_word.text().replace(replie_id, "")).caret(0);\r
233         leaveWord();\r
234 }\r
235 function getCookie(name){\r
236         var strCookie=document.cookie;\r
237         var arrCookie=strCookie.split("; ");\r
238         for(var i=0;i<arrCookie.length;i++){\r
239                 var arr=arrCookie[i].split("=");\r
240                 if(arr[0]==name)return unescape(arr[1]);\r
241         }\r
242 return "";\r
243 }\r
244 function setCookie(name,value,expireHours){\r
245         var cookieString=name+"="+escape(value);\r
246         if(expireHours>0){\r
247                 var date=new Date();\r
248                 date.setTime(date.getTime+expireHours*3600*1000);\r
249                 cookieString=cookieString+"; expire="+date.toGMTString();\r
250         }\r
251         document.cookie=cookieString;\r
252\r
253 function onHide(){\r
254         $this = $("#info_hide_btn");\r
255         $this.after('<a class="btn" id="info_show_btn" href="javascript:void(0)">Show @</a>');\r
256         $this.remove();\r
257 \r
258         $("#info_show_btn").click(function(){\r
259                 $(".timeline li").each(function(i,o) {\r
260                         $(this).show();\r
261                 });\r
262                 $(this).after('<a class="btn" id="info_hide_btn" href="javascript:void(0)">Hide @</a>');\r
263                 $(this).remove();\r
264                 $("#info_hide_btn").live("click", function(){\r
265                         onHide();\r
266                 });\r
267                 setCookie("infoShow","show");\r
268         });\r
269 \r
270         $(".timeline li").each(function(i,o) {\r
271                 if ($(this).find(".status_word").text().indexOf("@") > -1) {\r
272                         $(this).hide();\r
273                 }\r
274         });\r
275         setCookie("infoShow","hide");\r
276 }