]> git.wh0rd.org - tt-rss.git/blob - functions.js
fix name display in catchup prompt in category view mode
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2
3 var xmlhttp_rpc = Ajax.getTransport();
4
5 function browser_has_opacity() {
6 return navigator.userAgent.match("Gecko") != null ||
7 navigator.userAgent.match("Opera") != null;
8 }
9
10 function exception_error(location, e, 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
31 function disableHotkeys() {
32 hotkeys_enabled = false;
33 }
34
35 function enableHotkeys() {
36 hotkeys_enabled = true;
37 }
38
39 function xmlhttp_ready(obj) {
40 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
41 }
42
43 function notify_callback() {
44 var container = document.getElementById('notify');
45 if (xmlhttp.readyState == 4) {
46 container.innerHTML=xmlhttp.responseText;
47 }
48 }
49
50 function rpc_notify_callback() {
51 var container = document.getElementById('notify');
52 if (xmlhttp_rpc.readyState == 4) {
53 container.innerHTML=xmlhttp_rpc.responseText;
54 }
55 }
56
57 function param_escape(arg) {
58 if (typeof encodeURIComponent != 'undefined')
59 return encodeURIComponent(arg);
60 else
61 return escape(arg);
62 }
63
64 function param_unescape(arg) {
65 if (typeof decodeURIComponent != 'undefined')
66 return decodeURIComponent(arg);
67 else
68 return unescape(arg);
69 }
70
71 function 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
80 var notify_hide_timerid = false;
81 var notify_last_doc = false;
82
83 var notify_effect = false;
84
85 function 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
103 function 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
143 function p_notify(msg, no_hide, is_err) {
144 notify_real(msg, parent.document, no_hide, is_err);
145 }
146
147 function notify(msg, no_hide, is_err) {
148 notify_real(msg, document, no_hide, is_err);
149 }
150
151 function printLockingError() {
152 notify("Please wait until operation finishes");}
153
154 var seq = "";
155
156 function 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(), 0, "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, 0, '');
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, 0, '');
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
243 function 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
271 function 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
279 function 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
293 function 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
308 function getFirstVisibleHeadlineId() {
309 var rows = getVisibleHeadlineIds();
310 return rows[0];
311 }
312
313 function getLastVisibleHeadlineId() {
314 var rows = getVisibleHeadlineIds();
315 return rows[rows.length-1];
316 }
317
318 function 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
345 function 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
360 function 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
373 function 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
381 function 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
391 function 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
410 function 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
443 function gotoPreferences() {
444 document.location.href = "prefs.php";
445 }
446
447 function gotoMain() {
448 document.location.href = "tt-rss.php";
449 }
450
451 function gotoExportOpml() {
452 document.location.href = "opml.php?op=Export";
453 }
454
455 function 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
465 function activeFeedIsCat() {
466 return getMainContext().active_feed_is_cat;
467 }
468
469 function setActiveFeedId(id) {
470 // return setCookie("ttrss_vf_actfeed", id);
471 try {
472 getMainContext().active_feed_id = id;
473 } catch (e) {
474 exception_error("setActiveFeedId", e);
475 }
476 }
477
478 function parse_counters(reply, scheduled_call) {
479 try {
480 var f_document = getFeedsContext().document;
481 var title_obj = getMainContext();
482
483 if (reply.firstChild && reply.firstChild.firstChild) {
484 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
485 reply = reply.firstChild;
486 }
487
488 debug("F_DOC: " + f_document + ", T_OBJ: " + title_obj);
489
490 for (var l = 0; l < reply.childNodes.length; l++) {
491 if (!reply.childNodes[l] ||
492 typeof(reply.childNodes[l].getAttribute) == "undefined") {
493 // where did this come from?
494 continue;
495 }
496
497 var id = reply.childNodes[l].getAttribute("id");
498 var t = reply.childNodes[l].getAttribute("type");
499 var ctr = reply.childNodes[l].getAttribute("counter");
500 var error = reply.childNodes[l].getAttribute("error");
501 var has_img = reply.childNodes[l].getAttribute("hi");
502 var updated = reply.childNodes[l].getAttribute("updated");
503
504 if (id == "global-unread") {
505 title_obj.global_unread = ctr;
506 title_obj.updateTitle();
507 continue;
508 }
509
510 if (t == "category") {
511 var catctr = f_document.getElementById("FCATCTR-" + id);
512 if (catctr) {
513 catctr.innerHTML = "(" + ctr + " unread)";
514 }
515 continue;
516 }
517
518 var feedctr = f_document.getElementById("FEEDCTR-" + id);
519 var feedu = f_document.getElementById("FEEDU-" + id);
520 var feedr = f_document.getElementById("FEEDR-" + id);
521 var feed_img = f_document.getElementById("FIMG-" + id);
522 var feedlink = f_document.getElementById("FEEDL-" + id);
523 var feedupd = f_document.getElementById("FLUPD-" + id);
524
525 if (updated && feedlink) {
526 if (error) {
527 feedlink.title = "Error: " + error + " (" + updated + ")";
528 } else {
529 feedlink.title = "Updated: " + updated;
530 }
531 }
532
533 if (updated && feedupd) {
534 if (error) {
535 feedupd.innerHTML = updated + " (Error)";
536 } else {
537 feedupd.innerHTML = updated;
538 }
539 }
540
541 if (feedctr && feedu && feedr) {
542
543 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
544 var hf = title_obj.parent.frames["headlines-frame"];
545 hf.location.reload(true);
546 }
547
548 feedu.innerHTML = ctr;
549
550 if (error) {
551 feedr.className = feedr.className.replace("feed", "error");
552 } else if (id > 0) {
553 feedr.className = feedr.className.replace("error", "feed");
554 }
555
556 if (ctr > 0) {
557 feedctr.className = "odd";
558 if (!feedr.className.match("Unread")) {
559 var is_selected = feedr.className.match("Selected");
560
561 feedr.className = feedr.className.replace("Selected", "");
562 feedr.className = feedr.className.replace("Unread", "");
563
564 feedr.className = feedr.className + "Unread";
565
566 if (is_selected) {
567 feedr.className = feedr.className + "Selected";
568 }
569
570 }
571 } else {
572 feedctr.className = "invisible";
573 feedr.className = feedr.className.replace("Unread", "");
574 }
575 }
576 }
577 } catch (e) {
578 exception_error("parse_counters", e);
579 }
580 }
581
582 function all_counters_callback() {
583 if (xmlhttp_rpc.readyState == 4) {
584 try {
585 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
586 debug("[all_counters_callback] backend did not return valid XML");
587 return;
588 }
589
590 debug("in all_counters_callback");
591
592 var reply = xmlhttp_rpc.responseXML.firstChild;
593
594 var counters = reply.firstChild;
595
596 parse_counters(counters);
597
598 var runtime = counters.nextSibling;
599
600 if (runtime) {
601 getMainContext().parse_runtime_info(runtime);
602 }
603
604 if (getInitParam("feeds_sort_by_unread") == 1) {
605 resort_feedlist();
606 }
607
608 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
609
610 } catch (e) {
611 exception_error("all_counters_callback", e);
612 }
613 }
614 }
615
616 function get_feed_entry_unread(doc, elem) {
617
618 var id = elem.id.replace("FEEDR-", "");
619
620 if (id <= 0) {
621 return -1;
622 }
623
624 try {
625 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
626 } catch (e) {
627 return -1;
628 }
629 }
630
631 function resort_category(doc, node) {
632 debug("resort_category: " + node);
633
634 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
635 for (i = 0; i < node.childNodes.length; i++) {
636 if (node.childNodes[i].nodeName != "LI") { continue; }
637
638 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
639 continue;
640 }
641
642 for (j = i+1; j < node.childNodes.length; j++) {
643 if (node.childNodes[j].nodeName != "LI") { continue; }
644
645 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
646 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
647
648 if (cur_val > tmp_val) {
649 tempnode_i = node.childNodes[i].cloneNode(true);
650 tempnode_j = node.childNodes[j].cloneNode(true);
651 node.replaceChild(tempnode_i, node.childNodes[j]);
652 node.replaceChild(tempnode_j, node.childNodes[i]);
653 }
654 }
655
656 }
657 }
658
659 }
660
661 function resort_feedlist() {
662 debug("resort_feedlist");
663
664 var fd = getFeedsContext().document;
665
666 if (fd.getElementById("feedCatHolder")) {
667
668 var feeds = fd.getElementById("feedList");
669 var child = feeds.firstChild;
670
671 while (child) {
672
673 if (child.id == "feedCatHolder") {
674 resort_category(fd, child.firstChild);
675 }
676
677 child = child.nextSibling;
678 }
679
680 } else {
681 resort_category(fd, fd.getElementById("feedList"));
682 }
683 }
684
685 function update_all_counters(feed) {
686 if (xmlhttp_ready(xmlhttp_rpc)) {
687 var query = "backend.php?op=rpc&subop=getAllCounters";
688
689 if (feed > 0) {
690 query = query + "&aid=" + feed;
691 }
692
693 xmlhttp_rpc.open("GET", query, true);
694 xmlhttp_rpc.onreadystatechange=all_counters_callback;
695 xmlhttp_rpc.send(null);
696 }
697 }
698
699 function popupHelp(tid) {
700 var w = window.open("backend.php?op=help&tid=" + tid,
701 "Popup Help",
702 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
703 }
704
705 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
706 * * @author Sundar Dorai-Raj
707 * * Email: sdoraira@vt.edu
708 * * This program is free software; you can redistribute it and/or
709 * * modify it under the terms of the GNU General Public License
710 * * as published by the Free Software Foundation; either version 2
711 * * of the License, or (at your option) any later version,
712 * * provided that any use properly credits the author.
713 * * This program is distributed in the hope that it will be useful,
714 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
715 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
716 * * GNU General Public License for more details at http://www.gnu.org * * */
717
718 var numbers=".0123456789";
719 function isNumeric(x) {
720 // is x a String or a character?
721 if(x.length>1) {
722 // remove negative sign
723 x=Math.abs(x)+"";
724 for(j=0;j<x.length;j++) {
725 // call isNumeric recursively for each character
726 number=isNumeric(x.substring(j,j+1));
727 if(!number) return number;
728 }
729 return number;
730 }
731 else {
732 // if x is number return true
733 if(numbers.indexOf(x)>=0) return true;
734 return false;
735 }
736 }
737
738
739 function hideOrShowFeeds(doc, hide) {
740
741 var fd = getFeedsContext().document;
742
743 var list = fd.getElementById("feedList");
744
745 if (fd.getElementById("feedCatHolder")) {
746
747 var feeds = fd.getElementById("feedList");
748 var child = feeds.firstChild;
749
750 while (child) {
751
752 if (child.id == "feedCatHolder") {
753 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
754 }
755
756 child = child.nextSibling;
757 }
758
759 } else {
760 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
761 }
762 }
763
764 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
765
766 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
767
768 var cat_unread = 0;
769
770 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
771 for (i = 0; i < node.childNodes.length; i++) {
772 if (node.childNodes[i].nodeName != "LI") { continue; }
773
774 var has_unread = (node.childNodes[i].className != "feed");
775
776 // debug(node.childNodes[i].id + " --> " + has_unread);
777
778 if (hide && !has_unread) {
779 node.childNodes[i].style.display = "none";
780 }
781
782 if (!hide) {
783 node.childNodes[i].style.display = "list-item";
784 }
785
786 if (has_unread) {
787 cat_unread++;
788 }
789
790 }
791 }
792
793 if (cat_unread == 0) {
794 if (hide) {
795 cat_node.style.display = "none";
796 } else {
797 cat_node.style.display = "list-item";
798 }
799 }
800
801 // debug("unread for category: " + cat_unread);
802 }
803
804 function selectTableRow(r, do_select) {
805 r.className = r.className.replace("Selected", "");
806
807 if (do_select) {
808 r.className = r.className + "Selected";
809 }
810 }
811
812 function selectTableRowById(elem_id, check_id, do_select) {
813
814 try {
815
816 var row = document.getElementById(elem_id);
817
818 if (row) {
819 selectTableRow(row, do_select);
820 }
821
822 var check = document.getElementById(check_id);
823
824 if (check) {
825 check.checked = do_select;
826 }
827 } catch (e) {
828 exception_error("selectTableRowById", e);
829 }
830 }
831
832 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
833 classcheck, reset_others) {
834
835 var content = document.getElementById(content_id);
836
837 if (!content) {
838 alert("[selectTableRows] Element " + content_id + " not found.");
839 return;
840 }
841
842 for (i = 0; i < content.rows.length; i++) {
843 if (!classcheck || content.rows[i].className.match(classcheck)) {
844
845 if (content.rows[i].id.match(prefix)) {
846 selectTableRow(content.rows[i], do_select);
847
848 var row_id = content.rows[i].id.replace(prefix, "");
849 var check = document.getElementById(check_prefix + row_id);
850
851 if (check) {
852 check.checked = do_select;
853 }
854 } else if (reset_others) {
855 selectTableRow(content.rows[i], false);
856
857 var row_id = content.rows[i].id.replace(prefix, "");
858 var check = document.getElementById(check_prefix + row_id);
859
860 if (check) {
861 check.checked = false;
862 }
863
864 }
865 } else if (reset_others) {
866 selectTableRow(content.rows[i], false);
867
868 var row_id = content.rows[i].id.replace(prefix, "");
869 var check = document.getElementById(check_prefix + row_id);
870
871 if (check) {
872 check.checked = false;
873 }
874
875 }
876 }
877 }
878
879 function getSelectedTableRowIds(content_id, prefix) {
880
881 var content = document.getElementById(content_id);
882
883 if (!content) {
884 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
885 return;
886 }
887
888 var sel_rows = new Array();
889
890 for (i = 0; i < content.rows.length; i++) {
891 if (content.rows[i].id.match(prefix) &&
892 content.rows[i].className.match("Selected")) {
893
894 var row_id = content.rows[i].id.replace(prefix + "-", "");
895 sel_rows.push(row_id);
896 }
897 }
898
899 return sel_rows;
900
901 }
902
903 function toggleSelectRowById(sender, id) {
904 var row = document.getElementById(id);
905
906 if (sender.checked) {
907 if (!row.className.match("Selected")) {
908 row.className = row.className + "Selected";
909 }
910 } else {
911 if (row.className.match("Selected")) {
912 row.className = row.className.replace("Selected", "");
913 }
914 }
915 }
916
917 function toggleSelectListRow(sender) {
918 var parent_row = sender.parentNode;
919
920 if (sender.checked) {
921 if (!parent_row.className.match("Selected")) {
922 parent_row.className = parent_row.className + "Selected";
923 }
924 } else {
925 if (parent_row.className.match("Selected")) {
926 parent_row.className = parent_row.className.replace("Selected", "");
927 }
928 }
929 }
930
931
932 function toggleSelectRow(sender) {
933 var parent_row = sender.parentNode.parentNode;
934
935 if (sender.checked) {
936 if (!parent_row.className.match("Selected")) {
937 parent_row.className = parent_row.className + "Selected";
938 }
939 } else {
940 if (parent_row.className.match("Selected")) {
941 parent_row.className = parent_row.className.replace("Selected", "");
942 }
943 }
944 }
945
946 function openExternalUrl(url) {
947 var w = window.open(url);
948 }
949
950 function getRelativeFeedId(list, id, direction, unread_only) {
951 if (!id) {
952 if (direction == "next") {
953 for (i = 0; i < list.childNodes.length; i++) {
954 var child = list.childNodes[i];
955 if (child.id && child.id == "feedCatHolder") {
956 if (child.lastChild) {
957 var cr = getRelativeFeedId(child.firstChild, id, direction);
958 if (cr) return cr;
959 }
960 } else if (child.id && child.id.match("FEEDR-")) {
961 return child.id.replace('FEEDR-', '');
962 }
963 }
964 }
965
966 // FIXME select last feed doesn't work when only unread feeds are visible
967
968 if (direction == "prev") {
969 for (i = list.childNodes.length-1; i >= 0; i--) {
970 var child = list.childNodes[i];
971 if (child.id == "feedCatHolder") {
972 if (child.firstChild) {
973 var cr = getRelativeFeedId(child.firstChild, id, direction);
974 if (cr) return cr;
975 }
976 } else if (child.id.match("FEEDR-")) {
977
978 if (getInitParam("hide_read_feeds") == 1) {
979 if (child.className != "feed") {
980 alert(child.className);
981 return child.id.replace('FEEDR-', '');
982 }
983 } else {
984 return child.id.replace('FEEDR-', '');
985 }
986 }
987 }
988 }
989 } else {
990
991 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
992
993 if (getInitParam("hide_read_feeds") == 1) {
994 unread_only = true;
995 }
996
997 if (direction == "next") {
998
999 var e = feed;
1000
1001 while (e) {
1002
1003 if (e.nextSibling) {
1004
1005 e = e.nextSibling;
1006
1007 } else if (e.parentNode.parentNode.nextSibling) {
1008
1009 var this_cat = e.parentNode.parentNode;
1010
1011 e = false;
1012
1013 if (this_cat && this_cat.nextSibling) {
1014 while (!e && this_cat.nextSibling) {
1015 this_cat = this_cat.nextSibling;
1016 if (this_cat.id == "feedCatHolder") {
1017 e = this_cat.firstChild.firstChild;
1018 }
1019 }
1020 }
1021
1022 } else {
1023 e = false;
1024 }
1025
1026 if (e) {
1027 if (!unread_only || (unread_only && e.className != "feed" &&
1028 e.className != "error")) {
1029 return e.id.replace("FEEDR-", "");
1030 }
1031 }
1032 }
1033
1034 } else if (direction == "prev") {
1035
1036 var e = feed;
1037
1038 while (e) {
1039
1040 if (e.previousSibling) {
1041
1042 e = e.previousSibling;
1043
1044 } else if (e.parentNode.parentNode.previousSibling) {
1045
1046 var this_cat = e.parentNode.parentNode;
1047
1048 e = false;
1049
1050 if (this_cat && this_cat.previousSibling) {
1051 while (!e && this_cat.previousSibling) {
1052 this_cat = this_cat.previousSibling;
1053 if (this_cat.id == "feedCatHolder") {
1054 e = this_cat.firstChild.lastChild;
1055 }
1056 }
1057 }
1058
1059 } else {
1060 e = false;
1061 }
1062
1063 if (e) {
1064 if (!unread_only || (unread_only && e.className != "feed" &&
1065 e.className != "error")) {
1066 return e.id.replace("FEEDR-", "");
1067 }
1068 }
1069 }
1070 }
1071 }
1072 }
1073
1074 function showBlockElement(id) {
1075 var elem = document.getElementById(id);
1076
1077 if (elem) {
1078 elem.style.display = "block";
1079 } else {
1080 alert("[showBlockElement] can't find element with id " + id);
1081 }
1082 }
1083
1084 function hideParentElement(e) {
1085 e.parentNode.style.display = "none";
1086 }
1087
1088 function dropboxSelect(e, v) {
1089 for (i = 0; i < e.length; i++) {
1090 if (e[i].value == v) {
1091 e.selectedIndex = i;
1092 break;
1093 }
1094 }
1095 }
1096
1097 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1098 // bugfixed just a little bit :-)
1099 function getURLParam(strParamName){
1100 var strReturn = "";
1101 var strHref = window.location.href;
1102
1103 if (strHref.indexOf("#") == strHref.length-1) {
1104 strHref = strHref.substring(0, strHref.length-1);
1105 }
1106
1107 if ( strHref.indexOf("?") > -1 ){
1108 var strQueryString = strHref.substr(strHref.indexOf("?"));
1109 var aQueryString = strQueryString.split("&");
1110 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1111 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1112 var aParam = aQueryString[iParam].split("=");
1113 strReturn = aParam[1];
1114 break;
1115 }
1116 }
1117 }
1118 return strReturn;
1119 }
1120
1121 function leading_zero(p) {
1122 var s = String(p);
1123 if (s.length == 1) s = "0" + s;
1124 return s;
1125 }
1126
1127 function closeInfoBox(cleanup) {
1128 var box = document.getElementById('infoBox');
1129 var shadow = document.getElementById('infoBoxShadow');
1130
1131 if (shadow) {
1132 shadow.style.display = "none";
1133 } else if (box) {
1134 box.style.display = "none";
1135 }
1136
1137 if (cleanup) box.innerHTML = "&nbsp;";
1138
1139 enableHotkeys();
1140
1141 return false;
1142 }
1143
1144
1145 function displayDlg(id, param) {
1146
1147 if (!xmlhttp_ready(xmlhttp)) {
1148 printLockingError();
1149 return
1150 }
1151
1152 notify("");
1153
1154 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1155 param_escape(id) + "&param=" + param_escape(param), true);
1156 xmlhttp.onreadystatechange=infobox_callback;
1157 xmlhttp.send(null);
1158
1159 disableHotkeys();
1160
1161 return false;
1162 }
1163
1164 function infobox_submit_callback() {
1165 if (xmlhttp.readyState == 4) {
1166 closeInfoBox();
1167
1168 // called from prefs, reload tab
1169 if (active_tab) {
1170 selectTab(active_tab, false);
1171 }
1172
1173 notify(xmlhttp.responseText);
1174
1175 }
1176 }
1177
1178 function infobox_callback() {
1179 if (xmlhttp.readyState == 4) {
1180 var box = document.getElementById('infoBox');
1181 var shadow = document.getElementById('infoBoxShadow');
1182 if (box) {
1183 box.innerHTML=xmlhttp.responseText;
1184 if (shadow) {
1185 shadow.style.display = "block";
1186 } else {
1187 box.style.display = "block";
1188 }
1189 }
1190 }
1191 }
1192
1193 function qaddFilter() {
1194
1195 if (!xmlhttp_ready(xmlhttp)) {
1196 printLockingError();
1197 return
1198 }
1199
1200 var query = Form.serialize("filter_add_form");
1201
1202 xmlhttp.open("GET", "backend.php?" + query, true);
1203 xmlhttp.onreadystatechange=infobox_submit_callback;
1204 xmlhttp.send(null);
1205
1206 return true;
1207 }
1208
1209 function toggleSubmitNotEmpty(e, submit_id) {
1210 try {
1211 document.getElementById(submit_id).disabled = (e.value == "")
1212 } catch (e) {
1213 exception_error("toggleSubmitNotEmpty", e);
1214 }
1215 }
1216
1217 function isValidURL(s) {
1218 return s.match("http://") != null || s.match("https://") != null;
1219 }
1220
1221 function qafAdd() {
1222
1223 if (!xmlhttp_ready(xmlhttp)) {
1224 printLockingError();
1225 return
1226 }
1227
1228 notify("Adding feed...");
1229
1230 closeInfoBox();
1231
1232 var feeds_doc = getFeedsContext().document;
1233
1234 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1235
1236 var query = Form.serialize("feed_add_form");
1237
1238 xmlhttp.open("GET", "backend.php?" + query, true);
1239 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1240 xmlhttp.send(null);
1241 }
1242
1243 function filterCR(e)
1244 {
1245 var key;
1246
1247 if(window.event)
1248 key = window.event.keyCode; //IE
1249 else
1250 key = e.which; //firefox
1251
1252 if(key == 13)
1253 return false;
1254 else
1255 return true;
1256 }
1257
1258 function getMainContext() {
1259 if (parent.window != window) {
1260 return parent.window;
1261 } else {
1262 return this.window;
1263 }
1264 }
1265
1266 function getFeedsContext() {
1267 try {
1268 return getMainContext().frames["feeds-frame"];
1269 } catch (e) {
1270 exception_error("getFeedsContext", e);
1271 }
1272 }
1273
1274
1275 function getHeadlinesContext() {
1276 try {
1277 return getMainContext().frames["headlines-frame"];
1278 } catch (e) {
1279 exception_error("getHeadlinesContext", e);
1280 }
1281 }
1282
1283 var debug_last_class = "even";
1284
1285 function debug(msg) {
1286 var ctx = getMainContext();
1287
1288 if (ctx.debug_last_class == "even") {
1289 ctx.debug_last_class = "odd";
1290 } else {
1291 ctx.debug_last_class = "even";
1292 }
1293
1294 var c = ctx.document.getElementById('debug_output');
1295 if (c && c.style.display == "block") {
1296 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1297 c.removeChild(c.lastChild);
1298 }
1299
1300 var d = new Date();
1301 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1302 ":" + leading_zero(d.getSeconds());
1303 c.innerHTML = "<li class=\"" + ctx.debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1304 msg + "</li>" + c.innerHTML;
1305 }
1306 }
1307
1308 function getInitParam(key) {
1309 return getMainContext().init_params[key];
1310 }
1311
1312 function storeInitParam(key, value, is_client) {
1313 try {
1314 if (!is_client) {
1315 if (getMainContext().init_params[key] != value) {
1316 debug("storeInitParam: " + key + " => " + value);
1317 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1318 // param_escape(key) + "&value=" + param_escape(value));
1319 var f = getMainContext().document.getElementById("backReqBox");
1320 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1321 param_escape(key) + "&value=" + param_escape(value);
1322 }
1323 }
1324 getMainContext().init_params[key] = value;
1325 } catch (e) {
1326 exception_error("storeInitParam", e);
1327 }
1328 }
1329
1330 /*
1331 function storeInitParams(params, is_client) {
1332 try {
1333 var s = "";
1334
1335 for (k in params) {
1336 if (getMainContext().init_params[k] != params[k]) {
1337 s += k + "=" + params[k] + ";";
1338 getMainContext().init_params[k] = params[k];
1339 }
1340 }
1341
1342 debug("storeInitParams: " + s);
1343
1344 if (!is_client) {
1345 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1346 }
1347 } catch (e) {
1348 exception_error("storeInitParams", e);
1349 }
1350 }*/
1351
1352 function fatalError(code, message) {
1353 try {
1354 var fe = document.getElementById("fatal_error");
1355 var fc = document.getElementById("fatal_error_msg");
1356
1357 fc.innerHTML = "Code " + code + ": " + message;
1358
1359 fe.style.display = "block";
1360
1361 } catch (e) {
1362 exception_error("fatalError", e);
1363 }
1364 }
1365
1366 function getFeedName(id, is_cat) {
1367 var d = getFeedsContext().document;
1368
1369 var e;
1370
1371 if (is_cat) {
1372 e = d.getElementById("FCATN-" + id);
1373 } else {
1374 e = d.getElementById("FEEDN-" + id);
1375 }
1376 if (e) {
1377 return e.innerHTML.stripTags();
1378 } else {
1379 return null;
1380 }
1381 }