]> git.wh0rd.org - tt-rss.git/blob - functions.js
tweak category counter display, new styles: .catCtrNoUnread, .catCtrHasUnread
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2 var debug_mode_enabled = false;
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 is_opera() {
11 return navigator.userAgent.match("Opera");
12 }
13
14 function exception_error(location, e, silent) {
15 var msg;
16
17 if (e.fileName) {
18 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
19
20 msg = "Exception: " + e.name + ", " + e.message +
21 "\nFunction: " + location + "()" +
22 "\nLocation: " + base_fname + ":" + e.lineNumber;
23
24 } else {
25 msg = "Exception: " + e + "\nFunction: " + location + "()";
26 }
27
28 debug("<b>EXCEPTION: " + msg + "</b>");
29
30 if (!silent) {
31 alert(msg);
32 }
33 }
34
35 function disableHotkeys() {
36 hotkeys_enabled = false;
37 }
38
39 function enableHotkeys() {
40 hotkeys_enabled = true;
41 }
42
43 function xmlhttp_ready(obj) {
44 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
45 }
46
47 function notify_callback() {
48 var container = document.getElementById('notify');
49 if (xmlhttp.readyState == 4) {
50 container.innerHTML=xmlhttp.responseText;
51 }
52 }
53
54 function rpc_notify_callback() {
55 var container = document.getElementById('notify');
56 if (xmlhttp_rpc.readyState == 4) {
57 container.innerHTML=xmlhttp_rpc.responseText;
58 }
59 }
60
61 function param_escape(arg) {
62 if (typeof encodeURIComponent != 'undefined')
63 return encodeURIComponent(arg);
64 else
65 return escape(arg);
66 }
67
68 function param_unescape(arg) {
69 if (typeof decodeURIComponent != 'undefined')
70 return decodeURIComponent(arg);
71 else
72 return unescape(arg);
73 }
74
75 function delay(gap) {
76 var then,now;
77 then=new Date().getTime();
78 now=then;
79 while((now-then)<gap) {
80 now=new Date().getTime();
81 }
82 }
83
84 var notify_hide_timerid = false;
85 var notify_last_doc = false;
86
87 var notify_effect = false;
88
89 function hide_notify() {
90 if (notify_last_doc) {
91 var n = notify_last_doc.getElementById("notify");
92 n.style.display = "none";
93
94 /* if (browser_has_opacity()) {
95 if (notify_opacity >= 0) {
96 notify_opacity = notify_opacity - 0.1;
97 n.style.opacity = notify_opacity;
98 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
99 } else {
100 n.style.display = "none";
101 n.style.opacity = 1;
102 }
103 } else {
104 n.style.display = "none";
105 } */
106 }
107 }
108
109 function notify_real(msg, doc, no_hide, is_err) {
110
111 var n = doc.getElementById("notify");
112 var nb = doc.getElementById("notify_body");
113
114 if (!n || !nb) return;
115
116 if (notify_hide_timerid) {
117 window.clearTimeout(notify_hide_timerid);
118 }
119
120 notify_last_doc = doc;
121 notify_opacity = 1;
122
123 if (msg == "") {
124 if (n.style.display == "block") {
125 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
126 }
127 return;
128 } else {
129 n.style.display = "block";
130 }
131
132 if (is_err) {
133 n.className = "notifyError";
134 // n.style.backgroundColor = "#ffcccc";
135 // n.style.color = "black";
136 // n.style.borderColor = "#ff0000";
137 } else {
138 n.className = "notify";
139 // n.style.backgroundColor = "#fff7d5";
140 // n.style.borderColor = "#d7c47a";
141 // n.style.color = "black";
142 }
143
144 // msg = "<img src='images/live_com_loading.gif'> " + msg;
145
146 nb.innerHTML = msg;
147
148 if (!no_hide) {
149 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
150 }
151 }
152
153 function p_notify(msg, no_hide, is_err) {
154 notify_real(msg, document, no_hide, is_err);
155 }
156
157 function notify(msg, no_hide, is_err) {
158 notify_real(msg, document, no_hide, is_err);
159 }
160
161 function printLockingError() {
162 notify("Please wait until operation finishes");}
163
164 function hotkey_handler(e) {
165
166 try {
167
168 var keycode;
169 var shift_key = false;
170
171 try {
172 shift_key = e.shiftKey;
173 } catch (e) {
174
175 }
176
177 if (!hotkeys_enabled) return;
178
179 if (window.event) {
180 keycode = window.event.keyCode;
181 } else if (e) {
182 keycode = e.which;
183 }
184
185 if (keycode == 82) { // r
186 return scheduleFeedUpdate(true);
187 }
188
189 if (keycode == 83) { // s
190 return displayDlg("search", getActiveFeedId());
191 }
192
193 if (keycode == 85) { // u
194 if (getActiveFeedId()) {
195 return viewfeed(getActiveFeedId(), "ForceUpdate");
196 }
197 }
198
199 if (keycode == 65) { // a
200 return toggleDispRead();
201 }
202
203 var feedlist = document.getElementById('feedList');
204
205 if (keycode == 74) { // j
206 var feed = getActiveFeedId();
207 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
208 if (new_feed) viewfeed(new_feed, '');
209 }
210
211 if (keycode == 75) { // k
212 var feed = getActiveFeedId();
213 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
214 if (new_feed) viewfeed(new_feed, '');
215 }
216
217 if (keycode == 78 || keycode == 40) { // n, down
218 if (typeof moveToPost != 'undefined') {
219 return moveToPost('next');
220 }
221 }
222
223 if (keycode == 80 || keycode == 38) { // p, up
224 if (typeof moveToPost != 'undefined') {
225 return moveToPost('prev');
226 }
227 }
228
229 if (keycode == 68 && shift_key) { // d
230 if (!debug_mode_enabled) {
231 document.getElementById('debug_output').style.display = 'block';
232 debug('debug mode activated');
233 } else {
234 document.getElementById('debug_output').style.display = 'none';
235 }
236
237 debug_mode_enabled = !debug_mode_enabled;
238 }
239
240 if (keycode == 69 && shift_key) {
241 return editFeedDlg(getActiveFeedId());
242 }
243
244 if (typeof localHotkeyHandler != 'undefined') {
245 try {
246 return localHotkeyHandler(e);
247 } catch (e) {
248 exception_error("hotkey_handler, local:", e);
249 }
250 }
251
252 debug("KP=" + keycode);
253 } catch (e) {
254 exception_error("hotkey_handler", e);
255 }
256 }
257
258 function cleanSelectedList(element) {
259 var content = document.getElementById(element);
260
261 if (!document.getElementById("feedCatHolder")) {
262 for (i = 0; i < content.childNodes.length; i++) {
263 var child = content.childNodes[i];
264 try {
265 child.className = child.className.replace("Selected", "");
266 } catch (e) {
267 //
268 }
269 }
270 } else {
271 for (i = 0; i < content.childNodes.length; i++) {
272 var child = content.childNodes[i];
273 if (child.id == "feedCatHolder") {
274 debug(child.id);
275 var fcat = child.lastChild;
276 for (j = 0; j < fcat.childNodes.length; j++) {
277 var feed = fcat.childNodes[j];
278 feed.className = feed.className.replace("Selected", "");
279 }
280 }
281 }
282 }
283 }
284
285
286 function cleanSelected(element) {
287 var content = document.getElementById(element);
288
289 for (i = 0; i < content.rows.length; i++) {
290 content.rows[i].className = content.rows[i].className.replace("Selected", "");
291 }
292 }
293
294 function getVisibleUnreadHeadlines() {
295 var content = document.getElementById("headlinesList");
296
297 var rows = new Array();
298
299 for (i = 0; i < content.rows.length; i++) {
300 var row_id = content.rows[i].id.replace("RROW-", "");
301 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
302 rows.push(row_id);
303 }
304 }
305 return rows;
306 }
307
308 function getVisibleHeadlineIds() {
309
310 var content = document.getElementById("headlinesList");
311
312 var rows = new Array();
313
314 for (i = 0; i < content.rows.length; i++) {
315 var row_id = content.rows[i].id.replace("RROW-", "");
316 if (row_id.length > 0) {
317 rows.push(row_id);
318 }
319 }
320 return rows;
321 }
322
323 function getFirstVisibleHeadlineId() {
324 var rows = getVisibleHeadlineIds();
325 return rows[0];
326 }
327
328 function getLastVisibleHeadlineId() {
329 var rows = getVisibleHeadlineIds();
330 return rows[rows.length-1];
331 }
332
333 function markHeadline(id) {
334 var row = document.getElementById("RROW-" + id);
335 if (row) {
336 var is_active = false;
337
338 if (row.className.match("Active")) {
339 is_active = true;
340 }
341 row.className = row.className.replace("Selected", "");
342 row.className = row.className.replace("Active", "");
343 row.className = row.className.replace("Insensitive", "");
344
345 if (is_active) {
346 row.className = row.className = "Active";
347 }
348
349 var check = document.getElementById("RCHK-" + id);
350
351 if (check) {
352 check.checked = true;
353 }
354
355 row.className = row.className + "Selected";
356
357 }
358 }
359
360 function getFeedIds() {
361 var content = document.getElementById("feedsList");
362
363 var rows = new Array();
364
365 for (i = 0; i < content.rows.length; i++) {
366 var id = content.rows[i].id.replace("FEEDR-", "");
367 if (id.length > 0) {
368 rows.push(id);
369 }
370 }
371
372 return rows;
373 }
374
375 function setCookie(name, value, lifetime, path, domain, secure) {
376
377 var d = false;
378
379 if (lifetime) {
380 d = new Date();
381 d.setTime(lifetime * 1000);
382 }
383
384 int_setCookie(name, value, d, path, domain, secure);
385
386 }
387
388 function int_setCookie(name, value, expires, path, domain, secure) {
389 document.cookie= name + "=" + escape(value) +
390 ((expires) ? "; expires=" + expires.toGMTString() : "") +
391 ((path) ? "; path=" + path : "") +
392 ((domain) ? "; domain=" + domain : "") +
393 ((secure) ? "; secure" : "");
394 }
395
396 function delCookie(name, path, domain) {
397 if (getCookie(name)) {
398 document.cookie = name + "=" +
399 ((path) ? ";path=" + path : "") +
400 ((domain) ? ";domain=" + domain : "" ) +
401 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
402 }
403 }
404
405
406 function getCookie(name) {
407
408 var dc = document.cookie;
409 var prefix = name + "=";
410 var begin = dc.indexOf("; " + prefix);
411 if (begin == -1) {
412 begin = dc.indexOf(prefix);
413 if (begin != 0) return null;
414 }
415 else {
416 begin += 2;
417 }
418 var end = document.cookie.indexOf(";", begin);
419 if (end == -1) {
420 end = dc.length;
421 }
422 return unescape(dc.substring(begin + prefix.length, end));
423 }
424
425 function disableContainerChildren(id, disable, doc) {
426
427 if (!doc) doc = document;
428
429 var container = doc.getElementById(id);
430
431 if (!container) {
432 //alert("disableContainerChildren: element " + id + " not found");
433 return;
434 }
435
436 for (var i = 0; i < container.childNodes.length; i++) {
437 var child = container.childNodes[i];
438
439 try {
440 child.disabled = disable;
441 } catch (E) {
442
443 }
444
445 if (disable) {
446 if (child.className && child.className.match("button")) {
447 child.className = "disabledButton";
448 }
449 } else {
450 if (child.className && child.className.match("disabledButton")) {
451 child.className = "button";
452 }
453 }
454 }
455
456 }
457
458 function gotoPreferences() {
459 document.location.href = "prefs.php";
460 }
461
462 function gotoMain() {
463 document.location.href = "tt-rss.php";
464 }
465
466 function gotoExportOpml() {
467 document.location.href = "opml.php?op=Export";
468 }
469
470 function getActiveFeedId() {
471 // return getCookie("ttrss_vf_actfeed");
472 try {
473 debug("gAFID: " + active_feed_id);
474 return active_feed_id;
475 } catch (e) {
476 exception_error("getActiveFeedId", e);
477 }
478 }
479
480 function activeFeedIsCat() {
481 return active_feed_is_cat;
482 }
483
484 function setActiveFeedId(id) {
485 // return setCookie("ttrss_vf_actfeed", id);
486 try {
487 debug("sAFID(" + id + ")");
488 active_feed_id = id;
489 } catch (e) {
490 exception_error("setActiveFeedId", e);
491 }
492 }
493
494 function parse_counters(reply, scheduled_call) {
495 try {
496
497 var feeds_found = 0;
498
499 if (reply.firstChild && reply.firstChild.firstChild) {
500 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
501 reply = reply.firstChild;
502 }
503
504 for (var l = 0; l < reply.childNodes.length; l++) {
505 if (!reply.childNodes[l] ||
506 typeof(reply.childNodes[l].getAttribute) == "undefined") {
507 // where did this come from?
508 continue;
509 }
510
511 var id = reply.childNodes[l].getAttribute("id");
512 var t = reply.childNodes[l].getAttribute("type");
513 var ctr = reply.childNodes[l].getAttribute("counter");
514 var error = reply.childNodes[l].getAttribute("error");
515 var has_img = reply.childNodes[l].getAttribute("hi");
516 var updated = reply.childNodes[l].getAttribute("updated");
517
518 if (id == "global-unread") {
519 global_unread = ctr;
520 updateTitle();
521 continue;
522 }
523
524 if (id == "subscribed-feeds") {
525 feeds_found = ctr;
526 continue;
527 }
528
529 if (t == "category") {
530 var catctr = document.getElementById("FCATCTR-" + id);
531 if (catctr) {
532 catctr.innerHTML = "(" + ctr + ")";
533 if (ctr > 0) {
534 catctr.className = "catCtrHasUnread";
535 } else {
536 catctr.className = "catCtrNoUnread";
537 }
538 }
539 continue;
540 }
541
542 var feedctr = document.getElementById("FEEDCTR-" + id);
543 var feedu = document.getElementById("FEEDU-" + id);
544 var feedr = document.getElementById("FEEDR-" + id);
545 var feed_img = document.getElementById("FIMG-" + id);
546 var feedlink = document.getElementById("FEEDL-" + id);
547 var feedupd = document.getElementById("FLUPD-" + id);
548
549 if (updated && feedlink) {
550 if (error) {
551 feedlink.title = "Error: " + error + " (" + updated + ")";
552 } else {
553 feedlink.title = "Updated: " + updated;
554 }
555 }
556
557 if (updated && feedupd) {
558 if (error) {
559 feedupd.innerHTML = updated + " (Error)";
560 } else {
561 feedupd.innerHTML = updated;
562 }
563 }
564
565 if (feedctr && feedu && feedr) {
566
567 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
568 viewCurrentFeed();
569 }
570
571 feedu.innerHTML = ctr;
572
573 if (error) {
574 feedr.className = feedr.className.replace("feed", "error");
575 } else if (id > 0) {
576 feedr.className = feedr.className.replace("error", "feed");
577 }
578
579 if (ctr > 0) {
580 feedctr.className = "odd";
581 if (!feedr.className.match("Unread")) {
582 var is_selected = feedr.className.match("Selected");
583
584 feedr.className = feedr.className.replace("Selected", "");
585 feedr.className = feedr.className.replace("Unread", "");
586
587 feedr.className = feedr.className + "Unread";
588
589 if (is_selected) {
590 feedr.className = feedr.className + "Selected";
591 }
592
593 }
594 } else {
595 feedctr.className = "invisible";
596 feedr.className = feedr.className.replace("Unread", "");
597 }
598 }
599 }
600
601 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
602
603 var feeds_stored = number_of_feeds;
604
605 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
606
607 if (feeds_stored != feeds_found) {
608 number_of_feeds = feeds_found;
609
610 if (feeds_stored != 0) {
611 debug("Subscribed feed number changed, refreshing feedlist");
612 setTimeout('updateFeedList(false, false)', 50);
613 }
614 }
615
616 } catch (e) {
617 exception_error("parse_counters", e);
618 }
619 }
620
621 function parse_counters_reply(xmlhttp, scheduled_call) {
622
623 if (!xmlhttp.responseXML) {
624 notify("refetch_callback: backend did not return valid XML", true, true);
625 return;
626 }
627
628 var reply = xmlhttp.responseXML.firstChild;
629
630 if (!reply) {
631 notify("refetch_callback: backend did not return expected XML object", true, true);
632 updateTitle("");
633 return;
634 }
635
636 var error_code = false;
637 var error_msg = false;
638
639 if (reply.firstChild) {
640 error_code = reply.firstChild.getAttribute("error-code");
641 error_msg = reply.firstChild.getAttribute("error-msg");
642 }
643
644 if (!error_code) {
645 error_code = reply.getAttribute("error-code");
646 error_msg = reply.getAttribute("error-msg");
647 }
648
649 if (error_code && error_code != 0) {
650 debug("refetch_callback: got error code " + error_code);
651 return fatalError(error_code, error_msg);
652 }
653
654 var counters = reply.firstChild;
655
656 parse_counters(counters, scheduled_call);
657
658 var runtime_info = counters.nextSibling;
659
660 parse_runtime_info(runtime_info);
661
662 if (getInitParam("feeds_sort_by_unread") == 1) {
663 resort_feedlist();
664 }
665
666 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
667
668 }
669
670 function all_counters_callback() {
671 if (xmlhttp_rpc.readyState == 4) {
672 try {
673 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
674 debug("[all_counters_callback] backend did not return valid XML");
675 return;
676 }
677
678 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
679
680 var reply = xmlhttp_rpc.responseXML.firstChild;
681
682 var counters = reply.firstChild;
683
684 parse_counters(counters);
685
686 var runtime = counters.nextSibling;
687
688 if (runtime) {
689 parse_runtime_info(runtime);
690 }
691
692 if (getInitParam("feeds_sort_by_unread") == 1) {
693 resort_feedlist();
694 }
695
696 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
697
698 debug("in all_counters_callback");
699
700 parse_counters_reply(xmlhttp_rpc);
701
702 } catch (e) {
703 exception_error("all_counters_callback", e);
704 }
705 }
706 }
707
708 function get_feed_entry_unread(doc, elem) {
709
710 var id = elem.id.replace("FEEDR-", "");
711
712 if (id <= 0) {
713 return -1;
714 }
715
716 try {
717 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
718 } catch (e) {
719 return -1;
720 }
721 }
722
723 function resort_category(doc, node) {
724 debug("resort_category: " + node);
725
726 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
727 for (i = 0; i < node.childNodes.length; i++) {
728 if (node.childNodes[i].nodeName != "LI") { continue; }
729
730 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
731 continue;
732 }
733
734 for (j = i+1; j < node.childNodes.length; j++) {
735 if (node.childNodes[j].nodeName != "LI") { continue; }
736
737 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
738 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
739
740 if (cur_val > tmp_val) {
741 tempnode_i = node.childNodes[i].cloneNode(true);
742 tempnode_j = node.childNodes[j].cloneNode(true);
743 node.replaceChild(tempnode_i, node.childNodes[j]);
744 node.replaceChild(tempnode_j, node.childNodes[i]);
745 }
746 }
747
748 }
749 }
750
751 }
752
753 function resort_feedlist() {
754 debug("resort_feedlist");
755
756 var fd = document;
757
758 if (fd.getElementById("feedCatHolder")) {
759
760 var feeds = fd.getElementById("feedList");
761 var child = feeds.firstChild;
762
763 while (child) {
764
765 if (child.id == "feedCatHolder") {
766 resort_category(fd, child.firstChild);
767 }
768
769 child = child.nextSibling;
770 }
771
772 } else {
773 resort_category(fd, fd.getElementById("feedList"));
774 }
775 }
776
777 function update_all_counters(feed) {
778 if (xmlhttp_ready(xmlhttp_rpc)) {
779 var query = "backend.php?op=rpc&subop=getAllCounters";
780
781 if (feed > 0) {
782 query = query + "&aid=" + feed;
783 }
784
785 xmlhttp_rpc.open("GET", query, true);
786 xmlhttp_rpc.onreadystatechange=all_counters_callback;
787 xmlhttp_rpc.send(null);
788 }
789 }
790
791 function popupHelp(tid) {
792 var w = window.open("backend.php?op=help&tid=" + tid,
793 "Popup Help",
794 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
795 }
796
797 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
798 * * @author Sundar Dorai-Raj
799 * * Email: sdoraira@vt.edu
800 * * This program is free software; you can redistribute it and/or
801 * * modify it under the terms of the GNU General Public License
802 * * as published by the Free Software Foundation; either version 2
803 * * of the License, or (at your option) any later version,
804 * * provided that any use properly credits the author.
805 * * This program is distributed in the hope that it will be useful,
806 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
807 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
808 * * GNU General Public License for more details at http://www.gnu.org * * */
809
810 var numbers=".0123456789";
811 function isNumeric(x) {
812 // is x a String or a character?
813 if(x.length>1) {
814 // remove negative sign
815 x=Math.abs(x)+"";
816 for(j=0;j<x.length;j++) {
817 // call isNumeric recursively for each character
818 number=isNumeric(x.substring(j,j+1));
819 if(!number) return number;
820 }
821 return number;
822 }
823 else {
824 // if x is number return true
825 if(numbers.indexOf(x)>=0) return true;
826 return false;
827 }
828 }
829
830
831 function hideOrShowFeeds(doc, hide) {
832
833 debug("hideOrShowFeeds: " + doc + ", " + hide);
834
835 var fd = document;
836
837 var list = fd.getElementById("feedList");
838
839 if (fd.getElementById("feedCatHolder")) {
840
841 var feeds = fd.getElementById("feedList");
842 var child = feeds.firstChild;
843
844 while (child) {
845
846 if (child.id == "feedCatHolder") {
847 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
848 }
849
850 child = child.nextSibling;
851 }
852
853 } else {
854 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
855 }
856 }
857
858 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
859
860 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
861
862 var cat_unread = 0;
863
864 if (!node) {
865 debug("hideOrShowFeeds: passed node is null, aborting");
866 return;
867 }
868
869 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
870 for (i = 0; i < node.childNodes.length; i++) {
871 if (node.childNodes[i].nodeName != "LI") { continue; }
872
873 if (node.childNodes[i].style != undefined) {
874
875 var has_unread = (node.childNodes[i].className != "feed");
876
877 // debug(node.childNodes[i].id + " --> " + has_unread);
878
879 if (hide && !has_unread) {
880 node.childNodes[i].style.display = "none";
881 }
882
883 if (!hide) {
884 node.childNodes[i].style.display = "list-item";
885 }
886
887 if (has_unread) {
888 node.childNodes[i].style.display = "list-item";
889 cat_unread++;
890 }
891 }
892 }
893 }
894
895 if (cat_unread == 0) {
896 if (cat_node.style == undefined) {
897 debug("ERROR: supplied cat_node " + cat_node +
898 " has no styles. WTF?");
899 return;
900 }
901 if (hide) {
902 cat_node.style.display = "none";
903 } else {
904 cat_node.style.display = "list-item";
905 }
906 } else {
907 try {
908 cat_node.style.display = "list-item";
909 } catch (e) {
910 debug(e);
911 }
912 }
913
914 // debug("unread for category: " + cat_unread);
915 }
916
917 function selectTableRow(r, do_select) {
918 r.className = r.className.replace("Selected", "");
919
920 if (do_select) {
921 r.className = r.className + "Selected";
922 }
923 }
924
925 function selectTableRowById(elem_id, check_id, do_select) {
926
927 try {
928
929 var row = document.getElementById(elem_id);
930
931 if (row) {
932 selectTableRow(row, do_select);
933 }
934
935 var check = document.getElementById(check_id);
936
937 if (check) {
938 check.checked = do_select;
939 }
940 } catch (e) {
941 exception_error("selectTableRowById", e);
942 }
943 }
944
945 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
946 classcheck, reset_others) {
947
948 var content = document.getElementById(content_id);
949
950 if (!content) {
951 alert("[selectTableRows] Element " + content_id + " not found.");
952 return;
953 }
954
955 for (i = 0; i < content.rows.length; i++) {
956 if (!classcheck || content.rows[i].className.match(classcheck)) {
957
958 if (content.rows[i].id.match(prefix)) {
959 selectTableRow(content.rows[i], do_select);
960
961 var row_id = content.rows[i].id.replace(prefix, "");
962 var check = document.getElementById(check_prefix + row_id);
963
964 if (check) {
965 check.checked = do_select;
966 }
967 } else if (reset_others) {
968 selectTableRow(content.rows[i], false);
969
970 var row_id = content.rows[i].id.replace(prefix, "");
971 var check = document.getElementById(check_prefix + row_id);
972
973 if (check) {
974 check.checked = false;
975 }
976
977 }
978 } else if (reset_others) {
979 selectTableRow(content.rows[i], false);
980
981 var row_id = content.rows[i].id.replace(prefix, "");
982 var check = document.getElementById(check_prefix + row_id);
983
984 if (check) {
985 check.checked = false;
986 }
987
988 }
989 }
990 }
991
992 function getSelectedTableRowIds(content_id, prefix) {
993
994 var content = document.getElementById(content_id);
995
996 if (!content) {
997 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
998 return;
999 }
1000
1001 var sel_rows = new Array();
1002
1003 for (i = 0; i < content.rows.length; i++) {
1004 if (content.rows[i].id.match(prefix) &&
1005 content.rows[i].className.match("Selected")) {
1006
1007 var row_id = content.rows[i].id.replace(prefix + "-", "");
1008 sel_rows.push(row_id);
1009 }
1010 }
1011
1012 return sel_rows;
1013
1014 }
1015
1016 function toggleSelectRowById(sender, id) {
1017 var row = document.getElementById(id);
1018
1019 if (sender.checked) {
1020 if (!row.className.match("Selected")) {
1021 row.className = row.className + "Selected";
1022 }
1023 } else {
1024 if (row.className.match("Selected")) {
1025 row.className = row.className.replace("Selected", "");
1026 }
1027 }
1028 }
1029
1030 function toggleSelectListRow(sender) {
1031 var parent_row = sender.parentNode;
1032
1033 if (sender.checked) {
1034 if (!parent_row.className.match("Selected")) {
1035 parent_row.className = parent_row.className + "Selected";
1036 }
1037 } else {
1038 if (parent_row.className.match("Selected")) {
1039 parent_row.className = parent_row.className.replace("Selected", "");
1040 }
1041 }
1042 }
1043
1044
1045 function toggleSelectRow(sender) {
1046 var parent_row = sender.parentNode.parentNode;
1047
1048 if (sender.checked) {
1049 if (!parent_row.className.match("Selected")) {
1050 parent_row.className = parent_row.className + "Selected";
1051 }
1052 } else {
1053 if (parent_row.className.match("Selected")) {
1054 parent_row.className = parent_row.className.replace("Selected", "");
1055 }
1056 }
1057 }
1058
1059 function openExternalUrl(url) {
1060 var w = window.open(url);
1061 }
1062
1063 function getRelativeFeedId(list, id, direction, unread_only) {
1064 if (!id) {
1065 if (direction == "next") {
1066 for (i = 0; i < list.childNodes.length; i++) {
1067 var child = list.childNodes[i];
1068 if (child.id && child.id == "feedCatHolder") {
1069 if (child.lastChild) {
1070 var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only);
1071 if (cr) return cr;
1072 }
1073 } else if (child.id && child.id.match("FEEDR-")) {
1074 return child.id.replace('FEEDR-', '');
1075 }
1076 }
1077 }
1078
1079 // FIXME select last feed doesn't work when only unread feeds are visible
1080
1081 if (direction == "prev") {
1082 for (i = list.childNodes.length-1; i >= 0; i--) {
1083 var child = list.childNodes[i];
1084 if (child.id == "feedCatHolder") {
1085 if (child.firstChild) {
1086 var cr = getRelativeFeedId(child.firstChild, id, direction);
1087 if (cr) return cr;
1088 }
1089 } else if (child.id.match("FEEDR-")) {
1090
1091 if (getInitParam("hide_read_feeds") == 1) {
1092 if (child.className != "feed") {
1093 alert(child.className);
1094 return child.id.replace('FEEDR-', '');
1095 }
1096 } else {
1097 return child.id.replace('FEEDR-', '');
1098 }
1099 }
1100 }
1101 }
1102 } else {
1103
1104 var feed = list.ownerDocument.getElementById("FEEDR-" + id);
1105
1106 if (getInitParam("hide_read_feeds") == 1) {
1107 unread_only = true;
1108 }
1109
1110 if (direction == "next") {
1111
1112 var e = feed;
1113
1114 while (e) {
1115
1116 if (e.nextSibling) {
1117
1118 e = e.nextSibling;
1119
1120 } else if (e.parentNode.parentNode.nextSibling) {
1121
1122 var this_cat = e.parentNode.parentNode;
1123
1124 e = false;
1125
1126 if (this_cat && this_cat.nextSibling) {
1127 while (!e && this_cat.nextSibling) {
1128 this_cat = this_cat.nextSibling;
1129 if (this_cat.id == "feedCatHolder") {
1130 e = this_cat.firstChild.firstChild;
1131 }
1132 }
1133 }
1134
1135 } else {
1136 e = false;
1137 }
1138
1139 if (e) {
1140 if (!unread_only || (unread_only && e.className != "feed" &&
1141 e.className.match("feed"))) {
1142 return e.id.replace("FEEDR-", "");
1143 }
1144 }
1145 }
1146
1147 } else if (direction == "prev") {
1148
1149 var e = feed;
1150
1151 while (e) {
1152
1153 if (e.previousSibling) {
1154
1155 e = e.previousSibling;
1156
1157 } else if (e.parentNode.parentNode.previousSibling) {
1158
1159 var this_cat = e.parentNode.parentNode;
1160
1161 e = false;
1162
1163 if (this_cat && this_cat.previousSibling) {
1164 while (!e && this_cat.previousSibling) {
1165 this_cat = this_cat.previousSibling;
1166 if (this_cat.id == "feedCatHolder") {
1167 e = this_cat.firstChild.lastChild;
1168 }
1169 }
1170 }
1171
1172 } else {
1173 e = false;
1174 }
1175
1176 if (e) {
1177 if (!unread_only || (unread_only && e.className != "feed" &&
1178 e.className.match("feed"))) {
1179 return e.id.replace("FEEDR-", "");
1180 }
1181 }
1182 }
1183 }
1184 }
1185 }
1186
1187 function showBlockElement(id) {
1188 var elem = document.getElementById(id);
1189
1190 if (elem) {
1191 elem.style.display = "block";
1192 } else {
1193 alert("[showBlockElement] can't find element with id " + id);
1194 }
1195 }
1196
1197 function hideParentElement(e) {
1198 e.parentNode.style.display = "none";
1199 }
1200
1201 function dropboxSelect(e, v) {
1202 for (i = 0; i < e.length; i++) {
1203 if (e[i].value == v) {
1204 e.selectedIndex = i;
1205 break;
1206 }
1207 }
1208 }
1209
1210 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1211 // bugfixed just a little bit :-)
1212 function getURLParam(strParamName){
1213 var strReturn = "";
1214 var strHref = window.location.href;
1215
1216 if (strHref.indexOf("#") == strHref.length-1) {
1217 strHref = strHref.substring(0, strHref.length-1);
1218 }
1219
1220 if ( strHref.indexOf("?") > -1 ){
1221 var strQueryString = strHref.substr(strHref.indexOf("?"));
1222 var aQueryString = strQueryString.split("&");
1223 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1224 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1225 var aParam = aQueryString[iParam].split("=");
1226 strReturn = aParam[1];
1227 break;
1228 }
1229 }
1230 }
1231 return strReturn;
1232 }
1233
1234 function leading_zero(p) {
1235 var s = String(p);
1236 if (s.length == 1) s = "0" + s;
1237 return s;
1238 }
1239
1240 function closeInfoBox(cleanup) {
1241 var box = document.getElementById('infoBox');
1242 var shadow = document.getElementById('infoBoxShadow');
1243
1244 if (shadow) {
1245 shadow.style.display = "none";
1246 } else if (box) {
1247 box.style.display = "none";
1248 }
1249
1250 if (cleanup) box.innerHTML = "&nbsp;";
1251
1252 enableHotkeys();
1253
1254 return false;
1255 }
1256
1257
1258 function displayDlg(id, param) {
1259
1260 if (!xmlhttp_ready(xmlhttp)) {
1261 printLockingError();
1262 return
1263 }
1264
1265 notify("");
1266
1267 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1268 param_escape(id) + "&param=" + param_escape(param), true);
1269 xmlhttp.onreadystatechange=infobox_callback;
1270 xmlhttp.send(null);
1271
1272 disableHotkeys();
1273
1274 return false;
1275 }
1276
1277 function infobox_submit_callback() {
1278 if (xmlhttp.readyState == 4) {
1279 closeInfoBox();
1280
1281 try {
1282 // called from prefs, reload tab
1283 if (active_tab) {
1284 selectTab(active_tab, false);
1285 }
1286 } catch (e) { }
1287
1288 notify(xmlhttp.responseText);
1289
1290 }
1291 }
1292
1293 function infobox_callback() {
1294 if (xmlhttp.readyState == 4) {
1295 var box = document.getElementById('infoBox');
1296 var shadow = document.getElementById('infoBoxShadow');
1297 if (box) {
1298 box.innerHTML=xmlhttp.responseText;
1299 if (shadow) {
1300 shadow.style.display = "block";
1301 } else {
1302 box.style.display = "block";
1303 }
1304 }
1305 notify("");
1306 }
1307 }
1308
1309 function qaddFilter() {
1310
1311 if (!xmlhttp_ready(xmlhttp)) {
1312 printLockingError();
1313 return
1314 }
1315
1316 var form = document.forms['filter_add_form'];
1317 var reg_exp = form.reg_exp.value;
1318
1319 if (reg_exp == "") {
1320 alert("Can't add filter: nothing to match on.");
1321 return false;
1322 }
1323
1324 var query = Form.serialize("filter_add_form");
1325
1326 xmlhttp.open("GET", "backend.php?" + query, true);
1327 xmlhttp.onreadystatechange=infobox_submit_callback;
1328 xmlhttp.send(null);
1329
1330 return true;
1331 }
1332
1333 function toggleSubmitNotEmpty(e, submit_id) {
1334 try {
1335 document.getElementById(submit_id).disabled = (e.value == "")
1336 } catch (e) {
1337 exception_error("toggleSubmitNotEmpty", e);
1338 }
1339 }
1340
1341 function isValidURL(s) {
1342 return s.match("http://") != null || s.match("https://") != null;
1343 }
1344
1345 function qafAdd() {
1346
1347 if (!xmlhttp_ready(xmlhttp)) {
1348 printLockingError();
1349 return
1350 }
1351
1352 var form = document.forms['feed_add_form'];
1353 var feed_url = form.feed_url.value;
1354
1355 if (feed_url == "") {
1356 alert("Can't subscribe: no feed URL given.");
1357 return false;
1358 }
1359
1360 notify("Adding feed...", true);
1361
1362 closeInfoBox();
1363
1364 var feeds_doc = document;
1365
1366 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1367
1368 var query = Form.serialize("feed_add_form");
1369
1370 xmlhttp.open("GET", "backend.php?" + query, true);
1371 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1372 xmlhttp.send(null);
1373
1374 return false;
1375 }
1376
1377 function filterCR(e, f)
1378 {
1379 var key;
1380
1381 if(window.event)
1382 key = window.event.keyCode; //IE
1383 else
1384 key = e.which; //firefox
1385
1386 if (key == 13) {
1387 if (typeof f != 'undefined') {
1388 f();
1389 return false;
1390 } else {
1391 return false;
1392 }
1393 } else {
1394 return true;
1395 }
1396 }
1397
1398 function getMainContext() {
1399 return this.window;
1400 }
1401
1402 function getFeedsContext() {
1403 return this.window;
1404 }
1405
1406 function getContentContext() {
1407 return this.window;
1408 }
1409
1410 function getHeadlinesContext() {
1411 return this.window;
1412 }
1413
1414 var debug_last_class = "even";
1415
1416 function debug(msg) {
1417
1418 if (debug_last_class == "even") {
1419 debug_last_class = "odd";
1420 } else {
1421 debug_last_class = "even";
1422 }
1423
1424 var c = document.getElementById('debug_output');
1425 if (c && c.style.display == "block") {
1426 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1427 c.removeChild(c.lastChild);
1428 }
1429
1430 var d = new Date();
1431 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1432 ":" + leading_zero(d.getSeconds());
1433 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1434 msg + "</li>" + c.innerHTML;
1435 }
1436 }
1437
1438 function getInitParam(key) {
1439 return getMainContext().init_params[key];
1440 }
1441
1442 function storeInitParam(key, value, is_client) {
1443 try {
1444 if (!is_client) {
1445 if (getMainContext().init_params[key] != value) {
1446 debug("storeInitParam: " + key + " => " + value);
1447 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1448 // param_escape(key) + "&value=" + param_escape(value));
1449 var f = getMainContext().document.getElementById("backReqBox");
1450 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1451 param_escape(key) + "&value=" + param_escape(value);
1452 }
1453 }
1454 getMainContext().init_params[key] = value;
1455 } catch (e) {
1456 exception_error("storeInitParam", e);
1457 }
1458 }
1459
1460 /*
1461 function storeInitParams(params, is_client) {
1462 try {
1463 var s = "";
1464
1465 for (k in params) {
1466 if (getMainContext().init_params[k] != params[k]) {
1467 s += k + "=" + params[k] + ";";
1468 getMainContext().init_params[k] = params[k];
1469 }
1470 }
1471
1472 debug("storeInitParams: " + s);
1473
1474 if (!is_client) {
1475 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1476 }
1477 } catch (e) {
1478 exception_error("storeInitParams", e);
1479 }
1480 }*/
1481
1482 function fatalError(code, message) {
1483 try {
1484
1485 if (code != 6) {
1486
1487 var fe = document.getElementById("fatal_error");
1488 var fc = document.getElementById("fatal_error_msg");
1489
1490 fc.innerHTML = "Code " + code + ": " + message;
1491
1492 fe.style.display = "block";
1493 } else {
1494 window.location.href = "login.php?rt=none";
1495 }
1496
1497 } catch (e) {
1498 exception_error("fatalError", e);
1499 }
1500 }
1501
1502 function getFeedName(id, is_cat) {
1503 var d = getFeedsContext().document;
1504
1505 var e;
1506
1507 if (is_cat) {
1508 e = d.getElementById("FCATN-" + id);
1509 } else {
1510 e = d.getElementById("FEEDN-" + id);
1511 }
1512 if (e) {
1513 return e.innerHTML.stripTags();
1514 } else {
1515 return null;
1516 }
1517 }
1518
1519 function viewContentUrl(url) {
1520 getContentContext().location = url;
1521 }