]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
compat theme: properly reflow container height
[tt-rss.git] / tt-rss.js
1 var total_unread = 0;
2 var first_run = true;
3 var display_tags = false;
4 var global_unread = -1;
5 var active_title_text = "";
6 var current_subtitle = "";
7 var daemon_enabled = false;
8 var daemon_refresh_only = false;
9 //var _qfd_deleted_feed = 0;
10 var firsttime_update = true;
11 var cookie_lifetime = 0;
12 var active_feed_id = 0;
13 var active_feed_is_cat = false;
14 var number_of_feeds = 0;
15 var sanity_check_done = false;
16 var _hfd_scrolltop = 0;
17
18 var init_params = new Object();
19
20 function tagsAreDisplayed() {
21 return display_tags;
22 }
23
24 function toggleTags(show_all) {
25
26 try {
27
28 debug("toggleTags: " + show_all + "; " + display_tags);
29
30 var p = document.getElementById("dispSwitchPrompt");
31
32 if (!show_all && !display_tags) {
33 displayDlg("printTagCloud");
34 } else if (show_all) {
35 closeInfoBox();
36 display_tags = true;
37 p.innerHTML = __("display feeds");
38 notify_progress("Loading, please wait...", true);
39 updateFeedList();
40 } else if (display_tags) {
41 display_tags = false;
42 p.innerHTML = __("tag cloud");
43 notify_progress("Loading, please wait...", true);
44 updateFeedList();
45 }
46
47 } catch (e) {
48 exception_error("toggleTags", e);
49 }
50 }
51
52 function dlg_frefresh_callback(transport, deleted_feed) {
53 if (getActiveFeedId() == deleted_feed) {
54 var h = document.getElementById("headlines-frame");
55 if (h) {
56 h.innerHTML = "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
57 }
58 }
59
60 setTimeout('updateFeedList(false, false)', 50);
61 closeInfoBox();
62 }
63
64 function refetch_callback2(transport) {
65 try {
66
67 var date = new Date();
68
69 parse_counters_reply(transport, true);
70
71 debug("refetch_callback2: done");
72
73 /* if (!daemon_enabled && !daemon_refresh_only) {
74 notify_info("All feeds updated.");
75 updateTitle("");
76 } else {
77 //notify("");
78 } */
79 } catch (e) {
80 exception_error("refetch_callback", e);
81 updateTitle("");
82 }
83 }
84
85 function backend_sanity_check_callback(transport) {
86
87 try {
88
89 if (sanity_check_done) {
90 fatalError(11, "Sanity check request received twice. This can indicate "+
91 "presence of Firebug or some other disrupting extension. "+
92 "Please disable it and try again.");
93 return;
94 }
95
96 if (!transport.responseXML) {
97 fatalError(3, "[D001, Received reply is not XML]: " + transport.responseText);
98 return;
99 }
100
101 var reply = transport.responseXML.firstChild.firstChild;
102
103 if (!reply) {
104 fatalError(3, "[D002, Invalid RPC reply]: " + transport.responseText);
105 return;
106 }
107
108 var error_code = reply.getAttribute("error-code");
109
110 if (error_code && error_code != 0) {
111 return fatalError(error_code, reply.getAttribute("error-msg"));
112 }
113
114 debug("sanity check ok");
115
116 var params = reply.nextSibling;
117
118 if (params) {
119 debug('reading init-params...');
120 var param = params.firstChild;
121
122 while (param) {
123 var k = param.getAttribute("key");
124 var v = param.getAttribute("value");
125 debug(k + " => " + v);
126 init_params[k] = v;
127 param = param.nextSibling;
128 }
129 }
130
131 sanity_check_done = true;
132
133 init_second_stage();
134
135 } catch (e) {
136 exception_error("backend_sanity_check_callback", e);
137 }
138 }
139
140 function scheduleFeedUpdate(force) {
141
142 debug("in scheduleFeedUpdate");
143
144 /* if (!daemon_enabled && !daemon_refresh_only) {
145 notify_progress("Updating feeds...", true);
146 } */
147
148 var query_str = "backend.php?op=rpc&subop=";
149
150 if (force) {
151 query_str = query_str + "forceUpdateAllFeeds";
152 } else {
153 query_str = query_str + "updateAllFeeds";
154 }
155
156 var omode;
157
158 if (firsttime_update && !navigator.userAgent.match("Opera")) {
159 firsttime_update = false;
160 omode = "T";
161 } else {
162 if (display_tags) {
163 omode = "tl";
164 } else {
165 omode = "flc";
166 }
167 }
168
169 query_str = query_str + "&omode=" + omode;
170 query_str = query_str + "&uctr=" + global_unread;
171
172 var date = new Date();
173 var timestamp = Math.round(date.getTime() / 1000);
174 query_str = query_str + "&ts=" + timestamp
175
176 debug("REFETCH query: " + query_str);
177
178 new Ajax.Request(query_str, {
179 onComplete: function(transport) {
180 refetch_callback2(transport);
181 } });
182 }
183
184 function updateFeedList(silent, fetch) {
185
186 // if (silent != true) {
187 // notify("Loading feed list...");
188 // }
189
190 debug("<b>updateFeedList</b>");
191
192 var query_str = "backend.php?op=feeds";
193
194 if (display_tags) {
195 query_str = query_str + "&tags=1";
196 }
197
198 if (getActiveFeedId() && !activeFeedIsCat()) {
199 query_str = query_str + "&actid=" + getActiveFeedId();
200 }
201
202 var date = new Date();
203 var timestamp = Math.round(date.getTime() / 1000);
204 query_str = query_str + "&ts=" + timestamp
205
206 if (fetch) query_str = query_str + "&fetch=yes";
207
208 // var feeds_frame = document.getElementById("feeds-frame");
209 // feeds_frame.src = query_str;
210
211 debug("updateFeedList Q=" + query_str);
212
213 new Ajax.Request(query_str, {
214 onComplete: function(transport) {
215 feedlist_callback2(transport);
216 } });
217
218 }
219
220 function catchupAllFeeds() {
221
222 var str = __("Mark all articles as read?");
223
224 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
225
226 var query_str = "backend.php?op=feeds&subop=catchupAll";
227
228 notify_progress("Marking all feeds as read...");
229
230 debug("catchupAllFeeds Q=" + query_str);
231
232 new Ajax.Request(query_str, {
233 onComplete: function(transport) {
234 feedlist_callback2(transport);
235 } });
236
237 global_unread = 0;
238 updateTitle("");
239 }
240 }
241
242 function viewCurrentFeed(subop) {
243
244 // if (getActiveFeedId()) {
245 if (getActiveFeedId() != undefined) {
246 viewfeed(getActiveFeedId(), subop, active_feed_is_cat);
247 } else {
248 disableContainerChildren("headlinesToolbar", false, document);
249 // viewfeed(-1, subop); // FIXME
250 }
251 return false; // block unneeded form submits
252 }
253
254 function viewfeed(feed, subop) {
255 var f = window.frames["feeds-frame"];
256 f.viewfeed(feed, subop);
257 }
258
259 function timeout() {
260 scheduleFeedUpdate(false);
261
262 var refresh_time = getInitParam("feeds_frame_refresh");
263
264 if (!refresh_time) refresh_time = 600;
265
266 setTimeout("timeout()", refresh_time*1000);
267 }
268
269 function resetSearch() {
270 var searchbox = document.getElementById("searchbox")
271
272 if (searchbox.value != "" && getActiveFeedId()) {
273 searchbox.value = "";
274 viewfeed(getActiveFeedId(), "");
275 }
276 }
277
278 function searchCancel() {
279 closeInfoBox(true);
280 }
281
282 function search() {
283 closeInfoBox();
284 viewCurrentFeed(0, "");
285 }
286
287 // if argument is undefined, current subtitle is not updated
288 // use blank string to clear subtitle
289 function updateTitle(s) {
290 var tmp = "Tiny Tiny RSS";
291
292 if (s != undefined) {
293 current_subtitle = s;
294 }
295
296 if (global_unread > 0) {
297 tmp = tmp + " (" + global_unread + ")";
298 }
299
300 if (current_subtitle) {
301 tmp = tmp + " - " + current_subtitle;
302 }
303
304 if (active_title_text.length > 0) {
305 tmp = tmp + " > " + active_title_text;
306 }
307
308 document.title = tmp;
309 }
310
311 function genericSanityCheck() {
312
313 // if (!Ajax.getTransport()) fatalError(1);
314
315 setCookie("ttrss_vf_test", "TEST");
316
317 if (getCookie("ttrss_vf_test") != "TEST") {
318 fatalError(2);
319 }
320
321 return true;
322 }
323
324 function init() {
325
326 try {
327
328 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
329
330 if (arguments.callee.done) return;
331 arguments.callee.done = true;
332
333 disableContainerChildren("headlinesToolbar", true);
334
335 Form.disable("main_toolbar_form");
336
337 if (!genericSanityCheck())
338 return;
339
340 if (getURLParam('debug')) {
341 document.getElementById('debug_output').style.display = 'block';
342 debug('debug mode activated');
343 }
344
345 var params = "&ua=" + param_escape(navigator.userAgent);
346
347 new Ajax.Request("backend.php?op=rpc&subop=sanityCheck" + params, {
348 onComplete: function(transport) {
349 backend_sanity_check_callback(transport);
350 } });
351
352 } catch (e) {
353 exception_error("init", e);
354 }
355 }
356
357 function resize_headlines() {
358
359 var h_frame = document.getElementById("headlines-frame");
360 var c_frame = document.getElementById("content-frame");
361 var f_frame = document.getElementById("footer");
362 var feeds_frame = document.getElementById("feeds-holder");
363
364 if (!c_frame || !h_frame) return;
365
366 if (feeds_frame && getInitParam("theme") == "compat") {
367 feeds_frame.style.bottom = f_frame.offsetHeight + "px";
368 }
369
370 if (getInitParam("theme") == "3pane") {
371 debug("resize_headlines: HOR-mode");
372
373 c_frame.style.width = '35%';
374 h_frame.style.right = c_frame.offsetWidth - 1 + "px";
375
376 } else {
377 debug("resize_headlines: VER-mode");
378
379 if (!is_msie()) {
380 h_frame.style.height = 30 + "%";
381 c_frame.style.top = h_frame.offsetTop + h_frame.offsetHeight + 1 + "px";
382 h_frame.style.height = h_frame.offsetHeight + "px";
383 } else {
384 h_frame.style.height = document.documentElement.clientHeight * 0.3 + "px";
385 c_frame.style.top = h_frame.offsetTop + h_frame.offsetHeight + 1 + "px";
386
387 var c_bottom = document.documentElement.clientHeight;
388
389 if (f_frame) {
390 c_bottom = f_frame.offsetTop;
391 }
392
393 c_frame.style.height = c_bottom - (h_frame.offsetTop +
394 h_frame.offsetHeight + 1) + "px";
395 h_frame.style.height = h_frame.offsetHeight + "px";
396
397 }
398
399 }
400
401 }
402
403 function init_second_stage() {
404
405 try {
406
407 cookie_lifetime = getCookie("ttrss_cltime");
408
409 delCookie("ttrss_vf_test");
410
411 // document.onresize = resize_headlines;
412 resize_headlines();
413
414 var toolbar = document.forms["main_toolbar_form"];
415
416 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
417 dropboxSelect(toolbar.limit, getInitParam("default_view_limit"));
418
419 daemon_enabled = getInitParam("daemon_enabled") == 1;
420 daemon_refresh_only = getInitParam("daemon_refresh_only") == 1;
421
422 setTimeout('updateFeedList(false, false)', 50);
423
424 debug("second stage ok");
425
426 } catch (e) {
427 exception_error("init_second_stage", e);
428 }
429 }
430
431 function quickMenuChange() {
432 var chooser = document.getElementById("quickMenuChooser");
433 var opid = chooser[chooser.selectedIndex].value;
434
435 chooser.selectedIndex = 0;
436 quickMenuGo(opid);
437 }
438
439 function quickMenuGo(opid) {
440 try {
441
442 if (opid == "qmcPrefs") {
443 gotoPreferences();
444 }
445
446 if (opid == "qmcSearch") {
447 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
448 return;
449 }
450
451 if (opid == "qmcAddFeed") {
452 displayDlg("quickAddFeed");
453 return;
454 }
455
456 if (opid == "qmcEditFeed") {
457 editFeedDlg(getActiveFeedId());
458 }
459
460 if (opid == "qmcRemoveFeed") {
461 var actid = getActiveFeedId();
462
463 if (activeFeedIsCat()) {
464 alert(__("You can't unsubscribe from the category."));
465 return;
466 }
467
468 if (!actid) {
469 alert(__("Please select some feed first."));
470 return;
471 }
472
473 var fn = getFeedName(actid);
474
475 var pr = __("Unsubscribe from %s?").replace("%s", fn);
476
477 if (confirm(pr)) {
478 unsubscribeFeed(actid);
479 }
480
481 return;
482 }
483
484 if (opid == "qmcClearFeed") {
485 var actid = getActiveFeedId();
486
487 if (!actid) {
488 alert(__("Please select some feed first."));
489 return;
490 }
491
492 if (activeFeedIsCat() || actid < 0) {
493 alert(__("You can't clear this type of feed."));
494 return;
495 }
496
497 var fn = getFeedName(actid);
498
499 var pr = __("Erase all non-starred articles in %s?").replace("%s", fn);
500
501 if (confirm(pr)) {
502 clearFeedArticles(actid);
503 }
504
505 return;
506 }
507
508
509 if (opid == "qmcUpdateFeeds") {
510 scheduleFeedUpdate(true);
511 return;
512 }
513
514 if (opid == "qmcCatchupAll") {
515 catchupAllFeeds();
516 return;
517 }
518
519 if (opid == "qmcShowOnlyUnread") {
520 toggleDispRead();
521 return;
522 }
523
524 if (opid == "qmcAddFilter") {
525 displayDlg("quickAddFilter", getActiveFeedId());
526 }
527
528 if (opid == "qmcRescoreFeed") {
529 rescoreCurrentFeed();
530 }
531
532 } catch (e) {
533 exception_error("quickMenuGo", e);
534 }
535 }
536
537 function unsubscribeFeed(feed_id) {
538
539 notify_progress("Removing feed...");
540
541 var query = "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id;
542
543 new Ajax.Request(query, {
544 onComplete: function(transport) {
545 dlg_frefresh_callback(transport, feed_id);
546 } });
547
548
549 return false;
550 }
551
552
553 function updateFeedTitle(t) {
554 active_title_text = t;
555 updateTitle();
556 }
557
558 function toggleDispRead() {
559 try {
560
561 var hide_read_feeds = (getInitParam("hide_read_feeds") == "1");
562
563 hide_read_feeds = !hide_read_feeds;
564
565 debug("toggle_disp_read => " + hide_read_feeds);
566
567 hideOrShowFeeds(getFeedsContext().document, hide_read_feeds);
568
569 storeInitParam("hide_read_feeds", hide_read_feeds, true);
570
571 } catch (e) {
572 exception_error("toggleDispRead", e);
573 }
574 }
575
576 function parse_runtime_info(elem) {
577 if (!elem) {
578 debug("parse_runtime_info: elem is null, aborting");
579 return;
580 }
581
582 var param = elem.firstChild;
583
584 debug("parse_runtime_info: " + param);
585
586 while (param) {
587 var k = param.getAttribute("key");
588 var v = param.getAttribute("value");
589
590 debug("RI: " + k + " => " + v);
591
592 if (k == "new_version_available") {
593 var icon = document.getElementById("newVersionIcon");
594 if (icon) {
595 if (v == "1") {
596 icon.style.display = "inline";
597 } else {
598 icon.style.display = "none";
599 }
600 }
601 }
602
603 var error_flag;
604
605 if (k == "daemon_is_running" && v != 1) {
606 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
607 error_flag = true;
608 }
609
610 if (k == "daemon_stamp_ok" && v != 1) {
611 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
612 error_flag = true;
613 }
614
615 if (!error_flag) {
616 notify('');
617 }
618
619 /* var w = document.getElementById("noDaemonWarning");
620
621 if (w) {
622 if (k == "daemon_is_running" && v != 1) {
623 w.style.display = "block";
624 } else {
625 w.style.display = "none";
626 }
627 } */
628 param = param.nextSibling;
629 }
630 }
631
632 function catchupCurrentFeed() {
633
634 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
635
636 var str = __("Mark all articles in %s as read?").replace("%s", fn);
637
638 /* if (active_feed_is_cat) {
639 str = "Mark all articles in this category as read?";
640 } */
641
642 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
643 return viewCurrentFeed('MarkAllRead')
644 }
645 }
646
647 function editFeedDlg(feed) {
648 try {
649
650 if (!feed) {
651 alert(__("Please select some feed first."));
652 return;
653 }
654
655 if ((feed <= 0 && feed > -10) || activeFeedIsCat() || tagsAreDisplayed()) {
656 alert(__("You can't edit this kind of feed."));
657 return;
658 }
659
660 var query = "";
661
662 if (feed > 0) {
663 query = "backend.php?op=pref-feeds&subop=editfeed&id=" + param_escape(feed);
664 } else {
665 query = "backend.php?op=pref-labels&subop=edit&id=" + param_escape(-feed-11);
666 }
667
668 disableHotkeys();
669
670 new Ajax.Request(query, {
671 onComplete: function(transport) {
672 infobox_callback2(transport);
673 } });
674
675 } catch (e) {
676 exception_error("editFeedDlg", e);
677 }
678 }
679
680 /* this functions duplicate those of prefs.js feed editor, with
681 some differences because there is no feedlist */
682
683 function feedEditCancel() {
684 closeInfoBox();
685 return false;
686 }
687
688 function feedEditSave() {
689
690 try {
691
692 // FIXME: add parameter validation
693
694 var query = Form.serialize("edit_feed_form");
695
696 notify_progress("Saving feed...");
697
698 new Ajax.Request("backend.php", {
699 parameters: query,
700 onComplete: function(transport) {
701 dlg_frefresh_callback(transport);
702 } });
703
704
705 closeInfoBox();
706
707 return false;
708
709 } catch (e) {
710 exception_error("feedEditSave (main)", e);
711 }
712 }
713
714 function labelEditCancel() {
715 closeInfoBox();
716 return false;
717 }
718
719 function labelEditSave() {
720
721 try {
722
723 closeInfoBox();
724
725 notify_progress("Saving label...");
726
727 query = Form.serialize("label_edit_form");
728
729 new Ajax.Request("backend.php?" + query, {
730 onComplete: function(transport) {
731 dlg_frefresh_callback(transport);
732 } });
733
734 return false;
735
736 } catch (e) {
737 exception_error("feedEditSave (main)", e);
738 }
739
740 }
741
742 function clearFeedArticles(feed_id) {
743
744 notify_progress("Clearing feed...");
745
746 var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
747
748 new Ajax.Request(query, {
749 onComplete: function(transport) {
750 dlg_frefresh_callback(transport, feed_id);
751 } });
752
753 return false;
754 }
755
756 /*
757 function toggle_feedlist() {
758 try {
759 debug("toggle_feedlist");
760
761 var fl = document.getElementById("feeds-holder");
762
763 if (!Element.visible(fl)) {
764 Element.show(fl);
765 fl.style.zIndex = 30;
766 fl.scrollTop = _hfd_scrolltop;
767 } else {
768 _hfd_scrolltop = fl.scrollTop;
769 Element.hide(fl);
770 // Effect.Fade(fl, {duration : 0.2,
771 // queue: { position: 'end', scope: 'FLFADEQ', limit: 1 }});
772 }
773 } catch (e) {
774 exception_error(e, "toggle_feedlist");
775 }
776 } */
777
778 function collapse_feedlist() {
779 try {
780 debug("toggle_feedlist");
781
782 var theme = getInitParam("theme");
783 if (theme != "" && theme != "compact" && theme != "graycube" &&
784 theme != "compat") return;
785
786 var fl = document.getElementById("feeds-holder");
787 var fh = document.getElementById("headlines-frame");
788 var fc = document.getElementById("content-frame");
789 var ft = document.getElementById("toolbar");
790 var ff = document.getElementById("footer");
791 var fhdr = document.getElementById("header");
792 var fbtn = document.getElementById("collapse_feeds_btn");
793
794 if (!Element.visible(fl)) {
795 Element.show(fl);
796 fbtn.value = "<<";
797
798 if (theme != "graycube") {
799
800 fh.style.left = fl.offsetWidth + "px";
801 ft.style.left = fl.offsetWidth + "px";
802 if (fc) fc.style.left = fl.offsetWidth + "px";
803 if (ff && theme != "compat") ff.style.left = (fl.offsetWidth-1) + "px";
804
805 if (theme == "compact") fhdr.style.left = (fl.offsetWidth + 10) + "px";
806 } else {
807 fh.style.left = fl.offsetWidth + 40 + "px";
808 ft.style.left = fl.offsetWidth + 40 +"px";
809 if (fc) fc.style.left = fl.offsetWidth + 40 + "px";
810 }
811
812 setCookie("ttrss_vf_fclps", "0");
813
814 } else {
815 Element.hide(fl);
816 fbtn.value = ">>";
817
818 if (theme != "graycube") {
819
820 fh.style.left = "0px";
821 ft.style.left = "0px";
822 if (fc) fc.style.left = "0px";
823 if (ff) ff.style.left = "0px";
824
825 if (theme == "compact") fhdr.style.left = "10px";
826
827 } else {
828 fh.style.left = "20px";
829 ft.style.left = "20px";
830 if (fc) fc.style.left = "20px";
831
832 }
833
834 setCookie("ttrss_vf_fclps", "1");
835 }
836 } catch (e) {
837 exception_error(e, "toggle_feedlist");
838 }
839 }
840
841 function viewModeChanged() {
842 cache_empty();
843 return viewCurrentFeed(0, '')
844 }
845
846 function viewLimitChanged() {
847 cache_empty();
848 return viewCurrentFeed(0, '')
849 }
850
851 function adjustArticleScore(id, score) {
852 try {
853
854 var pr = prompt(__("Assign score to article:"), score);
855
856 if (pr != undefined) {
857 var query = "backend.php?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
858
859 new Ajax.Request(query, {
860 onComplete: function(transport) {
861 viewCurrentFeed();
862 } });
863
864 }
865 } catch (e) {
866 exception_error(e, "adjustArticleScore");
867 }
868 }
869
870 function rescoreCurrentFeed() {
871
872 var actid = getActiveFeedId();
873
874 if (activeFeedIsCat() || actid < 0 || tagsAreDisplayed()) {
875 alert(__("You can't rescore this kind of feed."));
876 return;
877 }
878
879 if (!actid) {
880 alert(__("Please select some feed first."));
881 return;
882 }
883
884 var fn = getFeedName(actid);
885 var pr = __("Rescore articles in %s?").replace("%s", fn);
886
887 if (confirm(pr)) {
888 notify_progress("Rescoring articles...");
889
890 var query = "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
891
892 new Ajax.Request(query, {
893 onComplete: function(transport) {
894 viewCurrentFeed();
895 } });
896 }
897 }
898
899