]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
getRelativeFeedId iterates over hidden categories correctly (2)
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194 1var xmlhttp = false;
76798ff3 2var total_unread = 0;
525116d4 3var first_run = true;
8143ae1f 4var display_tags = false;
806a3d14 5var global_unread = -1;
21703604 6var active_title_text = "";
21703604 7var current_subtitle = "";
c6784aea 8var daemon_enabled = false;
0d51e25d 9var daemon_refresh_only = false;
15da5cc1 10var _qfd_deleted_feed = 0;
2bf6e0a8 11var firsttime_update = true;
c441662f 12var last_refetch = 0;
76b4eae1 13var cookie_lifetime = 0;
33d13e72 14var active_feed_id = 0;
0a6c4846 15var active_feed_is_cat = false;
9e397d0f 16var number_of_feeds = 0;
7a09510c 17var sanity_check_done = false;
15da5cc1 18
a58069db 19var xmlhttp = Ajax.getTransport();
abbe0154 20var xmlhttp_ctr = Ajax.getTransport();
1cd17194 21
1035fcec 22var init_params = new Object();
3ac2b520 23
1dc8dba0
AD
24var op_history = new Array();
25
0b126ac2
AD
26function tagsAreDisplayed() {
27 return display_tags;
28}
29
8143ae1f
AD
30function toggleTags() {
31 display_tags = !display_tags;
32
33 var p = document.getElementById("dispSwitchPrompt");
34
35 if (display_tags) {
709e7dc2 36 p.innerHTML = __("display feeds");
8143ae1f 37 } else {
709e7dc2 38 p.innerHTML = __("display tags");
8143ae1f
AD
39 }
40
42c32916 41 notify_progress("Loading, please wait...");
807f452a 42
8143ae1f
AD
43 updateFeedList();
44}
45
6de5d056 46function dlg_frefresh_callback() {
abbe0154 47 if (xmlhttp.readyState == 4) {
a58d997c 48// notify(xmlhttp.responseText);
abbe0154
AD
49
50 if (getActiveFeedId() == _qfd_deleted_feed) {
51 var h = document.getElementById("headlines-frame");
52 if (h) {
53 h.innerHTML = "<div class='whiteBox'>No feed selected.</div>";
54 }
55 }
56
0e9dd1ba 57 setTimeout('updateFeedList(false, false)', 50);
eff4997c 58 closeInfoBox();
c0e5a40e 59 }
1cd17194 60}
e2f8f7b4 61
8158c57a 62function refetch_callback() {
abbe0154 63 if (xmlhttp_ctr.readyState == 4) {
7719618b 64 try {
310da49d 65
c441662f
AD
66 var date = new Date();
67
68 last_refetch = date.getTime() / 1000;
69
3ac2f3c7 70 parse_counters_reply(xmlhttp_ctr, true);
71ad883b 71
0ee1d1a0
AD
72 debug("refetch_callback: done");
73
0d51e25d 74 if (!daemon_enabled && !daemon_refresh_only) {
42c32916 75 notify_info("All feeds updated.");
5a180505 76 updateTitle("");
4c059b7b 77 } else {
0f088bfc 78 //notify("");
c6784aea 79 }
7719618b
AD
80 } catch (e) {
81 exception_error("refetch_callback", e);
e2cb4c6d 82 updateTitle("");
7719618b 83 }
090e250b
AD
84 }
85}
1a66d16e 86
295f9b42
AD
87function backend_sanity_check_callback() {
88
89 if (xmlhttp.readyState == 4) {
295f9b42 90
7719618b 91 try {
7a09510c
AD
92
93 if (sanity_check_done) {
81352b54
AD
94 fatalError(11, "Sanity check request received twice. This can indicate "+
95 "presence of Firebug or some other disrupting extension. "+
96 "Please disable it and try again.");
7a09510c
AD
97 return;
98 }
99
7719618b 100 if (!xmlhttp.responseXML) {
462a192b 101 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
7719618b
AD
102 return;
103 }
295f9b42 104
3ac2b520 105 var reply = xmlhttp.responseXML.firstChild.firstChild;
7719618b
AD
106
107 if (!reply) {
af106b0e 108 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
7719618b
AD
109 return;
110 }
111
112 var error_code = reply.getAttribute("error-code");
113
114 if (error_code && error_code != 0) {
af106b0e 115 return fatalError(error_code, reply.getAttribute("error-msg"));
7719618b
AD
116 }
117
0ee1d1a0
AD
118 debug("sanity check ok");
119
3ac2b520
AD
120 var params = reply.nextSibling;
121
122 if (params) {
123 debug('reading init-params...');
124 var param = params.firstChild;
125
126 while (param) {
127 var k = param.getAttribute("key");
128 var v = param.getAttribute("value");
129 debug(k + " => " + v);
130 init_params[k] = v;
131 param = param.nextSibling;
132 }
133 }
134
7a09510c
AD
135 sanity_check_done = true;
136
7719618b 137 init_second_stage();
295f9b42 138
7719618b
AD
139 } catch (e) {
140 exception_error("backend_sanity_check_callback", e);
141 }
295f9b42
AD
142 }
143}
144
cb246176 145function scheduleFeedUpdate(force) {
525116d4 146
0d51e25d 147 if (!daemon_enabled && !daemon_refresh_only) {
42c32916 148 notify_progress("Updating feeds, please wait.", true);
c6784aea
AD
149 updateTitle("Updating");
150 }
55193822 151
cb246176
AD
152 var query_str = "backend.php?op=rpc&subop=";
153
154 if (force) {
c3b81db0 155 query_str = query_str + "forceUpdateAllFeeds";
cb246176 156 } else {
c3b81db0 157 query_str = query_str + "updateAllFeeds";
cb246176 158 }
525116d4 159
9826bd2e
AD
160 var omode;
161
b6104dee 162 if (firsttime_update && !navigator.userAgent.match("Opera")) {
2bf6e0a8
AD
163 firsttime_update = false;
164 omode = "T";
9826bd2e 165 } else {
2bf6e0a8 166 if (display_tags) {
cf4d339c 167 omode = "tl";
2bf6e0a8
AD
168 } else {
169 omode = "flc";
170 }
9826bd2e 171 }
2bf6e0a8 172
9826bd2e 173 query_str = query_str + "&omode=" + omode;
78ea1de0 174 query_str = query_str + "&uctr=" + global_unread;
9826bd2e 175
0ee1d1a0 176 debug("in scheduleFeedUpdate");
2bf6e0a8 177
c441662f
AD
178 var date = new Date();
179
89fbb3bc
AD
180 var timestamp = Math.round(date.getTime() / 1000);
181 query_str = query_str + "&ts=" + timestamp
182
abbe0154 183 if (!xmlhttp_ready(xmlhttp_ctr) && last_refetch < date.getTime() / 1000 - 60) {
a7565293 184 debug("<b>xmlhttp seems to be stuck, aborting</b>");
abbe0154 185 xmlhttp_ctr.abort();
c441662f
AD
186 }
187
52db9978
AD
188 debug("REFETCH query: " + query_str);
189
abbe0154
AD
190 if (xmlhttp_ready(xmlhttp_ctr)) {
191 xmlhttp_ctr.open("GET", query_str, true);
192 xmlhttp_ctr.onreadystatechange=refetch_callback;
193 xmlhttp_ctr.send(null);
525116d4 194 } else {
abbe0154 195 debug("xmlhttp_ctr busy");
bed0f18f 196 //printLockingError();
c0e5a40e 197 }
525116d4 198}
1cd17194 199
525116d4 200function updateFeedList(silent, fetch) {
c0e5a40e 201
1a66d16e
AD
202// if (silent != true) {
203// notify("Loading feed list...");
204// }
82baad4a 205
cf4d339c
AD
206 debug("<b>updateFeedList</b>");
207
331900c6
AD
208 var query_str = "backend.php?op=feeds";
209
8143ae1f
AD
210 if (display_tags) {
211 query_str = query_str + "&tags=1";
212 }
213
5c365f60 214 if (getActiveFeedId() && !activeFeedIsCat()) {
86741347 215 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
216 }
217
86173d9a
AD
218 var date = new Date();
219 var timestamp = Math.round(date.getTime() / 1000);
220 query_str = query_str + "&ts=" + timestamp
59b8192f 221
1a66d16e 222 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 223
6b4163cb
AD
224// var feeds_frame = document.getElementById("feeds-frame");
225// feeds_frame.src = query_str;
226
0e9dd1ba 227 debug("updateFeedList Q=" + query_str);
6b4163cb
AD
228
229 if (xmlhttp_ready(xmlhttp)) {
230 xmlhttp.open("GET", query_str, true);
231 xmlhttp.onreadystatechange=feedlist_callback;
232 xmlhttp.send(null);
233 } else {
234 debug("xmlhttp busy");
235 //printLockingError();
236 }
e1123aee 237
1a66d16e 238}
175847de 239
476cac42 240function catchupAllFeeds() {
076682aa 241
476cac42
AD
242 var query_str = "backend.php?op=feeds&subop=catchupAll";
243
42c32916 244 notify_progress("Marking all feeds as read...");
476cac42 245
ca2f46a7 246 debug("catchupAllFeeds Q=" + query_str);
1a66d16e 247
ca2f46a7
AD
248 if (xmlhttp_ready(xmlhttp)) {
249 xmlhttp.open("GET", query_str, true);
250 xmlhttp.onreadystatechange=feedlist_callback;
251 xmlhttp.send(null);
252 } else {
253 debug("xmlhttp busy");
254 //printLockingError();
255 }
476cac42 256
fc69e641 257 global_unread = 0;
21703604 258 updateTitle("");
fc69e641 259
476cac42 260}
1cd17194 261
767e2486 262function viewCurrentFeed(subop) {
1a66d16e 263
ec6e2fd3
AD
264// if (getActiveFeedId()) {
265 if (getActiveFeedId() != undefined) {
767e2486 266 viewfeed(getActiveFeedId(), subop);
033e47e0
AD
267 } else {
268 disableContainerChildren("headlinesToolbar", false, document);
ec6e2fd3 269// viewfeed(-1, subop); // FIXME
f0601b87 270 }
164f4738 271 return false; // block unneeded form submits
f0601b87
AD
272}
273
767e2486 274function viewfeed(feed, subop) {
db8d6f67 275 var f = window.frames["feeds-frame"];
767e2486 276 f.viewfeed(feed, subop);
9cfc649a
AD
277}
278
40d13c28 279function timeout() {
05732aa0 280 scheduleFeedUpdate(false);
f5de0d8d 281
3ac2b520 282 var refresh_time = getInitParam("feeds_frame_refresh");
f5de0d8d 283
3ac2b520 284 if (!refresh_time) refresh_time = 600;
f5de0d8d
AD
285
286 setTimeout("timeout()", refresh_time*1000);
ac53063a
AD
287}
288
c374a3fe 289function resetSearch() {
64c620ce
AD
290 var searchbox = document.getElementById("searchbox")
291
86741347 292 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 293 searchbox.value = "";
767e2486 294 viewfeed(getActiveFeedId(), "");
ac43eba1 295 }
c374a3fe 296}
ac53063a 297
86b682ce
AD
298function searchCancel() {
299 closeInfoBox(true);
300}
301
f0601b87 302function search() {
eff4997c 303 closeInfoBox();
4ce19859 304 viewCurrentFeed(0, "");
76798ff3 305}
1cd17194 306
13ad9102
AD
307function localPiggieFunction(enable) {
308 if (enable) {
309 var query_str = "backend.php?op=feeds&subop=piggie";
310
c0e5a40e 311 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
312
313 xmlhttp.open("GET", query_str, true);
314 xmlhttp.onreadystatechange=feedlist_callback;
315 xmlhttp.send(null);
316 }
317 }
318}
319
806a3d14
AD
320// if argument is undefined, current subtitle is not updated
321// use blank string to clear subtitle
fc69e641
AD
322function updateTitle(s) {
323 var tmp = "Tiny Tiny RSS";
21703604 324
5a494a0b 325 if (s != undefined) {
21703604
AD
326 current_subtitle = s;
327 }
328
fc69e641
AD
329 if (global_unread > 0) {
330 tmp = tmp + " (" + global_unread + ")";
331 }
332
5a494a0b 333 if (current_subtitle) {
21703604 334 tmp = tmp + " - " + current_subtitle;
fc69e641 335 }
21703604
AD
336
337 if (active_title_text.length > 0) {
338 tmp = tmp + " > " + active_title_text;
339 }
340
fc69e641
AD
341 document.title = tmp;
342}
343
22a93ad8 344function genericSanityCheck() {
ac43eba1 345
295f9b42
AD
346 if (!xmlhttp) fatalError(1);
347
348 setCookie("ttrss_vf_test", "TEST");
349
350 if (getCookie("ttrss_vf_test") != "TEST") {
351 fatalError(2);
352 }
353
22a93ad8
AD
354 return true;
355}
356
357function init() {
358
7719618b 359 try {
fe2f1970 360
97dcd654
AD
361 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
362
363 if (arguments.callee.done) return;
364 arguments.callee.done = true;
365
7719618b 366 disableContainerChildren("headlinesToolbar", true);
70830c87 367
86b682ce
AD
368 Form.disable("main_toolbar_form");
369
7719618b
AD
370 if (!genericSanityCheck())
371 return;
ac43eba1 372
0ee1d1a0
AD
373 if (getURLParam('debug')) {
374 document.getElementById('debug_output').style.display = 'block';
375 debug('debug mode activated');
376 }
377
4220d6b0
AD
378 var params = "&ua=" + param_escape(navigator.userAgent);
379
380 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params, true);
7719618b
AD
381 xmlhttp.onreadystatechange=backend_sanity_check_callback;
382 xmlhttp.send(null);
47179952 383
7719618b
AD
384 } catch (e) {
385 exception_error("init", e);
a8d28f48 386 }
7719618b 387}
86741347 388
a9d42cf7 389function resize_headlines() {
770bbb02 390
a9d42cf7
AD
391 var h_frame = document.getElementById("headlines-frame");
392 var c_frame = document.getElementById("content-frame");
586822fd
AD
393 var f_frame = document.getElementById("footer");
394
395 if (!c_frame || !h_frame) return;
a9d42cf7
AD
396
397 debug("resize_headlines");
398
586822fd 399 if (!is_msie()) {
a9d42cf7
AD
400 h_frame.style.height = 30 + "%";
401 c_frame.style.top = h_frame.offsetTop + h_frame.offsetHeight + 1 + "px";
402 h_frame.style.height = h_frame.offsetHeight + "px";
586822fd
AD
403 } else {
404 h_frame.style.height = document.documentElement.clientHeight * 0.3 + "px";
405 c_frame.style.top = h_frame.offsetTop + h_frame.offsetHeight + 1 + "px";
406
407 var c_bottom = document.documentElement.clientHeight;
408
409 if (f_frame) {
410 c_bottom = f_frame.offsetTop;
411 }
412
413 c_frame.style.height = c_bottom - (h_frame.offsetTop +
414 h_frame.offsetHeight + 1) + "px";
415 h_frame.style.height = h_frame.offsetHeight + "px";
416
a9d42cf7
AD
417 }
418}
419
7719618b 420function init_second_stage() {
295f9b42 421
7719618b 422 try {
2f587484 423
76b4eae1
AD
424 cookie_lifetime = getCookie("ttrss_cltime");
425
426 delCookie("ttrss_vf_test");
770bbb02 427
586822fd
AD
428// document.onresize = resize_headlines;
429 resize_headlines();
1b0809ae 430
40496720 431 var toolbar = document.forms["main_toolbar_form"];
f31673f7 432
40496720
AD
433 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
434 dropboxSelect(toolbar.limit, getInitParam("default_view_limit"));
c6784aea 435
0d51e25d
AD
436 daemon_enabled = getInitParam("daemon_enabled") == 1;
437 daemon_refresh_only = getInitParam("daemon_refresh_only") == 1;
5f136c9a 438
0e9dd1ba 439 setTimeout('updateFeedList(false, false)', 50);
0ee1d1a0
AD
440
441 debug("second stage ok");
7719618b 442
7719618b
AD
443 } catch (e) {
444 exception_error("init_second_stage", e);
2f587484 445 }
1cd17194 446}
ac43eba1 447
c09ec856 448function quickMenuChange() {
cbe45fa8 449 var chooser = document.getElementById("quickMenuChooser");
86b682ce 450 var opid = chooser[chooser.selectedIndex].value;
e2f8f7b4 451
c09ec856
AD
452 chooser.selectedIndex = 0;
453 quickMenuGo(opid);
454}
455
456function quickMenuGo(opid) {
bb3423cf 457 try {
c09ec856 458
bb3423cf
AD
459 if (opid == "qmcPrefs") {
460 gotoPreferences();
461 }
462
463 if (opid == "qmcSearch") {
0a6c4846 464 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
6de5d056
AD
465 return;
466 }
bb3423cf
AD
467
468 if (opid == "qmcAddFeed") {
469 displayDlg("quickAddFeed");
470 return;
69668465 471 }
7086277c
AD
472
473 if (opid == "qmcEditFeed") {
474 editFeedDlg(getActiveFeedId());
475 }
6de5d056 476
bb3423cf
AD
477 if (opid == "qmcRemoveFeed") {
478 var actid = getActiveFeedId();
479
5c365f60 480 if (!actid || activeFeedIsCat()) {
0530ddd8 481 alert("Please select some feed first.");
bb3423cf
AD
482 return;
483 }
64a2875d
AD
484
485 var fn = getFeedName(actid);
bb3423cf 486
64a2875d 487 if (confirm("Unsubscribe from " + fn + "?")) {
bb3423cf
AD
488 qfdDelete(actid);
489 }
490
491 return;
492 }
493
494 if (opid == "qmcUpdateFeeds") {
495 scheduleFeedUpdate(true);
496 return;
497 }
498
499 if (opid == "qmcCatchupAll") {
500 catchupAllFeeds();
501 return;
502 }
503
504 if (opid == "qmcShowOnlyUnread") {
505 toggleDispRead();
506 return;
507 }
508
509 if (opid == "qmcAddFilter") {
510 displayDlg("quickAddFilter", getActiveFeedId());
511 }
512 } catch (e) {
513 exception_error("quickMenuGo", e);
a24f525c 514 }
e2f8f7b4
AD
515}
516
6de5d056
AD
517function qfdDelete(feed_id) {
518
42c32916 519 notify_progress("Removing feed...");
6de5d056 520
7f123cda
AD
521 if (!xmlhttp_ready(xmlhttp)) {
522 printLockingError();
523 return
524 }
525
15da5cc1
AD
526 _qfd_deleted_feed = feed_id;
527
69668465 528 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
6de5d056
AD
529 xmlhttp.onreadystatechange=dlg_frefresh_callback;
530 xmlhttp.send(null);
7bc4f251
AD
531
532 return false;
6de5d056 533}
033e47e0 534
3745788e 535
21703604
AD
536function updateFeedTitle(t) {
537 active_title_text = t;
538 updateTitle();
539}
540
3745788e 541function toggleDispRead() {
7f123cda 542 try {
3745788e 543
7f123cda
AD
544 if (!xmlhttp_ready(xmlhttp)) {
545 printLockingError();
546 return
5158ced9 547 }
3745788e 548
e8bd0da9 549 var hide_read_feeds = (getInitParam("hide_read_feeds") == "1");
3745788e 550
7f123cda 551 hide_read_feeds = !hide_read_feeds;
e8bd0da9
AD
552
553 debug("toggle_disp_read => " + hide_read_feeds);
554
555 hideOrShowFeeds(getFeedsContext().document, hide_read_feeds);
556
e8bd0da9
AD
557 storeInitParam("hide_read_feeds", hide_read_feeds, true);
558
5158ced9
AD
559/* var query = "backend.php?op=rpc&subop=setpref" +
560 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
561
562 new Ajax.Request(query); */
563
7f123cda
AD
564 } catch (e) {
565 exception_error("toggleDispRead", e);
3745788e 566 }
3745788e 567}
295f9b42 568
71ad883b 569function parse_runtime_info(elem) {
4724a093
AD
570 if (!elem) {
571 debug("parse_runtime_info: elem is null, aborting");
572 return;
573 }
574
71ad883b
AD
575 var param = elem.firstChild;
576
52db9978 577 debug("parse_runtime_info: " + param);
1cb7492d 578
71ad883b
AD
579 while (param) {
580 var k = param.getAttribute("key");
581 var v = param.getAttribute("value");
3ac2b520 582
1cb7492d
AD
583 debug("RI: " + k + " => " + v);
584
d9fa39f1
AD
585 if (k == "new_version_available") {
586 var icon = document.getElementById("newVersionIcon");
587 if (icon) {
588 if (v == "1") {
589 icon.style.display = "inline";
590 } else {
591 icon.style.display = "none";
592 }
593 }
594 }
595
ef16ae37 596 if (k == "daemon_is_running" && v != 1) {
42c32916 597 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not runing.</span>");
ef16ae37
AD
598 }
599
600/* var w = document.getElementById("noDaemonWarning");
71ad883b
AD
601
602 if (w) {
603 if (k == "daemon_is_running" && v != 1) {
604 w.style.display = "block";
605 } else {
606 w.style.display = "none";
607 }
ef16ae37 608 } */
71ad883b
AD
609 param = param.nextSibling;
610 }
611}
fce24838
AD
612
613function catchupCurrentFeed() {
614
234e467c 615 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
fce24838 616
234e467c
AD
617 var str = "Mark all articles in " + fn + " as read?";
618
619/* if (active_feed_is_cat) {
620 str = "Mark all articles in this category as read?";
621 } */
622
f6d6e22f 623 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
28de3732 624 return viewCurrentFeed('MarkAllRead')
fce24838
AD
625 }
626}
88040f57 627
461766f3
AD
628function userSwitch() {
629 var chooser = document.getElementById("userSwitch");
630 var user = chooser[chooser.selectedIndex].value;
631 window.location = "tt-rss.php?swu=" + user;
632}
6e6504bc 633
7086277c
AD
634function editFeedDlg(feed) {
635
729bafaa
AD
636 disableHotkeys();
637
7086277c
AD
638 if (!feed) {
639 alert("Please select some feed first.");
640 return;
641 }
642
92f3bcae
AD
643 if (feed <= 0 || active_feed_is_cat || tagsAreDisplayed()) {
644 alert("You can't edit this kind of feed.");
645 return;
646 }
647
7086277c
AD
648 if (xmlhttp_ready(xmlhttp)) {
649 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
650 param_escape(feed), true);
651 xmlhttp.onreadystatechange=infobox_callback;
652 xmlhttp.send(null);
653 } else {
654 printLockingError();
655 }
656}
657
658/* this functions duplicate those of prefs.js feed editor, with
659 some differences because there is no feedlist */
660
661function feedEditCancel() {
662 closeInfoBox();
663 return false;
664}
665
666function feedEditSave() {
667
668 try {
669
670 if (!xmlhttp_ready(xmlhttp)) {
671 printLockingError();
672 return
673 }
674
675 // FIXME: add parameter validation
676
677 var query = Form.serialize("edit_feed_form");
678
42c32916 679 notify_progress("Saving feed...");
7086277c
AD
680
681 xmlhttp.open("POST", "backend.php", true);
682 xmlhttp.onreadystatechange=dlg_frefresh_callback;
683 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
684 xmlhttp.send(query);
685
686 closeInfoBox();
687
688 return false;
689
690 } catch (e) {
691 exception_error("feedEditSave (main)", e);
692 }
693}
6e6504bc 694
1dc8dba0
AD
695function localHotkeyHandler(e) {
696
697 var keycode;
698
699 if (window.event) {
700 keycode = window.event.keyCode;
701 } else if (e) {
702 keycode = e.which;
703 }
704
705 var shift_key = false;
706
707 try {
708 shift_key = e.shiftKey;
709 } catch (e) { }
710
711 if (keycode == 66 && shift_key) { // shift-B
712
713 var op = history_pop();
714
715 if (op) {
716 var op_s = op.split(":");
717
718 var i;
719 for (i = 0; i < op_s.length; i++) {
720 if (op_s[i] == 'undefined') {
721 op_s[i] = undefined;
722 }
723
724 if (op_s[i] == 'false') {
725 op_s[i] = false;
726 }
727
728 if (op_s[i] == 'true') {
729 op_s[i] = true;
730 }
731
732 }
733
734 debug("history split: " + op_s);
735
736 if (op_s[0] == "ARTICLE") {
737 debug("history: reverting to article " + op_s[1] + "/" + op_s[2]);
738 view(op_s[1], op_s[2], true);
739 }
740
741 if (op_s[0] == "FEED") {
742 viewfeed(op_s[1], op_s[2], op_s[3], op_s[4], true);
743 }
744
745 } else {
42c32916 746 notify_error("No operation to undo");
1dc8dba0
AD
747 }
748
749 return false;
750
751 }
752
753 debug("LKP=" + keycode);
754}
755
756function history_push(op) {
757 debug("history_push: " + op);
758 op_history.push(op);
759
760 while (op_history.length > 30) {
761 op_history.shift();
762 }
763}
764
765function history_pop() {
766 var op = op_history.pop();
767 debug("history_pop: " + op);
768 return op;
769}
770
771function history_clear() {
772 debug("history_clear");
773 op_history.clear();
774}