OSDN Git Service

eccaa4578eb9ce3e743fa59d4866e9e82ee48824
[embrj/master.git] / js / list.js
1 $(function(){\r
2         $(".rt_btn").click(function(e){\r
3                 e.preventDefault();\r
4                 if ($("#textbox").length > 0) {\r
5                         onRT($(this));\r
6                 } else {\r
7                         $("#info_head").before('<h2>What are you doing?</h2>' + formHTML);\r
8                         formFunc();\r
9                         onRT($(this));\r
10                 }\r
11         });\r
12         \r
13         $(".replie_btn").click(function(e){\r
14                 e.preventDefault();\r
15                 if ($("#textbox").length > 0) {\r
16                         onReplie($(this));\r
17                 } else {\r
18                         $("#info_head").before('<h2>What are you doing?</h2>' + formHTML);\r
19                         formFunc();\r
20                         onReplie($(this));\r
21                 }\r
22         });\r
23 \r
24         $("#list_send_btn").click(function(e){\r
25                 e.preventDefault();\r
26                 if ($("#textbox").length == 0) {\r
27                         $("#info_head").before('<h2>What are you doing?</h2>' + formHTML);\r
28                 formFunc();\r
29                 }\r
30         });\r
31         \r
32         $(".favor_btn").live("click", function(e){\r
33                 e.preventDefault();\r
34                 onFavor($(this));\r
35         });\r
36 \r
37         $("#list_follow_btn").live("click", function(e){\r
38                 e.preventDefault();\r
39                 var $this = $(this);\r
40                 var id = $("#info_name").text();\r
41                 updateSentTip("Following list " + id + "...", 5000, "ing");\r
42                 \r
43                 $.ajax({\r
44                         url: "ajax/list.php",\r
45                         type: "POST",\r
46                         data: "action=create&id=" + id,\r
47                         success: function(msg) {\r
48                                 if (msg.indexOf("success") >= 0) {\r
49                                         updateSentTip("You have followed " + id + ".", 3000, "success");\r
50                                         $this.after('<a class="info_btn_hover" id="list_block_btn" href="javascript:void(0)">Unfollow</a>');\r
51                                         $this.remove();\r
52                                 } else {\r
53                                         updateSentTip("Failed to follow list " + id + ".", 3000, "failure");\r
54                                 }\r
55                         },\r
56                         error: function(msg) {\r
57                                 updateSentTip("Failed to follow list " + id + ".", 3000, "failure");\r
58                         }\r
59                 });\r
60         });\r
61         \r
62         \r
63         $("#list_block_btn").live("click", function(e){\r
64                 e.preventDefault();\r
65                 var $this = $(this);\r
66                 var id = $("#info_name").text();\r
67                 updateSentTip("Unfollowing list " + id + "...");\r
68                 $.ajax({\r
69                         url: "ajax/list.php",\r
70                         type: "POST",\r
71                         data: "action=destory&id=" + id,\r
72                         success: function(msg) {\r
73                                 if (msg.indexOf("success") >= 0) {\r
74                                         updateSentTip("You have unfollowed list " + id + ".", 3000, "success");\r
75                                         $this.after('<a class="info_btn" id="list_follow_btn" href="javascript:void(0)">Unfollow</a>');\r
76                                         $this.remove();\r
77                                 } else {\r
78                                         updateSentTip("Failed to unfollow list " + id + ".", 3000, "failure");\r
79                                 }\r
80                         },\r
81                         error: function(msg) {\r
82                                 updateSentTip("Failed to unfollow list " + id + ".", 3000, "failure");\r
83                         }\r
84                 });\r
85                 \r
86         });\r
87         \r
88         document.onclick = function(){\r
89                 document.title =document.title.replace(/(\([0-9]+\))/g, "");\r
90         }\r
91         var args = location.href.split("?")[1]; \r
92         if (!args.split("&")[1] || args.split("&")[1] == "p=1") {\r
93                 setInterval(function(){\r
94                                 update();\r
95                 }, 2000*60);\r
96         }\r
97 });\r
98 \r
99 function update() {\r
100         var since_id = $(".timeline li:first-child").find(".status_id").text();\r
101         var list_id = $("#info_name").text();\r
102         $.ajax({\r
103                 url: "ajax/updateList.php",\r
104                 type: "GET",\r
105                 dataType: "text",\r
106                 data: "id=" + list_id + "&since_id=" + since_id,\r
107                 success: function(msg) {\r
108                         \r
109                         if ($.trim(msg).indexOf("</li>") > 0) {\r
110                                 $(".timeline").prepend(msg);\r
111                                 var num = 0;\r
112                                 if (document.title.match(/\d+/) != null) {\r
113                                         num = parseInt(document.title.match(/\d+/));\r
114                                 }\r
115                                 document.title = "(" + (num+$(msg).length )+ ")" + document.title.replace(/(\([0-9]+\))/g, "");\r
116                         }\r
117                         \r
118                 }\r
119         });\r
120 }