]> git.wh0rd.org Git - tt-rss.git/blob - js/tt-rss.js
remove page title stuff for the time being
[tt-rss.git] / js / tt-rss.js
1 var global_unread = -1;
2 var hotkey_prefix = false;
3 var hotkey_prefix_pressed = false;
4 var _widescreen_mode = false;
5 var _rpc_seq = 0;
6 var _active_feed_id = 0;
7 var _active_feed_is_cat = false;
8
9 function next_seq() {
10         _rpc_seq += 1;
11         return _rpc_seq;
12 }
13
14 function get_seq() {
15         return _rpc_seq;
16 }
17
18 function activeFeedIsCat() {
19         return _active_feed_is_cat;
20 }
21
22 function getActiveFeedId() {
23         try {
24                 return _active_feed_id;
25         } catch (e) {
26                 exception_error("getActiveFeedId", e);
27         }
28 }
29
30 function setActiveFeedId(id, is_cat) {
31         try {
32                 hash_set('f', id);
33                 hash_set('c', is_cat ? 1 : 0);
34
35                 _active_feed_id = id;
36                 _active_feed_is_cat = is_cat;
37
38                 selectFeed(id, is_cat);
39         } catch (e) {
40                 exception_error("setActiveFeedId", e);
41         }
42 }
43
44
45 function updateFeedList() {
46         try {
47
48 //              $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
49 //                      __("Loading, please wait...") + "</div>";
50
51                 Element.show("feedlistLoading");
52
53                 if (dijit.byId("feedTree")) {
54                         dijit.byId("feedTree").destroyRecursive();
55                 }
56
57                 var store = new dojo.data.ItemFileWriteStore({
58          url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"});
59
60                 var treeModel = new fox.FeedStoreModel({
61                         store: store,
62                         query: {
63                                 "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
64                         },
65                         rootId: "root",
66                         rootLabel: "Feeds",
67                         childrenAttrs: ["items"]
68                 });
69
70                 var tree = new fox.FeedTree({
71                 model: treeModel,
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);
77                         return false;
78                 },
79                 openOnClick: false,
80                 showRoot: false,
81                 id: "feedTree",
82                 }, "feedTree");
83
84 /*              var menu = new dijit.Menu({id: 'feedMenu'});
85
86                 menu.addChild(new dijit.MenuItem({
87           label: "Simple menu item"
88                 }));
89
90 //              menu.bindDomNode(tree.domNode); */
91
92                 var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
93                         console.log(dijit.getEnclosingWidget(event.target));
94                         dojo.disconnect(tmph);
95                 });
96
97                 $("feeds-holder").appendChild(tree.domNode);
98
99                 var tmph = dojo.connect(tree, 'onLoad', function() {
100                 dojo.disconnect(tmph);
101                         Element.hide("feedlistLoading");
102
103                         feedlist_init();
104
105 //                      var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
106 //                      menu.bindDomNode(node);
107
108                         loading_set_progress(25);
109                 });
110
111                 tree.startup();
112
113         } catch (e) {
114                 exception_error("updateFeedList", e);
115         }
116 }
117
118 function catchupAllFeeds() {
119
120         var str = __("Mark all articles as read?");
121
122         if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
123
124                 var query_str = "backend.php?op=feeds&method=catchupAll";
125
126                 notify_progress("Marking all feeds as read...");
127
128                 //console.log("catchupAllFeeds Q=" + query_str);
129
130                 new Ajax.Request("backend.php", {
131                         parameters: query_str,
132                         onComplete: function(transport) {
133                                 feedlist_callback2(transport);
134                         } });
135
136                 global_unread = 0;
137                 updateTitle("");
138         }
139 }
140
141 function viewCurrentFeed(method) {
142         console.log("viewCurrentFeed");
143
144         if (getActiveFeedId() != undefined) {
145                 viewfeed(getActiveFeedId(), method, activeFeedIsCat());
146         }
147         return false; // block unneeded form submits
148 }
149
150 function timeout() {
151         if (getInitParam("bw_limit") != "1") {
152                 request_counters();
153                 setTimeout("timeout()", 60*1000);
154         }
155 }
156
157 function search() {
158         var query = "backend.php?op=dlg&method=search&param=" +
159                 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
160
161         if (dijit.byId("searchDlg"))
162                 dijit.byId("searchDlg").destroyRecursive();
163
164         dialog = new dijit.Dialog({
165                 id: "searchDlg",
166                 title: __("Search"),
167                 style: "width: 600px",
168                 execute: function() {
169                         if (this.validate()) {
170                                 _search_query = dojo.objectToQuery(this.attr('value'));
171                                 this.hide();
172                                 viewCurrentFeed();
173                         }
174                 },
175                 href: query});
176
177         dialog.show();
178 }
179
180 function updateTitle() {
181         var tmp = "Tiny Tiny RSS";
182
183         if (global_unread > 0) {
184                 tmp = "(" + global_unread + ") " + tmp;
185         }
186
187         if (window.fluid) {
188                 if (global_unread > 0) {
189                         window.fluid.dockBadge = global_unread;
190                 } else {
191                         window.fluid.dockBadge = "";
192                 }
193         }
194
195         document.title = tmp;
196 }
197
198 function genericSanityCheck() {
199         setCookie("ttrss_test", "TEST");
200
201         if (getCookie("ttrss_test") != "TEST") {
202                 return fatalError(2);
203         }
204
205         return true;
206 }
207
208 function init() {
209         try {
210                 //dojo.registerModulePath("fox", "../../js/");
211
212                 dojo.require("fox.FeedTree");
213
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");
238
239                 dojo.parser.parse();
240
241                 if (!genericSanityCheck())
242                         return false;
243
244                 loading_set_progress(20);
245
246                 var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType);
247                 var hasSandbox = "sandbox" in document.createElement("iframe");
248
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);
254                                 } });
255
256         } catch (e) {
257                 exception_error("init", e);
258         }
259 }
260
261 function init_second_stage() {
262
263         try {
264                 dojo.addOnLoad(function() {
265                         updateFeedList();
266                         closeArticlePanel();
267
268                         _widescreen_mode = getInitParam("widescreen");
269
270                         if (_widescreen_mode) {
271                                 switchPanelMode(_widescreen_mode);
272                         }
273
274                 });
275
276                 delCookie("ttrss_test");
277
278                 var toolbar = document.forms["main_toolbar_form"];
279
280                 dijit.getEnclosingWidget(toolbar.view_mode).attr('value',
281                         getInitParam("default_view_mode"));
282
283                 dijit.getEnclosingWidget(toolbar.order_by).attr('value',
284                         getInitParam("default_view_order_by"));
285
286                 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
287
288                 var hash_feed_id = hash_get('f');
289                 var hash_feed_is_cat = hash_get('c') == "1";
290
291                 if (hash_feed_id != undefined) {
292                         setActiveFeedId(hash_feed_id, hash_feed_is_cat);
293                 }
294
295                 loading_set_progress(30);
296
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();
300
301                 var hotkeys = getInitParam("hotkeys");
302                 var tmp = [];
303
304                 for (sequence in hotkeys[1]) {
305                         filtered = sequence.replace(/\|.*$/, "");
306                         tmp[filtered] = hotkeys[1][sequence];
307                 }
308
309                 hotkeys[1] = tmp;
310                 setInitParam("hotkeys", hotkeys);
311
312                 console.log("second stage ok");
313
314                 if (getInitParam("simple_update")) {
315                         console.log("scheduling simple feed updater...");
316                         window.setTimeout("update_random_feed()", 30*1000);
317                 }
318
319         } catch (e) {
320                 exception_error("init_second_stage", e);
321         }
322 }
323
324 function quickMenuGo(opid) {
325         try {
326                 switch (opid) {
327                 case "qmcPrefs":
328                         gotoPreferences();
329                         break;
330                 case "qmcLogout":
331                         gotoLogout();
332                         break;
333                 case "qmcTagCloud":
334                         displayDlg("printTagCloud");
335                         break;
336                 case "qmcTagSelect":
337                         displayDlg("printTagSelect");
338                         break;
339                 case "qmcSearch":
340                         search();
341                         break;
342                 case "qmcAddFeed":
343                         quickAddFeed();
344                         break;
345                 case "qmcDigest":
346                         window.location.href = "backend.php?op=digest";
347                         break;
348                 case "qmcEditFeed":
349                         if (activeFeedIsCat())
350                                 alert(__("You can't edit this kind of feed."));
351                         else
352                                 editFeed(getActiveFeedId());
353                         break;
354                 case "qmcRemoveFeed":
355                         var actid = getActiveFeedId();
356
357                         if (activeFeedIsCat()) {
358                                 alert(__("You can't unsubscribe from the category."));
359                                 return;
360                         }
361
362                         if (!actid) {
363                                 alert(__("Please select some feed first."));
364                                 return;
365                         }
366
367                         var fn = getFeedName(actid);
368
369                         var pr = __("Unsubscribe from %s?").replace("%s", fn);
370
371                         if (confirm(pr)) {
372                                 unsubscribeFeed(actid);
373                         }
374                         break;
375                 case "qmcCatchupAll":
376                         catchupAllFeeds();
377                         break;
378                 case "qmcShowOnlyUnread":
379                         toggleDispRead();
380                         break;
381                 case "qmcAddFilter":
382                         quickAddFilter();
383                         break;
384                 case "qmcAddLabel":
385                         addLabel();
386                         break;
387                 case "qmcRescoreFeed":
388                         rescoreCurrentFeed();
389                         break;
390                 case "qmcToggleWidescreen":
391                         if (!isCdmMode()) {
392                                 _widescreen_mode = !_widescreen_mode;
393
394                                 switchPanelMode(_widescreen_mode);
395                         }
396                         break;
397                 case "qmcHKhelp":
398                         helpDialog("main");
399                         break;
400                 default:
401                         console.log("quickMenuGo: unknown action: " + opid);
402                 }
403
404         } catch (e) {
405                 exception_error("quickMenuGo", e);
406         }
407 }
408
409 function toggleDispRead() {
410         try {
411
412                 var hide = !(getInitParam("hide_read_feeds") == "1");
413
414                 hideOrShowFeeds(hide);
415
416                 var query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" +
417                         param_escape(hide);
418
419                 setInitParam("hide_read_feeds", hide);
420
421                 new Ajax.Request("backend.php", {
422                         parameters: query,
423                         onComplete: function(transport) {
424                         } });
425
426         } catch (e) {
427                 exception_error("toggleDispRead", e);
428         }
429 }
430
431 function parse_runtime_info(data) {
432
433         //console.log("parsing runtime info...");
434
435         for (k in data) {
436                 var v = data[k];
437
438 //              console.log("RI: " + k + " => " + v);
439
440                 if (k == "new_version_available") {
441                         if (v == "1") {
442                                 Element.show(dijit.byId("newVersionIcon").domNode);
443                         } else {
444                                 Element.hide(dijit.byId("newVersionIcon").domNode);
445                         }
446                         return;
447                 }
448
449                 if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
450                         if (parseInt(getInitParam("dep_ts")) < parseInt(v)) {
451                                 window.location.reload();
452                         }
453                 }
454
455                 if (k == "daemon_is_running" && v != 1) {
456                         notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
457                         return;
458                 }
459
460                 if (k == "daemon_stamp_ok" && v != 1) {
461                         notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
462                         return;
463                 }
464
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.");
468                                 updateFeedList();
469                         }
470                 }
471
472                 init_params[k] = v;
473                 notify('');
474         }
475 }
476
477 function collapse_feedlist() {
478         try {
479
480                 if (!Element.visible('feeds-holder')) {
481                         Element.show('feeds-holder');
482                         Element.show('feeds-holder_splitter');
483                         $("collapse_feeds_btn").innerHTML = "&lt;&lt;";
484                 } else {
485                         Element.hide('feeds-holder');
486                         Element.hide('feeds-holder_splitter');
487                         $("collapse_feeds_btn").innerHTML = "&gt;&gt;";
488                 }
489
490                 dijit.byId("main").resize();
491
492                 query = "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true";
493                 new Ajax.Request("backend.php", { parameters: query });
494
495         } catch (e) {
496                 exception_error("collapse_feedlist", e);
497         }
498 }
499
500 function viewModeChanged() {
501         cache_clear();
502         return viewCurrentFeed('');
503 }
504
505 function viewLimitChanged() {
506         return viewCurrentFeed('');
507 }
508
509 function rescoreCurrentFeed() {
510
511         var actid = getActiveFeedId();
512
513         if (activeFeedIsCat() || actid < 0) {
514                 alert(__("You can't rescore this kind of feed."));
515                 return;
516         }
517
518         if (!actid) {
519                 alert(__("Please select some feed first."));
520                 return;
521         }
522
523         var fn = getFeedName(actid);
524         var pr = __("Rescore articles in %s?").replace("%s", fn);
525
526         if (confirm(pr)) {
527                 notify_progress("Rescoring articles...");
528
529                 var query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid;
530
531                 new Ajax.Request("backend.php", {
532                         parameters: query,
533                         onComplete: function(transport) {
534                                 viewCurrentFeed();
535                         } });
536         }
537 }
538
539 function hotkey_handler(e) {
540         try {
541
542                 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
543
544                 var keycode = false;
545                 var shift_key = false;
546
547                 var cmdline = $('cmdline');
548
549                 shift_key = e.shiftKey;
550                 ctrl_key = e.ctrlKey;
551
552                 if (window.event) {
553                         keycode = window.event.keyCode;
554                 } else if (e) {
555                         keycode = e.which;
556                 }
557
558                 var keychar = String.fromCharCode(keycode);
559
560                 if (keycode == 27) { // escape
561                         hotkey_prefix = false;
562                 }
563
564                 if (keycode == 16) return; // ignore lone shift
565                 if (keycode == 17) return; // ignore lone ctrl
566
567                 keychar = keychar.toLowerCase();
568
569                 var hotkeys = getInitParam("hotkeys");
570
571                 if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) {
572
573                         var date = new Date();
574                         var ts = Math.round(date.getTime() / 1000);
575
576                         hotkey_prefix = keychar;
577                         hotkey_prefix_pressed = ts;
578
579                         cmdline.innerHTML = keychar;
580                         Element.show(cmdline);
581
582                         return true;
583                 }
584
585                 Element.hide(cmdline);
586
587                 var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
588
589                 // ensure ^*char notation
590                 if (shift_key) hotkey = "*" + hotkey;
591                 if (ctrl_key) hotkey = "^" + hotkey;
592
593                 hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
594                 hotkey_prefix = false;
595
596                 var hotkey_action = false;
597                 var hotkeys = getInitParam("hotkeys");
598
599                 for (sequence in hotkeys[1]) {
600                         if (sequence == hotkey) {
601                                 hotkey_action = hotkeys[1][sequence];
602                                 break;
603                         }
604                 }
605
606                 switch (hotkey_action) {
607                 case "next_feed":
608                         var rv = dijit.byId("feedTree").getNextFeed(
609                                         getActiveFeedId(), activeFeedIsCat());
610
611                         if (rv) viewfeed(rv[0], '', rv[1]);
612                         return false;
613                 case "prev_feed":
614                         var rv = dijit.byId("feedTree").getPreviousFeed(
615                                         getActiveFeedId(), activeFeedIsCat());
616
617                         if (rv) viewfeed(rv[0], '', rv[1]);
618                         return false;
619                 case "next_article":
620                         moveToPost('next');
621                         return false;
622                 case "prev_article":
623                         moveToPost('prev');
624                         return false;
625                 case "next_article_noscroll":
626                         moveToPost('next', true);
627                         return false;
628                 case "prev_article_noscroll":
629                         moveToPost('prev', true);
630                         return false;
631                 case "search_dialog":
632                         search();
633                         return ;
634                 case "toggle_mark":
635                         selectionToggleMarked(undefined, false, true);
636                         return false;
637                 case "toggle_publ":
638                         selectionTogglePublished(undefined, false, true);
639                         return false;
640                 case "toggle_unread":
641                         selectionToggleUnread(undefined, false, true);
642                         return false;
643                 case "edit_tags":
644                         var id = getActiveArticleId();
645                         if (id) {
646                                 editArticleTags(id, getActiveFeedId(), isCdmMode());
647                                 return;
648                         }
649                         return false;
650                 case "dismiss_selected":
651                         dismissSelectedArticles();
652                         return false;
653                 case "dismiss_read":
654                         return false;
655                 case "open_in_new_window":
656                         if (getActiveArticleId()) {
657                                 openArticleInNewWindow(getActiveArticleId());
658                                 return;
659                         }
660                         return false;
661                 case "catchup_below":
662                         catchupRelativeToArticle(1);
663                         return false;
664                 case "catchup_above":
665                         catchupRelativeToArticle(0);
666                         return false;
667                 case "article_scroll_down":
668                         var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
669
670                         scrollArticle(ctr.offsetHeight/3);
671                         return false;
672                 case "article_scroll_up":
673                         var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
674
675                         scrollArticle(-ctr.offsetHeight/3);
676                         return false;
677                 case "close_article":
678                         if (isCdmMode()) {
679                                 if (!getInitParam("cdm_expanded")) {
680                                         cdmCollapseArticle(false, getActiveArticleId());
681                                 } else {
682                                         dismissArticle(getActiveArticleId());
683                                 }
684                         } else {
685                                 closeArticlePanel();
686                         }
687                         return false;
688                 case "email_article":
689                         if (typeof emailArticle != "undefined") {
690                                 emailArticle();
691                         } else if (typeof mailtoArticle != "undefined") {
692                                 mailtoArticle();
693                         } else {
694                                 alert(__("Please enable mail plugin first."));
695                         }
696                         return false;
697                 case "select_all":
698                         selectArticles('all');
699                         return false;
700                 case "select_unread":
701                         selectArticles('unread');
702                         return false;
703                 case "select_marked":
704                         selectArticles('marked');
705                         return false;
706                 case "select_published":
707                         selectArticles('published');
708                         return false;
709                 case "select_invert":
710                         selectArticles('invert');
711                         return false;
712                 case "select_none":
713                         selectArticles('none');
714                         return false;
715                 case "feed_refresh":
716                         if (getActiveFeedId() != undefined) {
717                                 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
718                                 return;
719                         }
720                         return false;
721                 case "feed_unhide_read":
722                         toggleDispRead();
723                         return false;
724                 case "feed_subscribe":
725                         quickAddFeed();
726                         return false;
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"));
732                         return false;
733                 case "feed_edit":
734                         if (activeFeedIsCat())
735                                 alert(__("You can't edit this kind of feed."));
736                         else
737                                 editFeed(getActiveFeedId());
738                         return false;
739                 case "feed_catchup":
740                         if (getActiveFeedId() != undefined) {
741                                 catchupCurrentFeed();
742                                 return;
743                         }
744                         return false;
745                 case "feed_reverse":
746                         reverseHeadlineOrder();
747                         return false;
748                 case "catchup_all":
749                         catchupAllFeeds();
750                         return false;
751                 case "cat_toggle_collapse":
752                         if (activeFeedIsCat()) {
753                                 dijit.byId("feedTree").collapseCat(getActiveFeedId());
754                                 return;
755                         }
756                         return false;
757                 case "goto_all":
758                         viewfeed(-4);
759                         return false;
760                 case "goto_fresh":
761                         viewfeed(-3);
762                         return false;
763                 case "goto_marked":
764                         viewfeed(-1);
765                         return false;
766                 case "goto_published":
767                         viewfeed(-2);
768                         return false;
769                 case "goto_tagcloud":
770                         displayDlg("printTagCloud");
771                         return false;
772                 case "goto_prefs":
773                         gotoPreferences();
774                         return false;
775                 case "select_article_cursor":
776                         var id = getArticleUnderPointer();
777                         if (id) {
778                                 var cb = dijit.byId("RCHK-" + id);
779                                 if (cb) {
780                                         cb.attr("checked", !cb.attr("checked"));
781                                         toggleSelectRowById(cb, "RROW-" + id);
782                                         return false;
783                                 }
784                         }
785                         return false;
786                 case "create_label":
787                         addLabel();
788                         return false;
789                 case "create_filter":
790                         quickAddFilter();
791                         return false;
792                 case "collapse_sidebar":
793                         collapse_feedlist();
794                         return false;
795                 case "toggle_embed_original":
796                         if (typeof embedOriginalArticle != "undefined") {
797                                 if (getActiveArticleId())
798                                         embedOriginalArticle(getActiveArticleId());
799                         } else {
800                                 alert(__("Please enable embed_original plugin first."));
801                         }
802                         return false;
803                 case "toggle_widescreen":
804                         if (!isCdmMode()) {
805                                 _widescreen_mode = !_widescreen_mode;
806
807                                 switchPanelMode(_widescreen_mode);
808                         }
809                         return false;
810                 case "help_dialog":
811                         helpDialog("main");
812                         return false;
813                 case "toggle_combined_mode":
814                         notify_progress("Loading, please wait...");
815
816                         var value = isCdmMode() ? "false" : "true";
817                         var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value;
818
819                         new Ajax.Request("backend.php", {
820                                 parameters: query,
821                                 onComplete: function(transport) {
822                                         window.location.reload();
823                                 } });
824
825                         return false;
826                 default:
827                         console.log("unhandled action: " + hotkey_action + "; hotkey: " + hotkey);
828                 }
829
830         } catch (e) {
831                 exception_error("hotkey_handler", e);
832         }
833 }
834
835 function inPreferences() {
836         return false;
837 }
838
839 function reverseHeadlineOrder() {
840         try {
841
842                 var query_str = "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
843
844                 new Ajax.Request("backend.php", {
845                         parameters: query_str,
846                         onComplete: function(transport) {
847                                         viewCurrentFeed();
848                                 } });
849
850         } catch (e) {
851                 exception_error("reverseHeadlineOrder", e);
852         }
853 }
854
855 function newVersionDlg() {
856         try {
857                 var query = "backend.php?op=dlg&method=newVersion";
858
859                 if (dijit.byId("newVersionDlg"))
860                         dijit.byId("newVersionDlg").destroyRecursive();
861
862                 dialog = new dijit.Dialog({
863                         id: "newVersionDlg",
864                         title: __("New version available!"),
865                         style: "width: 600px",
866                         href: query,
867                 });
868
869                 dialog.show();
870
871         } catch (e) {
872                 exception_error("newVersionDlg", e);
873         }
874 }
875
876 function handle_rpc_json(transport, scheduled_call) {
877         try {
878                 var reply = JSON.parse(transport.responseText);
879
880                 if (reply) {
881
882                         var error = reply['error'];
883
884                         if (error) {
885                                 var code = error['code'];
886                                 var msg = error['msg'];
887
888                                 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
889
890                                 if (code != 0) {
891                                         fatalError(code, msg);
892                                         return false;
893                                 }
894                         }
895
896                         var seq = reply['seq'];
897
898                         if (seq) {
899                                 if (get_seq() != seq) {
900                                         console.log("[handle_rpc_json] sequence mismatch: " + seq +
901                                                 " (want: " + get_seq() + ")");
902                                         return true;
903                                 }
904                         }
905
906                         var message = reply['message'];
907
908                         if (message) {
909                                 if (message == "UPDATE_COUNTERS") {
910                                         console.log("need to refresh counters...");
911                                         setInitParam("last_article_id", -1);
912                                         request_counters(true);
913                                 }
914                         }
915
916                         var counters = reply['counters'];
917
918                         if (counters)
919                                 parse_counters(counters, scheduled_call);
920
921                         var runtime_info = reply['runtime-info'];;
922
923                         if (runtime_info)
924                                 parse_runtime_info(runtime_info);
925
926                         Element.hide(dijit.byId("net-alert").domNode);
927
928                 } else {
929                         //notify_error("Error communicating with server.");
930                         Element.show(dijit.byId("net-alert").domNode);
931                 }
932
933         } catch (e) {
934                 Element.show(dijit.byId("net-alert").domNode);
935                 //notify_error("Error communicating with server.");
936                 console.log(e);
937                 //exception_error("handle_rpc_json", e, transport);
938         }
939
940         return true;
941 }
942
943 function switchPanelMode(wide) {
944         try {
945                 if (isCdmMode()) return;
946
947                 article_id = getActiveArticleId();
948
949                 if (wide) {
950                         dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
951                         dijit.byId("content-insert").attr("region", "trailing");
952
953                         dijit.byId("content-insert").domNode.setStyle({width: '50%',
954                                 height: 'auto',
955                                 borderLeftWidth: '1px',
956                                 borderLeftColor: '#c0c0c0',
957                                 borderTopWidth: '0px' });
958
959                         $("headlines-toolbar").setStyle({ borderBottomWidth: '0px' });
960
961                 } else {
962
963                         dijit.byId("content-insert").attr("region", "bottom");
964
965                         dijit.byId("content-insert").domNode.setStyle({width: 'auto',
966                                 height: '50%',
967                                 borderLeftWidth: '0px',
968                                 borderTopWidth: '1px'});
969
970                         $("headlines-toolbar").setStyle({ borderBottomWidth: '1px' });
971                 }
972
973                 closeArticlePanel();
974
975                 if (article_id) view(article_id);
976
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);
981                         } });
982
983
984         } catch (e) {
985                 exception_error("switchPanelMode", e);
986         }
987 }
988
989 function update_random_feed() {
990         try {
991                 console.log("in update_random_feed");
992
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);
998                         } });
999
1000         } catch (e) {
1001                 exception_error("update_random_feed", e);
1002         }
1003 }
1004
1005 function hash_get(key) {
1006         try {
1007                 kv = window.location.hash.substring(1).toQueryParams();
1008                 return kv[key];
1009         } catch (e) {
1010                 exception_error("hash_set", e);
1011         }
1012 }
1013 function hash_set(key, value) {
1014         try {
1015                 kv = window.location.hash.substring(1).toQueryParams();
1016                 kv[key] = value;
1017                 window.location.hash = $H(kv).toQueryString();
1018         } catch (e) {
1019                 exception_error("hash_set", e);
1020         }
1021 }