]>
Commit | Line | Data |
---|---|---|
1cd17194 AD |
1 | var xmlhttp = false; |
2 | ||
76798ff3 | 3 | var total_unread = 0; |
525116d4 | 4 | var first_run = true; |
76798ff3 | 5 | |
8143ae1f AD |
6 | var display_tags = false; |
7 | ||
806a3d14 | 8 | var global_unread = -1; |
fc69e641 | 9 | |
21703604 AD |
10 | var active_title_text = ""; |
11 | ||
12 | var current_subtitle = ""; | |
13 | ||
1cd17194 AD |
14 | /*@cc_on @*/ |
15 | /*@if (@_jscript_version >= 5) | |
16 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
17 | // and security blocked creation of the objects. | |
18 | try { | |
19 | xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); | |
20 | } catch (e) { | |
21 | try { | |
22 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
23 | } catch (E) { | |
24 | xmlhttp = false; | |
25 | } | |
26 | } | |
27 | @end @*/ | |
28 | ||
29 | if (!xmlhttp && typeof XMLHttpRequest!='undefined') { | |
30 | xmlhttp = new XMLHttpRequest(); | |
31 | } | |
32 | ||
8143ae1f AD |
33 | function toggleTags() { |
34 | display_tags = !display_tags; | |
35 | ||
36 | var p = document.getElementById("dispSwitchPrompt"); | |
37 | ||
38 | if (display_tags) { | |
39 | p.innerHTML = "display feeds"; | |
40 | } else { | |
41 | p.innerHTML = "display tags"; | |
42 | } | |
43 | ||
44 | updateFeedList(); | |
45 | } | |
46 | ||
6de5d056 | 47 | function dlg_frefresh_callback() { |
1cd17194 | 48 | if (xmlhttp.readyState == 4) { |
e2f8f7b4 | 49 | updateFeedList(false, false); |
f84a97a3 | 50 | closeDlg(); |
c0e5a40e | 51 | } |
1cd17194 | 52 | } |
e2f8f7b4 | 53 | |
f84a97a3 AD |
54 | function dialog_refresh_callback() { |
55 | if (xmlhttp.readyState == 4) { | |
56 | var dlg = document.getElementById("userDlg"); | |
76332f3c | 57 | var dlg_s = document.getElementById("userDlgShadow"); |
f84a97a3 AD |
58 | |
59 | dlg.innerHTML = xmlhttp.responseText; | |
76332f3c | 60 | dlg_s.style.display = "block"; |
f84a97a3 AD |
61 | } |
62 | } | |
1a66d16e | 63 | |
8158c57a | 64 | function refetch_callback() { |
29fb8c70 | 65 | if (xmlhttp.readyState == 4) { |
7719618b | 66 | try { |
310da49d | 67 | |
7719618b AD |
68 | if (!xmlhttp.responseXML) { |
69 | notify("refetch_callback: backend did not return valid XML"); | |
70 | return; | |
71 | } | |
72 | ||
73 | var reply = xmlhttp.responseXML.firstChild; | |
262bd8ea | 74 | |
7719618b AD |
75 | if (!reply) { |
76 | notify("refetch_callback: backend did not return expected XML object"); | |
77 | return; | |
78 | } | |
262bd8ea | 79 | |
7719618b AD |
80 | var error_code = reply.getAttribute("error-code"); |
81 | ||
82 | if (error_code && error_code != 0) { | |
83 | return fatalError(error_code); | |
84 | } | |
85 | ||
86 | var f_document = window.frames["feeds-frame"].document; | |
87 | ||
88 | for (var l = 0; l < reply.childNodes.length; l++) { | |
89 | var id = reply.childNodes[l].getAttribute("id"); | |
90 | var ctr = reply.childNodes[l].getAttribute("counter"); | |
91 | ||
92 | var feedctr = f_document.getElementById("FEEDCTR-" + id); | |
93 | var feedu = f_document.getElementById("FEEDU-" + id); | |
94 | var feedr = f_document.getElementById("FEEDR-" + id); | |
95 | ||
7719618b AD |
96 | if (id == "global-unread") { |
97 | global_unread = ctr; | |
806a3d14 AD |
98 | continue; |
99 | } | |
7719618b AD |
100 | |
101 | if (feedctr && feedu && feedr) { | |
8143ae1f | 102 | |
7719618b AD |
103 | feedu.innerHTML = ctr; |
104 | ||
105 | if (ctr > 0) { | |
106 | feedctr.className = "odd"; | |
107 | if (!feedr.className.match("Unread")) { | |
108 | feedr.className = feedr.className + "Unread"; | |
109 | } | |
110 | } else { | |
111 | feedctr.className = "invisible"; | |
112 | feedr.className = feedr.className.replace("Unread", ""); | |
8143ae1f | 113 | } |
090e250b | 114 | } |
7719618b AD |
115 | } |
116 | ||
117 | updateTitle(""); | |
118 | notify("All feeds updated."); | |
119 | } catch (e) { | |
120 | exception_error("refetch_callback", e); | |
121 | } | |
090e250b AD |
122 | } |
123 | } | |
1a66d16e | 124 | |
295f9b42 AD |
125 | function backend_sanity_check_callback() { |
126 | ||
127 | if (xmlhttp.readyState == 4) { | |
295f9b42 | 128 | |
7719618b AD |
129 | try { |
130 | ||
131 | if (!xmlhttp.responseXML) { | |
132 | fatalError(3); | |
133 | return; | |
134 | } | |
295f9b42 | 135 | |
7719618b AD |
136 | var reply = xmlhttp.responseXML.firstChild; |
137 | ||
138 | if (!reply) { | |
139 | fatalError(3); | |
140 | return; | |
141 | } | |
142 | ||
143 | var error_code = reply.getAttribute("error-code"); | |
144 | ||
145 | if (error_code && error_code != 0) { | |
146 | return fatalError(error_code); | |
147 | } | |
148 | ||
149 | init_second_stage(); | |
295f9b42 | 150 | |
7719618b AD |
151 | } catch (e) { |
152 | exception_error("backend_sanity_check_callback", e); | |
153 | } | |
295f9b42 AD |
154 | } |
155 | } | |
156 | ||
cb246176 | 157 | function scheduleFeedUpdate(force) { |
525116d4 AD |
158 | |
159 | notify("Updating feeds in background..."); | |
160 | ||
fc69e641 AD |
161 | // document.title = "Tiny Tiny RSS - Updating..."; |
162 | ||
21703604 | 163 | updateTitle("Updating"); |
55193822 | 164 | |
cb246176 AD |
165 | var query_str = "backend.php?op=rpc&subop="; |
166 | ||
167 | if (force) { | |
c3b81db0 | 168 | query_str = query_str + "forceUpdateAllFeeds"; |
cb246176 | 169 | } else { |
c3b81db0 | 170 | query_str = query_str + "updateAllFeeds"; |
cb246176 | 171 | } |
525116d4 | 172 | |
9826bd2e AD |
173 | var omode; |
174 | ||
175 | if (display_tags) { | |
176 | omode = "t"; | |
177 | } else { | |
178 | omode = "fl"; | |
179 | } | |
180 | ||
181 | query_str = query_str + "&omode=" + omode; | |
182 | ||
29fb8c70 AD |
183 | if (xmlhttp_ready(xmlhttp)) { |
184 | xmlhttp.open("GET", query_str, true); | |
185 | xmlhttp.onreadystatechange=refetch_callback; | |
186 | xmlhttp.send(null); | |
525116d4 AD |
187 | } else { |
188 | printLockingError(); | |
c0e5a40e | 189 | } |
525116d4 | 190 | } |
1cd17194 | 191 | |
525116d4 | 192 | function updateFeedList(silent, fetch) { |
c0e5a40e | 193 | |
1a66d16e AD |
194 | // if (silent != true) { |
195 | // notify("Loading feed list..."); | |
196 | // } | |
82baad4a | 197 | |
331900c6 AD |
198 | var query_str = "backend.php?op=feeds"; |
199 | ||
8143ae1f AD |
200 | if (display_tags) { |
201 | query_str = query_str + "&tags=1"; | |
202 | } | |
203 | ||
86741347 AD |
204 | if (getActiveFeedId()) { |
205 | query_str = query_str + "&actid=" + getActiveFeedId(); | |
175847de AD |
206 | } |
207 | ||
1a66d16e | 208 | if (fetch) query_str = query_str + "&fetch=yes"; |
e1123aee | 209 | |
1a66d16e | 210 | var feeds_frame = document.getElementById("feeds-frame"); |
e1123aee | 211 | |
1a66d16e AD |
212 | feeds_frame.src = query_str; |
213 | } | |
175847de | 214 | |
476cac42 | 215 | function catchupAllFeeds() { |
076682aa | 216 | |
476cac42 AD |
217 | var query_str = "backend.php?op=feeds&subop=catchupAll"; |
218 | ||
219 | notify("Marking all feeds as read..."); | |
220 | ||
1a66d16e AD |
221 | var feeds_frame = document.getElementById("feeds-frame"); |
222 | ||
223 | feeds_frame.src = query_str; | |
476cac42 | 224 | |
fc69e641 | 225 | global_unread = 0; |
21703604 | 226 | updateTitle(""); |
fc69e641 | 227 | |
476cac42 | 228 | } |
1cd17194 | 229 | |
f0601b87 | 230 | function viewCurrentFeed(skip, subop) { |
1a66d16e | 231 | |
86741347 AD |
232 | if (getActiveFeedId()) { |
233 | viewfeed(getActiveFeedId(), skip, subop); | |
033e47e0 AD |
234 | } else { |
235 | disableContainerChildren("headlinesToolbar", false, document); | |
236 | viewfeed(-1, skip, subop); // FIXME | |
f0601b87 AD |
237 | } |
238 | } | |
239 | ||
476cac42 | 240 | function viewfeed(feed, skip, subop) { |
db8d6f67 AD |
241 | var f = window.frames["feeds-frame"]; |
242 | f.viewfeed(feed, skip, subop); | |
9cfc649a AD |
243 | } |
244 | ||
40d13c28 | 245 | function timeout() { |
05732aa0 | 246 | scheduleFeedUpdate(false); |
ac53063a | 247 | setTimeout("timeout()", 1800*1000); |
ac53063a AD |
248 | } |
249 | ||
c374a3fe | 250 | function resetSearch() { |
64c620ce AD |
251 | var searchbox = document.getElementById("searchbox") |
252 | ||
86741347 | 253 | if (searchbox.value != "" && getActiveFeedId()) { |
64c620ce | 254 | searchbox.value = ""; |
86741347 | 255 | viewfeed(getActiveFeedId(), 0, ""); |
ac43eba1 | 256 | } |
c374a3fe | 257 | } |
ac53063a | 258 | |
f0601b87 | 259 | function search() { |
4ce19859 | 260 | viewCurrentFeed(0, ""); |
76798ff3 | 261 | } |
1cd17194 | 262 | |
13ad9102 AD |
263 | function localPiggieFunction(enable) { |
264 | if (enable) { | |
265 | var query_str = "backend.php?op=feeds&subop=piggie"; | |
266 | ||
c0e5a40e | 267 | if (xmlhttp_ready(xmlhttp)) { |
13ad9102 AD |
268 | |
269 | xmlhttp.open("GET", query_str, true); | |
270 | xmlhttp.onreadystatechange=feedlist_callback; | |
271 | xmlhttp.send(null); | |
272 | } | |
273 | } | |
274 | } | |
275 | ||
9cfc649a AD |
276 | function localHotkeyHandler(keycode) { |
277 | ||
f0601b87 | 278 | /* if (keycode == 78) { |
c3a8d71a | 279 | return moveToPost('next'); |
9cfc649a AD |
280 | } |
281 | ||
282 | if (keycode == 80) { | |
c3a8d71a | 283 | return moveToPost('prev'); |
f0601b87 | 284 | } */ |
c3a8d71a | 285 | |
b623b3ed | 286 | if (keycode == 82) { // r |
c3a8d71a AD |
287 | return scheduleFeedUpdate(true); |
288 | } | |
289 | ||
b623b3ed AD |
290 | if (keycode == 85) { // u |
291 | if (getActiveFeedId()) { | |
292 | return viewfeed(getActiveFeedId(), 0, "ForceUpdate"); | |
293 | } | |
294 | } | |
295 | ||
296 | if (keycode == 65) { // a | |
297 | return toggleDispRead(); | |
c3a8d71a AD |
298 | } |
299 | ||
7b433d8c AD |
300 | var f_doc = window.frames["feeds-frame"].document; |
301 | var feedlist = f_doc.getElementById('feedList'); | |
302 | ||
303 | if (keycode == 74) { // j | |
304 | var feed = getActiveFeedId(); | |
305 | var new_feed = getRelativeFeedId(feedlist, feed, 'prev'); | |
306 | if (new_feed) viewfeed(new_feed, 0, ''); | |
307 | } | |
308 | ||
309 | if (keycode == 75) { // k | |
310 | var feed = getActiveFeedId(); | |
311 | var new_feed = getRelativeFeedId(feedlist, feed, 'next'); | |
312 | if (new_feed) viewfeed(new_feed, 0, ''); | |
313 | } | |
314 | ||
c3a8d71a AD |
315 | // notify("KC: " + keycode); |
316 | ||
9cfc649a AD |
317 | } |
318 | ||
806a3d14 AD |
319 | // if argument is undefined, current subtitle is not updated |
320 | // use blank string to clear subtitle | |
fc69e641 AD |
321 | function updateTitle(s) { |
322 | var tmp = "Tiny Tiny RSS"; | |
21703604 AD |
323 | |
324 | if (s && s.length > 0) { | |
325 | current_subtitle = s; | |
326 | } | |
327 | ||
fc69e641 AD |
328 | if (global_unread > 0) { |
329 | tmp = tmp + " (" + global_unread + ")"; | |
330 | } | |
331 | ||
332 | if (s) { | |
21703604 | 333 | tmp = tmp + " - " + current_subtitle; |
fc69e641 | 334 | } |
21703604 AD |
335 | |
336 | if (active_title_text.length > 0) { | |
337 | tmp = tmp + " > " + active_title_text; | |
338 | } | |
339 | ||
fc69e641 AD |
340 | document.title = tmp; |
341 | } | |
342 | ||
22a93ad8 | 343 | function genericSanityCheck() { |
ac43eba1 | 344 | |
295f9b42 AD |
345 | if (!xmlhttp) fatalError(1); |
346 | ||
347 | setCookie("ttrss_vf_test", "TEST"); | |
348 | ||
349 | if (getCookie("ttrss_vf_test") != "TEST") { | |
350 | fatalError(2); | |
351 | } | |
352 | ||
22a93ad8 AD |
353 | return true; |
354 | } | |
355 | ||
356 | function init() { | |
357 | ||
7719618b | 358 | try { |
fe2f1970 | 359 | |
7719618b | 360 | disableContainerChildren("headlinesToolbar", true); |
70830c87 | 361 | |
7719618b AD |
362 | if (!genericSanityCheck()) |
363 | return; | |
ac43eba1 | 364 | |
7719618b AD |
365 | xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true); |
366 | xmlhttp.onreadystatechange=backend_sanity_check_callback; | |
367 | xmlhttp.send(null); | |
47179952 | 368 | |
7719618b AD |
369 | } catch (e) { |
370 | exception_error("init", e); | |
a8d28f48 | 371 | } |
7719618b | 372 | } |
86741347 | 373 | |
7719618b | 374 | function init_second_stage() { |
295f9b42 | 375 | |
7719618b | 376 | try { |
2f587484 | 377 | |
7719618b AD |
378 | setCookie("ttrss_vf_actfeed", ""); |
379 | ||
380 | updateFeedList(false, false); | |
381 | document.onkeydown = hotkey_handler; | |
382 | ||
383 | var content = document.getElementById("content"); | |
384 | ||
385 | if (getCookie("ttrss_vf_vmode")) { | |
386 | var viewbox = document.getElementById("viewbox"); | |
387 | viewbox.value = getCookie("ttrss_vf_vmode"); | |
388 | } | |
389 | ||
390 | if (getCookie("ttrss_vf_limit")) { | |
391 | var limitbox = document.getElementById("limitbox"); | |
392 | limitbox.value = getCookie("ttrss_vf_limit"); | |
393 | } | |
394 | ||
395 | // if (getCookie("ttrss_vf_actfeed")) { | |
396 | // viewfeed(getCookie("ttrss_vf_actfeed"), 0, ''); | |
397 | // } | |
398 | ||
399 | // setTimeout("timeout()", 2*1000); | |
400 | // scheduleFeedUpdate(true); | |
401 | ||
7719618b AD |
402 | } catch (e) { |
403 | exception_error("init_second_stage", e); | |
2f587484 | 404 | } |
1cd17194 | 405 | } |
ac43eba1 | 406 | |
e2f8f7b4 | 407 | function quickMenuGo() { |
e2f8f7b4 | 408 | |
cbe45fa8 AD |
409 | var chooser = document.getElementById("quickMenuChooser"); |
410 | var opid = chooser[chooser.selectedIndex].id; | |
e2f8f7b4 | 411 | |
cbe45fa8 | 412 | if (opid == "qmcPrefs") { |
e2f8f7b4 AD |
413 | gotoPreferences(); |
414 | } | |
415 | ||
cbe45fa8 | 416 | if (opid == "qmcAdvSearch") { |
033e47e0 AD |
417 | displayDlg("search"); |
418 | return; | |
419 | } | |
420 | ||
cbe45fa8 | 421 | if (opid == "qmcAddFeed") { |
f84a97a3 | 422 | displayDlg("quickAddFeed"); |
6de5d056 AD |
423 | return; |
424 | } | |
425 | ||
cbe45fa8 | 426 | if (opid == "qmcRemoveFeed") { |
6de5d056 AD |
427 | var actid = getActiveFeedId(); |
428 | ||
429 | if (!actid) { | |
430 | notify("Please select some feed first."); | |
431 | return; | |
432 | } | |
433 | ||
434 | displayDlg("quickDelFeed", actid); | |
435 | return; | |
e2f8f7b4 | 436 | } |
7a991cac | 437 | |
cbe45fa8 | 438 | if (opid == "qmcUpdateFeeds") { |
7a991cac AD |
439 | scheduleFeedUpdate(true); |
440 | return; | |
441 | } | |
442 | ||
cbe45fa8 | 443 | if (opid == "qmcCatchupAll") { |
7a991cac AD |
444 | catchupAllFeeds(); |
445 | return; | |
446 | } | |
447 | ||
cbe45fa8 | 448 | if (opid == "qmcShowOnlyUnread") { |
7a991cac AD |
449 | toggleDispRead(); |
450 | return; | |
451 | } | |
452 | ||
e2f8f7b4 AD |
453 | } |
454 | ||
455 | function qafAdd() { | |
ac43eba1 | 456 | |
e2f8f7b4 AD |
457 | if (!xmlhttp_ready(xmlhttp)) { |
458 | printLockingError(); | |
459 | return | |
460 | } | |
461 | ||
462 | var link = document.getElementById("qafInput"); | |
463 | ||
464 | if (link.value.length == 0) { | |
465 | notify("Missing feed URL."); | |
466 | } else { | |
467 | notify("Adding feed..."); | |
468 | ||
469 | var feeds_doc = window.frames["feeds-frame"].document; | |
470 | ||
471 | feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; | |
472 | ||
473 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" + | |
474 | param_escape(link.value), true); | |
6de5d056 | 475 | xmlhttp.onreadystatechange=dlg_frefresh_callback; |
e2f8f7b4 AD |
476 | xmlhttp.send(null); |
477 | ||
478 | link.value = ""; | |
479 | ||
480 | } | |
f84a97a3 AD |
481 | } |
482 | ||
6de5d056 | 483 | function displayDlg(id, param) { |
e2f8f7b4 | 484 | |
40d601c5 AD |
485 | notify(""); |
486 | ||
f84a97a3 | 487 | xmlhttp.open("GET", "backend.php?op=dlg&id=" + |
6de5d056 | 488 | param_escape(id) + "¶m=" + param_escape(param), true); |
f84a97a3 AD |
489 | xmlhttp.onreadystatechange=dialog_refresh_callback; |
490 | xmlhttp.send(null); | |
e2f8f7b4 AD |
491 | |
492 | } | |
f84a97a3 AD |
493 | |
494 | function closeDlg() { | |
76332f3c | 495 | var dlg = document.getElementById("userDlgShadow"); |
f84a97a3 AD |
496 | dlg.style.display = "none"; |
497 | } | |
498 | ||
6de5d056 AD |
499 | function qfdDelete(feed_id) { |
500 | ||
501 | notify("Removing feed..."); | |
502 | ||
503 | var feeds_doc = window.frames["feeds-frame"].document; | |
504 | feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; | |
505 | ||
506 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id); | |
507 | xmlhttp.onreadystatechange=dlg_frefresh_callback; | |
508 | xmlhttp.send(null); | |
6de5d056 | 509 | } |
033e47e0 | 510 | |
3745788e AD |
511 | |
512 | function allFeedsMenuGo() { | |
513 | var chooser = document.getElementById("allFeedsChooser"); | |
514 | ||
515 | var opname = chooser[chooser.selectedIndex].text; | |
516 | ||
517 | if (opname == "Update") { | |
518 | scheduleFeedUpdate(true); | |
519 | return; | |
520 | } | |
521 | ||
522 | if (opname == "Mark as read") { | |
523 | catchupAllFeeds(); | |
524 | return; | |
525 | } | |
526 | ||
bdf7f1bc | 527 | if (opname == "Show only unread") { |
3745788e AD |
528 | toggleDispRead(); |
529 | return; | |
530 | } | |
531 | ||
532 | } | |
533 | ||
21703604 AD |
534 | function updateFeedTitle(t) { |
535 | active_title_text = t; | |
536 | updateTitle(); | |
537 | } | |
538 | ||
3745788e AD |
539 | function toggleDispRead() { |
540 | var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1); | |
541 | ||
542 | hide_read_feeds = !hide_read_feeds; | |
543 | ||
544 | var feeds_doc = window.frames["feeds-frame"].document; | |
545 | ||
546 | hideOrShowFeeds(feeds_doc, hide_read_feeds); | |
547 | ||
548 | if (hide_read_feeds) { | |
549 | setCookie("ttrss_vf_hreadf", 1); | |
550 | } else { | |
551 | setCookie("ttrss_vf_hreadf", 0); | |
552 | } | |
553 | ||
554 | } | |
295f9b42 AD |
555 | |
556 |