OSDN Git Service

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