]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
disable simultaneous xmlhttp calls
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
1/*
2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
4*/
5
6var xmlhttp = false;
7
76798ff3
AD
8var total_unread = 0;
9
1cd17194
AD
10/*@cc_on @*/
11/*@if (@_jscript_version >= 5)
12// JScript gives us Conditional compilation, we can cope with old IE versions.
13// and security blocked creation of the objects.
14try {
15 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
16} catch (e) {
17 try {
18 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
19 } catch (E) {
20 xmlhttp = false;
21 }
22}
23@end @*/
24
25if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
26 xmlhttp = new XMLHttpRequest();
27}
28
175847de
AD
29function notify_callback() {
30 var container = document.getElementById('notify');
31 if (xmlhttp.readyState == 4) {
32 container.innerHTML=xmlhttp.responseText;
33 }
34}
35
1cd17194 36function feedlist_callback() {
d76a3b03 37 var container = document.getElementById('feeds');
1cd17194 38 if (xmlhttp.readyState == 4) {
d76a3b03 39 container.innerHTML=xmlhttp.responseText;
76798ff3
AD
40
41 var feedtu = document.getElementById("FEEDTU");
42
43 if (feedtu) {
44 total_unread = feedtu.innerHTML;
45 update_title();
46 }
476cac42
AD
47
48 notify("");
1cd17194
AD
49 }
50}
51
52function viewfeed_callback() {
d76a3b03 53 var container = document.getElementById('headlines');
1cd17194 54 if (xmlhttp.readyState == 4) {
d76a3b03 55 container.innerHTML = xmlhttp.responseText;
a1a8a2be
AD
56
57 var factive = document.getElementById("FACTIVE");
58 var funread = document.getElementById("FUNREAD");
59 var ftotal = document.getElementById("FTOTAL");
60
61 if (ftotal && factive && funread) {
62 var feed_id = factive.innerHTML;
63
64 var feedr = document.getElementById("FEEDR-" + feed_id);
65 var feedt = document.getElementById("FEEDT-" + feed_id);
66 var feedu = document.getElementById("FEEDU-" + feed_id);
67
68 feedt.innerHTML = ftotal.innerHTML;
69 feedu.innerHTML = funread.innerHTML;
70
71 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
72 feedr.className = feedr.className + "Unread";
73 } else if (feedu.innerHTML <= 0) {
74 feedr.className = feedr.className.replace("Unread", "");
75 }
76
77 }
1c37c607
AD
78
79 notify("");
80
81 }
1cd17194
AD
82}
83
84function view_callback() {
d76a3b03 85 var container = document.getElementById('content');
1cd17194 86 if (xmlhttp.readyState == 4) {
d76a3b03 87 container.innerHTML=xmlhttp.responseText;
1cd17194
AD
88 }
89}
90
91
476cac42 92function updateFeedList(called_from_timer, fetch) {
076682aa 93
40d13c28 94 if (called_from_timer != true) {
476cac42
AD
95 //document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
96 notify("Updating feeds...");
40d13c28 97 }
82baad4a 98
331900c6
AD
99 var query_str = "backend.php?op=feeds";
100
101 if (fetch) query_str = query_str + "&fetch=yes";
102
076682aa
AD
103 if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
104 xmlhttp.open("GET", query_str, true);
105 xmlhttp.onreadystatechange=feedlist_callback;
106 xmlhttp.send(null);
107 } else {
108 notify("Please wait until operation finishes.");
109 }
1cd17194
AD
110}
111
175847de
AD
112function catchupPage(feed) {
113
076682aa
AD
114 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
115 notify("Please wait until operation finishes.");
116 return
117 }
118
175847de
AD
119 var content = document.getElementById("headlinesList");
120
121 var rows = new Array();
122
123 for (i = 0; i < content.rows.length; i++) {
124 var row_id = content.rows[i].id.replace("RROW-", "");
125 if (row_id.length > 0) {
126 rows.push(row_id);
127 content.rows[i].className = content.rows[i].className.replace("Unread", "");
128 }
129 }
130
131 var feedr = document.getElementById("FEEDR-" + feed);
132 var feedu = document.getElementById("FEEDU-" + feed);
133
134 feedu.innerHTML = feedu.innerHTML - rows.length;
135
136 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
137 feedr.className = feedr.className + "Unread";
138 } else if (feedu.innerHTML <= 0) {
139 feedr.className = feedr.className.replace("Unread", "");
140 }
141
142 var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" +
143 param_escape(rows.toString());
144
145 notify("Marking this page as read...");
146
147 xmlhttp.open("GET", query_str, true);
148 xmlhttp.onreadystatechange=notify_callback;
149 xmlhttp.send(null);
150
151}
152
476cac42 153function catchupAllFeeds() {
076682aa
AD
154
155 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
156 notify("Please wait until operation finishes.");
157 return
158 }
476cac42
AD
159 var query_str = "backend.php?op=feeds&subop=catchupAll";
160
161 notify("Marking all feeds as read...");
162
163 xmlhttp.open("GET", query_str, true);
164 xmlhttp.onreadystatechange=feedlist_callback;
165 xmlhttp.send(null);
166
167}
1cd17194 168
476cac42 169function viewfeed(feed, skip, subop) {
1cd17194 170
1c37c607
AD
171// document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
172// document.getElementById('content').innerHTML='&nbsp;';
d76a3b03 173
076682aa
AD
174 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
175 notify("Please wait until operation finishes.");
176 return
177 }
178
d76a3b03 179 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
476cac42 180 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
1cd17194
AD
181 xmlhttp.onreadystatechange=viewfeed_callback;
182 xmlhttp.send(null);
183
1c37c607
AD
184 notify("Loading headlines...");
185
1cd17194
AD
186}
187
a1a8a2be 188function view(id,feed_id) {
d76a3b03 189
076682aa
AD
190 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
191 notify("Please wait until operation finishes.");
192 return
193 }
194
d76a3b03
AD
195 var crow = document.getElementById("RROW-" + id);
196
a1a8a2be
AD
197 if (crow.className.match("Unread")) {
198 var umark = document.getElementById("FEEDU-" + feed_id);
199 umark.innerHTML = umark.innerHTML - 1;
d76a3b03 200 crow.className = crow.className.replace("Unread", "");
d76a3b03 201
a1a8a2be
AD
202 if (umark.innerHTML == "0") {
203 var feedr = document.getElementById("FEEDR-" + feed_id);
204 feedr.className = feedr.className.replace("Unread", "");
205 }
b197f117 206
76798ff3
AD
207 total_unread--;
208
b197f117 209 update_title();
76798ff3 210 }
1cd17194 211
b197f117
AD
212 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
213
214 if (upd_img_pic) {
215 upd_img_pic.innerHTML = "";
216 }
217
d76a3b03 218 document.getElementById('content').innerHTML='Loading, please wait...';
1cd17194 219
d76a3b03 220 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
1cd17194
AD
221 xmlhttp.onreadystatechange=view_callback;
222 xmlhttp.send(null);
223
224}
225
40d13c28
AD
226function timeout() {
227
5d348fee 228 updateFeedList(true, true);
40d13c28 229
ac53063a
AD
230 setTimeout("timeout()", 1800*1000);
231
232}
233
234function search(feed, sender) {
235
076682aa
AD
236 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
237 notify("Please wait until operation finishes.");
238 return
239 }
240
ac53063a
AD
241 notify("Search: " + feed + ", " + sender.value)
242
243 document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
244 document.getElementById('content').innerHTML='&nbsp;';
245
246 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
247 "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
248 xmlhttp.onreadystatechange=viewfeed_callback;
249 xmlhttp.send(null);
40d13c28
AD
250
251}
252
76798ff3
AD
253function update_title() {
254 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
255}
1cd17194 256
76798ff3 257function init() {
476cac42 258 updateFeedList(false, false);
ac53063a 259 setTimeout("timeout()", 1800*1000);
1cd17194 260}