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