]> git.wh0rd.org - tt-rss.git/blob - js/tt-rss.js
pngcrush.sh
[tt-rss.git] / js / tt-rss.js
1 /* global dijit, __ */
2
3 let global_unread = -1;
4 let _widescreen_mode = false;
5 let _rpc_seq = 0;
6 let _active_feed_id = 0;
7 let _active_feed_is_cat = false;
8 let hotkey_actions = {};
9
10 function next_seq() {
11 _rpc_seq += 1;
12 return _rpc_seq;
13 }
14
15 function get_seq() {
16 return _rpc_seq;
17 }
18
19 function activeFeedIsCat() {
20 return !!_active_feed_is_cat;
21 }
22
23 function getActiveFeedId() {
24 return _active_feed_id;
25 }
26
27 function setActiveFeedId(id, is_cat) {
28 hash_set('f', id);
29 hash_set('c', is_cat ? 1 : 0);
30
31 _active_feed_id = id;
32 _active_feed_is_cat = is_cat;
33
34 $("headlines-frame").setAttribute("feed-id", id);
35 $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0);
36
37 selectFeed(id, is_cat);
38
39 PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id);
40 }
41
42
43 function updateFeedList() {
44 try {
45 Element.show("feedlistLoading");
46
47 resetCounterCache();
48
49 if (dijit.byId("feedTree")) {
50 dijit.byId("feedTree").destroyRecursive();
51 }
52
53 const store = new dojo.data.ItemFileWriteStore({
54 url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"
55 });
56
57 const treeModel = new fox.FeedStoreModel({
58 store: store,
59 query: {
60 "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
61 },
62 rootId: "root",
63 rootLabel: "Feeds",
64 childrenAttrs: ["items"]
65 });
66
67 const tree = new fox.FeedTree({
68 model: treeModel,
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});
74 return false;
75 },
76 openOnClick: false,
77 showRoot: false,
78 persist: true,
79 id: "feedTree",
80 }, "feedTree");
81
82 var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
83 console.log(dijit.getEnclosingWidget(event.target));
84 dojo.disconnect(tmph);
85 });
86
87 $("feeds-holder").appendChild(tree.domNode);
88
89 var tmph = dojo.connect(tree, 'onLoad', function () {
90 dojo.disconnect(tmph);
91 Element.hide("feedlistLoading");
92
93 try {
94 feedlist_init();
95
96 loading_set_progress(25);
97 } catch (e) {
98 exception_error(e);
99 }
100 });
101
102 tree.startup();
103 } catch (e) {
104 exception_error(e);
105 }
106 }
107
108 function catchupAllFeeds() {
109
110 const str = __("Mark all articles as read?");
111
112 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
113
114 notify_progress("Marking all feeds as read...");
115
116 xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => {
117 request_counters(true);
118 viewCurrentFeed();
119 });
120
121 global_unread = 0;
122 updateTitle("");
123 }
124 }
125
126 function viewCurrentFeed(method) {
127 console.log("viewCurrentFeed: " + method);
128
129 if (getActiveFeedId() != undefined) {
130 viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), method: method});
131 }
132 return false; // block unneeded form submits
133 }
134
135 function timeout() {
136 if (getInitParam("bw_limit") != "1") {
137 request_counters(true);
138 setTimeout(timeout, 60*1000);
139 }
140 }
141
142 function search() {
143 const query = "backend.php?op=feeds&method=search&param=" +
144 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
145
146 if (dijit.byId("searchDlg"))
147 dijit.byId("searchDlg").destroyRecursive();
148
149 const dialog = new dijit.Dialog({
150 id: "searchDlg",
151 title: __("Search"),
152 style: "width: 600px",
153 execute: function() {
154 if (this.validate()) {
155 _search_query = this.attr('value');
156 this.hide();
157 viewCurrentFeed();
158 }
159 },
160 href: query});
161
162 dialog.show();
163 }
164
165 function updateTitle() {
166 let tmp = "Tiny Tiny RSS";
167
168 if (global_unread > 0) {
169 tmp = "(" + global_unread + ") " + tmp;
170 }
171
172 document.title = tmp;
173 }
174
175 function genericSanityCheck() {
176 setCookie("ttrss_test", "TEST");
177
178 if (getCookie("ttrss_test") != "TEST") {
179 return fatalError(2);
180 }
181
182 return true;
183 }
184
185
186 function init() {
187
188 window.onerror = function(message, filename, lineno, colno, error) {
189 report_error(message, filename, lineno, colno, error);
190 };
191
192 require(["dojo/_base/kernel",
193 "dojo/ready",
194 "dojo/parser",
195 "dojo/_base/loader",
196 "dojo/_base/html",
197 "dojo/query",
198 "dijit/ProgressBar",
199 "dijit/ColorPalette",
200 "dijit/Dialog",
201 "dijit/form/Button",
202 "dijit/form/ComboButton",
203 "dijit/form/CheckBox",
204 "dijit/form/DropDownButton",
205 "dijit/form/FilteringSelect",
206 "dijit/form/Form",
207 "dijit/form/RadioButton",
208 "dijit/form/Select",
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",
220 "dijit/Menu",
221 "dijit/Toolbar",
222 "dijit/Tree",
223 "dijit/tree/dndSource",
224 "dijit/tree/ForestStoreModel",
225 "dojo/data/ItemFileWriteStore",
226 "fox/FeedStoreModel",
227 "fox/FeedTree" ], function (dojo, ready, parser) {
228
229 ready(function() {
230
231 try {
232 parser.parse();
233
234 if (!genericSanityCheck())
235 return false;
236
237 loading_set_progress(30);
238 init_hotkey_actions();
239
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;
245
246 const params = {
247 op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
248 hasMp3: hasMp3,
249 clientTzOffset: clientTzOffset,
250 hasSandbox: hasSandbox
251 };
252
253 xhrPost("backend.php", params, (transport) => {
254 try {
255 backend_sanity_check_callback(transport);
256 } catch (e) {
257 console.error(e);
258 }
259 });
260
261 } catch (e) {
262 exception_error(e);
263 }
264
265 });
266
267
268 });
269 }
270
271 function init_hotkey_actions() {
272 hotkey_actions["next_feed"] = function() {
273 const rv = dijit.byId("feedTree").getNextFeed(
274 getActiveFeedId(), activeFeedIsCat());
275
276 if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true})
277 };
278 hotkey_actions["prev_feed"] = function() {
279 const rv = dijit.byId("feedTree").getPreviousFeed(
280 getActiveFeedId(), activeFeedIsCat());
281
282 if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true})
283 };
284 hotkey_actions["next_article"] = function() {
285 moveToPost('next');
286 };
287 hotkey_actions["prev_article"] = function() {
288 moveToPost('prev');
289 };
290 hotkey_actions["next_article_noscroll"] = function() {
291 moveToPost('next', true);
292 };
293 hotkey_actions["prev_article_noscroll"] = function() {
294 moveToPost('prev', true);
295 };
296 hotkey_actions["next_article_noexpand"] = function() {
297 moveToPost('next', true, true);
298 };
299 hotkey_actions["prev_article_noexpand"] = function() {
300 moveToPost('prev', true, true);
301 };
302 hotkey_actions["search_dialog"] = function() {
303 search();
304 };
305 hotkey_actions["toggle_mark"] = function() {
306 selectionToggleMarked(undefined, false, true);
307 };
308 hotkey_actions["toggle_publ"] = function() {
309 selectionTogglePublished(undefined, false, true);
310 };
311 hotkey_actions["toggle_unread"] = function() {
312 selectionToggleUnread(undefined, false, true);
313 };
314 hotkey_actions["edit_tags"] = function() {
315 const id = getActiveArticleId();
316 if (id) {
317 editArticleTags(id);
318 }
319 }
320 hotkey_actions["open_in_new_window"] = function() {
321 if (getActiveArticleId()) {
322 openArticleInNewWindow(getActiveArticleId());
323 }
324 };
325 hotkey_actions["catchup_below"] = function() {
326 catchupRelativeToArticle(1);
327 };
328 hotkey_actions["catchup_above"] = function() {
329 catchupRelativeToArticle(0);
330 };
331 hotkey_actions["article_scroll_down"] = function() {
332 scrollArticle(40);
333 };
334 hotkey_actions["article_scroll_up"] = function() {
335 scrollArticle(-40);
336 };
337 hotkey_actions["close_article"] = function() {
338 if (isCdmMode()) {
339 cdmCollapseActive();
340 } else {
341 closeArticlePanel();
342 }
343 };
344 hotkey_actions["email_article"] = function() {
345 if (typeof emailArticle != "undefined") {
346 emailArticle();
347 } else if (typeof mailtoArticle != "undefined") {
348 mailtoArticle();
349 } else {
350 alert(__("Please enable mail plugin first."));
351 }
352 };
353 hotkey_actions["select_all"] = function() {
354 selectArticles('all');
355 };
356 hotkey_actions["select_unread"] = function() {
357 selectArticles('unread');
358 };
359 hotkey_actions["select_marked"] = function() {
360 selectArticles('marked');
361 };
362 hotkey_actions["select_published"] = function() {
363 selectArticles('published');
364 };
365 hotkey_actions["select_invert"] = function() {
366 selectArticles('invert');
367 };
368 hotkey_actions["select_none"] = function() {
369 selectArticles('none');
370 };
371 hotkey_actions["feed_refresh"] = function() {
372 if (getActiveFeedId() != undefined) {
373 viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()});
374 return;
375 }
376 };
377 hotkey_actions["feed_unhide_read"] = function() {
378 toggleDispRead();
379 };
380 hotkey_actions["feed_subscribe"] = function() {
381 quickAddFeed();
382 };
383 hotkey_actions["feed_debug_update"] = function() {
384 if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) {
385 window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() +
386 "&csrf_token=" + getInitParam("csrf_token"));
387 } else {
388 alert("You can't debug this kind of feed.");
389 }
390 };
391
392 hotkey_actions["feed_debug_viewfeed"] = function() {
393 viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true});
394 };
395
396 hotkey_actions["feed_edit"] = function() {
397 if (activeFeedIsCat())
398 alert(__("You can't edit this kind of feed."));
399 else
400 editFeed(getActiveFeedId());
401 };
402 hotkey_actions["feed_catchup"] = function() {
403 if (getActiveFeedId() != undefined) {
404 catchupCurrentFeed();
405 return;
406 }
407 };
408 hotkey_actions["feed_reverse"] = function() {
409 reverseHeadlineOrder();
410 };
411 hotkey_actions["feed_toggle_vgroup"] = function() {
412 xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => {
413 viewCurrentFeed();
414 })
415 };
416 hotkey_actions["catchup_all"] = function() {
417 catchupAllFeeds();
418 };
419 hotkey_actions["cat_toggle_collapse"] = function() {
420 if (activeFeedIsCat()) {
421 dijit.byId("feedTree").collapseCat(getActiveFeedId());
422 return;
423 }
424 };
425 hotkey_actions["goto_all"] = function() {
426 viewfeed({feed: -4});
427 };
428 hotkey_actions["goto_fresh"] = function() {
429 viewfeed({feed: -3});
430 };
431 hotkey_actions["goto_marked"] = function() {
432 viewfeed({feed: -1});
433 };
434 hotkey_actions["goto_published"] = function() {
435 viewfeed({feed: -2});
436 };
437 hotkey_actions["goto_tagcloud"] = function() {
438 displayDlg(__("Tag cloud"), "printTagCloud");
439 };
440 hotkey_actions["goto_prefs"] = function() {
441 gotoPreferences();
442 };
443 hotkey_actions["select_article_cursor"] = function() {
444 const id = getArticleUnderPointer();
445 if (id) {
446 const row = $("RROW-" + id);
447
448 if (row) {
449 const cb = dijit.getEnclosingWidget(
450 row.select(".rchk")[0]);
451
452 if (cb) {
453 if (!row.hasClassName("active"))
454 cb.attr("checked", !cb.attr("checked"));
455
456 toggleSelectRowById(cb, "RROW-" + id);
457 return false;
458 }
459 }
460 }
461 };
462 hotkey_actions["create_label"] = function() {
463 addLabel();
464 };
465 hotkey_actions["create_filter"] = function() {
466 quickAddFilter();
467 };
468 hotkey_actions["collapse_sidebar"] = function() {
469 collapse_feedlist();
470 };
471 hotkey_actions["toggle_embed_original"] = function() {
472 if (typeof embedOriginalArticle != "undefined") {
473 if (getActiveArticleId())
474 embedOriginalArticle(getActiveArticleId());
475 } else {
476 alert(__("Please enable embed_original plugin first."));
477 }
478 };
479 hotkey_actions["toggle_widescreen"] = function() {
480 if (!isCdmMode()) {
481 _widescreen_mode = !_widescreen_mode;
482
483 // reset stored sizes because geometry changed
484 setCookie("ttrss_ci_width", 0);
485 setCookie("ttrss_ci_height", 0);
486
487 switchPanelMode(_widescreen_mode);
488 } else {
489 alert(__("Widescreen is not available in combined mode."));
490 }
491 };
492 hotkey_actions["help_dialog"] = function() {
493 helpDialog("main");
494 };
495 hotkey_actions["toggle_combined_mode"] = function() {
496 notify_progress("Loading, please wait...");
497
498 const value = isCdmMode() ? "false" : "true";
499
500 xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => {
501 setInitParam("combined_display_mode",
502 !getInitParam("combined_display_mode"));
503
504 closeArticlePanel();
505 viewCurrentFeed();
506 })
507 };
508 hotkey_actions["toggle_cdm_expanded"] = function() {
509 notify_progress("Loading, please wait...");
510
511 const value = getInitParam("cdm_expanded") ? "false" : "true";
512 const query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value;
513
514 new Ajax.Request("backend.php", {
515 parameters: query,
516 onComplete: function(transport) {
517 setInitParam("cdm_expanded", !getInitParam("cdm_expanded"));
518 viewCurrentFeed();
519 } });
520 };
521
522 }
523
524 function init_second_stage() {
525 updateFeedList();
526 closeArticlePanel();
527
528 if (parseInt(getCookie("ttrss_fh_width")) > 0) {
529 dijit.byId("feeds-holder").domNode.setStyle(
530 {width: getCookie("ttrss_fh_width") + "px" });
531 }
532
533 dijit.byId("main").resize();
534
535 var tmph = dojo.connect(dijit.byId('feeds-holder'), 'resize',
536 function (args) {
537 if (args && args.w >= 0) {
538 setCookie("ttrss_fh_width", args.w, getInitParam("cookie_lifetime"));
539 }
540 });
541
542 var tmph = dojo.connect(dijit.byId('content-insert'), 'resize',
543 function (args) {
544 if (args && args.w >= 0 && args.h >= 0) {
545 setCookie("ttrss_ci_width", args.w, getInitParam("cookie_lifetime"));
546 setCookie("ttrss_ci_height", args.h, getInitParam("cookie_lifetime"));
547 }
548 });
549
550 delCookie("ttrss_test");
551
552 const toolbar = document.forms["main_toolbar_form"];
553
554 dijit.getEnclosingWidget(toolbar.view_mode).attr('value',
555 getInitParam("default_view_mode"));
556
557 dijit.getEnclosingWidget(toolbar.order_by).attr('value',
558 getInitParam("default_view_order_by"));
559
560 const hash_feed_id = hash_get('f');
561 const hash_feed_is_cat = hash_get('c') == "1";
562
563 if (hash_feed_id != undefined) {
564 setActiveFeedId(hash_feed_id, hash_feed_is_cat);
565 }
566
567 loading_set_progress(50);
568
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();
572
573 /*const hotkeys = getInitParam("hotkeys");
574 const tmp = [];
575
576 for (const sequence in hotkeys[1]) {
577 const filtered = sequence.replace(/\|.*$/, "");
578 tmp[filtered] = hotkeys[1][sequence];
579 }
580
581 hotkeys[1] = tmp;
582 setInitParam("hotkeys", hotkeys);*/
583
584 _widescreen_mode = getInitParam("widescreen");
585 switchPanelMode(_widescreen_mode);
586
587 console.log("second stage ok");
588
589 if (getInitParam("simple_update")) {
590 console.log("scheduling simple feed updater...");
591 window.setTimeout(update_random_feed, 30*1000);
592 }
593 }
594
595 function quickMenuGo(opid) {
596 switch (opid) {
597 case "qmcPrefs":
598 gotoPreferences();
599 break;
600 case "qmcLogout":
601 gotoLogout();
602 break;
603 case "qmcTagCloud":
604 displayDlg(__("Tag cloud"), "printTagCloud");
605 break;
606 case "qmcSearch":
607 search();
608 break;
609 case "qmcAddFeed":
610 quickAddFeed();
611 break;
612 case "qmcDigest":
613 window.location.href = "backend.php?op=digest";
614 break;
615 case "qmcEditFeed":
616 if (activeFeedIsCat())
617 alert(__("You can't edit this kind of feed."));
618 else
619 editFeed(getActiveFeedId());
620 break;
621 case "qmcRemoveFeed":
622 var actid = getActiveFeedId();
623
624 if (activeFeedIsCat()) {
625 alert(__("You can't unsubscribe from the category."));
626 return;
627 }
628
629 if (!actid) {
630 alert(__("Please select some feed first."));
631 return;
632 }
633
634 var fn = getFeedName(actid);
635
636 var pr = __("Unsubscribe from %s?").replace("%s", fn);
637
638 if (confirm(pr)) {
639 unsubscribeFeed(actid);
640 }
641 break;
642 case "qmcCatchupAll":
643 catchupAllFeeds();
644 break;
645 case "qmcShowOnlyUnread":
646 toggleDispRead();
647 break;
648 case "qmcToggleWidescreen":
649 if (!isCdmMode()) {
650 _widescreen_mode = !_widescreen_mode;
651
652 // reset stored sizes because geometry changed
653 setCookie("ttrss_ci_width", 0);
654 setCookie("ttrss_ci_height", 0);
655
656 switchPanelMode(_widescreen_mode);
657 } else {
658 alert(__("Widescreen is not available in combined mode."));
659 }
660 break;
661 case "qmcHKhelp":
662 helpDialog("main");
663 break;
664 default:
665 console.log("quickMenuGo: unknown action: " + opid);
666 }
667 }
668
669 function toggleDispRead() {
670
671 const hide = !(getInitParam("hide_read_feeds") == "1");
672
673 xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => {
674 hideOrShowFeeds(hide);
675 setInitParam("hide_read_feeds", hide);
676 });
677 }
678
679 function parse_runtime_info(data) {
680
681 //console.log("parsing runtime info...");
682
683 for (const k in data) {
684 const v = data[k];
685
686 // console.log("RI: " + k + " => " + v);
687
688 if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
689 if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) {
690 window.location.reload();
691 }
692 }
693
694 if (k == "daemon_is_running" && v != 1) {
695 notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true);
696 return;
697 }
698
699 if (k == "update_result") {
700 const updatesIcon = dijit.byId("updatesIcon").domNode;
701
702 if (v) {
703 Element.show(updatesIcon);
704 } else {
705 Element.hide(updatesIcon);
706 }
707 }
708
709 if (k == "daemon_stamp_ok" && v != 1) {
710 notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true);
711 return;
712 }
713
714 if (k == "max_feed_id" || k == "num_feeds") {
715 if (init_params[k] != v) {
716 console.log("feed count changed, need to reload feedlist.");
717 updateFeedList();
718 }
719 }
720
721 init_params[k] = v;
722 notify('');
723 }
724
725 PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
726 }
727
728 function collapse_feedlist() {
729 Element.toggle("feeds-holder");
730
731 const splitter = $("feeds-holder_splitter");
732
733 Element.visible("feeds-holder") ? splitter.show() : splitter.hide();
734
735 dijit.byId("main").resize();
736 }
737
738 function viewModeChanged() {
739 cache_clear();
740 return viewCurrentFeed('');
741 }
742
743 function hotkey_handler(e) {
744 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
745
746 const action_name = keyevent_to_action(e);
747
748 if (action_name) {
749 const action_func = hotkey_actions[action_name];
750
751 if (action_func != null) {
752 action_func();
753 e.stopPropagation();
754 return false;
755 }
756 }
757 }
758
759 function inPreferences() {
760 return false;
761 }
762
763 function reverseHeadlineOrder() {
764
765 const toolbar = document.forms["main_toolbar_form"];
766 const order_by = dijit.getEnclosingWidget(toolbar.order_by);
767
768 let value = order_by.attr('value');
769
770 if (value == "date_reverse")
771 value = "default";
772 else
773 value = "date_reverse";
774
775 order_by.attr('value', value);
776
777 viewCurrentFeed();
778
779 }
780
781 function handle_rpc_json(transport, scheduled_call) {
782
783 const netalert_dijit = dijit.byId("net-alert");
784 let netalert = false;
785
786 if (netalert_dijit) netalert = netalert_dijit.domNode;
787
788 try {
789 const reply = JSON.parse(transport.responseText);
790
791 if (reply) {
792
793 const error = reply['error'];
794
795 if (error) {
796 const code = error['code'];
797 const msg = error['msg'];
798
799 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
800
801 if (code != 0) {
802 fatalError(code, msg);
803 return false;
804 }
805 }
806
807 const seq = reply['seq'];
808
809 if (seq && get_seq() != seq) {
810 console.log("[handle_rpc_json] sequence mismatch: " + seq +
811 " (want: " + get_seq() + ")");
812 return true;
813 }
814
815 const message = reply['message'];
816
817 if (message == "UPDATE_COUNTERS") {
818 console.log("need to refresh counters...");
819 setInitParam("last_article_id", -1);
820 request_counters(true);
821 }
822
823 const counters = reply['counters'];
824
825 if (counters)
826 parse_counters(counters, scheduled_call);
827
828 const runtime_info = reply['runtime-info'];
829
830 if (runtime_info)
831 parse_runtime_info(runtime_info);
832
833 if (netalert) netalert.hide();
834
835 return reply;
836
837 } else {
838 if (netalert)
839 netalert.show();
840 else
841 notify_error("Communication problem with server.");
842 }
843
844 } catch (e) {
845 if (netalert)
846 netalert.show();
847 else
848 notify_error("Communication problem with server.");
849
850 console.error(e);
851 }
852
853 return false;
854 }
855
856 function switchPanelMode(wide) {
857 if (isCdmMode()) return;
858
859 const article_id = getActiveArticleId();
860
861 if (wide) {
862 dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
863 dijit.byId("content-insert").attr("region", "trailing");
864
865 dijit.byId("content-insert").domNode.setStyle({width: '50%',
866 height: 'auto',
867 borderTopWidth: '0px' });
868
869 if (parseInt(getCookie("ttrss_ci_width")) > 0) {
870 dijit.byId("content-insert").domNode.setStyle(
871 {width: getCookie("ttrss_ci_width") + "px" });
872 }
873
874 $("headlines-frame").setStyle({ borderBottomWidth: '0px' });
875 $("headlines-frame").addClassName("wide");
876
877 } else {
878
879 dijit.byId("content-insert").attr("region", "bottom");
880
881 dijit.byId("content-insert").domNode.setStyle({width: 'auto',
882 height: '50%',
883 borderTopWidth: '0px'});
884
885 if (parseInt(getCookie("ttrss_ci_height")) > 0) {
886 dijit.byId("content-insert").domNode.setStyle(
887 {height: getCookie("ttrss_ci_height") + "px" });
888 }
889
890 $("headlines-frame").setStyle({ borderBottomWidth: '1px' });
891 $("headlines-frame").removeClassName("wide");
892
893 }
894
895 closeArticlePanel();
896
897 if (article_id) view(article_id);
898
899 xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0});
900 }
901
902 function update_random_feed() {
903 console.log("in update_random_feed");
904
905 xhrPost("backend.php", { op: "rpc", method: "updateRandomFeed" }, (transport) => {
906 handle_rpc_json(transport, true);
907 window.setTimeout(update_random_feed, 30*1000);
908 });
909 }
910
911 function hash_get(key) {
912 const kv = window.location.hash.substring(1).toQueryParams();
913 return kv[key];
914 }
915 function hash_set(key, value) {
916 const kv = window.location.hash.substring(1).toQueryParams();
917 kv[key] = value;
918 window.location.hash = $H(kv).toQueryString();
919 }