2 var display_tags = false;
3 var global_unread = -1;
4 var firsttime_update = true;
5 var _active_feed_id = 0;
6 var _active_feed_is_cat = false;
7 var number_of_feeds = 0;
8 var hotkey_prefix = false;
9 var hotkey_prefix_pressed = false;
11 var _force_scheduled_update = false;
12 var last_scheduled_update = false;
25 function activeFeedIsCat() {
26 return _active_feed_is_cat;
29 function getActiveFeedId() {
31 //console.log("gAFID: " + _active_feed_id);
32 return _active_feed_id;
34 exception_error("getActiveFeedId", e);
38 function setActiveFeedId(id, is_cat) {
40 //console.log("sAFID(" + id + ", " + is_cat + ")");
43 if (is_cat != undefined) {
44 _active_feed_is_cat = is_cat;
48 exception_error("setActiveFeedId", e);
53 function isFeedlistSortable() {
54 return feedlist_sortable_enabled;
57 function tagsAreDisplayed() {
61 function toggleTags(show_all) {
65 console.log("toggleTags: " + show_all + "; " + display_tags);
67 var p = $("dispSwitchPrompt");
69 if (!show_all && !display_tags) {
70 displayDlg("printTagCloud");
71 } else if (show_all) {
74 p.innerHTML = __("display feeds");
75 notify_progress("Loading, please wait...", true);
77 } else if (display_tags) {
79 p.innerHTML = __("tag cloud");
80 notify_progress("Loading, please wait...", true);
85 exception_error("toggleTags", e);
89 function dlg_frefresh_callback(transport, deleted_feed) {
90 if (getActiveFeedId() == deleted_feed) {
91 setTimeout("viewfeed(-5)", 100);
94 setTimeout('updateFeedList(false, false)', 50);
98 function updateFeedList() {
100 //console.log("updateFeedList");
102 var query_str = "backend.php?op=feeds";
105 query_str = query_str + "&tags=1";
108 if (getActiveFeedId() && !activeFeedIsCat()) {
109 query_str = query_str + "&actid=" + getActiveFeedId();
112 new Ajax.Request("backend.php", {
113 parameters: query_str,
114 onComplete: function(transport) {
115 render_feedlist(transport.responseText);
119 exception_error("updateFeedList", e);
123 function catchupAllFeeds() {
125 var str = __("Mark all articles as read?");
127 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
129 var query_str = "backend.php?op=feeds&subop=catchupAll";
131 notify_progress("Marking all feeds as read...");
133 //console.log("catchupAllFeeds Q=" + query_str);
135 new Ajax.Request("backend.php", {
136 parameters: query_str,
137 onComplete: function(transport) {
138 feedlist_callback2(transport);
146 function viewCurrentFeed(subop) {
148 if (getActiveFeedId() != undefined) {
149 viewfeed(getActiveFeedId(), subop, activeFeedIsCat());
151 return false; // block unneeded form submits
155 if (getInitParam("bw_limit") == "1") return;
158 var date = new Date();
159 var ts = Math.round(date.getTime() / 1000);
161 if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
163 //console.log("timeout()");
165 window.clearTimeout(counter_timeout_id);
167 var query_str = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
171 if (firsttime_update && !navigator.userAgent.match("Opera")) {
172 firsttime_update = false;
182 query_str = query_str + "&omode=" + omode;
184 if (!_force_scheduled_update)
185 query_str = query_str + "&last_article_id=" + getInitParam("last_article_id");
187 //console.log("[timeout]" + query_str);
189 new Ajax.Request("backend.php", {
190 parameters: query_str,
191 onComplete: function(transport) {
192 handle_rpc_reply(transport, !_force_scheduled_update);
193 _force_scheduled_update = false;
196 last_scheduled_update = ts;
200 exception_error("timeout", e);
203 setTimeout("timeout()", 3000);
211 function updateTitle() {
212 var tmp = "Tiny Tiny RSS";
214 if (global_unread > 0) {
215 tmp = tmp + " (" + global_unread + ")";
219 if (global_unread > 0) {
220 window.fluid.dockBadge = global_unread;
222 window.fluid.dockBadge = "";
226 document.title = tmp;
229 function genericSanityCheck() {
230 setCookie("ttrss_test", "TEST");
232 if (getCookie("ttrss_test") != "TEST") {
241 Form.disable("main_toolbar_form");
243 dojo.require("dijit.layout.BorderContainer");
244 dojo.require("dijit.layout.ContentPane");
245 dojo.require("dijit.Dialog");
246 dojo.require("dijit.form.Button");
248 //return remove_splash();
250 if (!genericSanityCheck())
253 var params = "&ua=" + param_escape(navigator.userAgent);
255 loading_set_progress(30);
257 new Ajax.Request("backend.php", {
258 parameters: "backend.php?op=rpc&subop=sanityCheck" + params,
259 onComplete: function(transport) {
260 backend_sanity_check_callback(transport);
264 exception_error("init", e);
268 function init_second_stage() {
272 delCookie("ttrss_test");
274 var toolbar = document.forms["main_toolbar_form"];
276 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
277 dropboxSelect(toolbar.order_by, getInitParam("default_view_order_by"));
279 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
281 setTimeout('updateFeedList(false, false)', 50);
283 console.log("second stage ok");
285 loading_set_progress(60);
287 if (has_local_storage())
288 localStorage.clear();
291 exception_error("init_second_stage", e);
295 function quickMenuChange() {
296 var chooser = $("quickMenuChooser");
297 var opid = chooser[chooser.selectedIndex].value;
299 chooser.selectedIndex = 0;
303 function quickMenuGo(opid) {
306 if (opid == "qmcPrefs") {
310 if (opid == "qmcSearch") {
311 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
313 document.forms['search_form'].query.focus();
318 if (opid == "qmcAddFeed") {
323 if (opid == "qmcEditFeed") {
324 editFeedDlg(getActiveFeedId());
327 if (opid == "qmcRemoveFeed") {
328 var actid = getActiveFeedId();
330 if (activeFeedIsCat()) {
331 alert(__("You can't unsubscribe from the category."));
336 alert(__("Please select some feed first."));
340 var fn = getFeedName(actid);
342 var pr = __("Unsubscribe from %s?").replace("%s", fn);
345 unsubscribeFeed(actid);
351 if (opid == "qmcCatchupAll") {
356 if (opid == "qmcShowOnlyUnread") {
361 if (opid == "qmcAddFilter") {
362 displayDlg('quickAddFilter', '',
363 function () {document.forms['filter_add_form'].reg_exp.focus();});
366 if (opid == "qmcAddLabel") {
370 if (opid == "qmcRescoreFeed") {
371 rescoreCurrentFeed();
374 if (opid == "qmcHKhelp") {
375 //Element.show("hotkey_help_overlay");
376 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
379 if (opid == "qmcResetUI") {
380 alert("Function not implemented");
383 if (opid == "qmcToggleReorder") {
384 feedlist_sortable_enabled = !feedlist_sortable_enabled;
386 if (feedlist_sortable_enabled) {
387 notify_info("Category reordering enabled");
388 toggle_sortable_feedlist(true);
390 notify_info("Category reordering disabled");
391 toggle_sortable_feedlist(false);
395 if (opid == "qmcResetCats") {
397 if (confirm(__("Reset category order?"))) {
399 var query = "?op=feeds&subop=catsortreset";
401 notify_progress("Loading, please wait...", true);
403 new Ajax.Request("backend.php", {
405 onComplete: function(transport) {
406 window.setTimeout('updateFeedList(false, false)', 50);
412 exception_error("quickMenuGo", e);
416 function toggleDispRead() {
419 var hide = !(getInitParam("hide_read_feeds") == "1");
421 hideOrShowFeeds(hide);
423 var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
426 new Ajax.Request("backend.php", {
428 onComplete: function(transport) {
429 setInitParam("hide_read_feeds", hide);
433 exception_error("toggleDispRead", e);
437 function parse_runtime_info(elem) {
439 if (!elem || !elem.firstChild) {
440 console.warn("parse_runtime_info: invalid node passed");
444 var data = JSON.parse(elem.firstChild.nodeValue);
446 //console.log("parsing runtime info...");
451 // console.log("RI: " + k + " => " + v);
453 if (k == "new_version_available") {
454 var icon = $("newVersionIcon");
457 icon.style.display = "inline";
459 icon.style.display = "none";
467 if (k == "daemon_is_running" && v != 1) {
468 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
472 if (k == "daemon_stamp_ok" && v != 1) {
473 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
482 function catchupCurrentFeed() {
484 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
486 var str = __("Mark all articles in %s as read?").replace("%s", fn);
488 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
489 return viewCurrentFeed('MarkAllRead')
493 function catchupFeedInGroup(id) {
497 var title = getFeedName(id);
499 var str = __("Mark all articles in %s as read?").replace("%s", title);
501 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
502 return viewCurrentFeed('MarkAllReadGR:' + id)
506 exception_error("catchupFeedInGroup", e);
510 function editFeedDlg(feed) {
514 alert(__("Please select some feed first."));
518 if ((feed <= 0) || activeFeedIsCat() || tagsAreDisplayed()) {
519 alert(__("You can't edit this kind of feed."));
526 query = "?op=pref-feeds&subop=editfeed&id=" + param_escape(feed);
528 query = "?op=pref-labels&subop=edit&id=" + param_escape(-feed-11);
533 notify_progress("Loading, please wait...", true);
535 new Ajax.Request("backend.php", {
537 onComplete: function(transport) {
538 infobox_callback2(transport);
539 document.forms["edit_feed_form"].title.focus();
543 exception_error("editFeedDlg", e);
547 /* this functions duplicate those of prefs.js feed editor, with
548 some differences because there is no feedlist */
550 function feedEditCancel() {
555 function feedEditSave() {
559 // FIXME: add parameter validation
561 var query = Form.serialize("edit_feed_form");
563 notify_progress("Saving feed...");
565 new Ajax.Request("backend.php", {
567 onComplete: function(transport) {
568 dlg_frefresh_callback(transport);
577 exception_error("feedEditSave (main)", e);
581 function collapse_feedlist() {
583 //console.log("collapse_feedlist");
585 /* var theme = getInitParam("theme");
587 !getInitParam("theme_options").match("collapse_feedlist")) return;
589 var fl = $("feeds-holder");
590 var fh = $("headlines-frame");
591 var fc = $("content-frame");
592 var ft = $("toolbar");
593 var ff = $("footer");
594 var fhdr = $("header");
595 var fbtn = $("collapse_feeds_btn");
597 if (!Element.visible(fl)) {
599 fbtn.innerHTML = "<<";
601 if (theme != "graycube") {
603 fh.style.left = fl.offsetWidth + "px";
604 ft.style.left = fl.offsetWidth + "px";
605 if (fc) fc.style.left = fl.offsetWidth + "px";
606 if (ff && theme != "compat") ff.style.left = (fl.offsetWidth-1) + "px";
608 if (theme == "compact") fhdr.style.left = (fl.offsetWidth + 10) + "px";
610 fh.style.left = fl.offsetWidth + 40 + "px";
611 ft.style.left = fl.offsetWidth + 40 +"px";
612 if (fc) fc.style.left = fl.offsetWidth + 40 + "px";
615 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=false";
617 new Ajax.Request("backend.php", { parameters: query });
621 fbtn.innerHTML = ">>";
623 if (theme != "graycube") {
625 fh.style.left = "0px";
626 ft.style.left = "0px";
627 if (fc) fc.style.left = "0px";
628 if (ff) ff.style.left = "0px";
630 if (theme == "compact") fhdr.style.left = "10px";
633 fh.style.left = "20px";
634 ft.style.left = "20px";
635 if (fc) fc.style.left = "20px";
639 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
641 new Ajax.Request("backend.php", { parameters: query });
645 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
648 exception_error("collapse_feedlist", e);
652 function viewModeChanged() {
654 return viewCurrentFeed('')
657 function viewLimitChanged() {
659 return viewCurrentFeed('')
662 /* function adjustArticleScore(id, score) {
665 var pr = prompt(__("Assign score to article:"), score);
667 if (pr != undefined) {
668 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
670 new Ajax.Request("backend.php", {
672 onComplete: function(transport) {
678 exception_error("adjustArticleScore", e);
682 function rescoreCurrentFeed() {
684 var actid = getActiveFeedId();
686 if (activeFeedIsCat() || actid < 0 || tagsAreDisplayed()) {
687 alert(__("You can't rescore this kind of feed."));
692 alert(__("Please select some feed first."));
696 var fn = getFeedName(actid);
697 var pr = __("Rescore articles in %s?").replace("%s", fn);
700 notify_progress("Rescoring articles...");
702 var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
704 new Ajax.Request("backend.php", {
706 onComplete: function(transport) {
712 function hotkey_handler(e) {
717 var shift_key = false;
719 var cmdline = $('cmdline');
722 shift_key = e.shiftKey;
728 keycode = window.event.keyCode;
733 var keychar = String.fromCharCode(keycode);
735 if (keycode == 27) { // escape
736 if (Element.visible("hotkey_help_overlay")) {
737 Element.hide("hotkey_help_overlay");
739 hotkey_prefix = false;
743 if (dialogs.length > 0 || !hotkeys_enabled) {
744 console.log("hotkeys disabled");
748 if (keycode == 16) return; // ignore lone shift
749 if (keycode == 17) return; // ignore lone ctrl
751 if ((keycode == 70 || keycode == 67 || keycode == 71)
754 var date = new Date();
755 var ts = Math.round(date.getTime() / 1000);
757 hotkey_prefix = keycode;
758 hotkey_prefix_pressed = ts;
760 cmdline.innerHTML = keychar;
761 Element.show(cmdline);
763 console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
767 if (Element.visible("hotkey_help_overlay")) {
768 Element.hide("hotkey_help_overlay");
773 Element.hide(cmdline);
775 if (!hotkey_prefix) {
777 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
778 if (!Element.visible("hotkey_help_overlay")) {
779 //Element.show("hotkey_help_overlay");
780 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
782 Element.hide("hotkey_help_overlay");
787 if (keycode == 191 || keychar == '/') { // /
788 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
790 document.forms['search_form'].query.focus();
795 /* if (keycode == 82 && shift_key) { // R
796 scheduleFeedUpdate(true);
800 if (keycode == 74) { // j
801 var feed = getActiveFeedId();
802 var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'prev');
803 // alert(feed + " IC: " + activeFeedIsCat() + " => " + new_feed);
805 var is_cat = new_feed.match("CAT:");
807 new_feed = new_feed.replace("CAT:", "");
808 viewCategory(new_feed);
810 viewfeed(new_feed, '', false);
816 if (keycode == 75) { // k
817 var feed = getActiveFeedId();
818 var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'next');
819 // alert(feed + " IC: " + activeFeedIsCat() + " => " + new_feed);
821 var is_cat = new_feed.match("CAT:");
822 if (is_cat == "CAT:") {
823 new_feed = new_feed.replace("CAT:", "");
824 viewCategory(new_feed);
826 viewfeed(new_feed, '', false);
832 if (shift_key && keycode == 40) { // shift-down
833 catchupRelativeToArticle(1);
837 if (shift_key && keycode == 38) { // shift-up
838 catchupRelativeToArticle(0);
842 if (shift_key && keycode == 78) { // N
847 if (shift_key && keycode == 80) { // P
852 if (keycode == 68 && shift_key) { // shift-D
853 dismissSelectedArticles();
856 if (keycode == 88 && shift_key) { // shift-X
857 dismissReadArticles();
860 if (keycode == 78 || keycode == 40) { // n, down
861 if (typeof moveToPost != 'undefined') {
867 if (keycode == 80 || keycode == 38) { // p, up
868 if (typeof moveToPost != 'undefined') {
874 if (keycode == 83 && shift_key) { // S
875 selectionTogglePublished(undefined, false, true);
879 if (keycode == 83) { // s
880 selectionToggleMarked(undefined, false, true);
885 if (keycode == 85) { // u
886 selectionToggleUnread(undefined, false, true)
890 if (keycode == 84 && shift_key) { // T
891 var id = getActiveArticleId();
893 editArticleTags(id, getActiveFeedId(), isCdmMode());
898 if (keycode == 9) { // tab
899 var id = getArticleUnderPointer();
901 var cb = $("RCHK-" + id);
904 cb.checked = !cb.checked;
905 toggleSelectRowById(cb, "RROW-" + id);
911 if (keycode == 79) { // o
912 if (getActiveArticleId()) {
913 openArticleInNewWindow(getActiveArticleId());
918 if (keycode == 81 && shift_key) { // Q
919 if (typeof catchupAllFeeds != 'undefined') {
925 if (keycode == 88) { // x
926 if (activeFeedIsCat()) {
927 toggleCollapseCat(getActiveFeedId());
934 if (hotkey_prefix == 70) { // f
936 hotkey_prefix = false;
938 if (keycode == 81) { // q
939 if (getActiveFeedId()) {
940 catchupCurrentFeed();
945 if (keycode == 82) { // r
946 if (getActiveFeedId()) {
947 viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
952 if (keycode == 65) { // a
957 /* if (keycode == 85 && shift_key) { // U
958 scheduleFeedUpdate(true);
962 if (keycode == 85) { // u
963 if (getActiveFeedId()) {
964 viewfeed(getActiveFeedId(), "ForceUpdate");
969 if (keycode == 69) { // e
970 editFeedDlg(getActiveFeedId());
974 if (keycode == 83) { // s
979 if (keycode == 67 && shift_key) { // C
980 if (typeof catchupAllFeeds != 'undefined') {
986 if (keycode == 67) { // c
987 if (getActiveFeedId()) {
988 catchupCurrentFeed();
993 if (keycode == 87) { // w
994 feeds_sort_by_unread = !feeds_sort_by_unread;
995 return resort_feedlist();
998 if (keycode == 88) { // x
999 reverseHeadlineOrder();
1006 if (hotkey_prefix == 67) { // c
1007 hotkey_prefix = false;
1009 if (keycode == 70) { // f
1010 displayDlg('quickAddFilter', '',
1011 function () {document.forms['filter_add_form'].reg_exp.focus();});
1015 if (keycode == 76) { // l
1020 if (keycode == 83) { // s
1021 if (typeof collapse_feedlist != 'undefined') {
1022 collapse_feedlist();
1027 if (keycode == 77) { // m
1028 feedlist_sortable_enabled = !feedlist_sortable_enabled;
1029 if (feedlist_sortable_enabled) {
1030 notify_info("Category reordering enabled");
1031 toggle_sortable_feedlist(true);
1033 notify_info("Category reordering disabled");
1034 toggle_sortable_feedlist(false);
1038 if (keycode == 78) { // n
1039 catchupRelativeToArticle(1);
1043 if (keycode == 80) { // p
1044 catchupRelativeToArticle(0);
1053 if (hotkey_prefix == 71) { // g
1055 hotkey_prefix = false;
1058 if (keycode == 65) { // a
1063 if (keycode == 83) { // s
1068 if (keycode == 80 && shift_key) { // P
1073 if (keycode == 80) { // p
1078 if (keycode == 70) { // f
1083 if (keycode == 84 && shift_key) { // T
1091 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f
1092 hotkey_prefix = false;
1096 if (hotkey_prefix) {
1097 console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1099 console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
1104 exception_error("hotkey_handler", e);
1108 function inPreferences() {
1112 function reverseHeadlineOrder() {
1115 var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1117 new Ajax.Request("backend.php", {
1118 parameters: query_str,
1119 onComplete: function(transport) {
1124 exception_error("reverseHeadlineOrder", e);
1128 function showFeedsWithErrors() {
1129 displayDlg('feedUpdateErrors');
1132 function handle_rpc_reply(transport, scheduled_call) {
1134 if (transport.responseXML) {
1136 if (!transport_error_check(transport)) return false;
1138 var seq = transport.responseXML.getElementsByTagName("seq")[0];
1141 seq = seq.firstChild.nodeValue;
1143 if (get_seq() != seq) {
1144 //console.log("[handle_rpc_reply] sequence mismatch: " + seq);
1149 var message = transport.responseXML.getElementsByTagName("message")[0];
1152 message = message.firstChild.nodeValue;
1154 if (message == "UPDATE_COUNTERS") {
1155 console.log("need to refresh counters...");
1156 setInitParam("last_article_id", -1);
1157 _force_scheduled_update = true;
1161 var counters = transport.responseXML.getElementsByTagName("counters")[0];
1164 parse_counters(counters, scheduled_call);
1166 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
1169 parse_runtime_info(runtime_info);
1171 if (feedsSortByUnread())
1174 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1177 notify_error("Error communicating with server.");
1181 exception_error("handle_rpc_reply", e, transport);
1187 function scheduleFeedUpdate() {
1190 if (!getActiveFeedId()) {
1191 alert(__("Please select some feed first."));
1195 var query = "?op=rpc&subop=scheduleFeedUpdate&id=" +
1196 param_escape(getActiveFeedId()) +
1197 "&is_cat=" + param_escape(activeFeedIsCat());
1201 new Ajax.Request("backend.php", {
1203 onComplete: function(transport) {
1205 if (transport.responseXML) {
1206 var message = transport.responseXML.getElementsByTagName("message")[0];
1209 notify_info(message.firstChild.nodeValue);
1214 notify_error("Error communicating with server.");
1220 exception_error("scheduleFeedUpdate", e);