]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
js: misc code cleanup, handle ctrl-clicking on postContent
[tt-rss.git] / tt-rss.js
1 var total_unread = 0;
2 var global_unread = -1;
3 var firsttime_update = true;
4 var _active_feed_id = 0;
5 var _active_feed_is_cat = false;
6 var number_of_feeds = 0;
7 var hotkey_prefix = false;
8 var hotkey_prefix_pressed = false;
9 var init_params = {};
10 var _force_scheduled_update = false;
11 var last_scheduled_update = false;
12 var treeModel;
13
14 var _rpc_seq = 0;
15
16 function next_seq() {
17 _rpc_seq += 1;
18 return _rpc_seq;
19 }
20
21 function get_seq() {
22 return _rpc_seq;
23 }
24
25 function activeFeedIsCat() {
26 return _active_feed_is_cat;
27 }
28
29 function getActiveFeedId() {
30 try {
31 //console.log("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 _active_feed_id = id;
41
42 if (is_cat != undefined) {
43 _active_feed_is_cat = is_cat;
44 }
45
46 selectFeed(id, is_cat);
47
48 } catch (e) {
49 exception_error("setActiveFeedId", e);
50 }
51 }
52
53
54 function dlg_frefresh_callback(transport, deleted_feed) {
55 if (getActiveFeedId() == deleted_feed) {
56 setTimeout("viewfeed(-5)", 100);
57 }
58
59 setTimeout('updateFeedList()', 50);
60 closeInfoBox();
61 }
62
63 function updateFeedList() {
64 try {
65
66 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
67 // __("Loading, please wait...") + "</div>";
68
69 Element.show("feedlistLoading");
70
71 if (dijit.byId("feedTree")) {
72 dijit.byId("feedTree").destroyRecursive();
73 }
74
75 var store = new dojo.data.ItemFileWriteStore({
76 url: "backend.php?op=feeds"});
77
78 treeModel = new dijit.tree.ForestStoreModel({
79 store: store,
80 query: {
81 "type": "feed"
82 },
83 rootId: "root",
84 rootLabel: "Feeds",
85 childrenAttrs: ["items"]
86 });
87
88 var tree = new dijit.Tree({
89 model: treeModel,
90 _createTreeNode: function(args) {
91 var tnode = new dijit._TreeNode(args);
92
93 if (args.item.icon)
94 tnode.iconNode.src = args.item.icon[0];
95
96 //tnode.labelNode.innerHTML = args.label;
97 return tnode;
98 },
99 getIconClass: function (item, opened) {
100 return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
101 },
102 getLabelClass: function (item, opened) {
103 return (item.unread == 0) ? "dijitTreeLabel" : "dijitTreeLabel Unread";
104 },
105 getRowClass: function (item, opened) {
106 return (!item.error || item.error == '') ? "dijitTreeRow" :
107 "dijitTreeRow Error";
108 },
109 getLabel: function(item) {
110 if (item.unread > 0) {
111 return item.name + " (" + item.unread + ")";
112 } else {
113 return item.name;
114 }
115 },
116 onOpen: function (item, node) {
117 var id = String(item.id);
118 var cat_id = id.substr(id.indexOf(":")+1);
119
120 new Ajax.Request("backend.php",
121 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
122 param_escape(cat_id) + "&mode=1" } );
123 },
124 onClose: function (item, node) {
125 var id = String(item.id);
126 var cat_id = id.substr(id.indexOf(":")+1);
127
128 new Ajax.Request("backend.php",
129 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
130 param_escape(cat_id) + "&mode=0" } );
131
132 },
133 onClick: function (item, node) {
134 var id = String(item.id);
135 var is_cat = id.match("^CAT:");
136 var feed = id.substr(id.indexOf(":")+1);
137 viewfeed(feed, '', is_cat);
138 return false;
139 },
140 openOnClick: false,
141 showRoot: false,
142 id: "feedTree",
143 }, "feedTree");
144
145 $("feeds-holder").appendChild(tree.domNode);
146
147 var tmph = dojo.connect(tree, 'onLoad', function() {
148 dojo.disconnect(tmph);
149 Element.hide("feedlistLoading");
150 });
151
152 tree.startup();
153
154 } catch (e) {
155 exception_error("updateFeedList", e);
156 }
157 }
158
159 function catchupAllFeeds() {
160
161 var str = __("Mark all articles as read?");
162
163 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
164
165 var query_str = "backend.php?op=feeds&subop=catchupAll";
166
167 notify_progress("Marking all feeds as read...");
168
169 //console.log("catchupAllFeeds Q=" + query_str);
170
171 new Ajax.Request("backend.php", {
172 parameters: query_str,
173 onComplete: function(transport) {
174 feedlist_callback2(transport);
175 } });
176
177 global_unread = 0;
178 updateTitle("");
179 }
180 }
181
182 function viewCurrentFeed(subop) {
183
184 if (getActiveFeedId() != undefined) {
185 viewfeed(getActiveFeedId(), subop, activeFeedIsCat());
186 }
187 return false; // block unneeded form submits
188 }
189
190 function timeout() {
191 if (getInitParam("bw_limit") == "1") return;
192
193 try {
194 var date = new Date();
195 var ts = Math.round(date.getTime() / 1000);
196
197 if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
198
199 //console.log("timeout()");
200
201 window.clearTimeout(counter_timeout_id);
202
203 var query_str = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
204
205 var omode;
206
207 if (firsttime_update && !navigator.userAgent.match("Opera")) {
208 firsttime_update = false;
209 omode = "T";
210 } else {
211 omode = "flc";
212 }
213
214 query_str = query_str + "&omode=" + omode;
215
216 if (!_force_scheduled_update)
217 query_str = query_str + "&last_article_id=" + getInitParam("last_article_id");
218
219 //console.log("[timeout]" + query_str);
220
221 new Ajax.Request("backend.php", {
222 parameters: query_str,
223 onComplete: function(transport) {
224 handle_rpc_reply(transport, !_force_scheduled_update);
225 _force_scheduled_update = false;
226 } });
227
228 last_scheduled_update = ts;
229 }
230
231 } catch (e) {
232 exception_error("timeout", e);
233 }
234
235 setTimeout("timeout()", 3000);
236 }
237
238 function search() {
239 closeInfoBox();
240 viewCurrentFeed();
241 }
242
243 function updateTitle() {
244 var tmp = "Tiny Tiny RSS";
245
246 if (global_unread > 0) {
247 tmp = tmp + " (" + global_unread + ")";
248 }
249
250 if (window.fluid) {
251 if (global_unread > 0) {
252 window.fluid.dockBadge = global_unread;
253 } else {
254 window.fluid.dockBadge = "";
255 }
256 }
257
258 document.title = tmp;
259 }
260
261 function genericSanityCheck() {
262 setCookie("ttrss_test", "TEST");
263
264 if (getCookie("ttrss_test") != "TEST") {
265 fatalError(2);
266 }
267
268 return true;
269 }
270
271 function init() {
272 try {
273 Form.disable("main_toolbar_form");
274
275 dojo.require("dijit.layout.BorderContainer");
276 dojo.require("dijit.layout.TabContainer");
277 dojo.require("dijit.layout.ContentPane");
278 dojo.require("dijit.Dialog");
279 dojo.require("dijit.form.Button");
280 dojo.require("dojo.data.ItemFileWriteStore");
281 dojo.require("dijit.Tree");
282 dojo.require("dijit.form.Select");
283 dojo.require("dojo.parser");
284
285 dojo.addOnLoad(function() {
286 updateFeedList();
287 closeArticlePanel();
288 });
289
290 if (!genericSanityCheck())
291 return;
292
293 var params = "&ua=" + param_escape(navigator.userAgent);
294
295 loading_set_progress(30);
296
297 new Ajax.Request("backend.php", {
298 parameters: "backend.php?op=rpc&subop=sanityCheck" + params,
299 onComplete: function(transport) {
300 backend_sanity_check_callback(transport);
301 } });
302
303 } catch (e) {
304 exception_error("init", e);
305 }
306 }
307
308 function init_second_stage() {
309
310 try {
311
312 delCookie("ttrss_test");
313
314 var toolbar = document.forms["main_toolbar_form"];
315
316 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
317 dropboxSelect(toolbar.order_by, getInitParam("default_view_order_by"));
318
319 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
320
321 loading_set_progress(60);
322
323 if (has_local_storage())
324 localStorage.clear();
325
326 feedlist_init();
327 setTimeout("timeout()", 3000);
328
329 console.log("second stage ok");
330
331 } catch (e) {
332 exception_error("init_second_stage", e);
333 }
334 }
335
336 function quickMenuChange() {
337 var chooser = $("quickMenuChooser");
338 var opid = chooser[chooser.selectedIndex].value;
339
340 chooser.selectedIndex = 0;
341 quickMenuGo(opid);
342 }
343
344 function quickMenuGo(opid) {
345 try {
346
347 if (opid == "qmcPrefs") {
348 gotoPreferences();
349 }
350
351 if (opid == "qmcTagCloud") {
352 displayDlg("printTagCloud");
353 }
354
355 if (opid == "qmcSearch") {
356 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
357 function() {
358 document.forms['search_form'].query.focus();
359 });
360 return;
361 }
362
363 if (opid == "qmcAddFeed") {
364 quickAddFeed();
365 return;
366 }
367
368 if (opid == "qmcEditFeed") {
369 editFeedDlg(getActiveFeedId());
370 }
371
372 if (opid == "qmcRemoveFeed") {
373 var actid = getActiveFeedId();
374
375 if (activeFeedIsCat()) {
376 alert(__("You can't unsubscribe from the category."));
377 return;
378 }
379
380 if (!actid) {
381 alert(__("Please select some feed first."));
382 return;
383 }
384
385 var fn = getFeedName(actid);
386
387 var pr = __("Unsubscribe from %s?").replace("%s", fn);
388
389 if (confirm(pr)) {
390 unsubscribeFeed(actid);
391 }
392
393 return;
394 }
395
396 if (opid == "qmcCatchupAll") {
397 catchupAllFeeds();
398 return;
399 }
400
401 if (opid == "qmcShowOnlyUnread") {
402 toggleDispRead();
403 return;
404 }
405
406 if (opid == "qmcAddFilter") {
407 displayDlg('quickAddFilter', '',
408 function () {document.forms['filter_add_form'].reg_exp.focus();});
409 }
410
411 if (opid == "qmcAddLabel") {
412 addLabel();
413 }
414
415 if (opid == "qmcRescoreFeed") {
416 rescoreCurrentFeed();
417 }
418
419 if (opid == "qmcHKhelp") {
420 //Element.show("hotkey_help_overlay");
421 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
422 }
423
424 } catch (e) {
425 exception_error("quickMenuGo", e);
426 }
427 }
428
429 function toggleDispRead() {
430 try {
431
432 var hide = !(getInitParam("hide_read_feeds") == "1");
433
434 hideOrShowFeeds(hide);
435
436 var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
437 param_escape(hide);
438
439 new Ajax.Request("backend.php", {
440 parameters: query,
441 onComplete: function(transport) {
442 setInitParam("hide_read_feeds", hide);
443 } });
444
445 } catch (e) {
446 exception_error("toggleDispRead", e);
447 }
448 }
449
450 function parse_runtime_info(elem) {
451
452 if (!elem || !elem.firstChild) {
453 console.warn("parse_runtime_info: invalid node passed");
454 return;
455 }
456
457 var data = JSON.parse(elem.firstChild.nodeValue);
458
459 //console.log("parsing runtime info...");
460
461 for (k in data) {
462 var v = data[k];
463
464 // console.log("RI: " + k + " => " + v);
465
466 if (k == "new_version_available") {
467 var icon = $("newVersionIcon");
468 if (icon) {
469 if (v == "1") {
470 icon.style.display = "inline";
471 } else {
472 icon.style.display = "none";
473 }
474 }
475 return;
476 }
477
478 var error_flag;
479
480 if (k == "daemon_is_running" && v != 1) {
481 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
482 return;
483 }
484
485 if (k == "daemon_stamp_ok" && v != 1) {
486 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
487 return;
488 }
489
490 init_params[k] = v;
491 notify('');
492 }
493 }
494
495 function catchupCurrentFeed() {
496
497 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
498
499 var str = __("Mark all articles in %s as read?").replace("%s", fn);
500
501 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
502 return viewCurrentFeed('MarkAllRead')
503 }
504 }
505
506 function catchupFeedInGroup(id) {
507
508 try {
509
510 var title = getFeedName(id);
511
512 var str = __("Mark all articles in %s as read?").replace("%s", title);
513
514 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
515 return viewCurrentFeed('MarkAllReadGR:' + id)
516 }
517
518 } catch (e) {
519 exception_error("catchupFeedInGroup", e);
520 }
521 }
522
523 function editFeedDlg(feed) {
524 try {
525
526 if (!feed) {
527 alert(__("Please select some feed first."));
528 return;
529 }
530
531 if ((feed <= 0) || activeFeedIsCat()) {
532 alert(__("You can't edit this kind of feed."));
533 return;
534 }
535
536 var query = "";
537
538 if (feed > 0) {
539 query = "?op=pref-feeds&subop=editfeed&id=" + param_escape(feed);
540 } else {
541 query = "?op=pref-labels&subop=edit&id=" + param_escape(-feed-11);
542 }
543
544 disableHotkeys();
545
546 notify_progress("Loading, please wait...", true);
547
548 new Ajax.Request("backend.php", {
549 parameters: query,
550 onComplete: function(transport) {
551 infobox_callback2(transport);
552 document.forms["edit_feed_form"].title.focus();
553 } });
554
555 } catch (e) {
556 exception_error("editFeedDlg", e);
557 }
558 }
559
560 /* this functions duplicate those of prefs.js feed editor, with
561 some differences because there is no feedlist */
562
563 function feedEditCancel() {
564 closeInfoBox();
565 return false;
566 }
567
568 function feedEditSave() {
569
570 try {
571
572 // FIXME: add parameter validation
573
574 var query = Form.serialize("edit_feed_form");
575
576 notify_progress("Saving feed...");
577
578 new Ajax.Request("backend.php", {
579 parameters: query,
580 onComplete: function(transport) {
581 dlg_frefresh_callback(transport);
582 } });
583
584 cache_flush();
585 closeInfoBox();
586
587 return false;
588
589 } catch (e) {
590 exception_error("feedEditSave (main)", e);
591 }
592 }
593
594 function collapse_feedlist() {
595 try {
596
597 if (!Element.visible('feeds-holder')) {
598 Element.show('feeds-holder');
599 $("collapse_feeds_btn").innerHTML = "&lt;&lt;";
600 } else {
601 Element.hide('feeds-holder');
602 $("collapse_feeds_btn").innerHTML = "&gt;&gt;";
603 }
604
605 dijit.byId("main").resize();
606
607 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
608 new Ajax.Request("backend.php", { parameters: query });
609
610 } catch (e) {
611 exception_error("collapse_feedlist", e);
612 }
613 }
614
615 function viewModeChanged() {
616 cache_flush();
617 return viewCurrentFeed('')
618 }
619
620 function viewLimitChanged() {
621 cache_flush();
622 return viewCurrentFeed('')
623 }
624
625 /* function adjustArticleScore(id, score) {
626 try {
627
628 var pr = prompt(__("Assign score to article:"), score);
629
630 if (pr != undefined) {
631 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
632
633 new Ajax.Request("backend.php", {
634 parameters: query,
635 onComplete: function(transport) {
636 viewCurrentFeed();
637 } });
638
639 }
640 } catch (e) {
641 exception_error("adjustArticleScore", e);
642 }
643 } */
644
645 function rescoreCurrentFeed() {
646
647 var actid = getActiveFeedId();
648
649 if (activeFeedIsCat() || actid < 0) {
650 alert(__("You can't rescore this kind of feed."));
651 return;
652 }
653
654 if (!actid) {
655 alert(__("Please select some feed first."));
656 return;
657 }
658
659 var fn = getFeedName(actid);
660 var pr = __("Rescore articles in %s?").replace("%s", fn);
661
662 if (confirm(pr)) {
663 notify_progress("Rescoring articles...");
664
665 var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
666
667 new Ajax.Request("backend.php", {
668 parameters: query,
669 onComplete: function(transport) {
670 viewCurrentFeed();
671 } });
672 }
673 }
674
675 function hotkey_handler(e) {
676
677 try {
678
679 var keycode;
680 var shift_key = false;
681
682 var cmdline = $('cmdline');
683
684 try {
685 shift_key = e.shiftKey;
686 } catch (e) {
687
688 }
689
690 if (window.event) {
691 keycode = window.event.keyCode;
692 } else if (e) {
693 keycode = e.which;
694 }
695
696 var keychar = String.fromCharCode(keycode);
697
698 if (keycode == 27) { // escape
699 if (Element.visible("hotkey_help_overlay")) {
700 Element.hide("hotkey_help_overlay");
701 }
702 hotkey_prefix = false;
703 closeInfoBox();
704 }
705
706 var dialog = dijit.byId("infoBox");
707 var dialog_visible = false;
708
709 if (dialog)
710 dialog_visible = Element.visible(dialog.domNode);
711
712 if (dialog_visible || !hotkeys_enabled) {
713 console.log("hotkeys disabled");
714 return;
715 }
716
717 if (keycode == 16) return; // ignore lone shift
718 if (keycode == 17) return; // ignore lone ctrl
719
720 if ((keycode == 70 || keycode == 67 || keycode == 71)
721 && !hotkey_prefix) {
722
723 var date = new Date();
724 var ts = Math.round(date.getTime() / 1000);
725
726 hotkey_prefix = keycode;
727 hotkey_prefix_pressed = ts;
728
729 cmdline.innerHTML = keychar;
730 Element.show(cmdline);
731
732 console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
733 return true;
734 }
735
736 if (Element.visible("hotkey_help_overlay")) {
737 Element.hide("hotkey_help_overlay");
738 }
739
740 /* Global hotkeys */
741
742 Element.hide(cmdline);
743
744 if (!hotkey_prefix) {
745
746 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
747 if (!Element.visible("hotkey_help_overlay")) {
748 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
749 } else {
750 Element.hide("hotkey_help_overlay");
751 }
752 return false;
753 }
754
755 if (keycode == 191 || keychar == '/') { // /
756 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
757 function() {
758 document.forms['search_form'].query.focus();
759 });
760 return false;
761 }
762
763 if (keycode == 74) { // j
764 // TODO: move to previous feed
765 return;
766 }
767
768 if (keycode == 75) { // k
769 // TODO: move to next feed
770 return;
771 }
772
773 if (shift_key && keycode == 40) { // shift-down
774 catchupRelativeToArticle(1);
775 return;
776 }
777
778 if (shift_key && keycode == 38) { // shift-up
779 catchupRelativeToArticle(0);
780 return;
781 }
782
783 if (shift_key && keycode == 78) { // N
784 scrollArticle(50);
785 return;
786 }
787
788 if (shift_key && keycode == 80) { // P
789 scrollArticle(-50);
790 return;
791 }
792
793 if (keycode == 68 && shift_key) { // shift-D
794 dismissSelectedArticles();
795 }
796
797 if (keycode == 88 && shift_key) { // shift-X
798 dismissReadArticles();
799 }
800
801 if (keycode == 78 || keycode == 40) { // n, down
802 if (typeof moveToPost != 'undefined') {
803 moveToPost('next');
804 return false;
805 }
806 }
807
808 if (keycode == 80 || keycode == 38) { // p, up
809 if (typeof moveToPost != 'undefined') {
810 moveToPost('prev');
811 return false;
812 }
813 }
814
815 if (keycode == 83 && shift_key) { // S
816 selectionTogglePublished(undefined, false, true);
817 return;
818 }
819
820 if (keycode == 83) { // s
821 selectionToggleMarked(undefined, false, true);
822 return;
823 }
824
825
826 if (keycode == 85) { // u
827 selectionToggleUnread(undefined, false, true)
828 return;
829 }
830
831 if (keycode == 84 && shift_key) { // T
832 var id = getActiveArticleId();
833 if (id) {
834 editArticleTags(id, getActiveFeedId(), isCdmMode());
835 return;
836 }
837 }
838
839 if (keycode == 9) { // tab
840 var id = getArticleUnderPointer();
841 if (id) {
842 var cb = $("RCHK-" + id);
843
844 if (cb) {
845 cb.checked = !cb.checked;
846 toggleSelectRowById(cb, "RROW-" + id);
847 return false;
848 }
849 }
850 }
851
852 if (keycode == 79) { // o
853 if (getActiveArticleId()) {
854 openArticleInNewWindow(getActiveArticleId());
855 return;
856 }
857 }
858
859 if (keycode == 81 && shift_key) { // Q
860 if (typeof catchupAllFeeds != 'undefined') {
861 catchupAllFeeds();
862 return;
863 }
864 }
865
866 if (keycode == 88) { // x
867 if (activeFeedIsCat()) {
868 toggleCollapseCat(getActiveFeedId());
869 }
870 }
871 }
872
873 /* Prefix f */
874
875 if (hotkey_prefix == 70) { // f
876
877 hotkey_prefix = false;
878
879 if (keycode == 81) { // q
880 if (getActiveFeedId()) {
881 catchupCurrentFeed();
882 return;
883 }
884 }
885
886 if (keycode == 82) { // r
887 if (getActiveFeedId()) {
888 viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
889 return;
890 }
891 }
892
893 if (keycode == 65) { // a
894 toggleDispRead();
895 return false;
896 }
897
898 if (keycode == 85) { // u
899 if (getActiveFeedId()) {
900 viewfeed(getActiveFeedId(), "ForceUpdate");
901 return false;
902 }
903 }
904
905 if (keycode == 69) { // e
906 editFeedDlg(getActiveFeedId());
907 return false;
908 }
909
910 if (keycode == 83) { // s
911 quickAddFeed();
912 return false;
913 }
914
915 if (keycode == 67 && shift_key) { // C
916 if (typeof catchupAllFeeds != 'undefined') {
917 catchupAllFeeds();
918 return false;
919 }
920 }
921
922 if (keycode == 67) { // c
923 if (getActiveFeedId()) {
924 catchupCurrentFeed();
925 return false;
926 }
927 }
928
929 if (keycode == 87) { // w
930 feeds_sort_by_unread = !feeds_sort_by_unread;
931 return resort_feedlist();
932 }
933
934 if (keycode == 88) { // x
935 reverseHeadlineOrder();
936 return;
937 }
938 }
939
940 /* Prefix c */
941
942 if (hotkey_prefix == 67) { // c
943 hotkey_prefix = false;
944
945 if (keycode == 70) { // f
946 displayDlg('quickAddFilter', '',
947 function () {document.forms['filter_add_form'].reg_exp.focus();});
948 return false;
949 }
950
951 if (keycode == 76) { // l
952 addLabel();
953 return false;
954 }
955
956 if (keycode == 83) { // s
957 if (typeof collapse_feedlist != 'undefined') {
958 collapse_feedlist();
959 return false;
960 }
961 }
962
963 if (keycode == 77) { // m
964 // TODO: sortable feedlist
965 return;
966 }
967
968 if (keycode == 78) { // n
969 catchupRelativeToArticle(1);
970 return;
971 }
972
973 if (keycode == 80) { // p
974 catchupRelativeToArticle(0);
975 return;
976 }
977
978
979 }
980
981 /* Prefix g */
982
983 if (hotkey_prefix == 71) { // g
984
985 hotkey_prefix = false;
986
987
988 if (keycode == 65) { // a
989 viewfeed(-4);
990 return false;
991 }
992
993 if (keycode == 83) { // s
994 viewfeed(-1);
995 return false;
996 }
997
998 if (keycode == 80 && shift_key) { // P
999 gotoPreferences();
1000 return false;
1001 }
1002
1003 if (keycode == 80) { // p
1004 viewfeed(-2);
1005 return false;
1006 }
1007
1008 if (keycode == 70) { // f
1009 viewfeed(-3);
1010 return false;
1011 }
1012
1013 if (keycode == 84 && shift_key) { // T
1014 toggleTags();
1015 return false;
1016 }
1017 }
1018
1019 /* Cmd */
1020
1021 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f
1022 hotkey_prefix = false;
1023 return;
1024 }
1025
1026 if (hotkey_prefix) {
1027 console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1028 } else {
1029 console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
1030 }
1031
1032
1033 } catch (e) {
1034 exception_error("hotkey_handler", e);
1035 }
1036 }
1037
1038 function inPreferences() {
1039 return false;
1040 }
1041
1042 function reverseHeadlineOrder() {
1043 try {
1044
1045 var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1046
1047 new Ajax.Request("backend.php", {
1048 parameters: query_str,
1049 onComplete: function(transport) {
1050 viewCurrentFeed();
1051 } });
1052
1053 } catch (e) {
1054 exception_error("reverseHeadlineOrder", e);
1055 }
1056 }
1057
1058 function showFeedsWithErrors() {
1059 displayDlg('feedUpdateErrors');
1060 }
1061
1062 function handle_rpc_reply(transport, scheduled_call) {
1063 try {
1064 if (transport.responseXML) {
1065
1066 if (!transport_error_check(transport)) return false;
1067
1068 var seq = transport.responseXML.getElementsByTagName("seq")[0];
1069
1070 if (seq) {
1071 seq = seq.firstChild.nodeValue;
1072
1073 if (get_seq() != seq) {
1074 //console.log("[handle_rpc_reply] sequence mismatch: " + seq);
1075 return true;
1076 }
1077 }
1078
1079 var message = transport.responseXML.getElementsByTagName("message")[0];
1080
1081 if (message) {
1082 message = message.firstChild.nodeValue;
1083
1084 if (message == "UPDATE_COUNTERS") {
1085 console.log("need to refresh counters...");
1086 setInitParam("last_article_id", -1);
1087 _force_scheduled_update = true;
1088 }
1089 }
1090
1091 var counters = transport.responseXML.getElementsByTagName("counters")[0];
1092
1093 if (counters)
1094 parse_counters(counters, scheduled_call);
1095
1096 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
1097
1098 if (runtime_info)
1099 parse_runtime_info(runtime_info);
1100
1101 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1102
1103 } else {
1104 notify_error("Error communicating with server.");
1105 }
1106
1107 } catch (e) {
1108 exception_error("handle_rpc_reply", e, transport);
1109 }
1110
1111 return true;
1112 }
1113
1114 function scheduleFeedUpdate() {
1115 try {
1116
1117 if (!getActiveFeedId()) {
1118 alert(__("Please select some feed first."));
1119 return;
1120 }
1121
1122 var query = "?op=rpc&subop=scheduleFeedUpdate&id=" +
1123 param_escape(getActiveFeedId()) +
1124 "&is_cat=" + param_escape(activeFeedIsCat());
1125
1126 console.log(query);
1127
1128 new Ajax.Request("backend.php", {
1129 parameters: query,
1130 onComplete: function(transport) {
1131
1132 if (transport.responseXML) {
1133 var message = transport.responseXML.getElementsByTagName("message")[0];
1134
1135 if (message) {
1136 notify_info(message.firstChild.nodeValue);
1137 return;
1138 }
1139 }
1140
1141 notify_error("Error communicating with server.");
1142
1143 } });
1144
1145
1146 } catch (e) {
1147 exception_error("scheduleFeedUpdate", e);
1148 }
1149 }