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