OSDN Git Service

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