]>
Commit | Line | Data |
---|---|---|
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 | ||
6 | var xmlhttp = false; | |
525116d4 | 7 | var xmlhttp_rpc = false; |
1cd17194 | 8 | |
76798ff3 | 9 | var total_unread = 0; |
525116d4 | 10 | var first_run = true; |
76798ff3 | 11 | |
9cfc649a AD |
12 | var active_post_id = false; |
13 | var active_feed_id = false; | |
14 | ||
1cd17194 AD |
15 | /*@cc_on @*/ |
16 | /*@if (@_jscript_version >= 5) | |
17 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
18 | // and security blocked creation of the objects. | |
19 | try { | |
20 | xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); | |
21 | } catch (e) { | |
22 | try { | |
23 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
508a81e1 | 24 | xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); |
1cd17194 AD |
25 | } catch (E) { |
26 | xmlhttp = false; | |
508a81e1 | 27 | xmlhttp_rpc = false; |
1cd17194 AD |
28 | } |
29 | } | |
30 | @end @*/ | |
31 | ||
32 | if (!xmlhttp && typeof XMLHttpRequest!='undefined') { | |
33 | xmlhttp = new XMLHttpRequest(); | |
525116d4 AD |
34 | xmlhttp_rpc = new XMLHttpRequest(); |
35 | ||
1cd17194 AD |
36 | } |
37 | ||
1cd17194 | 38 | function feedlist_callback() { |
d76a3b03 | 39 | var container = document.getElementById('feeds'); |
1cd17194 | 40 | if (xmlhttp.readyState == 4) { |
d76a3b03 | 41 | container.innerHTML=xmlhttp.responseText; |
76798ff3 | 42 | |
c3b81db0 AD |
43 | // var feedtu = document.getElementById("FEEDTU"); |
44 | // if (feedtu) { | |
45 | // total_unread = feedtu.innerHTML; | |
46 | // update_title(); | |
47 | // } | |
476cac42 | 48 | |
525116d4 | 49 | if (first_run) { |
cb246176 | 50 | scheduleFeedUpdate(false); |
525116d4 AD |
51 | first_run = false; |
52 | } else { | |
53 | notify(""); | |
54 | } | |
1cd17194 AD |
55 | } |
56 | } | |
57 | ||
58 | function viewfeed_callback() { | |
d76a3b03 | 59 | var container = document.getElementById('headlines'); |
1cd17194 | 60 | if (xmlhttp.readyState == 4) { |
d76a3b03 | 61 | container.innerHTML = xmlhttp.responseText; |
a1a8a2be AD |
62 | |
63 | var factive = document.getElementById("FACTIVE"); | |
64 | var funread = document.getElementById("FUNREAD"); | |
65 | var ftotal = document.getElementById("FTOTAL"); | |
66 | ||
67 | if (ftotal && factive && funread) { | |
68 | var feed_id = factive.innerHTML; | |
69 | ||
70 | var feedr = document.getElementById("FEEDR-" + feed_id); | |
71 | var feedt = document.getElementById("FEEDT-" + feed_id); | |
72 | var feedu = document.getElementById("FEEDU-" + feed_id); | |
73 | ||
74 | feedt.innerHTML = ftotal.innerHTML; | |
75 | feedu.innerHTML = funread.innerHTML; | |
76 | ||
77 | if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) { | |
78 | feedr.className = feedr.className + "Unread"; | |
79 | } else if (feedu.innerHTML <= 0) { | |
80 | feedr.className = feedr.className.replace("Unread", ""); | |
81 | } | |
82 | ||
83 | } | |
1c37c607 AD |
84 | |
85 | notify(""); | |
86 | ||
87 | } | |
1cd17194 AD |
88 | } |
89 | ||
90 | function view_callback() { | |
d76a3b03 | 91 | var container = document.getElementById('content'); |
1cd17194 | 92 | if (xmlhttp.readyState == 4) { |
d76a3b03 | 93 | container.innerHTML=xmlhttp.responseText; |
1cd17194 AD |
94 | } |
95 | } | |
96 | ||
525116d4 AD |
97 | function refetch_callback() { |
98 | if (xmlhttp_rpc.readyState == 4) { | |
c3b81db0 AD |
99 | notify("All feeds updated"); |
100 | ||
101 | var container = document.getElementById('feeds'); | |
102 | ||
103 | container.innerHTML = xmlhttp_rpc.responseText; | |
104 | ||
55193822 AD |
105 | document.title = "Tiny Tiny RSS"; |
106 | ||
c3b81db0 | 107 | //updateFeedList(true, false); |
525116d4 AD |
108 | } |
109 | } | |
110 | ||
cb246176 | 111 | function scheduleFeedUpdate(force) { |
525116d4 AD |
112 | |
113 | notify("Updating feeds in background..."); | |
114 | ||
55193822 AD |
115 | document.title = "Tiny Tiny RSS - Updating..."; |
116 | ||
cb246176 AD |
117 | var query_str = "backend.php?op=rpc&subop="; |
118 | ||
119 | if (force) { | |
c3b81db0 | 120 | query_str = query_str + "forceUpdateAllFeeds"; |
cb246176 | 121 | } else { |
c3b81db0 | 122 | query_str = query_str + "updateAllFeeds"; |
cb246176 | 123 | } |
525116d4 AD |
124 | |
125 | if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) { | |
126 | xmlhttp_rpc.open("GET", query_str, true); | |
127 | xmlhttp_rpc.onreadystatechange=refetch_callback; | |
128 | xmlhttp_rpc.send(null); | |
129 | } else { | |
130 | printLockingError(); | |
131 | } | |
132 | } | |
1cd17194 | 133 | |
525116d4 | 134 | function updateFeedList(silent, fetch) { |
076682aa | 135 | |
525116d4 | 136 | if (silent != true) { |
11c2f3fa | 137 | notify("Loading feed list..."); |
40d13c28 | 138 | } |
82baad4a | 139 | |
331900c6 AD |
140 | var query_str = "backend.php?op=feeds"; |
141 | ||
142 | if (fetch) query_str = query_str + "&fetch=yes"; | |
143 | ||
076682aa AD |
144 | if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) { |
145 | xmlhttp.open("GET", query_str, true); | |
146 | xmlhttp.onreadystatechange=feedlist_callback; | |
147 | xmlhttp.send(null); | |
148 | } else { | |
a234aee5 | 149 | printLockingError(); |
076682aa | 150 | } |
1cd17194 AD |
151 | } |
152 | ||
175847de AD |
153 | function catchupPage(feed) { |
154 | ||
076682aa | 155 | if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { |
a234aee5 | 156 | printLockingError(); |
076682aa AD |
157 | return |
158 | } | |
159 | ||
175847de AD |
160 | var content = document.getElementById("headlinesList"); |
161 | ||
162 | var rows = new Array(); | |
163 | ||
164 | for (i = 0; i < content.rows.length; i++) { | |
165 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
166 | if (row_id.length > 0) { | |
cb0bd8bd AD |
167 | if (content.rows[i].className.match("Unread")) { |
168 | rows.push(row_id); | |
169 | content.rows[i].className = content.rows[i].className.replace("Unread", ""); | |
170 | } | |
175847de AD |
171 | } |
172 | } | |
173 | ||
cb0bd8bd | 174 | if (rows.length > 0) { |
175847de | 175 | |
cb0bd8bd AD |
176 | var feedr = document.getElementById("FEEDR-" + feed); |
177 | var feedu = document.getElementById("FEEDU-" + feed); | |
178 | ||
179 | feedu.innerHTML = feedu.innerHTML - rows.length; | |
180 | ||
181 | if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) { | |
182 | feedr.className = feedr.className + "Unread"; | |
183 | } else if (feedu.innerHTML <= 0) { | |
184 | feedr.className = feedr.className.replace("Unread", ""); | |
185 | } | |
186 | ||
187 | var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" + | |
188 | param_escape(rows.toString()); | |
189 | ||
190 | notify("Marking this page as read..."); | |
191 | ||
192 | xmlhttp.open("GET", query_str, true); | |
193 | xmlhttp.onreadystatechange=notify_callback; | |
194 | xmlhttp.send(null); | |
175847de | 195 | |
cb0bd8bd AD |
196 | } else { |
197 | notify("No unread items on this page."); | |
175847de | 198 | |
cb0bd8bd | 199 | } |
175847de AD |
200 | } |
201 | ||
476cac42 | 202 | function catchupAllFeeds() { |
076682aa AD |
203 | |
204 | if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { | |
a234aee5 | 205 | printLockingError(); |
076682aa AD |
206 | return |
207 | } | |
476cac42 AD |
208 | var query_str = "backend.php?op=feeds&subop=catchupAll"; |
209 | ||
210 | notify("Marking all feeds as read..."); | |
211 | ||
212 | xmlhttp.open("GET", query_str, true); | |
213 | xmlhttp.onreadystatechange=feedlist_callback; | |
214 | xmlhttp.send(null); | |
215 | ||
216 | } | |
1cd17194 | 217 | |
476cac42 | 218 | function viewfeed(feed, skip, subop) { |
1cd17194 | 219 | |
1c37c607 AD |
220 | // document.getElementById('headlines').innerHTML='Loading headlines, please wait...'; |
221 | // document.getElementById('content').innerHTML=' '; | |
d76a3b03 | 222 | |
076682aa | 223 | if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { |
a234aee5 | 224 | printLockingError(); |
076682aa AD |
225 | return |
226 | } | |
9cfc649a AD |
227 | |
228 | active_feed_id = feed; | |
229 | active_post_id = false; | |
076682aa | 230 | |
d76a3b03 | 231 | xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) + |
476cac42 | 232 | "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true); |
1cd17194 AD |
233 | xmlhttp.onreadystatechange=viewfeed_callback; |
234 | xmlhttp.send(null); | |
235 | ||
1c37c607 AD |
236 | notify("Loading headlines..."); |
237 | ||
1cd17194 AD |
238 | } |
239 | ||
9cfc649a AD |
240 | function cleanSelectedHeadlines() { |
241 | var content = document.getElementById("headlinesList"); | |
242 | ||
243 | var rows = new Array(); | |
244 | ||
245 | for (i = 0; i < content.rows.length; i++) { | |
246 | content.rows[i].className = content.rows[i].className.replace("Selected", ""); | |
247 | } | |
248 | ||
249 | } | |
250 | ||
a1a8a2be | 251 | function view(id,feed_id) { |
d76a3b03 | 252 | |
076682aa | 253 | if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { |
a234aee5 | 254 | printLockingError(); |
076682aa AD |
255 | return |
256 | } | |
257 | ||
d76a3b03 AD |
258 | var crow = document.getElementById("RROW-" + id); |
259 | ||
a1a8a2be AD |
260 | if (crow.className.match("Unread")) { |
261 | var umark = document.getElementById("FEEDU-" + feed_id); | |
262 | umark.innerHTML = umark.innerHTML - 1; | |
d76a3b03 | 263 | crow.className = crow.className.replace("Unread", ""); |
d76a3b03 | 264 | |
a1a8a2be AD |
265 | if (umark.innerHTML == "0") { |
266 | var feedr = document.getElementById("FEEDR-" + feed_id); | |
267 | feedr.className = feedr.className.replace("Unread", ""); | |
268 | } | |
9cfc649a | 269 | |
76798ff3 AD |
270 | total_unread--; |
271 | ||
b197f117 | 272 | update_title(); |
76798ff3 | 273 | } |
1cd17194 | 274 | |
9cfc649a AD |
275 | cleanSelectedHeadlines(); |
276 | ||
277 | crow.className = crow.className + "Selected"; | |
278 | ||
b197f117 AD |
279 | var upd_img_pic = document.getElementById("FUPDPIC-" + id); |
280 | ||
281 | if (upd_img_pic) { | |
282 | upd_img_pic.innerHTML = ""; | |
283 | } | |
284 | ||
d76a3b03 | 285 | document.getElementById('content').innerHTML='Loading, please wait...'; |
1cd17194 | 286 | |
9cfc649a AD |
287 | active_post_id = id; |
288 | ||
d76a3b03 | 289 | xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true); |
1cd17194 AD |
290 | xmlhttp.onreadystatechange=view_callback; |
291 | xmlhttp.send(null); | |
292 | ||
293 | } | |
294 | ||
40d13c28 AD |
295 | function timeout() { |
296 | ||
cb246176 | 297 | scheduleFeedUpdate(true); |
40d13c28 | 298 | |
ac53063a AD |
299 | setTimeout("timeout()", 1800*1000); |
300 | ||
301 | } | |
302 | ||
303 | function search(feed, sender) { | |
304 | ||
076682aa | 305 | if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { |
a234aee5 | 306 | printLockingError(); |
076682aa AD |
307 | return |
308 | } | |
309 | ||
ac53063a AD |
310 | notify("Search: " + feed + ", " + sender.value) |
311 | ||
312 | document.getElementById('headlines').innerHTML='Loading headlines, please wait...'; | |
313 | document.getElementById('content').innerHTML=' '; | |
314 | ||
315 | xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) + | |
97e98c11 | 316 | "&search=" + param_escape(sender.value) + "&subop=search", true); |
ac53063a AD |
317 | xmlhttp.onreadystatechange=viewfeed_callback; |
318 | xmlhttp.send(null); | |
40d13c28 AD |
319 | |
320 | } | |
321 | ||
76798ff3 AD |
322 | function update_title() { |
323 | //document.title = "Tiny Tiny RSS (" + total_unread + " unread)"; | |
324 | } | |
1cd17194 | 325 | |
13ad9102 AD |
326 | function localPiggieFunction(enable) { |
327 | if (enable) { | |
328 | var query_str = "backend.php?op=feeds&subop=piggie"; | |
329 | ||
330 | if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) { | |
331 | ||
332 | xmlhttp.open("GET", query_str, true); | |
333 | xmlhttp.onreadystatechange=feedlist_callback; | |
334 | xmlhttp.send(null); | |
335 | } | |
336 | } | |
337 | } | |
338 | ||
9cfc649a AD |
339 | function relativeid_callback() { |
340 | ||
341 | if (xmlhttp_rpc.readyState == 4) { | |
342 | notify(xmlhttp_rpc.responseText); | |
343 | } | |
344 | ||
345 | } | |
346 | ||
347 | function getVisibleHeadlineIds() { | |
348 | ||
349 | var content = document.getElementById("headlinesList"); | |
350 | ||
351 | var rows = new Array(); | |
352 | ||
353 | for (i = 0; i < content.rows.length; i++) { | |
354 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
355 | if (row_id.length > 0) { | |
356 | rows.push(row_id); | |
357 | } | |
358 | } | |
359 | ||
360 | return rows; | |
361 | ||
362 | } | |
363 | ||
364 | function moveToPost(mode) { | |
365 | ||
366 | /* var query_str = "backend.php?op=rpc&subop=getRelativeId&mode=" + mode + | |
367 | "&feed=" + active_feed_id + "&id=" + active_post_id; | |
368 | ||
369 | // notify(query_str); | |
370 | ||
371 | if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) { | |
372 | xmlhttp_rpc.open("GET", query_str, true); | |
373 | xmlhttp_rpc.onreadystatechange=relativeid_callback; | |
374 | xmlhttp_rpc.send(null); | |
375 | } else { | |
376 | printLockingError(); | |
377 | } */ | |
378 | ||
379 | var rows = getVisibleHeadlineIds(); | |
380 | ||
381 | var prev_id; | |
382 | var next_id; | |
383 | ||
384 | for (var i = 0; i < rows.length; i++) { | |
385 | if (rows[i] == active_post_id) { | |
386 | prev_id = rows[i-1]; | |
387 | next_id = rows[i+1]; | |
388 | } | |
389 | } | |
390 | ||
391 | if (mode == "next" && next_id != undefined) { | |
392 | view(next_id, active_feed_id); | |
393 | } | |
394 | ||
395 | if (mode == "prev" && prev_id != undefined) { | |
396 | view(prev_id, active_feed_id); | |
397 | } | |
398 | ||
399 | } | |
400 | ||
401 | function localHotkeyHandler(keycode) { | |
402 | ||
403 | // notify(keycode); | |
404 | ||
405 | if (keycode == 78) { | |
406 | moveToPost('next'); | |
407 | } | |
408 | ||
409 | if (keycode == 80) { | |
410 | moveToPost('prev'); | |
411 | } | |
412 | } | |
413 | ||
13ad9102 | 414 | |
76798ff3 | 415 | function init() { |
476cac42 | 416 | updateFeedList(false, false); |
13ad9102 | 417 | document.onkeydown = hotkey_handler; |
ac53063a | 418 | setTimeout("timeout()", 1800*1000); |
1cd17194 | 419 | } |