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