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