]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
more opera feeds frame size work
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194 1var xmlhttp = false;
76798ff3 2var total_unread = 0;
525116d4 3var first_run = true;
8143ae1f 4var display_tags = false;
806a3d14 5var global_unread = -1;
21703604 6var active_title_text = "";
21703604 7var current_subtitle = "";
c6784aea 8var daemon_enabled = false;
15da5cc1 9var _qfd_deleted_feed = 0;
2bf6e0a8 10var firsttime_update = true;
15da5cc1 11
1cd17194
AD
12/*@cc_on @*/
13/*@if (@_jscript_version >= 5)
14// JScript gives us Conditional compilation, we can cope with old IE versions.
15// and security blocked creation of the objects.
16try {
17 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
18} catch (e) {
19 try {
20 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
21 } catch (E) {
22 xmlhttp = false;
23 }
24}
25@end @*/
26
27if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
28 xmlhttp = new XMLHttpRequest();
29}
30
8143ae1f
AD
31function toggleTags() {
32 display_tags = !display_tags;
33
34 var p = document.getElementById("dispSwitchPrompt");
35
36 if (display_tags) {
37 p.innerHTML = "display feeds";
38 } else {
39 p.innerHTML = "display tags";
40 }
41
42 updateFeedList();
43}
44
6de5d056 45function dlg_frefresh_callback() {
1cd17194 46 if (xmlhttp.readyState == 4) {
a24f525c 47 notify(xmlhttp.responseText);
e2f8f7b4 48 updateFeedList(false, false);
15da5cc1
AD
49 if (_qfd_deleted_feed) {
50 var hframe = document.getElementById("headlines-frame");
51 if (hframe) {
52 hframe.src = "backend.php?op=error&msg=No%20feed%20selected.";
53 }
54 }
f84a97a3 55 closeDlg();
c0e5a40e 56 }
1cd17194 57}
e2f8f7b4 58
a24f525c
AD
59function dlg_submit_callback() {
60 if (xmlhttp.readyState == 4) {
61 notify(xmlhttp.responseText);
62 closeDlg();
63 }
64}
65
66function dlg_display_callback() {
f84a97a3
AD
67 if (xmlhttp.readyState == 4) {
68 var dlg = document.getElementById("userDlg");
76332f3c 69 var dlg_s = document.getElementById("userDlgShadow");
f84a97a3
AD
70
71 dlg.innerHTML = xmlhttp.responseText;
76332f3c 72 dlg_s.style.display = "block";
f84a97a3
AD
73 }
74}
1a66d16e 75
7f123cda
AD
76function hide_unread_callback() {
77 if (xmlhttp.readyState == 4) {
78
79 try {
80
81 var reply = xmlhttp.responseXML.firstChild.firstChild;
82 var value = reply.getAttribute("value");
83 var hide_read_feeds = (value != "false")
84 var feeds_doc = window.frames["feeds-frame"].document;
85
86 hideOrShowFeeds(feeds_doc, hide_read_feeds);
87
88 if (hide_read_feeds) {
89 setCookie("ttrss_vf_hreadf", 1);
90 } else {
91 setCookie("ttrss_vf_hreadf", 0);
92 }
93
94 } catch (e) {
95 exception_error("hide_unread_callback", e);
96 }
97
98 }
99}
100
8158c57a 101function refetch_callback() {
29fb8c70 102 if (xmlhttp.readyState == 4) {
7719618b 103 try {
310da49d 104
7719618b
AD
105 if (!xmlhttp.responseXML) {
106 notify("refetch_callback: backend did not return valid XML");
107 return;
108 }
109
110 var reply = xmlhttp.responseXML.firstChild;
262bd8ea 111
7719618b
AD
112 if (!reply) {
113 notify("refetch_callback: backend did not return expected XML object");
e2cb4c6d 114 updateTitle("");
7719618b
AD
115 return;
116 }
262bd8ea 117
7719618b
AD
118 var error_code = reply.getAttribute("error-code");
119
120 if (error_code && error_code != 0) {
121 return fatalError(error_code);
122 }
123
124 var f_document = window.frames["feeds-frame"].document;
1a6a9555 125
3bdb368b 126 parse_counters(reply, f_document, window);
c6784aea
AD
127
128 if (!daemon_enabled) {
c6784aea 129 notify("All feeds updated.");
5a180505 130 updateTitle("");
c6784aea 131 }
7719618b
AD
132 } catch (e) {
133 exception_error("refetch_callback", e);
e2cb4c6d 134 updateTitle("");
7719618b 135 }
090e250b
AD
136 }
137}
1a66d16e 138
295f9b42
AD
139function backend_sanity_check_callback() {
140
141 if (xmlhttp.readyState == 4) {
295f9b42 142
7719618b
AD
143 try {
144
145 if (!xmlhttp.responseXML) {
146 fatalError(3);
147 return;
148 }
295f9b42 149
7719618b
AD
150 var reply = xmlhttp.responseXML.firstChild;
151
152 if (!reply) {
153 fatalError(3);
154 return;
155 }
156
157 var error_code = reply.getAttribute("error-code");
158
159 if (error_code && error_code != 0) {
160 return fatalError(error_code);
161 }
162
163 init_second_stage();
295f9b42 164
7719618b
AD
165 } catch (e) {
166 exception_error("backend_sanity_check_callback", e);
167 }
295f9b42
AD
168 }
169}
170
cb246176 171function scheduleFeedUpdate(force) {
525116d4 172
c6784aea
AD
173 if (!daemon_enabled) {
174 notify("Updating feeds, please wait.");
175 updateTitle("Updating");
176 }
55193822 177
cb246176
AD
178 var query_str = "backend.php?op=rpc&subop=";
179
180 if (force) {
c3b81db0 181 query_str = query_str + "forceUpdateAllFeeds";
cb246176 182 } else {
c3b81db0 183 query_str = query_str + "updateAllFeeds";
cb246176 184 }
525116d4 185
9826bd2e
AD
186 var omode;
187
2bf6e0a8
AD
188 if (firsttime_update) {
189 firsttime_update = false;
190 omode = "T";
9826bd2e 191 } else {
2bf6e0a8
AD
192 if (display_tags) {
193 omode = "t";
194 } else {
195 omode = "flc";
196 }
9826bd2e 197 }
2bf6e0a8 198
9826bd2e 199 query_str = query_str + "&omode=" + omode;
78ea1de0 200 query_str = query_str + "&uctr=" + global_unread;
9826bd2e 201
2bf6e0a8 202
29fb8c70
AD
203 if (xmlhttp_ready(xmlhttp)) {
204 xmlhttp.open("GET", query_str, true);
205 xmlhttp.onreadystatechange=refetch_callback;
206 xmlhttp.send(null);
525116d4
AD
207 } else {
208 printLockingError();
c0e5a40e 209 }
525116d4 210}
1cd17194 211
525116d4 212function updateFeedList(silent, fetch) {
c0e5a40e 213
1a66d16e
AD
214// if (silent != true) {
215// notify("Loading feed list...");
216// }
82baad4a 217
331900c6
AD
218 var query_str = "backend.php?op=feeds";
219
8143ae1f
AD
220 if (display_tags) {
221 query_str = query_str + "&tags=1";
222 }
223
86741347
AD
224 if (getActiveFeedId()) {
225 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
226 }
227
1a66d16e 228 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 229
1a66d16e 230 var feeds_frame = document.getElementById("feeds-frame");
e1123aee 231
1a66d16e
AD
232 feeds_frame.src = query_str;
233}
175847de 234
476cac42 235function catchupAllFeeds() {
076682aa 236
476cac42
AD
237 var query_str = "backend.php?op=feeds&subop=catchupAll";
238
239 notify("Marking all feeds as read...");
240
1a66d16e
AD
241 var feeds_frame = document.getElementById("feeds-frame");
242
243 feeds_frame.src = query_str;
476cac42 244
fc69e641 245 global_unread = 0;
21703604 246 updateTitle("");
fc69e641 247
476cac42 248}
1cd17194 249
f0601b87 250function viewCurrentFeed(skip, subop) {
1a66d16e 251
86741347
AD
252 if (getActiveFeedId()) {
253 viewfeed(getActiveFeedId(), skip, subop);
033e47e0
AD
254 } else {
255 disableContainerChildren("headlinesToolbar", false, document);
256 viewfeed(-1, skip, subop); // FIXME
f0601b87
AD
257 }
258}
259
476cac42 260function viewfeed(feed, skip, subop) {
db8d6f67
AD
261 var f = window.frames["feeds-frame"];
262 f.viewfeed(feed, skip, subop);
9cfc649a
AD
263}
264
40d13c28 265function timeout() {
05732aa0 266 scheduleFeedUpdate(false);
f5de0d8d
AD
267
268 var refresh_time = getCookie('ttrss_vf_refresh');
269
270 if (!refresh_time) refresh_time = 600;
271
272 setTimeout("timeout()", refresh_time*1000);
ac53063a
AD
273}
274
c374a3fe 275function resetSearch() {
64c620ce
AD
276 var searchbox = document.getElementById("searchbox")
277
86741347 278 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 279 searchbox.value = "";
86741347 280 viewfeed(getActiveFeedId(), 0, "");
ac43eba1 281 }
c374a3fe 282}
ac53063a 283
f0601b87 284function search() {
49b7cbd3 285 closeDlg();
4ce19859 286 viewCurrentFeed(0, "");
76798ff3 287}
1cd17194 288
13ad9102
AD
289function localPiggieFunction(enable) {
290 if (enable) {
291 var query_str = "backend.php?op=feeds&subop=piggie";
292
c0e5a40e 293 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
294
295 xmlhttp.open("GET", query_str, true);
296 xmlhttp.onreadystatechange=feedlist_callback;
297 xmlhttp.send(null);
298 }
299 }
300}
301
9cfc649a
AD
302function localHotkeyHandler(keycode) {
303
b623b3ed 304 if (keycode == 82) { // r
c3a8d71a
AD
305 return scheduleFeedUpdate(true);
306 }
307
b623b3ed
AD
308 if (keycode == 85) { // u
309 if (getActiveFeedId()) {
310 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
311 }
312 }
313
314 if (keycode == 65) { // a
315 return toggleDispRead();
c3a8d71a
AD
316 }
317
7b433d8c
AD
318 var f_doc = window.frames["feeds-frame"].document;
319 var feedlist = f_doc.getElementById('feedList');
320
321 if (keycode == 74) { // j
322 var feed = getActiveFeedId();
323 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
324 if (new_feed) viewfeed(new_feed, 0, '');
325 }
326
327 if (keycode == 75) { // k
328 var feed = getActiveFeedId();
329 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
330 if (new_feed) viewfeed(new_feed, 0, '');
331 }
332
c3a8d71a
AD
333// notify("KC: " + keycode);
334
9cfc649a
AD
335}
336
806a3d14
AD
337// if argument is undefined, current subtitle is not updated
338// use blank string to clear subtitle
fc69e641
AD
339function updateTitle(s) {
340 var tmp = "Tiny Tiny RSS";
21703604 341
5a494a0b 342 if (s != undefined) {
21703604
AD
343 current_subtitle = s;
344 }
345
fc69e641
AD
346 if (global_unread > 0) {
347 tmp = tmp + " (" + global_unread + ")";
348 }
349
5a494a0b 350 if (current_subtitle) {
21703604 351 tmp = tmp + " - " + current_subtitle;
fc69e641 352 }
21703604
AD
353
354 if (active_title_text.length > 0) {
355 tmp = tmp + " > " + active_title_text;
356 }
357
fc69e641
AD
358 document.title = tmp;
359}
360
22a93ad8 361function genericSanityCheck() {
ac43eba1 362
295f9b42
AD
363 if (!xmlhttp) fatalError(1);
364
365 setCookie("ttrss_vf_test", "TEST");
366
367 if (getCookie("ttrss_vf_test") != "TEST") {
368 fatalError(2);
369 }
370
22a93ad8
AD
371 return true;
372}
373
374function init() {
375
7719618b 376 try {
fe2f1970 377
97dcd654
AD
378 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
379
380 if (arguments.callee.done) return;
381 arguments.callee.done = true;
382
7719618b 383 disableContainerChildren("headlinesToolbar", true);
70830c87 384
7719618b
AD
385 if (!genericSanityCheck())
386 return;
ac43eba1 387
7719618b
AD
388 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
389 xmlhttp.onreadystatechange=backend_sanity_check_callback;
390 xmlhttp.send(null);
47179952 391
7719618b
AD
392 } catch (e) {
393 exception_error("init", e);
a8d28f48 394 }
7719618b 395}
86741347 396
1de2b92c
AD
397function resize_feeds_frame() {
398 var f = document.getElementById("feeds-frame");
399 var tf = document.getElementById("mainFooter");
400 var th = document.getElementById("mainHeader");
401
402 f.style.height = document.body.scrollHeight - tf.scrollHeight -
403 th.scrollHeight - 50 + "px";
404}
405
7719618b 406function init_second_stage() {
295f9b42 407
7719618b 408 try {
2f587484 409
7719618b
AD
410 setCookie("ttrss_vf_actfeed", "");
411
412 updateFeedList(false, false);
413 document.onkeydown = hotkey_handler;
414
4bbd5aec
AD
415 var viewbox = document.getElementById("viewbox");
416 var limitbox = document.getElementById("limitbox");
1b0809ae
AD
417
418 dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
4bbd5aec 419 dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
c6784aea
AD
420
421 daemon_enabled = getCookie("ttrss_vf_daemon");
5f136c9a 422
1de2b92c
AD
423 // FIXME should be callled after window resize
424
5f136c9a 425 if (navigator.userAgent.match("Opera")) {
1de2b92c 426 resize_feeds_frame();
5f136c9a 427 }
7719618b 428
7719618b
AD
429 } catch (e) {
430 exception_error("init_second_stage", e);
2f587484 431 }
1cd17194 432}
ac43eba1 433
c09ec856 434function quickMenuChange() {
cbe45fa8
AD
435 var chooser = document.getElementById("quickMenuChooser");
436 var opid = chooser[chooser.selectedIndex].id;
e2f8f7b4 437
c09ec856
AD
438 chooser.selectedIndex = 0;
439 quickMenuGo(opid);
440}
441
442function quickMenuGo(opid) {
443
444
cbe45fa8 445 if (opid == "qmcPrefs") {
e2f8f7b4
AD
446 gotoPreferences();
447 }
448
27da8b1e 449 if (opid == "qmcSearch") {
49b7cbd3 450 displayDlg("search", getActiveFeedId());
033e47e0
AD
451 return;
452 }
453
cbe45fa8 454 if (opid == "qmcAddFeed") {
f84a97a3 455 displayDlg("quickAddFeed");
6de5d056
AD
456 return;
457 }
458
cbe45fa8 459 if (opid == "qmcRemoveFeed") {
6de5d056
AD
460 var actid = getActiveFeedId();
461
462 if (!actid) {
463 notify("Please select some feed first.");
464 return;
465 }
69668465
AD
466
467 if (confirm("Remove current feed?")) {
468 qfdDelete(actid);
469 }
6de5d056 470
6de5d056 471 return;
e2f8f7b4 472 }
7a991cac 473
cbe45fa8 474 if (opid == "qmcUpdateFeeds") {
7a991cac
AD
475 scheduleFeedUpdate(true);
476 return;
477 }
478
cbe45fa8 479 if (opid == "qmcCatchupAll") {
7a991cac
AD
480 catchupAllFeeds();
481 return;
482 }
483
cbe45fa8 484 if (opid == "qmcShowOnlyUnread") {
7a991cac
AD
485 toggleDispRead();
486 return;
487 }
488
a24f525c
AD
489 if (opid == "qmcAddFilter") {
490 displayDlg("quickAddFilter", getActiveFeedId());
491 }
492
e2f8f7b4
AD
493}
494
495function qafAdd() {
ac43eba1 496
e2f8f7b4
AD
497 if (!xmlhttp_ready(xmlhttp)) {
498 printLockingError();
499 return
500 }
501
502 var link = document.getElementById("qafInput");
503
504 if (link.value.length == 0) {
505 notify("Missing feed URL.");
506 } else {
507 notify("Adding feed...");
15da5cc1
AD
508
509 var cat = document.getElementById("qafCat");
510 var cat_id = "";
e2f8f7b4 511
15da5cc1
AD
512 if (cat) {
513 cat_id = cat[cat.selectedIndex].id;
514 } else {
515 cat_id = 0;
516 }
517
e2f8f7b4
AD
518 var feeds_doc = window.frames["feeds-frame"].document;
519
520 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
521
a24f525c 522 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
15da5cc1 523 param_escape(link.value) + "&cid=" + param_escape(cat_id), true);
6de5d056 524 xmlhttp.onreadystatechange=dlg_frefresh_callback;
e2f8f7b4
AD
525 xmlhttp.send(null);
526
527 link.value = "";
528
529 }
f84a97a3
AD
530}
531
a24f525c
AD
532function qaddFilter() {
533
534 if (!xmlhttp_ready(xmlhttp)) {
535 printLockingError();
536 return
537 }
538
539 var regexp = document.getElementById("fadd_regexp");
540 var match = document.getElementById("fadd_match");
541 var feed = document.getElementById("fadd_feed");
542 var action = document.getElementById("fadd_action");
543
544 if (regexp.value.length == 0) {
545 notify("Missing filter expression.");
546 } else {
547 notify("Adding filter...");
548
549 var v_match = match[match.selectedIndex].text;
550 var feed_id = feed[feed.selectedIndex].id;
551 var action_id = action[action.selectedIndex].id;
552
553 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add&regexp=" +
554 param_escape(regexp.value) + "&match=" + v_match +
555 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
556
557 xmlhttp.onreadystatechange=dlg_submit_callback;
558 xmlhttp.send(null);
559
560 regexp.value = "";
561 }
562
563}
564
565
6de5d056 566function displayDlg(id, param) {
e2f8f7b4 567
7f123cda
AD
568 if (!xmlhttp_ready(xmlhttp)) {
569 printLockingError();
570 return
571 }
572
40d601c5
AD
573 notify("");
574
f84a97a3 575 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
6de5d056 576 param_escape(id) + "&param=" + param_escape(param), true);
a24f525c 577 xmlhttp.onreadystatechange=dlg_display_callback;
f84a97a3 578 xmlhttp.send(null);
e2f8f7b4 579
ccedfddd 580 disableHotkeys();
e2f8f7b4 581}
f84a97a3
AD
582
583function closeDlg() {
76332f3c 584 var dlg = document.getElementById("userDlgShadow");
f84a97a3 585 dlg.style.display = "none";
ccedfddd 586 enableHotkeys();
f84a97a3
AD
587}
588
6de5d056
AD
589function qfdDelete(feed_id) {
590
591 notify("Removing feed...");
592
7f123cda
AD
593 if (!xmlhttp_ready(xmlhttp)) {
594 printLockingError();
595 return
596 }
597
69668465
AD
598// var feeds_doc = window.frames["feeds-frame"].document;
599// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
6de5d056 600
15da5cc1
AD
601 _qfd_deleted_feed = feed_id;
602
69668465 603 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
6de5d056
AD
604 xmlhttp.onreadystatechange=dlg_frefresh_callback;
605 xmlhttp.send(null);
6de5d056 606}
033e47e0 607
3745788e 608
c09ec856 609function allFeedsMenuChange() {
3745788e
AD
610 var chooser = document.getElementById("allFeedsChooser");
611
612 var opname = chooser[chooser.selectedIndex].text;
613
c09ec856
AD
614 chooser.selectedIndex = 0;
615
3745788e
AD
616 if (opname == "Update") {
617 scheduleFeedUpdate(true);
618 return;
619 }
620
621 if (opname == "Mark as read") {
622 catchupAllFeeds();
623 return;
624 }
625
bdf7f1bc 626 if (opname == "Show only unread") {
3745788e
AD
627 toggleDispRead();
628 return;
629 }
630
631}
632
21703604
AD
633function updateFeedTitle(t) {
634 active_title_text = t;
635 updateTitle();
636}
637
3745788e 638function toggleDispRead() {
7f123cda 639 try {
3745788e 640
7f123cda
AD
641 if (!xmlhttp_ready(xmlhttp)) {
642 printLockingError();
643 return
644 }
3745788e 645
7f123cda 646 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
3745788e 647
7f123cda
AD
648 hide_read_feeds = !hide_read_feeds;
649
650 var query = "backend.php?op=rpc&subop=setpref" +
651 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
3745788e 652
7f123cda
AD
653 xmlhttp.open("GET", query);
654 xmlhttp.onreadystatechange=hide_unread_callback;
655 xmlhttp.send(null);
656
657 } catch (e) {
658 exception_error("toggleDispRead", e);
3745788e 659 }
3745788e 660}
295f9b42 661