]>
git.wh0rd.org - tt-rss.git/blob - js/tt-rss.js
3 let global_unread
= -1;
4 let _widescreen_mode
= false;
6 let _active_feed_id
= 0;
7 let _active_feed_is_cat
= false;
8 let hotkey_actions
= {};
19 function activeFeedIsCat() {
20 return !!_active_feed_is_cat
;
23 function getActiveFeedId() {
24 return _active_feed_id
;
27 function setActiveFeedId(id
, is_cat
) {
29 hash_set('c', is_cat
? 1 : 0);
32 _active_feed_is_cat
= is_cat
;
34 $("headlines-frame").setAttribute("feed-id", id
);
35 $("headlines-frame").setAttribute("is-cat", is_cat
? 1 : 0);
37 selectFeed(id
, is_cat
);
39 PluginHost
.run(PluginHost
.HOOK_FEED_SET_ACTIVE
, _active_article_id
);
43 function updateFeedList() {
45 Element
.show("feedlistLoading");
49 if (dijit
.byId("feedTree")) {
50 dijit
.byId("feedTree").destroyRecursive();
53 const store
= new dojo
.data
.ItemFileWriteStore({
54 url
: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"
57 const treeModel
= new fox
.FeedStoreModel({
60 "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
64 childrenAttrs
: ["items"]
67 const tree
= new fox
.FeedTree({
69 onClick: function (item
, node
) {
70 const id
= String(item
.id
);
71 const is_cat
= id
.match("^CAT:");
72 const feed
= id
.substr(id
.indexOf(":") + 1);
73 viewfeed({feed
: feed
, is_cat
: is_cat
});
82 var tmph
= dojo
.connect(dijit
.byId('feedMenu'), '_openMyself', function (event
) {
83 console
.log(dijit
.getEnclosingWidget(event
.target
));
84 dojo
.disconnect(tmph
);
87 $("feeds-holder").appendChild(tree
.domNode
);
89 var tmph
= dojo
.connect(tree
, 'onLoad', function () {
90 dojo
.disconnect(tmph
);
91 Element
.hide("feedlistLoading");
96 loading_set_progress(25);
108 function catchupAllFeeds() {
110 const str
= __("Mark all articles as read?");
112 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
114 notify_progress("Marking all feeds as read...");
116 xhrPost("backend.php", {op
: "feeds", method
: "catchupAll"}, () => {
117 request_counters(true);
126 function viewCurrentFeed(method
) {
127 console
.log("viewCurrentFeed: " + method
);
129 if (getActiveFeedId() != undefined) {
130 viewfeed({feed
: getActiveFeedId(), is_cat
: activeFeedIsCat(), method
: method
});
132 return false; // block unneeded form submits
136 if (getInitParam("bw_limit") != "1") {
137 request_counters(true);
138 setTimeout(timeout
, 60*1000);
143 const query
= "backend.php?op=feeds&method=search¶m=" +
144 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
146 if (dijit
.byId("searchDlg"))
147 dijit
.byId("searchDlg").destroyRecursive();
149 const dialog
= new dijit
.Dialog({
152 style
: "width: 600px",
153 execute: function() {
154 if (this.validate()) {
155 _search_query
= this.attr('value');
165 function updateTitle() {
166 let tmp
= "Tiny Tiny RSS";
168 if (global_unread
> 0) {
169 tmp
= "(" + global_unread
+ ") " + tmp
;
172 document
.title
= tmp
;
175 function genericSanityCheck() {
176 setCookie("ttrss_test", "TEST");
178 if (getCookie("ttrss_test") != "TEST") {
179 return fatalError(2);
188 window
.onerror = function(message
, filename
, lineno
, colno
, error
) {
189 report_error(message
, filename
, lineno
, colno
, error
);
192 require(["dojo/_base/kernel",
199 "dijit/ColorPalette",
202 "dijit/form/ComboButton",
203 "dijit/form/CheckBox",
204 "dijit/form/DropDownButton",
205 "dijit/form/FilteringSelect",
207 "dijit/form/RadioButton",
209 "dijit/form/MultiSelect",
210 "dijit/form/SimpleTextarea",
211 "dijit/form/TextBox",
212 "dijit/form/ComboBox",
213 "dijit/form/ValidationTextBox",
214 "dijit/InlineEditBox",
215 "dijit/layout/AccordionContainer",
216 "dijit/layout/BorderContainer",
217 "dijit/layout/ContentPane",
218 "dijit/layout/TabContainer",
219 "dijit/PopupMenuItem",
223 "dijit/tree/dndSource",
224 "dijit/tree/ForestStoreModel",
225 "dojo/data/ItemFileWriteStore",
226 "fox/FeedStoreModel",
227 "fox/FeedTree" ], function (dojo
, ready
, parser
) {
234 if (!genericSanityCheck())
237 loading_set_progress(30);
239 const a
= document
.createElement('audio');
241 const hasAudio
= !!a
.canPlayType
;
242 const hasSandbox
= "sandbox" in document
.createElement("iframe");
243 const hasMp3
= !!(a
.canPlayType
&& a
.canPlayType('audio/mpeg;').replace(/no
/, ''));
244 const clientTzOffset
= new Date().getTimezoneOffset() * 60;
246 init_hotkey_actions();
249 op
: "rpc", method
: "sanityCheck", hasAudio
: hasAudio
,
251 clientTzOffset
: clientTzOffset
,
252 hasSandbox
: hasSandbox
255 xhrPost("backend.php", params
, (transport
) => {
257 backend_sanity_check_callback(transport
);
273 function init_hotkey_actions() {
274 hotkey_actions
["next_feed"] = function() {
275 const rv
= dijit
.byId("feedTree").getNextFeed(
276 getActiveFeedId(), activeFeedIsCat());
278 if (rv
) viewfeed({feed
: rv
[0], is_cat
: rv
[1], can_wait
: true})
280 hotkey_actions
["prev_feed"] = function() {
281 const rv
= dijit
.byId("feedTree").getPreviousFeed(
282 getActiveFeedId(), activeFeedIsCat());
284 if (rv
) viewfeed({feed
: rv
[0], is_cat
: rv
[1], can_wait
: true})
286 hotkey_actions
["next_article"] = function() {
289 hotkey_actions
["prev_article"] = function() {
292 hotkey_actions
["next_article_noscroll"] = function() {
293 moveToPost('next', true);
295 hotkey_actions
["prev_article_noscroll"] = function() {
296 moveToPost('prev', true);
298 hotkey_actions
["next_article_noexpand"] = function() {
299 moveToPost('next', true, true);
301 hotkey_actions
["prev_article_noexpand"] = function() {
302 moveToPost('prev', true, true);
304 hotkey_actions
["collapse_article"] = function() {
305 const id
= getActiveArticleId();
306 const elem
= $("CICD-"+id
);
309 if (elem
.visible()) {
310 cdmCollapseArticle(null, id
);
313 cdmExpandArticle(id
);
317 hotkey_actions
["toggle_expand"] = function() {
318 const id
= getActiveArticleId();
319 const elem
= $("CICD-"+id
);
322 if (elem
.visible()) {
323 cdmCollapseArticle(null, id
, false);
326 cdmExpandArticle(id
);
330 hotkey_actions
["search_dialog"] = function() {
333 hotkey_actions
["toggle_mark"] = function() {
334 selectionToggleMarked(undefined, false, true);
336 hotkey_actions
["toggle_publ"] = function() {
337 selectionTogglePublished(undefined, false, true);
339 hotkey_actions
["toggle_unread"] = function() {
340 selectionToggleUnread(undefined, false, true);
342 hotkey_actions
["edit_tags"] = function() {
343 const id
= getActiveArticleId();
348 hotkey_actions
["open_in_new_window"] = function() {
349 if (getActiveArticleId()) {
350 openArticleInNewWindow(getActiveArticleId());
353 hotkey_actions
["catchup_below"] = function() {
354 catchupRelativeToArticle(1);
356 hotkey_actions
["catchup_above"] = function() {
357 catchupRelativeToArticle(0);
359 hotkey_actions
["article_scroll_down"] = function() {
362 hotkey_actions
["article_scroll_up"] = function() {
365 hotkey_actions
["close_article"] = function() {
367 if (!getInitParam("cdm_expanded")) {
368 cdmCollapseArticle(false, getActiveArticleId());
374 hotkey_actions
["email_article"] = function() {
375 if (typeof emailArticle
!= "undefined") {
377 } else if (typeof mailtoArticle
!= "undefined") {
380 alert(__("Please enable mail plugin first."));
383 hotkey_actions
["select_all"] = function() {
384 selectArticles('all');
386 hotkey_actions
["select_unread"] = function() {
387 selectArticles('unread');
389 hotkey_actions
["select_marked"] = function() {
390 selectArticles('marked');
392 hotkey_actions
["select_published"] = function() {
393 selectArticles('published');
395 hotkey_actions
["select_invert"] = function() {
396 selectArticles('invert');
398 hotkey_actions
["select_none"] = function() {
399 selectArticles('none');
401 hotkey_actions
["feed_refresh"] = function() {
402 if (getActiveFeedId() != undefined) {
403 viewfeed({feed
: getActiveFeedId(), is_cat
: activeFeedIsCat()});
407 hotkey_actions
["feed_unhide_read"] = function() {
410 hotkey_actions
["feed_subscribe"] = function() {
413 hotkey_actions
["feed_debug_update"] = function() {
414 if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) {
415 window
.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() +
416 "&csrf_token=" + getInitParam("csrf_token"));
418 alert("You can't debug this kind of feed.");
422 hotkey_actions
["feed_debug_viewfeed"] = function() {
423 viewfeed({feed
: getActiveFeedId(), is_cat
: activeFeedIsCat(), viewfeed_debug
: true});
426 hotkey_actions
["feed_edit"] = function() {
427 if (activeFeedIsCat())
428 alert(__("You can't edit this kind of feed."));
430 editFeed(getActiveFeedId());
432 hotkey_actions
["feed_catchup"] = function() {
433 if (getActiveFeedId() != undefined) {
434 catchupCurrentFeed();
438 hotkey_actions
["feed_reverse"] = function() {
439 reverseHeadlineOrder();
441 hotkey_actions
["feed_toggle_vgroup"] = function() {
442 xhrPost("backend.php", {op
: "rpc", method
: "togglepref", key
: "VFEED_GROUP_BY_FEED"}, () => {
446 hotkey_actions
["catchup_all"] = function() {
449 hotkey_actions
["cat_toggle_collapse"] = function() {
450 if (activeFeedIsCat()) {
451 dijit
.byId("feedTree").collapseCat(getActiveFeedId());
455 hotkey_actions
["goto_all"] = function() {
456 viewfeed({feed
: -4});
458 hotkey_actions
["goto_fresh"] = function() {
459 viewfeed({feed
: -3});
461 hotkey_actions
["goto_marked"] = function() {
462 viewfeed({feed
: -1});
464 hotkey_actions
["goto_published"] = function() {
465 viewfeed({feed
: -2});
467 hotkey_actions
["goto_tagcloud"] = function() {
468 displayDlg(__("Tag cloud"), "printTagCloud");
470 hotkey_actions
["goto_prefs"] = function() {
473 hotkey_actions
["select_article_cursor"] = function() {
474 const id
= getArticleUnderPointer();
476 const row
= $("RROW-" + id
);
479 const cb
= dijit
.getEnclosingWidget(
480 row
.getElementsByClassName("rchk")[0]);
483 cb
.attr("checked", !cb
.attr("checked"));
484 toggleSelectRowById(cb
, "RROW-" + id
);
490 hotkey_actions
["create_label"] = function() {
493 hotkey_actions
["create_filter"] = function() {
496 hotkey_actions
["collapse_sidebar"] = function() {
499 hotkey_actions
["toggle_embed_original"] = function() {
500 if (typeof embedOriginalArticle
!= "undefined") {
501 if (getActiveArticleId())
502 embedOriginalArticle(getActiveArticleId());
504 alert(__("Please enable embed_original plugin first."));
507 hotkey_actions
["toggle_widescreen"] = function() {
509 _widescreen_mode
= !_widescreen_mode
;
511 // reset stored sizes because geometry changed
512 setCookie("ttrss_ci_width", 0);
513 setCookie("ttrss_ci_height", 0);
515 switchPanelMode(_widescreen_mode
);
517 alert(__("Widescreen is not available in combined mode."));
520 hotkey_actions
["help_dialog"] = function() {
523 hotkey_actions
["toggle_combined_mode"] = function() {
524 notify_progress("Loading, please wait...");
526 const value
= isCdmMode() ? "false" : "true";
528 xhrPost("backend.php", {op
: "rpc", method
: "setpref", key
: "COMBINED_DISPLAY_MODE", value
: value
}, () => {
529 setInitParam("combined_display_mode",
530 !getInitParam("combined_display_mode"));
536 hotkey_actions
["toggle_cdm_expanded"] = function() {
537 notify_progress("Loading, please wait...");
539 const value
= getInitParam("cdm_expanded") ? "false" : "true";
541 xhrPost("backend.php", {op
: "rpc", method
: "setpref", key
: "CDM_EXPANDED", value
: value
}, () => {
542 setInitParam("cdm_expanded", !getInitParam("cdm_expanded"));
548 function init_second_stage() {
552 if (parseInt(getCookie("ttrss_fh_width")) > 0) {
553 dijit
.byId("feeds-holder").domNode
.setStyle(
554 {width
: getCookie("ttrss_fh_width") + "px" });
557 dijit
.byId("main").resize();
559 var tmph
= dojo
.connect(dijit
.byId('feeds-holder'), 'resize',
561 if (args
&& args
.w
>= 0) {
562 setCookie("ttrss_fh_width", args
.w
, getInitParam("cookie_lifetime"));
566 var tmph
= dojo
.connect(dijit
.byId('content-insert'), 'resize',
568 if (args
&& args
.w
>= 0 && args
.h
>= 0) {
569 setCookie("ttrss_ci_width", args
.w
, getInitParam("cookie_lifetime"));
570 setCookie("ttrss_ci_height", args
.h
, getInitParam("cookie_lifetime"));
574 delCookie("ttrss_test");
576 const toolbar
= document
.forms
["main_toolbar_form"];
578 dijit
.getEnclosingWidget(toolbar
.view_mode
).attr('value',
579 getInitParam("default_view_mode"));
581 dijit
.getEnclosingWidget(toolbar
.order_by
).attr('value',
582 getInitParam("default_view_order_by"));
584 const hash_feed_id
= hash_get('f');
585 const hash_feed_is_cat
= hash_get('c') == "1";
587 if (hash_feed_id
!= undefined) {
588 setActiveFeedId(hash_feed_id
, hash_feed_is_cat
);
591 loading_set_progress(50);
593 // can't use cache_clear() here because viewfeed might not have initialized yet
594 if ('sessionStorage' in window
&& window
['sessionStorage'] !== null)
595 sessionStorage
.clear();
597 /*const hotkeys = getInitParam("hotkeys");
600 for (const sequence in hotkeys[1]) {
601 const filtered = sequence.replace(/\|.*$/, "");
602 tmp[filtered] = hotkeys[1][sequence];
606 setInitParam("hotkeys", hotkeys);*/
608 _widescreen_mode
= getInitParam("widescreen");
609 switchPanelMode(_widescreen_mode
);
611 console
.log("second stage ok");
613 if (getInitParam("simple_update")) {
614 console
.log("scheduling simple feed updater...");
615 window
.setTimeout(update_random_feed
, 30*1000);
619 function quickMenuGo(opid
) {
628 displayDlg(__("Tag cloud"), "printTagCloud");
637 window
.location
.href
= "backend.php?op=digest";
640 if (activeFeedIsCat())
641 alert(__("You can't edit this kind of feed."));
643 editFeed(getActiveFeedId());
645 case "qmcRemoveFeed":
646 var actid
= getActiveFeedId();
648 if (activeFeedIsCat()) {
649 alert(__("You can't unsubscribe from the category."));
654 alert(__("Please select some feed first."));
658 var fn
= getFeedName(actid
);
660 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
663 unsubscribeFeed(actid
);
666 case "qmcCatchupAll":
669 case "qmcShowOnlyUnread":
672 case "qmcToggleWidescreen":
674 _widescreen_mode
= !_widescreen_mode
;
676 // reset stored sizes because geometry changed
677 setCookie("ttrss_ci_width", 0);
678 setCookie("ttrss_ci_height", 0);
680 switchPanelMode(_widescreen_mode
);
682 alert(__("Widescreen is not available in combined mode."));
689 console
.log("quickMenuGo: unknown action: " + opid
);
693 function toggleDispRead() {
695 const hide
= !(getInitParam("hide_read_feeds") == "1");
697 xhrPost("backend.php", {op
: "rpc", method
: "setpref", key
: "HIDE_READ_FEEDS", value
: hide
}, () => {
698 hideOrShowFeeds(hide
);
699 setInitParam("hide_read_feeds", hide
);
703 function parse_runtime_info(data
) {
705 //console.log("parsing runtime info...");
707 for (const k
in data
) {
710 // console.log("RI: " + k + " => " + v);
712 if (k
== "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
713 if (parseInt(getInitParam("dep_ts")) < parseInt(v
) && getInitParam("reload_on_ts_change")) {
714 window
.location
.reload();
718 if (k
== "daemon_is_running" && v
!= 1) {
719 notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true);
723 if (k
== "update_result") {
724 const updatesIcon
= dijit
.byId("updatesIcon").domNode
;
727 Element
.show(updatesIcon
);
729 Element
.hide(updatesIcon
);
733 if (k
== "daemon_stamp_ok" && v
!= 1) {
734 notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true);
738 if (k
== "max_feed_id" || k
== "num_feeds") {
739 if (init_params
[k
] != v
) {
740 console
.log("feed count changed, need to reload feedlist.");
749 PluginHost
.run(PluginHost
.HOOK_RUNTIME_INFO_LOADED
, data
);
752 function collapse_feedlist() {
753 Element
.toggle("feeds-holder");
755 const splitter
= $("feeds-holder_splitter");
757 Element
.visible("feeds-holder") ? splitter
.show() : splitter
.hide();
759 dijit
.byId("main").resize();
762 function viewModeChanged() {
764 return viewCurrentFeed('');
767 function hotkey_handler(e
) {
768 if (e
.target
.nodeName
== "INPUT" || e
.target
.nodeName
== "TEXTAREA") return;
770 const action_name
= keyevent_to_action(e
);
773 const action_func
= hotkey_actions
[action_name
];
775 if (action_func
!= null) {
783 function inPreferences() {
787 function reverseHeadlineOrder() {
789 const toolbar
= document
.forms
["main_toolbar_form"];
790 const order_by
= dijit
.getEnclosingWidget(toolbar
.order_by
);
792 let value
= order_by
.attr('value');
794 if (value
== "date_reverse")
797 value
= "date_reverse";
799 order_by
.attr('value', value
);
805 function handle_rpc_json(transport
, scheduled_call
) {
807 const netalert_dijit
= dijit
.byId("net-alert");
808 let netalert
= false;
810 if (netalert_dijit
) netalert
= netalert_dijit
.domNode
;
813 const reply
= JSON
.parse(transport
.responseText
);
817 const error
= reply
['error'];
820 const code
= error
['code'];
821 const msg
= error
['msg'];
823 console
.warn("[handle_rpc_json] received fatal error " + code
+ "/" + msg
);
826 fatalError(code
, msg
);
831 const seq
= reply
['seq'];
833 if (seq
&& get_seq() != seq
) {
834 console
.log("[handle_rpc_json] sequence mismatch: " + seq
+
835 " (want: " + get_seq() + ")");
839 const message
= reply
['message'];
841 if (message
== "UPDATE_COUNTERS") {
842 console
.log("need to refresh counters...");
843 setInitParam("last_article_id", -1);
844 request_counters(true);
847 const counters
= reply
['counters'];
850 parse_counters(counters
, scheduled_call
);
852 const runtime_info
= reply
['runtime-info'];
855 parse_runtime_info(runtime_info
);
857 if (netalert
) netalert
.hide();
865 notify_error("Communication problem with server.");
872 notify_error("Communication problem with server.");
880 function switchPanelMode(wide
) {
881 if (isCdmMode()) return;
883 const article_id
= getActiveArticleId();
886 dijit
.byId("headlines-wrap-inner").attr("design", 'sidebar');
887 dijit
.byId("content-insert").attr("region", "trailing");
889 dijit
.byId("content-insert").domNode
.setStyle({width
: '50%',
891 borderTopWidth
: '0px' });
893 if (parseInt(getCookie("ttrss_ci_width")) > 0) {
894 dijit
.byId("content-insert").domNode
.setStyle(
895 {width
: getCookie("ttrss_ci_width") + "px" });
898 $("headlines-frame").setStyle({ borderBottomWidth
: '0px' });
899 $("headlines-frame").addClassName("wide");
903 dijit
.byId("content-insert").attr("region", "bottom");
905 dijit
.byId("content-insert").domNode
.setStyle({width
: 'auto',
907 borderTopWidth
: '0px'});
909 if (parseInt(getCookie("ttrss_ci_height")) > 0) {
910 dijit
.byId("content-insert").domNode
.setStyle(
911 {height
: getCookie("ttrss_ci_height") + "px" });
914 $("headlines-frame").setStyle({ borderBottomWidth
: '1px' });
915 $("headlines-frame").removeClassName("wide");
921 if (article_id
) view(article_id
);
923 xhrPost("backend.php", {op
: "rpc", method
: "setpanelmode", wide
: wide
? 1 : 0});
926 function update_random_feed() {
927 console
.log("in update_random_feed");
929 xhrPost("backend.php", { op
: "rpc", method
: "updateRandomFeed" }, (transport
) => {
930 handle_rpc_json(transport
, true);
931 window
.setTimeout(update_random_feed
, 30*1000);
935 function hash_get(key
) {
936 const kv
= window
.location
.hash
.substring(1).toQueryParams();
939 function hash_set(key
, value
) {
940 const kv
= window
.location
.hash
.substring(1).toQueryParams();
942 window
.location
.hash
= $H(kv
).toQueryString();