OSDN Git Service

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