]> git.wh0rd.org - tt-rss.git/blob - functions.js
call parse_runtime_info from all_counters_callback
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2
3 var xmlhttp_rpc = Ajax.getTransport();
4
5 function browser_has_opacity() {
6 return navigator.userAgent.match("Gecko") != null ||
7 navigator.userAgent.match("Opera") != null;
8 }
9
10 function exception_error(location, e) {
11 var msg;
12
13 if (e.fileName) {
14 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
15
16 msg = "Exception: " + e.name + ", " + e.message +
17 "\nFunction: " + location + "()" +
18 "\nLocation: " + base_fname + ":" + e.lineNumber;
19
20 } else {
21 msg = "Exception: " + e + "\nFunction: " + location + "()";
22 }
23
24 debug("<b>EXCEPTION: " + msg + "</b>");
25
26 alert(msg);
27 }
28
29 function disableHotkeys() {
30 hotkeys_enabled = false;
31 }
32
33 function enableHotkeys() {
34 hotkeys_enabled = true;
35 }
36
37 function xmlhttp_ready(obj) {
38 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
39 }
40
41 function notify_callback() {
42 var container = document.getElementById('notify');
43 if (xmlhttp.readyState == 4) {
44 container.innerHTML=xmlhttp.responseText;
45 }
46 }
47
48 function rpc_notify_callback() {
49 var container = document.getElementById('notify');
50 if (xmlhttp_rpc.readyState == 4) {
51 container.innerHTML=xmlhttp_rpc.responseText;
52 }
53 }
54
55 function param_escape(arg) {
56 if (typeof encodeURIComponent != 'undefined')
57 return encodeURIComponent(arg);
58 else
59 return escape(arg);
60 }
61
62 function param_unescape(arg) {
63 if (typeof decodeURIComponent != 'undefined')
64 return decodeURIComponent(arg);
65 else
66 return unescape(arg);
67 }
68
69 function delay(gap) {
70 var then,now;
71 then=new Date().getTime();
72 now=then;
73 while((now-then)<gap) {
74 now=new Date().getTime();
75 }
76 }
77
78 var notify_hide_timerid = false;
79 var notify_last_doc = false;
80
81 var notify_effect = false;
82
83 function hide_notify() {
84 if (notify_last_doc) {
85 var n = notify_last_doc.getElementById("notify");
86 if (browser_has_opacity()) {
87 if (notify_opacity >= 0) {
88 notify_opacity = notify_opacity - 0.1;
89 n.style.opacity = notify_opacity;
90 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
91 } else {
92 n.style.display = "none";
93 n.style.opacity = 1;
94 }
95 } else {
96 n.style.display = "none";
97 }
98 }
99 }
100
101 function notify_real(msg, doc, no_hide, is_err) {
102
103 var n = doc.getElementById("notify");
104 var nb = doc.getElementById("notify_body");
105
106 if (!n || !nb) return;
107
108 if (notify_hide_timerid) {
109 window.clearTimeout(notify_hide_timerid);
110 }
111
112 notify_last_doc = doc;
113 notify_opacity = 1;
114
115 if (msg == "") {
116 if (n.style.display == "block") {
117 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
118 }
119 return;
120 } else {
121 n.style.display = "block";
122 }
123
124 if (is_err) {
125 n.style.backgroundColor = "#ffcccc";
126 n.style.color = "black";
127 n.style.borderColor = "#ff0000";
128 } else {
129 n.style.backgroundColor = "#fff7d5";
130 n.style.borderColor = "#d7c47a";
131 n.style.color = "black";
132 }
133
134 nb.innerHTML = msg;
135
136 if (!no_hide) {
137 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
138 }
139 }
140
141 function p_notify(msg, no_hide, is_err) {
142 notify_real(msg, parent.document, no_hide, is_err);
143 }
144
145 function notify(msg, no_hide, is_err) {
146 notify_real(msg, document, no_hide, is_err);
147 }
148
149 function printLockingError() {
150 notify("Please wait until operation finishes");}
151
152 var seq = "";
153
154 function hotkey_handler(e) {
155
156 try {
157
158 var keycode;
159
160 if (!hotkeys_enabled) return;
161
162 if (window.event) {
163 keycode = window.event.keyCode;
164 } else if (e) {
165 keycode = e.which;
166 }
167
168 if (keycode == 13 || keycode == 27) {
169 seq = "";
170 } else {
171 seq = seq + "" + keycode;
172 }
173
174 var m_ctx = getMainContext();
175 var f_ctx = getFeedsContext();
176 var h_ctx = getHeadlinesContext();
177
178 if (keycode == 82) { // r
179 return m_ctx.scheduleFeedUpdate(true);
180 }
181
182 if (keycode == 85) { // u
183 if (getActiveFeedId()) {
184 return f_ctx.viewfeed(getActiveFeedId(), 0, "ForceUpdate");
185 }
186 }
187
188 if (keycode == 65) { // a
189 return m_ctx.toggleDispRead();
190 }
191
192 var f_doc = m_ctx.frames["feeds-frame"].document;
193 var feedlist = f_doc.getElementById('feedList');
194
195 if (keycode == 74) { // j
196 var feed = getActiveFeedId();
197 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
198 if (new_feed) viewfeed(new_feed, 0, '');
199 }
200
201 if (keycode == 75) { // k
202 var feed = getActiveFeedId();
203 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
204 if (new_feed) viewfeed(new_feed, 0, '');
205 }
206
207 if (keycode == 78 || keycode == 40) { // n, down
208 return h_ctx.moveToPost('next');
209 }
210
211 if (keycode == 80 || keycode == 38) { // p, up
212 return h_ctx.moveToPost('prev');
213 }
214
215 if (document.getElementById("piggie")) {
216
217 if (seq.match("807371717369")) {
218 seq = "";
219 localPiggieFunction(true);
220 } else {
221 localPiggieFunction(false);
222 }
223 }
224
225 if (typeof localHotkeyHandler != 'undefined') {
226 try {
227 localHotkeyHandler(keycode);
228 } catch (e) {
229 exception_error("hotkey_handler, local:", e);
230 }
231 }
232 } catch (e) {
233 exception_error("hotkey_handler", e);
234 }
235 }
236
237 function cleanSelectedList(element) {
238 var content = document.getElementById(element);
239
240 if (!document.getElementById("feedCatHolder")) {
241 for (i = 0; i < content.childNodes.length; i++) {
242 var child = content.childNodes[i];
243 try {
244 child.className = child.className.replace("Selected", "");
245 } catch (e) {
246 //
247 }
248 }
249 } else {
250 for (i = 0; i < content.childNodes.length; i++) {
251 var child = content.childNodes[i];
252 if (child.id == "feedCatHolder") {
253 parent.debug(child.id);
254 var fcat = child.lastChild;
255 for (j = 0; j < fcat.childNodes.length; j++) {
256 var feed = fcat.childNodes[j];
257 feed.className = feed.className.replace("Selected", "");
258 }
259 }
260 }
261 }
262 }
263
264
265 function cleanSelected(element) {
266 var content = document.getElementById(element);
267
268 for (i = 0; i < content.rows.length; i++) {
269 content.rows[i].className = content.rows[i].className.replace("Selected", "");
270 }
271 }
272
273 function getVisibleUnreadHeadlines() {
274 var content = document.getElementById("headlinesList");
275
276 var rows = new Array();
277
278 for (i = 0; i < content.rows.length; i++) {
279 var row_id = content.rows[i].id.replace("RROW-", "");
280 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
281 rows.push(row_id);
282 }
283 }
284 return rows;
285 }
286
287 function getVisibleHeadlineIds() {
288
289 var content = document.getElementById("headlinesList");
290
291 var rows = new Array();
292
293 for (i = 0; i < content.rows.length; i++) {
294 var row_id = content.rows[i].id.replace("RROW-", "");
295 if (row_id.length > 0) {
296 rows.push(row_id);
297 }
298 }
299 return rows;
300 }
301
302 function getFirstVisibleHeadlineId() {
303 var rows = getVisibleHeadlineIds();
304 return rows[0];
305 }
306
307 function getLastVisibleHeadlineId() {
308 var rows = getVisibleHeadlineIds();
309 return rows[rows.length-1];
310 }
311
312 function markHeadline(id) {
313 var row = document.getElementById("RROW-" + id);
314 if (row) {
315 var is_active = false;
316
317 if (row.className.match("Active")) {
318 is_active = true;
319 }
320 row.className = row.className.replace("Selected", "");
321 row.className = row.className.replace("Active", "");
322 row.className = row.className.replace("Insensitive", "");
323
324 if (is_active) {
325 row.className = row.className = "Active";
326 }
327
328 var check = document.getElementById("RCHK-" + id);
329
330 if (check) {
331 check.checked = true;
332 }
333
334 row.className = row.className + "Selected";
335
336 }
337 }
338
339 function getFeedIds() {
340 var content = document.getElementById("feedsList");
341
342 var rows = new Array();
343
344 for (i = 0; i < content.rows.length; i++) {
345 var id = content.rows[i].id.replace("FEEDR-", "");
346 if (id.length > 0) {
347 rows.push(id);
348 }
349 }
350
351 return rows;
352 }
353
354 function setCookie(name, value, lifetime, path, domain, secure) {
355
356 var d = false;
357
358 if (lifetime) {
359 d = new Date();
360 d.setTime(lifetime * 1000);
361 }
362
363 int_setCookie(name, value, d, path, domain, secure);
364
365 }
366
367 function int_setCookie(name, value, expires, path, domain, secure) {
368 document.cookie= name + "=" + escape(value) +
369 ((expires) ? "; expires=" + expires.toGMTString() : "") +
370 ((path) ? "; path=" + path : "") +
371 ((domain) ? "; domain=" + domain : "") +
372 ((secure) ? "; secure" : "");
373 }
374
375 function delCookie(name, path, domain) {
376 if (getCookie(name)) {
377 document.cookie = name + "=" +
378 ((path) ? ";path=" + path : "") +
379 ((domain) ? ";domain=" + domain : "" ) +
380 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
381 }
382 }
383
384
385 function getCookie(name) {
386
387 var dc = document.cookie;
388 var prefix = name + "=";
389 var begin = dc.indexOf("; " + prefix);
390 if (begin == -1) {
391 begin = dc.indexOf(prefix);
392 if (begin != 0) return null;
393 }
394 else {
395 begin += 2;
396 }
397 var end = document.cookie.indexOf(";", begin);
398 if (end == -1) {
399 end = dc.length;
400 }
401 return unescape(dc.substring(begin + prefix.length, end));
402 }
403
404 function disableContainerChildren(id, disable, doc) {
405
406 if (!doc) doc = document;
407
408 var container = doc.getElementById(id);
409
410 if (!container) {
411 //alert("disableContainerChildren: element " + id + " not found");
412 return;
413 }
414
415 for (var i = 0; i < container.childNodes.length; i++) {
416 var child = container.childNodes[i];
417
418 try {
419 child.disabled = disable;
420 } catch (E) {
421
422 }
423
424 if (disable) {
425 if (child.className && child.className.match("button")) {
426 child.className = "disabledButton";
427 }
428 } else {
429 if (child.className && child.className.match("disabledButton")) {
430 child.className = "button";
431 }
432 }
433 }
434
435 }
436
437 function gotoPreferences() {
438 document.location.href = "prefs.php";
439 }
440
441 function gotoMain() {
442 document.location.href = "tt-rss.php";
443 }
444
445 function gotoExportOpml() {
446 document.location.href = "opml.php?op=Export";
447 }
448
449 function getActiveFeedId() {
450 // return getCookie("ttrss_vf_actfeed");
451 try {
452 debug("gAFID: " + getMainContext().active_feed_id);
453 return getMainContext().active_feed_id;
454 } catch (e) {
455 exception_error("getActiveFeedId", e);
456 }
457 }
458
459 function setActiveFeedId(id) {
460 // return setCookie("ttrss_vf_actfeed", id);
461 try {
462 getMainContext().active_feed_id = id;
463 } catch (e) {
464 exception_error("setActiveFeedId", e);
465 }
466 }
467
468 function parse_counters(reply, scheduled_call) {
469 try {
470 var f_document = getFeedsContext().document;
471 var title_obj = getMainContext();
472
473 if (reply.firstChild && reply.firstChild.firstChild) {
474 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
475 reply = reply.firstChild;
476 }
477
478 debug("F_DOC: " + f_document + ", T_OBJ: " + title_obj);
479
480 for (var l = 0; l < reply.childNodes.length; l++) {
481 if (!reply.childNodes[l] ||
482 typeof(reply.childNodes[l].getAttribute) == "undefined") {
483 // where did this come from?
484 continue;
485 }
486
487 var id = reply.childNodes[l].getAttribute("id");
488 var t = reply.childNodes[l].getAttribute("type");
489 var ctr = reply.childNodes[l].getAttribute("counter");
490 var error = reply.childNodes[l].getAttribute("error");
491 var has_img = reply.childNodes[l].getAttribute("hi");
492 var updated = reply.childNodes[l].getAttribute("updated");
493
494 if (id == "global-unread") {
495 title_obj.global_unread = ctr;
496 title_obj.updateTitle();
497 continue;
498 }
499
500 if (t == "category") {
501 var catctr = f_document.getElementById("FCATCTR-" + id);
502 if (catctr) {
503 catctr.innerHTML = "(" + ctr + " unread)";
504 }
505 continue;
506 }
507
508 var feedctr = f_document.getElementById("FEEDCTR-" + id);
509 var feedu = f_document.getElementById("FEEDU-" + id);
510 var feedr = f_document.getElementById("FEEDR-" + id);
511 var feed_img = f_document.getElementById("FIMG-" + id);
512 var feedlink = f_document.getElementById("FEEDL-" + id);
513
514 if (updated && feedlink) {
515 if (error) {
516 feedlink.title = "Error: " + error + " (" + updated + ")";
517 } else {
518 feedlink.title = "Updated: " + updated;
519 }
520 }
521
522 if (feedctr && feedu && feedr) {
523
524 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
525 var hf = title_obj.parent.frames["headlines-frame"];
526 hf.location.reload(true);
527 }
528
529 feedu.innerHTML = ctr;
530
531 if (error) {
532 feedr.className = feedr.className.replace("feed", "error");
533 } else if (id > 0) {
534 feedr.className = feedr.className.replace("error", "feed");
535 }
536
537 if (ctr > 0) {
538 feedctr.className = "odd";
539 if (!feedr.className.match("Unread")) {
540 var is_selected = feedr.className.match("Selected");
541
542 feedr.className = feedr.className.replace("Selected", "");
543 feedr.className = feedr.className.replace("Unread", "");
544
545 feedr.className = feedr.className + "Unread";
546
547 if (is_selected) {
548 feedr.className = feedr.className + "Selected";
549 }
550
551 }
552 } else {
553 feedctr.className = "invisible";
554 feedr.className = feedr.className.replace("Unread", "");
555 }
556 }
557 }
558 } catch (e) {
559 exception_error("parse_counters", e);
560 }
561 }
562
563 function all_counters_callback() {
564 if (xmlhttp_rpc.readyState == 4) {
565 try {
566 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
567 notify("[all_counters_callback] backend did not return valid XML");
568 return;
569 }
570
571 debug("in all_counters_callback");
572
573 var reply = xmlhttp_rpc.responseXML.firstChild;
574
575 var counters = reply.firstChild;
576
577 parse_counters(counters);
578
579 var runtime = counters.nextSibling;
580
581 if (runtime) {
582 getMainContext().parse_runtime_info(runtime);
583 }
584
585 } catch (e) {
586 exception_error("all_counters_callback", e);
587 }
588 }
589 }
590
591 function update_all_counters(feed) {
592 if (xmlhttp_ready(xmlhttp_rpc)) {
593 var query = "backend.php?op=rpc&subop=getAllCounters";
594
595 if (feed > 0) {
596 query = query + "&aid=" + feed;
597 }
598
599 xmlhttp_rpc.open("GET", query, true);
600 xmlhttp_rpc.onreadystatechange=all_counters_callback;
601 xmlhttp_rpc.send(null);
602 }
603 }
604
605 function popupHelp(tid) {
606 var w = window.open("backend.php?op=help&tid=" + tid,
607 "Popup Help",
608 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
609 }
610
611 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
612 * * @author Sundar Dorai-Raj
613 * * Email: sdoraira@vt.edu
614 * * This program is free software; you can redistribute it and/or
615 * * modify it under the terms of the GNU General Public License
616 * * as published by the Free Software Foundation; either version 2
617 * * of the License, or (at your option) any later version,
618 * * provided that any use properly credits the author.
619 * * This program is distributed in the hope that it will be useful,
620 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
621 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
622 * * GNU General Public License for more details at http://www.gnu.org * * */
623
624 var numbers=".0123456789";
625 function isNumeric(x) {
626 // is x a String or a character?
627 if(x.length>1) {
628 // remove negative sign
629 x=Math.abs(x)+"";
630 for(j=0;j<x.length;j++) {
631 // call isNumeric recursively for each character
632 number=isNumeric(x.substring(j,j+1));
633 if(!number) return number;
634 }
635 return number;
636 }
637 else {
638 // if x is number return true
639 if(numbers.indexOf(x)>=0) return true;
640 return false;
641 }
642 }
643
644
645 function hideOrShowFeeds(doc, hide) {
646
647 if (!doc.styleSheets) return;
648
649 var css_rules = doc.styleSheets[0].cssRules;
650
651 if (!css_rules || !css_rules.length) return;
652
653 for (i = 0; i < css_rules.length; i++) {
654 var rule = css_rules[i];
655
656 if (rule.selectorText == "ul.feedList li.feed") {
657 if (!hide) {
658 rule.style.display = "block";
659 } else {
660 rule.style.display = "none";
661 }
662 }
663
664 }
665
666 }
667
668 function selectTableRow(r, do_select) {
669 r.className = r.className.replace("Selected", "");
670
671 if (do_select) {
672 r.className = r.className + "Selected";
673 }
674 }
675
676 function selectTableRowById(elem_id, check_id, do_select) {
677
678 try {
679
680 var row = document.getElementById(elem_id);
681
682 if (row) {
683 selectTableRow(row, do_select);
684 }
685
686 var check = document.getElementById(check_id);
687
688 if (check) {
689 check.checked = do_select;
690 }
691 } catch (e) {
692 exception_error("selectTableRowById", e);
693 }
694 }
695
696 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
697 classcheck, reset_others) {
698
699 var content = document.getElementById(content_id);
700
701 if (!content) {
702 alert("[selectTableRows] Element " + content_id + " not found.");
703 return;
704 }
705
706 for (i = 0; i < content.rows.length; i++) {
707 if (!classcheck || content.rows[i].className.match(classcheck)) {
708
709 if (content.rows[i].id.match(prefix)) {
710 selectTableRow(content.rows[i], do_select);
711
712 var row_id = content.rows[i].id.replace(prefix, "");
713 var check = document.getElementById(check_prefix + row_id);
714
715 if (check) {
716 check.checked = do_select;
717 }
718 } else if (reset_others) {
719 selectTableRow(content.rows[i], false);
720
721 var row_id = content.rows[i].id.replace(prefix, "");
722 var check = document.getElementById(check_prefix + row_id);
723
724 if (check) {
725 check.checked = false;
726 }
727
728 }
729 } else if (reset_others) {
730 selectTableRow(content.rows[i], false);
731
732 var row_id = content.rows[i].id.replace(prefix, "");
733 var check = document.getElementById(check_prefix + row_id);
734
735 if (check) {
736 check.checked = false;
737 }
738
739 }
740 }
741 }
742
743 function getSelectedTableRowIds(content_id, prefix) {
744
745 var content = document.getElementById(content_id);
746
747 if (!content) {
748 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
749 return;
750 }
751
752 var sel_rows = new Array();
753
754 for (i = 0; i < content.rows.length; i++) {
755 if (content.rows[i].id.match(prefix) &&
756 content.rows[i].className.match("Selected")) {
757
758 var row_id = content.rows[i].id.replace(prefix + "-", "");
759 sel_rows.push(row_id);
760 }
761 }
762
763 return sel_rows;
764
765 }
766
767 function toggleSelectRowById(sender, id) {
768 var row = document.getElementById(id);
769
770 if (sender.checked) {
771 if (!row.className.match("Selected")) {
772 row.className = row.className + "Selected";
773 }
774 } else {
775 if (row.className.match("Selected")) {
776 row.className = row.className.replace("Selected", "");
777 }
778 }
779 }
780
781 function toggleSelectListRow(sender) {
782 var parent_row = sender.parentNode;
783
784 if (sender.checked) {
785 if (!parent_row.className.match("Selected")) {
786 parent_row.className = parent_row.className + "Selected";
787 }
788 } else {
789 if (parent_row.className.match("Selected")) {
790 parent_row.className = parent_row.className.replace("Selected", "");
791 }
792 }
793 }
794
795
796 function toggleSelectRow(sender) {
797 var parent_row = sender.parentNode.parentNode;
798
799 if (sender.checked) {
800 if (!parent_row.className.match("Selected")) {
801 parent_row.className = parent_row.className + "Selected";
802 }
803 } else {
804 if (parent_row.className.match("Selected")) {
805 parent_row.className = parent_row.className.replace("Selected", "");
806 }
807 }
808 }
809
810 function openExternalUrl(url) {
811 var w = window.open(url);
812 }
813
814 function getRelativeFeedId(list, id, direction, unread_only) {
815 if (!id) {
816 if (direction == "next") {
817 for (i = 0; i < list.childNodes.length; i++) {
818 var child = list.childNodes[i];
819 if (child.id && child.id == "feedCatHolder") {
820 if (child.lastChild) {
821 var cr = getRelativeFeedId(child.firstChild, id, direction);
822 if (cr) return cr;
823 }
824 } else if (child.id && child.id.match("FEEDR-")) {
825 return child.id.replace('FEEDR-', '');
826 }
827 }
828 }
829
830 // FIXME select last feed doesn't work when only unread feeds are visible
831
832 if (direction == "prev") {
833 for (i = list.childNodes.length-1; i >= 0; i--) {
834 var child = list.childNodes[i];
835 if (child.id == "feedCatHolder") {
836 if (child.firstChild) {
837 var cr = getRelativeFeedId(child.firstChild, id, direction);
838 if (cr) return cr;
839 }
840 } else if (child.id.match("FEEDR-")) {
841
842 if (getInitParam("hide_read_feeds") == 1) {
843 if (child.className != "feed") {
844 alert(child.className);
845 return child.id.replace('FEEDR-', '');
846 }
847 } else {
848 return child.id.replace('FEEDR-', '');
849 }
850 }
851 }
852 }
853 } else {
854
855 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
856
857 if (getInitParam("hide_read_feeds") == 1) {
858 unread_only = true;
859 }
860
861 if (direction == "next") {
862
863 var e = feed;
864
865 while (e) {
866
867 if (e.nextSibling) {
868
869 e = e.nextSibling;
870
871 } else if (e.parentNode.parentNode.nextSibling) {
872
873 var this_cat = e.parentNode.parentNode;
874
875 e = false;
876
877 if (this_cat && this_cat.nextSibling) {
878 while (!e && this_cat.nextSibling) {
879 this_cat = this_cat.nextSibling;
880 if (this_cat.id == "feedCatHolder") {
881 e = this_cat.firstChild.firstChild;
882 }
883 }
884 }
885
886 } else {
887 e = false;
888 }
889
890 if (e) {
891 if (!unread_only || (unread_only && e.className != "feed" &&
892 e.className != "error")) {
893 return e.id.replace("FEEDR-", "");
894 }
895 }
896 }
897
898 } else if (direction == "prev") {
899
900 var e = feed;
901
902 while (e) {
903
904 if (e.previousSibling) {
905
906 e = e.previousSibling;
907
908 } else if (e.parentNode.parentNode.previousSibling) {
909
910 var this_cat = e.parentNode.parentNode;
911
912 e = false;
913
914 if (this_cat && this_cat.previousSibling) {
915 while (!e && this_cat.previousSibling) {
916 this_cat = this_cat.previousSibling;
917 if (this_cat.id == "feedCatHolder") {
918 e = this_cat.firstChild.lastChild;
919 }
920 }
921 }
922
923 } else {
924 e = false;
925 }
926
927 if (e) {
928 if (!unread_only || (unread_only && e.className != "feed" &&
929 e.className != "error")) {
930 return e.id.replace("FEEDR-", "");
931 }
932 }
933 }
934 }
935 }
936 }
937
938 function showBlockElement(id) {
939 var elem = document.getElementById(id);
940
941 if (elem) {
942 elem.style.display = "block";
943 } else {
944 alert("[showBlockElement] can't find element with id " + id);
945 }
946 }
947
948 function hideParentElement(e) {
949 e.parentNode.style.display = "none";
950 }
951
952 function dropboxSelect(e, v) {
953 for (i = 0; i < e.length; i++) {
954 if (e[i].value == v) {
955 e.selectedIndex = i;
956 break;
957 }
958 }
959 }
960
961 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
962 // bugfixed just a little bit :-)
963 function getURLParam(strParamName){
964 var strReturn = "";
965 var strHref = window.location.href;
966
967 if (strHref.indexOf("#") == strHref.length-1) {
968 strHref = strHref.substring(0, strHref.length-1);
969 }
970
971 if ( strHref.indexOf("?") > -1 ){
972 var strQueryString = strHref.substr(strHref.indexOf("?"));
973 var aQueryString = strQueryString.split("&");
974 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
975 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
976 var aParam = aQueryString[iParam].split("=");
977 strReturn = aParam[1];
978 break;
979 }
980 }
981 }
982 return strReturn;
983 }
984
985 function leading_zero(p) {
986 var s = String(p);
987 if (s.length == 1) s = "0" + s;
988 return s;
989 }
990
991 function closeInfoBox(cleanup) {
992 var box = document.getElementById('infoBox');
993 var shadow = document.getElementById('infoBoxShadow');
994
995 if (shadow) {
996 shadow.style.display = "none";
997 } else if (box) {
998 box.style.display = "none";
999 }
1000
1001 if (cleanup) box.innerHTML = "&nbsp;";
1002
1003 enableHotkeys();
1004
1005 }
1006
1007
1008 function displayDlg(id, param) {
1009
1010 if (!xmlhttp_ready(xmlhttp)) {
1011 printLockingError();
1012 return
1013 }
1014
1015 notify("");
1016
1017 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1018 param_escape(id) + "&param=" + param_escape(param), true);
1019 xmlhttp.onreadystatechange=infobox_callback;
1020 xmlhttp.send(null);
1021
1022 disableHotkeys();
1023
1024 }
1025
1026 function infobox_submit_callback() {
1027 if (xmlhttp.readyState == 4) {
1028 closeInfoBox();
1029
1030 // called from prefs, reload tab
1031 if (active_tab) {
1032 selectTab(active_tab, false);
1033 }
1034
1035 notify(xmlhttp.responseText);
1036
1037 }
1038 }
1039
1040 function infobox_callback() {
1041 if (xmlhttp.readyState == 4) {
1042 var box = document.getElementById('infoBox');
1043 var shadow = document.getElementById('infoBoxShadow');
1044 if (box) {
1045 box.innerHTML=xmlhttp.responseText;
1046 if (shadow) {
1047 shadow.style.display = "block";
1048 } else {
1049 box.style.display = "block";
1050 }
1051 }
1052 }
1053 }
1054
1055 function qaddFilter() {
1056
1057 if (!xmlhttp_ready(xmlhttp)) {
1058 printLockingError();
1059 return
1060 }
1061
1062 var query = Form.serialize("filter_add_form");
1063
1064 xmlhttp.open("GET", "backend.php?" + query, true);
1065 xmlhttp.onreadystatechange=infobox_submit_callback;
1066 xmlhttp.send(null);
1067
1068 return true;
1069 }
1070
1071 function toggleSubmitNotEmpty(e, submit_id) {
1072 try {
1073 document.getElementById(submit_id).disabled = (e.value == "")
1074 } catch (e) {
1075 exception_error("toggleSubmitNotEmpty", e);
1076 }
1077 }
1078
1079 function isValidURL(s) {
1080 return s.match("http://") != null || s.match("https://") != null;
1081 }
1082
1083 function qafAdd() {
1084
1085 if (!xmlhttp_ready(xmlhttp)) {
1086 printLockingError();
1087 return
1088 }
1089
1090 notify("Adding feed...");
1091
1092 closeInfoBox();
1093
1094 var feeds_doc = getFeedsContext().document;
1095
1096 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1097
1098 var query = Form.serialize("feed_add_form");
1099
1100 xmlhttp.open("GET", "backend.php?" + query, true);
1101 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1102 xmlhttp.send(null);
1103 }
1104
1105 function filterCR(e)
1106 {
1107 var key;
1108
1109 if(window.event)
1110 key = window.event.keyCode; //IE
1111 else
1112 key = e.which; //firefox
1113
1114 if(key == 13)
1115 return false;
1116 else
1117 return true;
1118 }
1119
1120 function getMainContext() {
1121 if (parent.window != window) {
1122 return parent.window;
1123 } else {
1124 return this.window;
1125 }
1126 }
1127
1128 function getFeedsContext() {
1129 try {
1130 return getMainContext().frames["feeds-frame"];
1131 } catch (e) {
1132 exception_error("getFeedsContext", e);
1133 }
1134 }
1135
1136
1137 function getHeadlinesContext() {
1138 try {
1139 return getMainContext().frames["headlines-frame"];
1140 } catch (e) {
1141 exception_error("getHeadlinesContext", e);
1142 }
1143 }
1144
1145 function debug(msg) {
1146 var ctx = getMainContext();
1147
1148 var c = ctx.document.getElementById('debug_output');
1149 if (c && c.style.display == "block") {
1150 while (c.lastChild != 'undefined' && c.childNodes.length > 20) {
1151 c.removeChild(c.lastChild);
1152 }
1153
1154 var d = new Date();
1155 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1156 ":" + leading_zero(d.getSeconds());
1157 c.innerHTML = "<li>[" + ts + "] " + msg + "</li>" + c.innerHTML;
1158 }
1159 }
1160
1161 function getInitParam(key) {
1162 return getMainContext().init_params[key];
1163 }
1164
1165 // TODO: batch mode
1166 function storeInitParam(key, value, is_client) {
1167 try {
1168 getMainContext().init_params[key] = value;
1169 if (!is_client) {
1170 new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1171 param_escape(key) + "&value=" + param_escape(value));
1172 }
1173 } catch (e) {
1174 exception_error("storeInitParam", e);
1175 }
1176 }
1177
1178 function fatalError(code, message) {
1179 try {
1180 var fe = document.getElementById("fatal_error");
1181 var fc = document.getElementById("fatal_error_msg");
1182
1183 fc.innerHTML = "Code " + code + ": " + message;
1184
1185 fe.style.display = "block";
1186
1187 } catch (e) {
1188 exception_error("fatalError", e);
1189 }
1190 }
1191
1192 function getFeedName(id) {
1193 var d = getFeedsContext().document;
1194 var e = d.getElementById("FEEDN-" + id);
1195 if (e) {
1196 return e.innerHTML.stripTags();
1197 } else {
1198 return null;
1199 }
1200 }