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