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