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