1 var global_unread = -1;
2 var hotkey_prefix = false;
3 var hotkey_prefix_pressed = false;
4 var _widescreen_mode = false;
6 var _active_feed_id = 0;
7 var _active_feed_is_cat = false;
18 function activeFeedIsCat() {
19 return _active_feed_is_cat;
22 function getActiveFeedId() {
24 return _active_feed_id;
26 exception_error("getActiveFeedId", e);
30 function setActiveFeedId(id, is_cat) {
33 hash_set('c', is_cat ? 1 : 0);
36 _active_feed_is_cat = is_cat;
38 selectFeed(id, is_cat);
40 exception_error("setActiveFeedId", e);
45 function updateFeedList() {
48 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
49 // __("Loading, please wait...") + "</div>";
51 Element.show("feedlistLoading");
53 if (dijit.byId("feedTree")) {
54 dijit.byId("feedTree").destroyRecursive();
57 var store = new dojo.data.ItemFileWriteStore({
58 url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"});
60 var treeModel = new fox.FeedStoreModel({
63 "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
67 childrenAttrs: ["items"]
70 var tree = new fox.FeedTree({
72 onClick: function (item, node) {
73 var id = String(item.id);
74 var is_cat = id.match("^CAT:");
75 var feed = id.substr(id.indexOf(":")+1);
76 viewfeed(feed, '', is_cat);
84 /* var menu = new dijit.Menu({id: 'feedMenu'});
86 menu.addChild(new dijit.MenuItem({
87 label: "Simple menu item"
90 // menu.bindDomNode(tree.domNode); */
92 var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
93 console.log(dijit.getEnclosingWidget(event.target));
94 dojo.disconnect(tmph);
97 $("feeds-holder").appendChild(tree.domNode);
99 var tmph = dojo.connect(tree, 'onLoad', function() {
100 dojo.disconnect(tmph);
101 Element.hide("feedlistLoading");
105 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
106 // menu.bindDomNode(node);
108 loading_set_progress(25);
114 exception_error("updateFeedList", e);
118 function catchupAllFeeds() {
120 var str = __("Mark all articles as read?");
122 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
124 var query_str = "backend.php?op=feeds&method=catchupAll";
126 notify_progress("Marking all feeds as read...");
128 //console.log("catchupAllFeeds Q=" + query_str);
130 new Ajax.Request("backend.php", {
131 parameters: query_str,
132 onComplete: function(transport) {
133 feedlist_callback2(transport);
141 function viewCurrentFeed(method) {
142 console.log("viewCurrentFeed");
144 if (getActiveFeedId() != undefined) {
145 viewfeed(getActiveFeedId(), method, activeFeedIsCat());
147 return false; // block unneeded form submits
151 if (getInitParam("bw_limit") != "1") {
153 setTimeout("timeout()", 60*1000);
158 var query = "backend.php?op=dlg&method=search¶m=" +
159 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
161 if (dijit.byId("searchDlg"))
162 dijit.byId("searchDlg").destroyRecursive();
164 dialog = new dijit.Dialog({
167 style: "width: 600px",
168 execute: function() {
169 if (this.validate()) {
170 _search_query = dojo.objectToQuery(this.attr('value'));
180 function updateTitle() {
181 var tmp = "Tiny Tiny RSS";
183 if (global_unread > 0) {
184 tmp = "(" + global_unread + ") " + tmp;
188 if (global_unread > 0) {
189 window.fluid.dockBadge = global_unread;
191 window.fluid.dockBadge = "";
195 document.title = tmp;
198 function genericSanityCheck() {
199 setCookie("ttrss_test", "TEST");
201 if (getCookie("ttrss_test") != "TEST") {
202 return fatalError(2);
210 //dojo.registerModulePath("fox", "../../js/");
212 dojo.require("fox.FeedTree");
214 dojo.require("dijit.ColorPalette");
215 dojo.require("dijit.Dialog");
216 dojo.require("dijit.form.Button");
217 dojo.require("dijit.form.CheckBox");
218 dojo.require("dijit.form.DropDownButton");
219 dojo.require("dijit.form.FilteringSelect");
220 dojo.require("dijit.form.Form");
221 dojo.require("dijit.form.RadioButton");
222 dojo.require("dijit.form.Select");
223 dojo.require("dijit.form.SimpleTextarea");
224 dojo.require("dijit.form.TextBox");
225 dojo.require("dijit.form.ValidationTextBox");
226 dojo.require("dijit.InlineEditBox");
227 dojo.require("dijit.layout.AccordionContainer");
228 dojo.require("dijit.layout.BorderContainer");
229 dojo.require("dijit.layout.ContentPane");
230 dojo.require("dijit.layout.TabContainer");
231 dojo.require("dijit.Menu");
232 dojo.require("dijit.ProgressBar");
233 dojo.require("dijit.ProgressBar");
234 dojo.require("dijit.Toolbar");
235 dojo.require("dijit.Tree");
236 dojo.require("dijit.tree.dndSource");
237 dojo.require("dojo.data.ItemFileWriteStore");
241 if (!genericSanityCheck())
244 loading_set_progress(20);
246 var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType);
247 var hasSandbox = "sandbox" in document.createElement("iframe");
249 new Ajax.Request("backend.php", {
250 parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
251 hasSandbox: hasSandbox},
252 onComplete: function(transport) {
253 backend_sanity_check_callback(transport);
257 exception_error("init", e);
261 function init_second_stage() {
264 dojo.addOnLoad(function() {
268 _widescreen_mode = getInitParam("widescreen");
270 if (_widescreen_mode) {
271 switchPanelMode(_widescreen_mode);
276 delCookie("ttrss_test");
278 var toolbar = document.forms["main_toolbar_form"];
280 dijit.getEnclosingWidget(toolbar.view_mode).attr('value',
281 getInitParam("default_view_mode"));
283 dijit.getEnclosingWidget(toolbar.order_by).attr('value',
284 getInitParam("default_view_order_by"));
286 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
288 var hash_feed_id = hash_get('f');
289 var hash_feed_is_cat = hash_get('c') == "1";
291 if (hash_feed_id != undefined) {
292 setActiveFeedId(hash_feed_id, hash_feed_is_cat);
295 loading_set_progress(30);
297 // can't use cache_clear() here because viewfeed might not have initialized yet
298 if ('sessionStorage' in window && window['sessionStorage'] !== null)
299 sessionStorage.clear();
301 var hotkeys = getInitParam("hotkeys");
304 for (sequence in hotkeys[1]) {
305 filtered = sequence.replace(/\|.*$/, "");
306 tmp[filtered] = hotkeys[1][sequence];
310 setInitParam("hotkeys", hotkeys);
312 console.log("second stage ok");
314 if (getInitParam("simple_update")) {
315 console.log("scheduling simple feed updater...");
316 window.setTimeout("update_random_feed()", 30*1000);
320 exception_error("init_second_stage", e);
324 function quickMenuGo(opid) {
334 displayDlg("printTagCloud");
337 displayDlg("printTagSelect");
346 window.location.href = "backend.php?op=digest";
349 if (activeFeedIsCat())
350 alert(__("You can't edit this kind of feed."));
352 editFeed(getActiveFeedId());
354 case "qmcRemoveFeed":
355 var actid = getActiveFeedId();
357 if (activeFeedIsCat()) {
358 alert(__("You can't unsubscribe from the category."));
363 alert(__("Please select some feed first."));
367 var fn = getFeedName(actid);
369 var pr = __("Unsubscribe from %s?").replace("%s", fn);
372 unsubscribeFeed(actid);
375 case "qmcCatchupAll":
378 case "qmcShowOnlyUnread":
387 case "qmcRescoreFeed":
388 rescoreCurrentFeed();
390 case "qmcToggleWidescreen":
392 _widescreen_mode = !_widescreen_mode;
394 switchPanelMode(_widescreen_mode);
401 console.log("quickMenuGo: unknown action: " + opid);
405 exception_error("quickMenuGo", e);
409 function toggleDispRead() {
412 var hide = !(getInitParam("hide_read_feeds") == "1");
414 hideOrShowFeeds(hide);
416 var query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" +
419 setInitParam("hide_read_feeds", hide);
421 new Ajax.Request("backend.php", {
423 onComplete: function(transport) {
427 exception_error("toggleDispRead", e);
431 function parse_runtime_info(data) {
433 //console.log("parsing runtime info...");
438 // console.log("RI: " + k + " => " + v);
440 if (k == "new_version_available") {
442 Element.show(dijit.byId("newVersionIcon").domNode);
444 Element.hide(dijit.byId("newVersionIcon").domNode);
449 if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
450 if (parseInt(getInitParam("dep_ts")) < parseInt(v)) {
451 window.location.reload();
455 if (k == "daemon_is_running" && v != 1) {
456 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
460 if (k == "daemon_stamp_ok" && v != 1) {
461 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
465 if (k == "max_feed_id" || k == "num_feeds") {
466 if (init_params[k] != v) {
467 console.log("feed count changed, need to reload feedlist.");
477 function collapse_feedlist() {
480 if (!Element.visible('feeds-holder')) {
481 Element.show('feeds-holder');
482 Element.show('feeds-holder_splitter');
483 $("collapse_feeds_btn").innerHTML = "<<";
485 Element.hide('feeds-holder');
486 Element.hide('feeds-holder_splitter');
487 $("collapse_feeds_btn").innerHTML = ">>";
490 dijit.byId("main").resize();
492 query = "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true";
493 new Ajax.Request("backend.php", { parameters: query });
496 exception_error("collapse_feedlist", e);
500 function viewModeChanged() {
502 return viewCurrentFeed('');
505 function viewLimitChanged() {
506 return viewCurrentFeed('');
509 function rescoreCurrentFeed() {
511 var actid = getActiveFeedId();
513 if (activeFeedIsCat() || actid < 0) {
514 alert(__("You can't rescore this kind of feed."));
519 alert(__("Please select some feed first."));
523 var fn = getFeedName(actid);
524 var pr = __("Rescore articles in %s?").replace("%s", fn);
527 notify_progress("Rescoring articles...");
529 var query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid;
531 new Ajax.Request("backend.php", {
533 onComplete: function(transport) {
539 function hotkey_handler(e) {
542 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
545 var shift_key = false;
547 var cmdline = $('cmdline');
549 shift_key = e.shiftKey;
550 ctrl_key = e.ctrlKey;
553 keycode = window.event.keyCode;
558 var keychar = String.fromCharCode(keycode);
560 if (keycode == 27) { // escape
561 hotkey_prefix = false;
564 if (keycode == 16) return; // ignore lone shift
565 if (keycode == 17) return; // ignore lone ctrl
567 keychar = keychar.toLowerCase();
569 var hotkeys = getInitParam("hotkeys");
571 if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) {
573 var date = new Date();
574 var ts = Math.round(date.getTime() / 1000);
576 hotkey_prefix = keychar;
577 hotkey_prefix_pressed = ts;
579 cmdline.innerHTML = keychar;
580 Element.show(cmdline);
585 Element.hide(cmdline);
587 var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
589 // ensure ^*char notation
590 if (shift_key) hotkey = "*" + hotkey;
591 if (ctrl_key) hotkey = "^" + hotkey;
593 hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
594 hotkey_prefix = false;
596 var hotkey_action = false;
597 var hotkeys = getInitParam("hotkeys");
599 for (sequence in hotkeys[1]) {
600 if (sequence == hotkey) {
601 hotkey_action = hotkeys[1][sequence];
606 switch (hotkey_action) {
608 var rv = dijit.byId("feedTree").getNextFeed(
609 getActiveFeedId(), activeFeedIsCat());
611 if (rv) viewfeed(rv[0], '', rv[1]);
614 var rv = dijit.byId("feedTree").getPreviousFeed(
615 getActiveFeedId(), activeFeedIsCat());
617 if (rv) viewfeed(rv[0], '', rv[1]);
625 case "next_article_noscroll":
626 moveToPost('next', true);
628 case "prev_article_noscroll":
629 moveToPost('prev', true);
631 case "search_dialog":
635 selectionToggleMarked(undefined, false, true);
638 selectionTogglePublished(undefined, false, true);
640 case "toggle_unread":
641 selectionToggleUnread(undefined, false, true);
644 var id = getActiveArticleId();
646 editArticleTags(id, getActiveFeedId(), isCdmMode());
650 case "dismiss_selected":
651 dismissSelectedArticles();
655 case "open_in_new_window":
656 if (getActiveArticleId()) {
657 openArticleInNewWindow(getActiveArticleId());
661 case "catchup_below":
662 catchupRelativeToArticle(1);
664 case "catchup_above":
665 catchupRelativeToArticle(0);
667 case "article_scroll_down":
668 var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
670 scrollArticle(ctr.offsetHeight/3);
672 case "article_scroll_up":
673 var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
675 scrollArticle(-ctr.offsetHeight/3);
677 case "close_article":
679 if (!getInitParam("cdm_expanded")) {
680 cdmCollapseArticle(false, getActiveArticleId());
682 dismissArticle(getActiveArticleId());
688 case "email_article":
689 if (typeof emailArticle != "undefined") {
691 } else if (typeof mailtoArticle != "undefined") {
694 alert(__("Please enable mail plugin first."));
698 selectArticles('all');
700 case "select_unread":
701 selectArticles('unread');
703 case "select_marked":
704 selectArticles('marked');
706 case "select_published":
707 selectArticles('published');
709 case "select_invert":
710 selectArticles('invert');
713 selectArticles('none');
716 if (getActiveFeedId() != undefined) {
717 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
721 case "feed_unhide_read":
724 case "feed_subscribe":
727 case "feed_debug_update":
728 window.open("backend.php?op=feeds&method=view&feed=" + getActiveFeedId() +
729 "&view_mode=adaptive&order_by=default&update=&m=ForceUpdate&cat=" +
730 activeFeedIsCat() + "&DevForceUpdate=1&debug=1&xdebug=1&csrf_token=" +
731 getInitParam("csrf_token"));
734 if (activeFeedIsCat())
735 alert(__("You can't edit this kind of feed."));
737 editFeed(getActiveFeedId());
740 if (getActiveFeedId() != undefined) {
741 catchupCurrentFeed();
746 reverseHeadlineOrder();
751 case "cat_toggle_collapse":
752 if (activeFeedIsCat()) {
753 dijit.byId("feedTree").collapseCat(getActiveFeedId());
766 case "goto_published":
769 case "goto_tagcloud":
770 displayDlg("printTagCloud");
775 case "select_article_cursor":
776 var id = getArticleUnderPointer();
778 var cb = dijit.byId("RCHK-" + id);
780 cb.attr("checked", !cb.attr("checked"));
781 toggleSelectRowById(cb, "RROW-" + id);
789 case "create_filter":
792 case "collapse_sidebar":
795 case "toggle_embed_original":
796 if (typeof embedOriginalArticle != "undefined") {
797 if (getActiveArticleId())
798 embedOriginalArticle(getActiveArticleId());
800 alert(__("Please enable embed_original plugin first."));
803 case "toggle_widescreen":
805 _widescreen_mode = !_widescreen_mode;
807 switchPanelMode(_widescreen_mode);
813 case "toggle_combined_mode":
814 notify_progress("Loading, please wait...");
816 var value = isCdmMode() ? "false" : "true";
817 var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value;
819 new Ajax.Request("backend.php", {
821 onComplete: function(transport) {
822 window.location.reload();
827 console.log("unhandled action: " + hotkey_action + "; hotkey: " + hotkey);
831 exception_error("hotkey_handler", e);
835 function inPreferences() {
839 function reverseHeadlineOrder() {
842 var query_str = "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
844 new Ajax.Request("backend.php", {
845 parameters: query_str,
846 onComplete: function(transport) {
851 exception_error("reverseHeadlineOrder", e);
855 function newVersionDlg() {
857 var query = "backend.php?op=dlg&method=newVersion";
859 if (dijit.byId("newVersionDlg"))
860 dijit.byId("newVersionDlg").destroyRecursive();
862 dialog = new dijit.Dialog({
864 title: __("New version available!"),
865 style: "width: 600px",
872 exception_error("newVersionDlg", e);
876 function handle_rpc_json(transport, scheduled_call) {
878 var reply = JSON.parse(transport.responseText);
882 var error = reply['error'];
885 var code = error['code'];
886 var msg = error['msg'];
888 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
891 fatalError(code, msg);
896 var seq = reply['seq'];
899 if (get_seq() != seq) {
900 console.log("[handle_rpc_json] sequence mismatch: " + seq +
901 " (want: " + get_seq() + ")");
906 var message = reply['message'];
909 if (message == "UPDATE_COUNTERS") {
910 console.log("need to refresh counters...");
911 setInitParam("last_article_id", -1);
912 request_counters(true);
916 var counters = reply['counters'];
919 parse_counters(counters, scheduled_call);
921 var runtime_info = reply['runtime-info'];;
924 parse_runtime_info(runtime_info);
926 Element.hide(dijit.byId("net-alert").domNode);
929 //notify_error("Error communicating with server.");
930 Element.show(dijit.byId("net-alert").domNode);
934 Element.show(dijit.byId("net-alert").domNode);
935 //notify_error("Error communicating with server.");
937 //exception_error("handle_rpc_json", e, transport);
943 function switchPanelMode(wide) {
945 if (isCdmMode()) return;
947 article_id = getActiveArticleId();
950 dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
951 dijit.byId("content-insert").attr("region", "trailing");
953 dijit.byId("content-insert").domNode.setStyle({width: '50%',
955 borderLeftWidth: '1px',
956 borderLeftColor: '#c0c0c0',
957 borderTopWidth: '0px' });
959 $("headlines-toolbar").setStyle({ borderBottomWidth: '0px' });
963 dijit.byId("content-insert").attr("region", "bottom");
965 dijit.byId("content-insert").domNode.setStyle({width: 'auto',
967 borderLeftWidth: '0px',
968 borderTopWidth: '1px'});
970 $("headlines-toolbar").setStyle({ borderBottomWidth: '1px' });
975 if (article_id) view(article_id);
977 new Ajax.Request("backend.php", {
978 parameters: "op=rpc&method=setpanelmode&wide=" + (wide ? 1 : 0),
979 onComplete: function(transport) {
980 console.log(transport.responseText);
985 exception_error("switchPanelMode", e);
989 function update_random_feed() {
991 console.log("in update_random_feed");
993 new Ajax.Request("backend.php", {
994 parameters: "op=rpc&method=updateRandomFeed",
995 onComplete: function(transport) {
996 handle_rpc_json(transport, true);
997 window.setTimeout("update_random_feed()", 30*1000);
1001 exception_error("update_random_feed", e);
1005 function hash_get(key) {
1007 kv = window.location.hash.substring(1).toQueryParams();
1010 exception_error("hash_set", e);
1013 function hash_set(key, value) {
1015 kv = window.location.hash.substring(1).toQueryParams();
1017 window.location.hash = $H(kv).toQueryString();
1019 exception_error("hash_set", e);