1 var global_unread = -1;
2 var hotkey_prefix = false;
3 var hotkey_prefix_pressed = false;
4 var hotkey_actions = {};
5 var _widescreen_mode = false;
7 var _active_feed_id = 0;
8 var _active_feed_is_cat = false;
19 function activeFeedIsCat() {
20 return _active_feed_is_cat;
23 function getActiveFeedId() {
25 return _active_feed_id;
27 exception_error("getActiveFeedId", e);
31 function setActiveFeedId(id, is_cat) {
34 hash_set('c', is_cat ? 1 : 0);
37 _active_feed_is_cat = is_cat;
39 $("headlines-frame").setAttribute("feed-id", id);
40 $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0);
42 selectFeed(id, is_cat);
44 exception_error("setActiveFeedId", e);
49 function updateFeedList() {
52 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
53 // __("Loading, please wait...") + "</div>";
55 Element.show("feedlistLoading");
57 if (dijit.byId("feedTree")) {
58 dijit.byId("feedTree").destroyRecursive();
61 var store = new dojo.data.ItemFileWriteStore({
62 url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"});
64 var treeModel = new fox.FeedStoreModel({
67 "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
71 childrenAttrs: ["items"]
74 var tree = new fox.FeedTree({
76 onClick: function (item, node) {
77 var id = String(item.id);
78 var is_cat = id.match("^CAT:");
79 var feed = id.substr(id.indexOf(":")+1);
80 viewfeed(feed, '', is_cat);
88 /* var menu = new dijit.Menu({id: 'feedMenu'});
90 menu.addChild(new dijit.MenuItem({
91 label: "Simple menu item"
94 // menu.bindDomNode(tree.domNode); */
96 var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
97 console.log(dijit.getEnclosingWidget(event.target));
98 dojo.disconnect(tmph);
101 $("feeds-holder").appendChild(tree.domNode);
103 var tmph = dojo.connect(tree, 'onLoad', function() {
104 dojo.disconnect(tmph);
105 Element.hide("feedlistLoading");
109 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
110 // menu.bindDomNode(node);
112 loading_set_progress(25);
118 exception_error("updateFeedList", e);
122 function catchupAllFeeds() {
124 var str = __("Mark all articles as read?");
126 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
128 var query_str = "backend.php?op=feeds&method=catchupAll";
130 notify_progress("Marking all feeds as read...");
132 //console.log("catchupAllFeeds Q=" + query_str);
134 new Ajax.Request("backend.php", {
135 parameters: query_str,
136 onComplete: function(transport) {
137 feedlist_callback2(transport);
145 function viewCurrentFeed(method) {
146 console.log("viewCurrentFeed");
148 if (getActiveFeedId() != undefined) {
149 viewfeed(getActiveFeedId(), method, activeFeedIsCat());
151 return false; // block unneeded form submits
155 if (getInitParam("bw_limit") != "1") {
157 setTimeout("timeout()", 60*1000);
162 var query = "backend.php?op=feeds&method=search¶m=" +
163 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
165 if (dijit.byId("searchDlg"))
166 dijit.byId("searchDlg").destroyRecursive();
168 dialog = new dijit.Dialog({
171 style: "width: 600px",
172 execute: function() {
173 if (this.validate()) {
174 _search_query = dojo.objectToQuery(this.attr('value'));
184 function updateTitle() {
185 var tmp = "Tiny Tiny RSS";
187 if (global_unread > 0) {
188 tmp = "(" + global_unread + ") " + tmp;
192 if (global_unread > 0) {
193 window.fluid.dockBadge = global_unread;
195 window.fluid.dockBadge = "";
199 document.title = tmp;
202 function genericSanityCheck() {
203 setCookie("ttrss_test", "TEST");
205 if (getCookie("ttrss_test") != "TEST") {
206 return fatalError(2);
215 //dojo.registerModulePath("fox", "../../js/");
217 dojo.require("fox.FeedTree");
219 dojo.require("dijit.ColorPalette");
220 dojo.require("dijit.Dialog");
221 dojo.require("dijit.form.Button");
222 dojo.require("dijit.form.CheckBox");
223 dojo.require("dijit.form.DropDownButton");
224 dojo.require("dijit.form.FilteringSelect");
225 dojo.require("dijit.form.Form");
226 dojo.require("dijit.form.RadioButton");
227 dojo.require("dijit.form.Select");
228 dojo.require("dijit.form.SimpleTextarea");
229 dojo.require("dijit.form.TextBox");
230 dojo.require("dijit.form.ValidationTextBox");
231 dojo.require("dijit.InlineEditBox");
232 dojo.require("dijit.layout.AccordionContainer");
233 dojo.require("dijit.layout.BorderContainer");
234 dojo.require("dijit.layout.ContentPane");
235 dojo.require("dijit.layout.TabContainer");
236 dojo.require("dijit.Menu");
237 dojo.require("dijit.ProgressBar");
238 dojo.require("dijit.ProgressBar");
239 dojo.require("dijit.Toolbar");
240 dojo.require("dijit.Tree");
241 dojo.require("dijit.tree.dndSource");
242 dojo.require("dojo.data.ItemFileWriteStore");
246 if (!genericSanityCheck())
249 loading_set_progress(20);
251 var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType);
252 var hasSandbox = "sandbox" in document.createElement("iframe");
254 new Ajax.Request("backend.php", {
255 parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
256 hasSandbox: hasSandbox},
257 onComplete: function(transport) {
258 backend_sanity_check_callback(transport);
261 hotkey_actions["next_feed"] = function() {
262 var rv = dijit.byId("feedTree").getNextFeed(
263 getActiveFeedId(), activeFeedIsCat());
265 if (rv) viewfeed(rv[0], '', rv[1]);
267 hotkey_actions["prev_feed"] = function() {
268 var rv = dijit.byId("feedTree").getPreviousFeed(
269 getActiveFeedId(), activeFeedIsCat());
271 if (rv) viewfeed(rv[0], '', rv[1]);
273 hotkey_actions["next_article"] = function() {
276 hotkey_actions["prev_article"] = function() {
279 hotkey_actions["next_article_noscroll"] = function() {
280 moveToPost('next', true);
282 hotkey_actions["prev_article_noscroll"] = function() {
283 moveToPost('prev', true);
285 hotkey_actions["next_article_noexpand"] = function() {
286 moveToPost('next', true, true);
288 hotkey_actions["prev_article_noexpand"] = function() {
289 moveToPost('prev', true, true);
291 hotkey_actions["collapse_article"] = function() {
292 var id = getActiveArticleId();
293 var elem = $("CICD-"+id);
295 cdmCollapseArticle(null, id);
298 cdmExpandArticle(id);
301 hotkey_actions["toggle_expand"] = function() {
302 var id = getActiveArticleId();
303 var elem = $("CICD-"+id);
305 cdmUnexpandArticle(null, id);
308 cdmExpandArticle(id);
311 hotkey_actions["search_dialog"] = function() {
314 hotkey_actions["toggle_mark"] = function() {
315 selectionToggleMarked(undefined, false, true);
317 hotkey_actions["toggle_publ"] = function() {
318 selectionTogglePublished(undefined, false, true);
320 hotkey_actions["toggle_unread"] = function() {
321 selectionToggleUnread(undefined, false, true);
323 hotkey_actions["edit_tags"] = function() {
324 var id = getActiveArticleId();
326 editArticleTags(id, getActiveFeedId(), isCdmMode());
329 hotkey_actions["dismiss_selected"] = function() {
330 dismissSelectedArticles();
332 hotkey_actions["open_in_new_window"] = function() {
333 if (getActiveArticleId()) {
334 openArticleInNewWindow(getActiveArticleId());
338 hotkey_actions["catchup_below"] = function() {
339 catchupRelativeToArticle(1);
341 hotkey_actions["catchup_above"] = function() {
342 catchupRelativeToArticle(0);
344 hotkey_actions["article_scroll_down"] = function() {
345 var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
349 hotkey_actions["article_scroll_up"] = function() {
350 var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
354 hotkey_actions["close_article"] = function() {
356 if (!getInitParam("cdm_expanded")) {
357 cdmCollapseArticle(false, getActiveArticleId());
359 dismissArticle(getActiveArticleId());
365 hotkey_actions["email_article"] = function() {
366 if (typeof emailArticle != "undefined") {
368 } else if (typeof mailtoArticle != "undefined") {
371 alert(__("Please enable mail plugin first."));
374 hotkey_actions["select_all"] = function() {
375 selectArticles('all');
377 hotkey_actions["select_unread"] = function() {
378 selectArticles('unread');
380 hotkey_actions["select_marked"] = function() {
381 selectArticles('marked');
383 hotkey_actions["select_published"] = function() {
384 selectArticles('published');
386 hotkey_actions["select_invert"] = function() {
387 selectArticles('invert');
389 hotkey_actions["select_none"] = function() {
390 selectArticles('none');
392 hotkey_actions["feed_refresh"] = function() {
393 if (getActiveFeedId() != undefined) {
394 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
398 hotkey_actions["feed_unhide_read"] = function() {
401 hotkey_actions["feed_subscribe"] = function() {
404 hotkey_actions["feed_debug_update"] = function() {
405 window.open("backend.php?op=feeds&method=view&feed=" + getActiveFeedId() +
406 "&view_mode=adaptive&order_by=default&update=&m=ForceUpdate&cat=" +
407 activeFeedIsCat() + "&DevForceUpdate=1&debug=1&xdebug=1&csrf_token=" +
408 getInitParam("csrf_token"));
410 hotkey_actions["feed_edit"] = function() {
411 if (activeFeedIsCat())
412 alert(__("You can't edit this kind of feed."));
414 editFeed(getActiveFeedId());
416 hotkey_actions["feed_catchup"] = function() {
417 if (getActiveFeedId() != undefined) {
418 catchupCurrentFeed();
422 hotkey_actions["feed_reverse"] = function() {
423 reverseHeadlineOrder();
425 hotkey_actions["catchup_all"] = function() {
428 hotkey_actions["cat_toggle_collapse"] = function() {
429 if (activeFeedIsCat()) {
430 dijit.byId("feedTree").collapseCat(getActiveFeedId());
434 hotkey_actions["goto_all"] = function() {
437 hotkey_actions["goto_fresh"] = function() {
440 hotkey_actions["goto_marked"] = function() {
443 hotkey_actions["goto_published"] = function() {
446 hotkey_actions["goto_tagcloud"] = function() {
447 displayDlg(__("Tag cloud"), "printTagCloud");
449 hotkey_actions["goto_prefs"] = function() {
452 hotkey_actions["select_article_cursor"] = function() {
453 var id = getArticleUnderPointer();
455 var row = $("RROW-" + id);
458 var cb = dijit.getEnclosingWidget(
459 row.getElementsByClassName("rchk")[0]);
462 cb.attr("checked", !cb.attr("checked"));
463 toggleSelectRowById(cb, "RROW-" + id);
469 hotkey_actions["create_label"] = function() {
472 hotkey_actions["create_filter"] = function() {
475 hotkey_actions["collapse_sidebar"] = function() {
478 hotkey_actions["toggle_embed_original"] = function() {
479 if (typeof embedOriginalArticle != "undefined") {
480 if (getActiveArticleId())
481 embedOriginalArticle(getActiveArticleId());
483 alert(__("Please enable embed_original plugin first."));
486 hotkey_actions["toggle_widescreen"] = function() {
488 _widescreen_mode = !_widescreen_mode;
490 switchPanelMode(_widescreen_mode);
493 hotkey_actions["help_dialog"] = function() {
496 hotkey_actions["toggle_combined_mode"] = function() {
497 notify_progress("Loading, please wait...");
499 var value = isCdmMode() ? "false" : "true";
500 var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value;
502 new Ajax.Request("backend.php", {
504 onComplete: function(transport) {
505 setInitParam("combined_display_mode",
506 !getInitParam("combined_display_mode"));
513 hotkey_actions["toggle_cdm_expanded"] = function() {
514 notify_progress("Loading, please wait...");
516 var value = getInitParam("cdm_expanded") ? "false" : "true";
517 var query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value;
519 new Ajax.Request("backend.php", {
521 onComplete: function(transport) {
522 setInitParam("cdm_expanded", !getInitParam("cdm_expanded"));
529 exception_error("init", e);
533 function init_second_stage() {
536 dojo.addOnLoad(function() {
540 _widescreen_mode = getInitParam("widescreen");
542 if (_widescreen_mode) {
543 switchPanelMode(_widescreen_mode);
548 delCookie("ttrss_test");
550 var toolbar = document.forms["main_toolbar_form"];
552 dijit.getEnclosingWidget(toolbar.view_mode).attr('value',
553 getInitParam("default_view_mode"));
555 dijit.getEnclosingWidget(toolbar.order_by).attr('value',
556 getInitParam("default_view_order_by"));
558 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
560 var hash_feed_id = hash_get('f');
561 var hash_feed_is_cat = hash_get('c') == "1";
563 if (hash_feed_id != undefined) {
564 setActiveFeedId(hash_feed_id, hash_feed_is_cat);
567 loading_set_progress(30);
569 // can't use cache_clear() here because viewfeed might not have initialized yet
570 if ('sessionStorage' in window && window['sessionStorage'] !== null)
571 sessionStorage.clear();
573 var hotkeys = getInitParam("hotkeys");
576 for (sequence in hotkeys[1]) {
577 filtered = sequence.replace(/\|.*$/, "");
578 tmp[filtered] = hotkeys[1][sequence];
582 setInitParam("hotkeys", hotkeys);
584 console.log("second stage ok");
586 if (getInitParam("simple_update")) {
587 console.log("scheduling simple feed updater...");
588 window.setTimeout("update_random_feed()", 30*1000);
592 exception_error("init_second_stage", e);
596 function quickMenuGo(opid) {
606 displayDlg(__("Tag cloud"), "printTagCloud");
609 displayDlg(__("Select item(s) by tags"), "printTagSelect");
618 window.location.href = "backend.php?op=digest";
621 if (activeFeedIsCat())
622 alert(__("You can't edit this kind of feed."));
624 editFeed(getActiveFeedId());
626 case "qmcRemoveFeed":
627 var actid = getActiveFeedId();
629 if (activeFeedIsCat()) {
630 alert(__("You can't unsubscribe from the category."));
635 alert(__("Please select some feed first."));
639 var fn = getFeedName(actid);
641 var pr = __("Unsubscribe from %s?").replace("%s", fn);
644 unsubscribeFeed(actid);
647 case "qmcCatchupAll":
650 case "qmcShowOnlyUnread":
659 case "qmcRescoreFeed":
660 rescoreCurrentFeed();
662 case "qmcToggleWidescreen":
664 _widescreen_mode = !_widescreen_mode;
666 switchPanelMode(_widescreen_mode);
673 console.log("quickMenuGo: unknown action: " + opid);
677 exception_error("quickMenuGo", e);
681 function toggleDispRead() {
684 var hide = !(getInitParam("hide_read_feeds") == "1");
686 hideOrShowFeeds(hide);
688 var query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" +
691 setInitParam("hide_read_feeds", hide);
693 new Ajax.Request("backend.php", {
695 onComplete: function(transport) {
699 exception_error("toggleDispRead", e);
703 function parse_runtime_info(data) {
705 //console.log("parsing runtime info...");
710 // console.log("RI: " + k + " => " + v);
712 if (k == "new_version_available") {
714 Element.show(dijit.byId("newVersionIcon").domNode);
716 Element.hide(dijit.byId("newVersionIcon").domNode);
721 if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
722 if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) {
723 window.location.reload();
727 if (k == "daemon_is_running" && v != 1) {
728 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
732 if (k == "daemon_stamp_ok" && v != 1) {
733 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
737 if (k == "max_feed_id" || k == "num_feeds") {
738 if (init_params[k] != v) {
739 console.log("feed count changed, need to reload feedlist.");
749 function collapse_feedlist() {
752 if (!Element.visible('feeds-holder')) {
753 Element.show('feeds-holder');
754 Element.show('feeds-holder_splitter');
755 $("collapse_feeds_btn").innerHTML = "<<";
757 Element.hide('feeds-holder');
758 Element.hide('feeds-holder_splitter');
759 $("collapse_feeds_btn").innerHTML = ">>";
762 dijit.byId("main").resize();
764 query = "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true";
765 new Ajax.Request("backend.php", { parameters: query });
768 exception_error("collapse_feedlist", e);
772 function viewModeChanged() {
774 return viewCurrentFeed('');
777 function rescoreCurrentFeed() {
779 var actid = getActiveFeedId();
781 if (activeFeedIsCat() || actid < 0) {
782 alert(__("You can't rescore this kind of feed."));
787 alert(__("Please select some feed first."));
791 var fn = getFeedName(actid);
792 var pr = __("Rescore articles in %s?").replace("%s", fn);
795 notify_progress("Rescoring articles...");
797 var query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid;
799 new Ajax.Request("backend.php", {
801 onComplete: function(transport) {
807 function hotkey_handler(e) {
810 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
813 var shift_key = false;
815 var cmdline = $('cmdline');
817 shift_key = e.shiftKey;
818 ctrl_key = e.ctrlKey;
821 keycode = window.event.keyCode;
826 var keychar = String.fromCharCode(keycode);
828 if (keycode == 27) { // escape
829 hotkey_prefix = false;
832 if (keycode == 16) return; // ignore lone shift
833 if (keycode == 17) return; // ignore lone ctrl
835 keychar = keychar.toLowerCase();
837 var hotkeys = getInitParam("hotkeys");
839 if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) {
841 var date = new Date();
842 var ts = Math.round(date.getTime() / 1000);
844 hotkey_prefix = keychar;
845 hotkey_prefix_pressed = ts;
847 cmdline.innerHTML = keychar;
848 Element.show(cmdline);
853 Element.hide(cmdline);
855 var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
857 // ensure ^*char notation
858 if (shift_key) hotkey = "*" + hotkey;
859 if (ctrl_key) hotkey = "^" + hotkey;
861 hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
862 hotkey_prefix = false;
864 var hotkey_action = false;
865 var hotkeys = getInitParam("hotkeys");
867 for (sequence in hotkeys[1]) {
868 if (sequence == hotkey) {
869 hotkey_action = hotkeys[1][sequence];
874 var action = hotkey_actions[hotkey_action];
876 if (action != null) {
882 exception_error("hotkey_handler", e);
886 function inPreferences() {
890 function reverseHeadlineOrder() {
893 /* var query_str = "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
895 new Ajax.Request("backend.php", {
896 parameters: query_str,
897 onComplete: function(transport) {
901 var toolbar = document.forms["main_toolbar_form"];
902 var order_by = dijit.getEnclosingWidget(toolbar.order_by);
904 var value = order_by.attr('value');
906 if (value == "date_reverse")
909 value = "date_reverse";
911 order_by.attr('value', value);
916 exception_error("reverseHeadlineOrder", e);
920 function newVersionDlg() {
922 var query = "backend.php?op=dlg&method=newVersion";
924 if (dijit.byId("newVersionDlg"))
925 dijit.byId("newVersionDlg").destroyRecursive();
927 dialog = new dijit.Dialog({
929 title: __("New version available!"),
930 style: "width: 600px",
937 exception_error("newVersionDlg", e);
941 function handle_rpc_json(transport, scheduled_call) {
943 var reply = JSON.parse(transport.responseText);
947 var error = reply['error'];
950 var code = error['code'];
951 var msg = error['msg'];
953 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
956 fatalError(code, msg);
961 var seq = reply['seq'];
964 if (get_seq() != seq) {
965 console.log("[handle_rpc_json] sequence mismatch: " + seq +
966 " (want: " + get_seq() + ")");
971 var message = reply['message'];
974 if (message == "UPDATE_COUNTERS") {
975 console.log("need to refresh counters...");
976 setInitParam("last_article_id", -1);
977 request_counters(true);
981 var counters = reply['counters'];
984 parse_counters(counters, scheduled_call);
986 var runtime_info = reply['runtime-info'];;
989 parse_runtime_info(runtime_info);
991 Element.hide(dijit.byId("net-alert").domNode);
994 //notify_error("Error communicating with server.");
995 Element.show(dijit.byId("net-alert").domNode);
999 Element.show(dijit.byId("net-alert").domNode);
1000 //notify_error("Error communicating with server.");
1002 //exception_error("handle_rpc_json", e, transport);
1008 function switchPanelMode(wide) {
1010 if (isCdmMode()) return;
1012 article_id = getActiveArticleId();
1015 dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
1016 dijit.byId("content-insert").attr("region", "trailing");
1018 dijit.byId("content-insert").domNode.setStyle({width: '50%',
1020 borderLeftWidth: '1px',
1021 borderLeftColor: '#c0c0c0',
1022 borderTopWidth: '0px' });
1024 $("headlines-toolbar").setStyle({ borderBottomWidth: '0px' });
1028 dijit.byId("content-insert").attr("region", "bottom");
1030 dijit.byId("content-insert").domNode.setStyle({width: 'auto',
1032 borderLeftWidth: '0px',
1033 borderTopWidth: '1px'});
1035 $("headlines-toolbar").setStyle({ borderBottomWidth: '1px' });
1038 closeArticlePanel();
1040 if (article_id) view(article_id);
1042 new Ajax.Request("backend.php", {
1043 parameters: "op=rpc&method=setpanelmode&wide=" + (wide ? 1 : 0),
1044 onComplete: function(transport) {
1045 console.log(transport.responseText);
1050 exception_error("switchPanelMode", e);
1054 function update_random_feed() {
1056 console.log("in update_random_feed");
1058 new Ajax.Request("backend.php", {
1059 parameters: "op=rpc&method=updateRandomFeed",
1060 onComplete: function(transport) {
1061 handle_rpc_json(transport, true);
1062 window.setTimeout("update_random_feed()", 30*1000);
1066 exception_error("update_random_feed", e);
1070 function hash_get(key) {
1072 kv = window.location.hash.substring(1).toQueryParams();
1075 exception_error("hash_set", e);
1078 function hash_set(key, value) {
1080 kv = window.location.hash.substring(1).toQueryParams();
1082 window.location.hash = $H(kv).toQueryString();
1084 exception_error("hash_set", e);