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