]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
remove obsolete methods to call init(); code cleanup
[tt-rss.git] / tt-rss.js
1
2 var total_unread = 0;
3 var first_run = true;
4 var display_tags = false;
5 var global_unread = -1;
6 var active_title_text = "";
7 var current_subtitle = "";
8 var daemon_enabled = false;
9 var daemon_refresh_only = false;
10 //var _qfd_deleted_feed = 0;
11 var firsttime_update = true;
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 var hotkey_prefix = false;
18 var hotkey_prefix_pressed = false;
19 var init_params = new Object();
20 var ver_offset = 0;
21 var hor_offset = 0;
22 var feeds_sort_by_unread = false;
23 var feedlist_sortable_enabled = false;
24
25 function activeFeedIsCat() {
26 return _active_feed_is_cat;
27 }
28
29 function getActiveFeedId() {
30 // return getCookie("ttrss_vf_actfeed");
31 try {
32 debug("gAFID: " + _active_feed_id);
33 return _active_feed_id;
34 } catch (e) {
35 exception_error("getActiveFeedId", e);
36 }
37 }
38
39 function setActiveFeedId(id, is_cat) {
40 // return setCookie("ttrss_vf_actfeed", id);
41 try {
42 debug("sAFID(" + id + ", " + is_cat + ")");
43 _active_feed_id = id;
44
45 if (is_cat != undefined) {
46 _active_feed_is_cat = is_cat;
47 }
48
49 } catch (e) {
50 exception_error("setActiveFeedId", e);
51 }
52 }
53
54
55 function isFeedlistSortable() {
56 return feedlist_sortable_enabled;
57 }
58
59 function tagsAreDisplayed() {
60 return display_tags;
61 }
62
63 function toggleTags(show_all) {
64
65 try {
66
67 debug("toggleTags: " + show_all + "; " + display_tags);
68
69 var p = $("dispSwitchPrompt");
70
71 if (!show_all && !display_tags) {
72 displayDlg("printTagCloud");
73 } else if (show_all) {
74 closeInfoBox();
75 display_tags = true;
76 p.innerHTML = __("display feeds");
77 notify_progress("Loading, please wait...", true);
78 updateFeedList();
79 } else if (display_tags) {
80 display_tags = false;
81 p.innerHTML = __("tag cloud");
82 notify_progress("Loading, please wait...", true);
83 updateFeedList();
84 }
85
86 } catch (e) {
87 exception_error("toggleTags", e);
88 }
89 }
90
91 function dlg_frefresh_callback(transport, deleted_feed) {
92 if (getActiveFeedId() == deleted_feed) {
93 var h = $("headlines-frame");
94 if (h) {
95 h.innerHTML = "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
96 }
97 }
98
99 setTimeout('updateFeedList(false, false)', 50);
100 closeInfoBox();
101 }
102
103 function refetch_callback2(transport) {
104 try {
105
106 var date = new Date();
107
108 parse_counters_reply(transport, true);
109
110 debug("refetch_callback2: done");
111
112 /* if (!daemon_enabled && !daemon_refresh_only) {
113 notify_info("All feeds updated.");
114 updateTitle("");
115 } else {
116 //notify("");
117 } */
118 } catch (e) {
119 exception_error("refetch_callback", e);
120 updateTitle("");
121 }
122 }
123
124 function backend_sanity_check_callback(transport) {
125
126 try {
127
128 if (sanity_check_done) {
129 fatalError(11, "Sanity check request received twice. This can indicate "+
130 "presence of Firebug or some other disrupting extension. "+
131 "Please disable it and try again.");
132 return;
133 }
134
135 if (!transport.responseXML) {
136 if (!store) {
137 fatalError(3, "Sanity check: Received reply is not XML",
138 transport.responseText);
139 return;
140 } else {
141 init_offline();
142 return;
143 }
144 }
145
146 if (getURLParam("offline")) {
147 return init_offline();
148 }
149
150 var reply = transport.responseXML.firstChild.firstChild;
151
152 if (!reply) {
153 fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
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, reply.getAttribute("error-msg"));
161 }
162
163 debug("sanity check ok");
164
165 var params = reply.nextSibling;
166
167 if (params) {
168 debug('reading init-params...');
169 var param = params.firstChild;
170
171 while (param) {
172 var k = param.getAttribute("key");
173 var v = param.getAttribute("value");
174 debug(k + " => " + v);
175 init_params[k] = v;
176
177 if (db) {
178 db.execute("DELETE FROM init_params WHERE key = ?", [k]);
179 db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
180 [k, v]);
181 }
182
183 param = param.nextSibling;
184 }
185 }
186
187 sanity_check_done = true;
188
189 init_second_stage();
190
191 } catch (e) {
192 exception_error("backend_sanity_check_callback", e, transport);
193 }
194 }
195
196 function scheduleFeedUpdate(force) {
197
198 debug("in scheduleFeedUpdate");
199
200 /* if (!daemon_enabled && !daemon_refresh_only) {
201 notify_progress("Updating feeds...", true);
202 } */
203
204 var query_str = "backend.php?op=rpc&subop=";
205
206 if (force) {
207 query_str = query_str + "forceUpdateAllFeeds";
208 } else {
209 query_str = query_str + "updateAllFeeds";
210 }
211
212 var omode;
213
214 if (firsttime_update && !navigator.userAgent.match("Opera")) {
215 firsttime_update = false;
216 omode = "T";
217 } else {
218 if (display_tags) {
219 omode = "tl";
220 } else {
221 omode = "flc";
222 }
223 }
224
225 query_str = query_str + "&omode=" + omode;
226 query_str = query_str + "&uctr=" + global_unread;
227
228 var date = new Date();
229 var timestamp = Math.round(date.getTime() / 1000);
230 query_str = query_str + "&ts=" + timestamp
231
232 debug("REFETCH query: " + query_str);
233
234 new Ajax.Request(query_str, {
235 onComplete: function(transport) {
236 refetch_callback2(transport);
237 } });
238 }
239
240 function updateFeedList(silent, fetch) {
241
242 // if (silent != true) {
243 // notify("Loading feed list...");
244 // }
245
246 debug("<b>updateFeedList</b>");
247
248 if (offline_mode) return render_offline_feedlist();
249
250 var query_str = "backend.php?op=feeds";
251
252 if (display_tags) {
253 query_str = query_str + "&tags=1";
254 }
255
256 if (getActiveFeedId() && !activeFeedIsCat()) {
257 query_str = query_str + "&actid=" + getActiveFeedId();
258 }
259
260 var date = new Date();
261 var timestamp = Math.round(date.getTime() / 1000);
262 query_str = query_str + "&ts=" + timestamp
263
264 if (fetch) query_str = query_str + "&fetch=yes";
265
266 // var feeds_frame = $("feeds-frame");
267 // feeds_frame.src = query_str;
268
269 debug("updateFeedList Q=" + query_str);
270
271 new Ajax.Request(query_str, {
272 onComplete: function(transport) {
273 feedlist_callback2(transport);
274 } });
275
276 }
277
278 function catchupAllFeeds() {
279
280 var str = __("Mark all articles as read?");
281
282 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
283
284 var query_str = "backend.php?op=feeds&subop=catchupAll";
285
286 notify_progress("Marking all feeds as read...");
287
288 debug("catchupAllFeeds Q=" + query_str);
289
290 new Ajax.Request(query_str, {
291 onComplete: function(transport) {
292 feedlist_callback2(transport);
293 } });
294
295 global_unread = 0;
296 updateTitle("");
297 }
298 }
299
300 function viewCurrentFeed(subop) {
301
302 // if (getActiveFeedId()) {
303 if (getActiveFeedId() != undefined) {
304 viewfeed(getActiveFeedId(), subop, activeFeedIsCat());
305 } else {
306 disableContainerChildren("headlinesToolbar", false, document);
307 // viewfeed(-1, subop); // FIXME
308 }
309 return false; // block unneeded form submits
310 }
311
312 function viewfeed(feed, subop) {
313 var f = window.frames["feeds-frame"];
314 f.viewfeed(feed, subop);
315 }
316
317 function timeout() {
318 if (getInitParam("bw_limit") == "1") return;
319
320 scheduleFeedUpdate(false);
321
322 var refresh_time = getInitParam("feeds_frame_refresh");
323
324 if (!refresh_time) refresh_time = 600;
325
326 setTimeout("timeout()", refresh_time*1000);
327 }
328
329 function resetSearch() {
330 var searchbox = $("searchbox")
331
332 if (searchbox.value != "" && getActiveFeedId()) {
333 searchbox.value = "";
334 viewfeed(getActiveFeedId(), "");
335 }
336 }
337
338 function searchCancel() {
339 closeInfoBox(true);
340 }
341
342 function search() {
343 closeInfoBox();
344 viewCurrentFeed(0, "");
345 }
346
347 // if argument is undefined, current subtitle is not updated
348 // use blank string to clear subtitle
349 function updateTitle(s) {
350 var tmp = "Tiny Tiny RSS";
351
352 if (s != undefined) {
353 current_subtitle = s;
354 }
355
356 if (global_unread > 0) {
357 tmp = tmp + " (" + global_unread + ")";
358 }
359
360 if (current_subtitle) {
361 tmp = tmp + " - " + current_subtitle;
362 }
363
364 if (active_title_text.length > 0) {
365 tmp = tmp + " > " + active_title_text;
366 }
367
368 document.title = tmp;
369 }
370
371 function genericSanityCheck() {
372
373 // if (!Ajax.getTransport()) fatalError(1);
374
375 setCookie("ttrss_vf_test", "TEST");
376
377 if (getCookie("ttrss_vf_test") != "TEST") {
378 fatalError(2);
379 }
380
381 return true;
382 }
383
384 function init() {
385
386 try {
387
388 init_gears();
389
390 disableContainerChildren("headlinesToolbar", true);
391
392 Form.disable("main_toolbar_form");
393
394 if (!genericSanityCheck())
395 return;
396
397 if (getURLParam('debug')) {
398 Element.show("debug_output");
399 debug('debug mode activated');
400 }
401
402 var params = "&ua=" + param_escape(navigator.userAgent);
403
404 loading_set_progress(30);
405
406 new Ajax.Request("backend.php?op=rpc&subop=sanityCheck" + params, {
407 onComplete: function(transport) {
408 backend_sanity_check_callback(transport);
409 } });
410
411 } catch (e) {
412 exception_error("init", e);
413 }
414 }
415
416 function resize_headlines(delta_x, delta_y) {
417
418 try {
419
420 debug("resize_headlines: " + delta_x + ":" + delta_y);
421
422 var h_frame = $("headlines-frame");
423 var c_frame = $("content-frame");
424 var f_frame = $("footer");
425 var feeds_frame = $("feeds-holder");
426 var resize_grab = $("resize-grabber");
427 var resize_handle = $("resize-handle");
428
429 if (!c_frame || !h_frame) return;
430
431 if (feeds_frame && getInitParam("theme") == "compat") {
432 feeds_frame.style.bottom = f_frame.offsetHeight + "px";
433 }
434
435 if (getInitParam("theme") == "3pane") {
436
437 if (delta_x != undefined) {
438 if (c_frame.offsetLeft - delta_x > feeds_frame.offsetWidth + feeds_frame.offsetLeft + 100 && c_frame.offsetWidth + delta_x > 100) {
439 hor_offset = hor_offset + delta_x;
440 }
441 }
442
443 debug("resize_headlines: HOR-mode: " + hor_offset);
444
445 c_frame.style.width = (400 + hor_offset) + "px";
446 h_frame.style.right = c_frame.offsetWidth - 1 + "px";
447
448 resize_grab.style.top = (h_frame.offsetTop + h_frame.offsetHeight - 60) + "px";
449 resize_grab.style.left = (h_frame.offsetLeft + h_frame.offsetWidth -
450 4) + "px";
451 resize_grab.style.display = "block";
452
453 resize_handle.src = "themes/3pane/images/resize_handle_vert.png";
454 resize_handle.style.paddingTop = (resize_grab.offsetHeight / 2 - 7) + "px";
455
456 } else {
457
458 if (delta_y != undefined) {
459 if (c_frame.offsetHeight + delta_y > 100 && h_frame.offsetHeight - delta_y > 100) {
460 ver_offset = ver_offset + delta_y;
461 }
462 }
463
464 debug("resize_headlines: VER-mode: " + ver_offset);
465
466 h_frame.style.height = (300 - ver_offset) + "px";
467
468 c_frame.style.top = (h_frame.offsetTop + h_frame.offsetHeight + 0) + "px";
469 h_frame.style.height = h_frame.offsetHeight + "px";
470
471 var theme_c = 0;
472
473 if (getInitParam("theme") == "graycube") {
474 theme_c = 1;
475 }
476
477 if (getInitParam("theme") == "graycube" || getInitParam("theme") == "compat") {
478 resize_handle.src = "themes/graycube/images/resize_handle_horiz.png";
479 }
480
481 /* resize_grab.style.top = (h_frame.offsetTop + h_frame.offsetHeight -
482 4 - theme_c) + "px";
483 resize_grab.style.display = "block"; */
484
485 }
486
487 if (getInitParam("cookie_lifetime") != 0) {
488 setCookie("ttrss_offset_ver", ver_offset,
489 getInitParam("cookie_lifetime"));
490 setCookie("ttrss_offset_hor", hor_offset,
491 getInitParam("cookie_lifetime"));
492 } else {
493 setCookie("ttrss_offset_ver", ver_offset);
494 setCookie("ttrss_offset_hor", hor_offset);
495 }
496
497 } catch (e) {
498 exception_error("resize_headlines", e);
499 }
500
501 }
502
503 function init_second_stage() {
504
505 try {
506
507 delCookie("ttrss_vf_test");
508
509 // document.onresize = resize_headlines;
510 window.onresize=resize_headlines;
511
512 var toolbar = document.forms["main_toolbar_form"];
513
514 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
515 dropboxSelect(toolbar.limit, getInitParam("default_view_limit"));
516 dropboxSelect(toolbar.order_by, getInitParam("default_view_order_by"));
517
518 daemon_enabled = getInitParam("daemon_enabled") == 1;
519 daemon_refresh_only = getInitParam("daemon_refresh_only") == 1;
520 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
521
522 /* var fl = cache_find_param("FEEDLIST", getInitParam("num_feeds"));
523
524 if (fl) {
525 render_feedlist(fl);
526 if ($("feedList")) {
527 request_counters();
528 } else {
529 setTimeout('updateFeedList(false, false)', 50);
530 }
531 } else {
532 setTimeout('updateFeedList(false, false)', 50);
533 } */
534
535 setTimeout('updateFeedList(false, false)', 50);
536
537 debug("second stage ok");
538
539 loading_set_progress(60);
540
541 ver_offset = parseInt(getCookie("ttrss_offset_ver"));
542 hor_offset = parseInt(getCookie("ttrss_offset_hor"));
543
544 debug("got offsets from cookies: ver " + ver_offset + " hor " + hor_offset);
545
546 /* fuck IE */
547
548 if (isNaN(hor_offset)) hor_offset = 0;
549 if (isNaN(ver_offset)) ver_offset = 0;
550
551 debug("offsets from cookies [x:y]: " + hor_offset + ":" + ver_offset);
552
553 resize_headlines();
554
555 enable_offline_reading();
556
557 } catch (e) {
558 exception_error("init_second_stage", e);
559 }
560 }
561
562 function quickMenuChange() {
563 var chooser = $("quickMenuChooser");
564 var opid = chooser[chooser.selectedIndex].value;
565
566 chooser.selectedIndex = 0;
567 quickMenuGo(opid);
568 }
569
570 function quickMenuGo(opid) {
571 try {
572
573 if (opid == "qmcPrefs") {
574 gotoPreferences();
575 }
576
577 if (opid == "qmcSearch") {
578 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
579 return;
580 }
581
582 if (opid == "qmcAddFeed") {
583 displayDlg("quickAddFeed");
584 return;
585 }
586
587 if (opid == "qmcEditFeed") {
588 editFeedDlg(getActiveFeedId());
589 }
590
591 if (opid == "qmcRemoveFeed") {
592 var actid = getActiveFeedId();
593
594 if (activeFeedIsCat()) {
595 alert(__("You can't unsubscribe from the category."));
596 return;
597 }
598
599 if (!actid) {
600 alert(__("Please select some feed first."));
601 return;
602 }
603
604 var fn = getFeedName(actid);
605
606 var pr = __("Unsubscribe from %s?").replace("%s", fn);
607
608 if (confirm(pr)) {
609 unsubscribeFeed(actid);
610 }
611
612 return;
613 }
614
615 if (opid == "qmcClearFeed") {
616 var actid = getActiveFeedId();
617
618 if (!actid) {
619 alert(__("Please select some feed first."));
620 return;
621 }
622
623 if (activeFeedIsCat() || actid < 0) {
624 alert(__("You can't clear this type of feed."));
625 return;
626 }
627
628 var fn = getFeedName(actid);
629
630 var pr = __("Erase all non-starred articles in %s?").replace("%s", fn);
631
632 if (confirm(pr)) {
633 clearFeedArticles(actid);
634 }
635
636 return;
637 }
638
639
640 if (opid == "qmcUpdateFeeds") {
641 scheduleFeedUpdate(true);
642 return;
643 }
644
645 if (opid == "qmcCatchupAll") {
646 catchupAllFeeds();
647 return;
648 }
649
650 if (opid == "qmcShowOnlyUnread") {
651 toggleDispRead();
652 return;
653 }
654
655 if (opid == "qmcAddFilter") {
656 displayDlg("quickAddFilter", getActiveFeedId());
657 }
658
659 if (opid == "qmcAddLabel") {
660 addLabel();
661 }
662
663 if (opid == "qmcRescoreFeed") {
664 rescoreCurrentFeed();
665 }
666
667 if (opid == "qmcHKhelp") {
668 //Element.show("hotkey_help_overlay");
669 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
670 }
671
672 if (opid == "qmcResetUI") {
673 hor_offset = 0;
674 ver_offset = 0;
675 resize_headlines();
676 }
677
678 if (opid == "qmcResetCats") {
679
680 if (confirm(__("Reset category order?"))) {
681
682 var query = "backend.php?op=feeds&subop=catsortreset";
683
684 notify_progress("Loading, please wait...", true);
685
686 new Ajax.Request(query, {
687 onComplete: function(transport) {
688 window.setTimeout('updateFeedList(false, false)', 50);
689 } });
690 }
691 }
692
693 } catch (e) {
694 exception_error("quickMenuGo", e);
695 }
696 }
697
698 function unsubscribeFeed(feed_id, title) {
699
700
701 var msg = __("Unsubscribe from %s?").replace("%s", title);
702
703 if (title == undefined || confirm(msg)) {
704 notify_progress("Removing feed...");
705
706 var query = "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id;
707
708 new Ajax.Request(query, {
709 onComplete: function(transport) {
710 dlg_frefresh_callback(transport, feed_id);
711 } });
712 }
713
714 return false;
715 }
716
717
718 function updateFeedTitle(t) {
719 active_title_text = t;
720 updateTitle();
721 }
722
723 function toggleDispRead() {
724 try {
725
726 var hide_read_feeds = (getInitParam("hide_read_feeds") == "1");
727
728 hide_read_feeds = !hide_read_feeds;
729
730 debug("toggle_disp_read => " + hide_read_feeds);
731
732 hideOrShowFeeds(hide_read_feeds);
733
734 storeInitParam("hide_read_feeds", hide_read_feeds, true);
735
736 } catch (e) {
737 exception_error("toggleDispRead", e);
738 }
739 }
740
741 function parse_runtime_info(elem) {
742 if (!elem) {
743 debug("parse_runtime_info: elem is null, aborting");
744 return;
745 }
746
747 var param = elem.firstChild;
748
749 debug("parse_runtime_info: " + param);
750
751 while (param) {
752 var k = param.getAttribute("key");
753 var v = param.getAttribute("value");
754
755 debug("RI: " + k + " => " + v);
756
757 if (k == "num_feeds") {
758 init_params[k] = v;
759 }
760
761 if (k == "new_version_available") {
762 var icon = $("newVersionIcon");
763 if (icon) {
764 if (v == "1") {
765 icon.style.display = "inline";
766 } else {
767 icon.style.display = "none";
768 }
769 }
770 }
771
772 var error_flag;
773
774 if (k == "daemon_is_running" && v != 1) {
775 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
776 error_flag = true;
777 }
778
779 if (k == "daemon_stamp_ok" && v != 1) {
780 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
781 error_flag = true;
782 }
783
784 if (!error_flag) {
785 notify('');
786 }
787
788 /* var w = $("noDaemonWarning");
789
790 if (w) {
791 if (k == "daemon_is_running" && v != 1) {
792 w.style.display = "block";
793 } else {
794 w.style.display = "none";
795 }
796 } */
797 param = param.nextSibling;
798 }
799 }
800
801 function catchupCurrentFeed() {
802
803 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
804
805 var str = __("Mark all articles in %s as read?").replace("%s", fn);
806
807 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
808 return viewCurrentFeed('MarkAllRead')
809 }
810 }
811
812 function catchupFeedInGroup(id) {
813
814 try {
815
816 var title = getFeedName(id);
817
818 var str = __("Mark all articles in %s as read?").replace("%s", title);
819
820 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
821 return viewCurrentFeed('MarkAllReadGR:' + id)
822 }
823
824 } catch (e) {
825 exception_error("catchupFeedInGroup", e);
826 }
827 }
828
829 function editFeedDlg(feed) {
830 try {
831
832 if (!feed) {
833 alert(__("Please select some feed first."));
834 return;
835 }
836
837 if ((feed <= 0) || activeFeedIsCat() || tagsAreDisplayed()) {
838 alert(__("You can't edit this kind of feed."));
839 return;
840 }
841
842 var query = "";
843
844 if (feed > 0) {
845 query = "backend.php?op=pref-feeds&subop=editfeed&id=" + param_escape(feed);
846 } else {
847 query = "backend.php?op=pref-labels&subop=edit&id=" + param_escape(-feed-11);
848 }
849
850 disableHotkeys();
851
852 notify_progress("Loading, please wait...", true);
853
854 new Ajax.Request(query, {
855 onComplete: function(transport) {
856 infobox_callback2(transport);
857 } });
858
859 } catch (e) {
860 exception_error("editFeedDlg", e);
861 }
862 }
863
864 /* this functions duplicate those of prefs.js feed editor, with
865 some differences because there is no feedlist */
866
867 function feedEditCancel() {
868 closeInfoBox();
869 return false;
870 }
871
872 function feedEditSave() {
873
874 try {
875
876 // FIXME: add parameter validation
877
878 var query = Form.serialize("edit_feed_form");
879
880 notify_progress("Saving feed...");
881
882 new Ajax.Request("backend.php", {
883 parameters: query,
884 onComplete: function(transport) {
885 dlg_frefresh_callback(transport);
886 } });
887
888
889 closeInfoBox();
890
891 return false;
892
893 } catch (e) {
894 exception_error("feedEditSave (main)", e);
895 }
896 }
897
898 function clearFeedArticles(feed_id) {
899
900 notify_progress("Clearing feed...");
901
902 var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
903
904 new Ajax.Request(query, {
905 onComplete: function(transport) {
906 dlg_frefresh_callback(transport, feed_id);
907 } });
908
909 return false;
910 }
911
912 function collapse_feedlist() {
913 try {
914 debug("toggle_feedlist");
915
916 var theme = getInitParam("theme");
917 if (theme != "" && theme != "compact" && theme != "graycube" &&
918 theme != "compat") return;
919
920 var fl = $("feeds-holder");
921 var fh = $("headlines-frame");
922 var fc = $("content-frame");
923 var ft = $("toolbar");
924 var ff = $("footer");
925 var fhdr = $("header");
926 var fbtn = $("collapse_feeds_btn");
927
928 if (!Element.visible(fl)) {
929 Element.show(fl);
930 fbtn.value = "<<";
931
932 if (theme != "graycube") {
933
934 fh.style.left = fl.offsetWidth + "px";
935 ft.style.left = fl.offsetWidth + "px";
936 if (fc) fc.style.left = fl.offsetWidth + "px";
937 if (ff && theme != "compat") ff.style.left = (fl.offsetWidth-1) + "px";
938
939 if (theme == "compact") fhdr.style.left = (fl.offsetWidth + 10) + "px";
940 } else {
941 fh.style.left = fl.offsetWidth + 40 + "px";
942 ft.style.left = fl.offsetWidth + 40 +"px";
943 if (fc) fc.style.left = fl.offsetWidth + 40 + "px";
944 }
945
946 setCookie("ttrss_vf_fclps", "0");
947
948 } else {
949 Element.hide(fl);
950 fbtn.value = ">>";
951
952 if (theme != "graycube") {
953
954 fh.style.left = "0px";
955 ft.style.left = "0px";
956 if (fc) fc.style.left = "0px";
957 if (ff) ff.style.left = "0px";
958
959 if (theme == "compact") fhdr.style.left = "10px";
960
961 } else {
962 fh.style.left = "20px";
963 ft.style.left = "20px";
964 if (fc) fc.style.left = "20px";
965
966 }
967
968 setCookie("ttrss_vf_fclps", "1");
969 }
970 } catch (e) {
971 exception_error("toggle_feedlist", e);
972 }
973 }
974
975 function viewModeChanged() {
976 cache_empty();
977 return viewCurrentFeed(0, '')
978 }
979
980 function viewLimitChanged() {
981 cache_empty();
982 return viewCurrentFeed(0, '')
983 }
984
985 /* function adjustArticleScore(id, score) {
986 try {
987
988 var pr = prompt(__("Assign score to article:"), score);
989
990 if (pr != undefined) {
991 var query = "backend.php?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
992
993 new Ajax.Request(query, {
994 onComplete: function(transport) {
995 viewCurrentFeed();
996 } });
997
998 }
999 } catch (e) {
1000 exception_error("adjustArticleScore", e);
1001 }
1002 } */
1003
1004 function rescoreCurrentFeed() {
1005
1006 var actid = getActiveFeedId();
1007
1008 if (activeFeedIsCat() || actid < 0 || tagsAreDisplayed()) {
1009 alert(__("You can't rescore this kind of feed."));
1010 return;
1011 }
1012
1013 if (!actid) {
1014 alert(__("Please select some feed first."));
1015 return;
1016 }
1017
1018 var fn = getFeedName(actid);
1019 var pr = __("Rescore articles in %s?").replace("%s", fn);
1020
1021 if (confirm(pr)) {
1022 notify_progress("Rescoring articles...");
1023
1024 var query = "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
1025
1026 new Ajax.Request(query, {
1027 onComplete: function(transport) {
1028 viewCurrentFeed();
1029 } });
1030 }
1031 }
1032
1033 function hotkey_handler(e) {
1034
1035 try {
1036
1037 var keycode;
1038 var shift_key = false;
1039
1040 var cmdline = $('cmdline');
1041 var feedlist = $('feedList');
1042
1043 try {
1044 shift_key = e.shiftKey;
1045 } catch (e) {
1046
1047 }
1048
1049 if (window.event) {
1050 keycode = window.event.keyCode;
1051 } else if (e) {
1052 keycode = e.which;
1053 }
1054
1055 var keychar = String.fromCharCode(keycode);
1056
1057 if (keycode == 27) { // escape
1058 if (Element.visible("hotkey_help_overlay")) {
1059 Element.hide("hotkey_help_overlay");
1060 }
1061 hotkey_prefix = false;
1062 closeInfoBox();
1063 }
1064
1065 if (!hotkeys_enabled) {
1066 debug("hotkeys disabled");
1067 return;
1068 }
1069
1070 if (keycode == 16) return; // ignore lone shift
1071
1072 if ((keycode == 70 || keycode == 67 || keycode == 71)
1073 && !hotkey_prefix) {
1074
1075 var date = new Date();
1076 var ts = Math.round(date.getTime() / 1000);
1077
1078 hotkey_prefix = keycode;
1079 hotkey_prefix_pressed = ts;
1080
1081 cmdline.innerHTML = keychar;
1082 Element.show(cmdline);
1083
1084 debug("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
1085 return true;
1086 }
1087
1088 if (Element.visible("hotkey_help_overlay")) {
1089 Element.hide("hotkey_help_overlay");
1090 }
1091
1092 /* Global hotkeys */
1093
1094 Element.hide(cmdline);
1095
1096 if (!hotkey_prefix) {
1097
1098 if (keycode == 68 && shift_key) { // d
1099 if (!Element.visible("debug_output")) {
1100 Element.show("debug_output");
1101 debug('debug mode activated');
1102 } else {
1103 Element.hide("debug_output");
1104 }
1105
1106 return;
1107 }
1108
1109 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
1110 if (!Element.visible("hotkey_help_overlay")) {
1111 //Element.show("hotkey_help_overlay");
1112 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
1113 } else {
1114 Element.hide("hotkey_help_overlay");
1115 }
1116 return false;
1117 }
1118
1119 if (keycode == 191 || keychar == '/') { // /
1120 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
1121 return false;
1122 }
1123
1124 if (keycode == 82 && shift_key) { // R
1125 scheduleFeedUpdate(true);
1126 return;
1127 }
1128
1129 if (keycode == 74) { // j
1130 var feed = getActiveFeedId();
1131 var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'prev');
1132 // alert(feed + " IC: " + activeFeedIsCat() + " => " + new_feed);
1133 if (new_feed) {
1134 var is_cat = new_feed.match("CAT:");
1135 if (is_cat) {
1136 new_feed = new_feed.replace("CAT:", "");
1137 viewCategory(new_feed);
1138 } else {
1139 viewfeed(new_feed, '', false);
1140 }
1141 }
1142 return;
1143 }
1144
1145 if (keycode == 75) { // k
1146 var feed = getActiveFeedId();
1147 var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'next');
1148 // alert(feed + " IC: " + activeFeedIsCat() + " => " + new_feed);
1149 if (new_feed) {
1150 var is_cat = new_feed.match("CAT:");
1151 if (is_cat == "CAT:") {
1152 new_feed = new_feed.replace("CAT:", "");
1153 viewCategory(new_feed);
1154 } else {
1155 viewfeed(new_feed, '', false);
1156 }
1157 }
1158 return;
1159 }
1160
1161 if (shift_key && keycode == 40) { // shift-down
1162 catchupRelativeToArticle(1);
1163 return;
1164 }
1165
1166 if (shift_key && keycode == 38) { // shift-up
1167 catchupRelativeToArticle(0);
1168 return;
1169 }
1170
1171 if (shift_key && keycode == 78) { // N
1172 scrollArticle(50);
1173 return;
1174 }
1175
1176 if (shift_key && keycode == 80) { // P
1177 scrollArticle(-50);
1178 return;
1179 }
1180
1181
1182 if (keycode == 78 || keycode == 40) { // n, down
1183 if (typeof moveToPost != 'undefined') {
1184 moveToPost('next');
1185 return;
1186 }
1187 }
1188
1189 if (keycode == 80 || keycode == 38) { // p, up
1190 if (typeof moveToPost != 'undefined') {
1191 moveToPost('prev');
1192 return;
1193 }
1194 }
1195
1196 if (keycode == 83 && shift_key) { // S
1197 var id = getActiveArticleId();
1198 if (id) {
1199 togglePub(id);
1200 }
1201 return;
1202 }
1203
1204 if (keycode == 83) { // s
1205 var id = getActiveArticleId();
1206 if (id) {
1207 toggleMark(id);
1208 }
1209 return;
1210 }
1211
1212
1213 if (keycode == 85) { // u
1214 var id = getActiveArticleId();
1215 if (id) {
1216 toggleUnread(id);
1217 }
1218 return;
1219 }
1220
1221 if (keycode == 84 && shift_key) { // T
1222 var id = getActiveArticleId();
1223 if (id) {
1224 editArticleTags(id, getActiveFeedId(), isCdmMode());
1225 return;
1226 }
1227 }
1228
1229 if (keycode == 9) { // tab
1230 var id = getArticleUnderPointer();
1231 if (id) {
1232 var cb = $("RCHK-" + id);
1233
1234 if (cb) {
1235 cb.checked = !cb.checked;
1236 toggleSelectRowById(cb, "RROW-" + id);
1237 return false;
1238 }
1239 }
1240 }
1241
1242 if (keycode == 79) { // o
1243 if (getActiveArticleId()) {
1244 openArticleInNewWindow(getActiveArticleId());
1245 return;
1246 }
1247 }
1248
1249 if (keycode == 81 && shift_key) { // Q
1250 if (typeof catchupAllFeeds != 'undefined') {
1251 catchupAllFeeds();
1252 return;
1253 }
1254 }
1255
1256 if (keycode == 88) { // x
1257 if (activeFeedIsCat()) {
1258 toggleCollapseCat(getActiveFeedId());
1259 }
1260 }
1261 }
1262
1263 /* Prefix f */
1264
1265 if (hotkey_prefix == 70) { // f
1266
1267 hotkey_prefix = false;
1268
1269 if (keycode == 81) { // q
1270 if (getActiveFeedId()) {
1271 catchupCurrentFeed();
1272 return;
1273 }
1274 }
1275
1276 if (keycode == 82) { // r
1277 if (getActiveFeedId()) {
1278 viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
1279 return;
1280 }
1281 }
1282
1283 if (keycode == 65) { // a
1284 toggleDispRead();
1285 return false;
1286 }
1287
1288 if (keycode == 85 && shift_key) { // U
1289 scheduleFeedUpdate(true);
1290 return false;
1291 }
1292
1293 if (keycode == 85) { // u
1294 if (getActiveFeedId()) {
1295 viewfeed(getActiveFeedId(), "ForceUpdate");
1296 return false;
1297 }
1298 }
1299
1300 if (keycode == 69) { // e
1301 editFeedDlg(getActiveFeedId());
1302 return false;
1303 }
1304
1305 if (keycode == 83) { // s
1306 displayDlg("quickAddFeed");
1307 return false;
1308 }
1309
1310 if (keycode == 67 && shift_key) { // C
1311 if (typeof catchupAllFeeds != 'undefined') {
1312 catchupAllFeeds();
1313 return false;
1314 }
1315 }
1316
1317 if (keycode == 67) { // c
1318 if (getActiveFeedId()) {
1319 catchupCurrentFeed();
1320 return false;
1321 }
1322 }
1323
1324 if (keycode == 87) { // w
1325 feeds_sort_by_unread = !feeds_sort_by_unread;
1326 return resort_feedlist();
1327 }
1328
1329 if (keycode == 72) { // h
1330 hideReadHeadlines();
1331 return;
1332 }
1333
1334 }
1335
1336 /* Prefix c */
1337
1338 if (hotkey_prefix == 67) { // c
1339 hotkey_prefix = false;
1340
1341 if (keycode == 70) { // f
1342 displayDlg("quickAddFilter", getActiveFeedId());
1343 return false;
1344 }
1345
1346 if (keycode == 76) { // l
1347 addLabel();
1348 return false;
1349 }
1350
1351 if (keycode == 83) { // s
1352 if (typeof collapse_feedlist != 'undefined') {
1353 collapse_feedlist();
1354 return false;
1355 }
1356 }
1357
1358 if (keycode == 77) { // m
1359 feedlist_sortable_enabled = !feedlist_sortable_enabled;
1360 if (feedlist_sortable_enabled) {
1361 notify_info("Category reordering enabled");
1362 toggle_sortable_feedlist(true);
1363 } else {
1364 notify_info("Category reordering disabled");
1365 toggle_sortable_feedlist(false);
1366 }
1367 }
1368
1369 if (keycode == 78) { // n
1370 catchupRelativeToArticle(1);
1371 return;
1372 }
1373
1374 if (keycode == 80) { // p
1375 catchupRelativeToArticle(0);
1376 return;
1377 }
1378
1379
1380 }
1381
1382 /* Prefix g */
1383
1384 if (hotkey_prefix == 71) { // g
1385
1386 hotkey_prefix = false;
1387
1388
1389 if (keycode == 65) { // a
1390 viewfeed(-4);
1391 return false;
1392 }
1393
1394 if (keycode == 83) { // s
1395 viewfeed(-1);
1396 return false;
1397 }
1398
1399 if (keycode == 80 && shift_key) { // P
1400 gotoPreferences();
1401 return false;
1402 }
1403
1404 if (keycode == 80) { // p
1405 viewfeed(-2);
1406 return false;
1407 }
1408
1409 if (keycode == 70) { // f
1410 viewfeed(-3);
1411 return false;
1412 }
1413
1414 if (keycode == 84 && shift_key) { // T
1415 toggleTags();
1416 return false;
1417 }
1418 }
1419
1420 /* Cmd */
1421
1422 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f
1423 hotkey_prefix = false;
1424 return;
1425 }
1426
1427 if (hotkey_prefix) {
1428 debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1429 } else {
1430 debug("KP: CODE=" + keycode + " CHAR=" + keychar);
1431 }
1432
1433
1434 } catch (e) {
1435 exception_error("hotkey_handler", e);
1436 }
1437 }
1438
1439 function feedsSortByUnread() {
1440 return feeds_sort_by_unread;
1441 }
1442
1443 function addLabel() {
1444
1445 try {
1446
1447 var caption = prompt(__("Please enter label caption:"), "");
1448
1449 if (caption != undefined) {
1450
1451 if (caption == "") {
1452 alert(__("Can't create label: missing caption."));
1453 return false;
1454 }
1455
1456 var query = "backend.php?op=pref-labels&subop=add&caption=" +
1457 param_escape(caption);
1458
1459 notify_progress("Loading, please wait...", true);
1460
1461 new Ajax.Request(query, {
1462 onComplete: function(transport) {
1463 updateFeedList();
1464 } });
1465
1466 }
1467
1468 } catch (e) {
1469 exception_error("addLabel", e);
1470 }
1471 }
1472
1473 function visitOfficialSite() {
1474 window.open("http://tt-rss.org/");
1475 }
1476
1477
1478 function feedBrowserSubscribe() {
1479 try {
1480
1481 var selected = getSelectedFeedsFromBrowser();
1482
1483 if (selected.length > 0) {
1484 closeInfoBox();
1485
1486 notify_progress("Loading, please wait...", true);
1487
1488 var query = "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1489 param_escape(selected.toString());
1490
1491 new Ajax.Request(query, {
1492 onComplete: function(transport) {
1493 updateFeedList();
1494 } });
1495
1496 } else {
1497 alert(__("No feeds are selected."));
1498 }
1499
1500 } catch (e) {
1501 exception_error("feedBrowserSubscribe", e);
1502 }
1503 }
1504
1505