]>
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);
238 init_hotkey_actions();
240 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;
247 op
: "rpc", method
: "sanityCheck", hasAudio
: hasAudio
,
249 clientTzOffset
: clientTzOffset
,
250 hasSandbox
: hasSandbox
253 xhrPost("backend.php", params
, (transport
) => {
255 backend_sanity_check_callback(transport
);
271 function init_hotkey_actions() {
272 hotkey_actions
["next_feed"] = function() {
273 const rv
= dijit
.byId("feedTree").getNextFeed(
274 getActiveFeedId(), activeFeedIsCat());
276 if (rv
) viewfeed({feed
: rv
[0], is_cat
: rv
[1], can_wait
: true})
278 hotkey_actions
["prev_feed"] = function() {
279 const rv
= dijit
.byId("feedTree").getPreviousFeed(
280 getActiveFeedId(), activeFeedIsCat());
282 if (rv
) viewfeed({feed
: rv
[0], is_cat
: rv
[1], can_wait
: true})
284 hotkey_actions
["next_article"] = function() {
287 hotkey_actions
["prev_article"] = function() {
290 hotkey_actions
["next_article_noscroll"] = function() {
291 moveToPost('next', true);
293 hotkey_actions
["prev_article_noscroll"] = function() {
294 moveToPost('prev', true);
296 hotkey_actions
["next_article_noexpand"] = function() {
297 moveToPost('next', true, true);
299 hotkey_actions
["prev_article_noexpand"] = function() {
300 moveToPost('prev', true, true);
302 hotkey_actions
["search_dialog"] = function() {
305 hotkey_actions
["toggle_mark"] = function() {
306 selectionToggleMarked(undefined, false, true);
308 hotkey_actions
["toggle_publ"] = function() {
309 selectionTogglePublished(undefined, false, true);
311 hotkey_actions
["toggle_unread"] = function() {
312 selectionToggleUnread(undefined, false, true);
314 hotkey_actions
["edit_tags"] = function() {
315 const id
= getActiveArticleId();
320 hotkey_actions
["open_in_new_window"] = function() {
321 if (getActiveArticleId()) {
322 openArticleInNewWindow(getActiveArticleId());
325 hotkey_actions
["catchup_below"] = function() {
326 catchupRelativeToArticle(1);
328 hotkey_actions
["catchup_above"] = function() {
329 catchupRelativeToArticle(0);
331 hotkey_actions
["article_scroll_down"] = function() {
334 hotkey_actions
["article_scroll_up"] = function() {
337 hotkey_actions
["close_article"] = function() {
340 hotkey_actions
["email_article"] = function() {
341 if (typeof emailArticle
!= "undefined") {
343 } else if (typeof mailtoArticle
!= "undefined") {
346 alert(__("Please enable mail plugin first."));
349 hotkey_actions
["select_all"] = function() {
350 selectArticles('all');
352 hotkey_actions
["select_unread"] = function() {
353 selectArticles('unread');
355 hotkey_actions
["select_marked"] = function() {
356 selectArticles('marked');
358 hotkey_actions
["select_published"] = function() {
359 selectArticles('published');
361 hotkey_actions
["select_invert"] = function() {
362 selectArticles('invert');
364 hotkey_actions
["select_none"] = function() {
365 selectArticles('none');
367 hotkey_actions
["feed_refresh"] = function() {
368 if (getActiveFeedId() != undefined) {
369 viewfeed({feed
: getActiveFeedId(), is_cat
: activeFeedIsCat()});
373 hotkey_actions
["feed_unhide_read"] = function() {
376 hotkey_actions
["feed_subscribe"] = function() {
379 hotkey_actions
["feed_debug_update"] = function() {
380 if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) {
381 window
.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() +
382 "&csrf_token=" + getInitParam("csrf_token"));
384 alert("You can't debug this kind of feed.");
388 hotkey_actions
["feed_debug_viewfeed"] = function() {
389 viewfeed({feed
: getActiveFeedId(), is_cat
: activeFeedIsCat(), viewfeed_debug
: true});
392 hotkey_actions
["feed_edit"] = function() {
393 if (activeFeedIsCat())
394 alert(__("You can't edit this kind of feed."));
396 editFeed(getActiveFeedId());
398 hotkey_actions
["feed_catchup"] = function() {
399 if (getActiveFeedId() != undefined) {
400 catchupCurrentFeed();
404 hotkey_actions
["feed_reverse"] = function() {
405 reverseHeadlineOrder();
407 hotkey_actions
["feed_toggle_vgroup"] = function() {
408 xhrPost("backend.php", {op
: "rpc", method
: "togglepref", key
: "VFEED_GROUP_BY_FEED"}, () => {
412 hotkey_actions
["catchup_all"] = function() {
415 hotkey_actions
["cat_toggle_collapse"] = function() {
416 if (activeFeedIsCat()) {
417 dijit
.byId("feedTree").collapseCat(getActiveFeedId());
421 hotkey_actions
["goto_all"] = function() {
422 viewfeed({feed
: -4});
424 hotkey_actions
["goto_fresh"] = function() {
425 viewfeed({feed
: -3});
427 hotkey_actions
["goto_marked"] = function() {
428 viewfeed({feed
: -1});
430 hotkey_actions
["goto_published"] = function() {
431 viewfeed({feed
: -2});
433 hotkey_actions
["goto_tagcloud"] = function() {
434 displayDlg(__("Tag cloud"), "printTagCloud");
436 hotkey_actions
["goto_prefs"] = function() {
439 hotkey_actions
["select_article_cursor"] = function() {
440 const id
= getArticleUnderPointer();
442 const row
= $("RROW-" + id
);
445 const cb
= dijit
.getEnclosingWidget(
446 row
.getElementsByClassName("rchk")[0]);
449 cb
.attr("checked", !cb
.attr("checked"));
450 toggleSelectRowById(cb
, "RROW-" + id
);
456 hotkey_actions
["create_label"] = function() {
459 hotkey_actions
["create_filter"] = function() {
462 hotkey_actions
["collapse_sidebar"] = function() {
465 hotkey_actions
["toggle_embed_original"] = function() {
466 if (typeof embedOriginalArticle
!= "undefined") {
467 if (getActiveArticleId())
468 embedOriginalArticle(getActiveArticleId());
470 alert(__("Please enable embed_original plugin first."));
473 hotkey_actions
["toggle_widescreen"] = function() {
475 _widescreen_mode
= !_widescreen_mode
;
477 // reset stored sizes because geometry changed
478 setCookie("ttrss_ci_width", 0);
479 setCookie("ttrss_ci_height", 0);
481 switchPanelMode(_widescreen_mode
);
483 alert(__("Widescreen is not available in combined mode."));
486 hotkey_actions
["help_dialog"] = function() {
489 hotkey_actions
["toggle_combined_mode"] = function() {
490 notify_progress("Loading, please wait...");
492 const value
= isCdmMode() ? "false" : "true";
494 xhrPost("backend.php", {op
: "rpc", method
: "setpref", key
: "COMBINED_DISPLAY_MODE", value
: value
}, () => {
495 setInitParam("combined_display_mode",
496 !getInitParam("combined_display_mode"));
504 function init_second_stage() {
508 if (parseInt(getCookie("ttrss_fh_width")) > 0) {
509 dijit
.byId("feeds-holder").domNode
.setStyle(
510 {width
: getCookie("ttrss_fh_width") + "px" });
513 dijit
.byId("main").resize();
515 var tmph
= dojo
.connect(dijit
.byId('feeds-holder'), 'resize',
517 if (args
&& args
.w
>= 0) {
518 setCookie("ttrss_fh_width", args
.w
, getInitParam("cookie_lifetime"));
522 var tmph
= dojo
.connect(dijit
.byId('content-insert'), 'resize',
524 if (args
&& args
.w
>= 0 && args
.h
>= 0) {
525 setCookie("ttrss_ci_width", args
.w
, getInitParam("cookie_lifetime"));
526 setCookie("ttrss_ci_height", args
.h
, getInitParam("cookie_lifetime"));
530 delCookie("ttrss_test");
532 const toolbar
= document
.forms
["main_toolbar_form"];
534 dijit
.getEnclosingWidget(toolbar
.view_mode
).attr('value',
535 getInitParam("default_view_mode"));
537 dijit
.getEnclosingWidget(toolbar
.order_by
).attr('value',
538 getInitParam("default_view_order_by"));
540 const hash_feed_id
= hash_get('f');
541 const hash_feed_is_cat
= hash_get('c') == "1";
543 if (hash_feed_id
!= undefined) {
544 setActiveFeedId(hash_feed_id
, hash_feed_is_cat
);
547 loading_set_progress(50);
549 // can't use cache_clear() here because viewfeed might not have initialized yet
550 if ('sessionStorage' in window
&& window
['sessionStorage'] !== null)
551 sessionStorage
.clear();
553 /*const hotkeys = getInitParam("hotkeys");
556 for (const sequence in hotkeys[1]) {
557 const filtered = sequence.replace(/\|.*$/, "");
558 tmp[filtered] = hotkeys[1][sequence];
562 setInitParam("hotkeys", hotkeys);*/
564 _widescreen_mode
= getInitParam("widescreen");
565 switchPanelMode(_widescreen_mode
);
567 console
.log("second stage ok");
569 if (getInitParam("simple_update")) {
570 console
.log("scheduling simple feed updater...");
571 window
.setTimeout(update_random_feed
, 30*1000);
575 function quickMenuGo(opid
) {
584 displayDlg(__("Tag cloud"), "printTagCloud");
593 window
.location
.href
= "backend.php?op=digest";
596 if (activeFeedIsCat())
597 alert(__("You can't edit this kind of feed."));
599 editFeed(getActiveFeedId());
601 case "qmcRemoveFeed":
602 var actid
= getActiveFeedId();
604 if (activeFeedIsCat()) {
605 alert(__("You can't unsubscribe from the category."));
610 alert(__("Please select some feed first."));
614 var fn
= getFeedName(actid
);
616 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
619 unsubscribeFeed(actid
);
622 case "qmcCatchupAll":
625 case "qmcShowOnlyUnread":
628 case "qmcToggleWidescreen":
630 _widescreen_mode
= !_widescreen_mode
;
632 // reset stored sizes because geometry changed
633 setCookie("ttrss_ci_width", 0);
634 setCookie("ttrss_ci_height", 0);
636 switchPanelMode(_widescreen_mode
);
638 alert(__("Widescreen is not available in combined mode."));
645 console
.log("quickMenuGo: unknown action: " + opid
);
649 function toggleDispRead() {
651 const hide
= !(getInitParam("hide_read_feeds") == "1");
653 xhrPost("backend.php", {op
: "rpc", method
: "setpref", key
: "HIDE_READ_FEEDS", value
: hide
}, () => {
654 hideOrShowFeeds(hide
);
655 setInitParam("hide_read_feeds", hide
);
659 function parse_runtime_info(data
) {
661 //console.log("parsing runtime info...");
663 for (const k
in data
) {
666 // console.log("RI: " + k + " => " + v);
668 if (k
== "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
669 if (parseInt(getInitParam("dep_ts")) < parseInt(v
) && getInitParam("reload_on_ts_change")) {
670 window
.location
.reload();
674 if (k
== "daemon_is_running" && v
!= 1) {
675 notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true);
679 if (k
== "update_result") {
680 const updatesIcon
= dijit
.byId("updatesIcon").domNode
;
683 Element
.show(updatesIcon
);
685 Element
.hide(updatesIcon
);
689 if (k
== "daemon_stamp_ok" && v
!= 1) {
690 notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true);
694 if (k
== "max_feed_id" || k
== "num_feeds") {
695 if (init_params
[k
] != v
) {
696 console
.log("feed count changed, need to reload feedlist.");
705 PluginHost
.run(PluginHost
.HOOK_RUNTIME_INFO_LOADED
, data
);
708 function collapse_feedlist() {
709 Element
.toggle("feeds-holder");
711 const splitter
= $("feeds-holder_splitter");
713 Element
.visible("feeds-holder") ? splitter
.show() : splitter
.hide();
715 dijit
.byId("main").resize();
718 function viewModeChanged() {
720 return viewCurrentFeed('');
723 function hotkey_handler(e
) {
724 if (e
.target
.nodeName
== "INPUT" || e
.target
.nodeName
== "TEXTAREA") return;
726 const action_name
= keyevent_to_action(e
);
729 const action_func
= hotkey_actions
[action_name
];
731 if (action_func
!= null) {
739 function inPreferences() {
743 function reverseHeadlineOrder() {
745 const toolbar
= document
.forms
["main_toolbar_form"];
746 const order_by
= dijit
.getEnclosingWidget(toolbar
.order_by
);
748 let value
= order_by
.attr('value');
750 if (value
== "date_reverse")
753 value
= "date_reverse";
755 order_by
.attr('value', value
);
761 function handle_rpc_json(transport
, scheduled_call
) {
763 const netalert_dijit
= dijit
.byId("net-alert");
764 let netalert
= false;
766 if (netalert_dijit
) netalert
= netalert_dijit
.domNode
;
769 const reply
= JSON
.parse(transport
.responseText
);
773 const error
= reply
['error'];
776 const code
= error
['code'];
777 const msg
= error
['msg'];
779 console
.warn("[handle_rpc_json] received fatal error " + code
+ "/" + msg
);
782 fatalError(code
, msg
);
787 const seq
= reply
['seq'];
789 if (seq
&& get_seq() != seq
) {
790 console
.log("[handle_rpc_json] sequence mismatch: " + seq
+
791 " (want: " + get_seq() + ")");
795 const message
= reply
['message'];
797 if (message
== "UPDATE_COUNTERS") {
798 console
.log("need to refresh counters...");
799 setInitParam("last_article_id", -1);
800 request_counters(true);
803 const counters
= reply
['counters'];
806 parse_counters(counters
, scheduled_call
);
808 const runtime_info
= reply
['runtime-info'];
811 parse_runtime_info(runtime_info
);
813 if (netalert
) netalert
.hide();
821 notify_error("Communication problem with server.");
828 notify_error("Communication problem with server.");
836 function switchPanelMode(wide
) {
837 if (isCdmMode()) return;
839 const article_id
= getActiveArticleId();
842 dijit
.byId("headlines-wrap-inner").attr("design", 'sidebar');
843 dijit
.byId("content-insert").attr("region", "trailing");
845 dijit
.byId("content-insert").domNode
.setStyle({width
: '50%',
847 borderTopWidth
: '0px' });
849 if (parseInt(getCookie("ttrss_ci_width")) > 0) {
850 dijit
.byId("content-insert").domNode
.setStyle(
851 {width
: getCookie("ttrss_ci_width") + "px" });
854 $("headlines-frame").setStyle({ borderBottomWidth
: '0px' });
855 $("headlines-frame").addClassName("wide");
859 dijit
.byId("content-insert").attr("region", "bottom");
861 dijit
.byId("content-insert").domNode
.setStyle({width
: 'auto',
863 borderTopWidth
: '0px'});
865 if (parseInt(getCookie("ttrss_ci_height")) > 0) {
866 dijit
.byId("content-insert").domNode
.setStyle(
867 {height
: getCookie("ttrss_ci_height") + "px" });
870 $("headlines-frame").setStyle({ borderBottomWidth
: '1px' });
871 $("headlines-frame").removeClassName("wide");
877 if (article_id
) view(article_id
);
879 xhrPost("backend.php", {op
: "rpc", method
: "setpanelmode", wide
: wide
? 1 : 0});
882 function update_random_feed() {
883 console
.log("in update_random_feed");
885 xhrPost("backend.php", { op
: "rpc", method
: "updateRandomFeed" }, (transport
) => {
886 handle_rpc_json(transport
, true);
887 window
.setTimeout(update_random_feed
, 30*1000);
891 function hash_get(key
) {
892 const kv
= window
.location
.hash
.substring(1).toQueryParams();
895 function hash_set(key
, value
) {
896 const kv
= window
.location
.hash
.substring(1).toQueryParams();
898 window
.location
.hash
= $H(kv
).toQueryString();