OSDN Git Service

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