]>
git.wh0rd.org - tt-rss.git/blob - functions.js
194d83157598092cd8ce87dfae7ff6f176135029
1 var hotkeys_enabled
= true;
2 var debug_mode_enabled
= false;
3 var xmlhttp_rpc
= Ajax
.getTransport();
5 function browser_has_opacity() {
6 return navigator
.userAgent
.match("Gecko") != null ||
7 navigator
.userAgent
.match("Opera") != null;
11 return navigator
.userAgent
.match("Opera");
15 return navigator
.userAgent
.match("KHTML");
18 function is_safari() {
19 return navigator
.userAgent
.match("Safari");
22 function exception_error(location
, e
, silent
) {
26 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
28 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
29 "\nFunction: " + location
+ "()" +
30 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
33 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
36 debug("<b>EXCEPTION: " + msg
+ "</b>");
43 function disableHotkeys() {
44 hotkeys_enabled
= false;
47 function enableHotkeys() {
48 hotkeys_enabled
= true;
51 function xmlhttp_ready(obj
) {
52 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
55 function notify_callback() {
56 var container
= document
.getElementById('notify');
57 if (xmlhttp
.readyState
== 4) {
58 container
.innerHTML
=xmlhttp
.responseText
;
62 function rpc_notify_callback() {
63 var container
= document
.getElementById('notify');
64 if (xmlhttp_rpc
.readyState
== 4) {
65 container
.innerHTML
=xmlhttp_rpc
.responseText
;
69 function param_escape(arg
) {
70 if (typeof encodeURIComponent
!= 'undefined')
71 return encodeURIComponent(arg
);
76 function param_unescape(arg
) {
77 if (typeof decodeURIComponent
!= 'undefined')
78 return decodeURIComponent(arg
);
85 then
=new Date().getTime();
87 while((now
-then
)<gap
) {
88 now
=new Date().getTime();
92 var notify_hide_timerid
= false;
93 var notify_last_doc
= false;
95 var notify_effect
= false;
97 function hide_notify() {
98 if (notify_last_doc
) {
99 var n
= notify_last_doc
.getElementById("notify");
100 n
.style
.display
= "none";
102 /* if (browser_has_opacity()) {
103 if (notify_opacity >= 0) {
104 notify_opacity = notify_opacity - 0.1;
105 n.style.opacity = notify_opacity;
106 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
108 n.style.display = "none";
112 n.style.display = "none";
117 function notify_real(msg
, doc
, no_hide
, is_err
) {
119 var n
= doc
.getElementById("notify");
120 var nb
= doc
.getElementById("notify_body");
122 if (!n
|| !nb
) return;
124 if (notify_hide_timerid
) {
125 window
.clearTimeout(notify_hide_timerid
);
128 notify_last_doc
= doc
;
132 if (n
.style
.display
== "block") {
133 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
137 n
.style
.display
= "block";
141 n
.className
= "notifyError";
142 // n.style.backgroundColor = "#ffcccc";
143 // n.style.color = "black";
144 // n.style.borderColor = "#ff0000";
146 n
.className
= "notify";
147 // n.style.backgroundColor = "#fff7d5";
148 // n.style.borderColor = "#d7c47a";
149 // n.style.color = "black";
152 // msg = "<img src='images/live_com_loading.gif'> " + msg;
157 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
161 function p_notify(msg
, no_hide
, is_err
) {
162 notify_real(msg
, document
, no_hide
, is_err
);
165 function notify(msg
, no_hide
, is_err
) {
166 notify_real(msg
, document
, no_hide
, is_err
);
169 function printLockingError() {
170 notify("Please wait until operation finishes");}
172 function hotkey_handler(e
) {
177 var shift_key
= false;
180 shift_key
= e
.shiftKey
;
185 if (!hotkeys_enabled
) return;
188 keycode
= window
.event
.keyCode
;
193 if (keycode
== 82) { // r
194 return scheduleFeedUpdate(true);
197 if (keycode
== 83) { // s
198 return displayDlg("search", getActiveFeedId());
201 if (keycode
== 85) { // u
202 if (getActiveFeedId()) {
203 return viewfeed(getActiveFeedId(), "ForceUpdate");
207 if (keycode
== 65) { // a
208 return toggleDispRead();
211 var feedlist
= document
.getElementById('feedList');
213 if (keycode
== 74) { // j
214 var feed
= getActiveFeedId();
215 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
216 if (new_feed
) viewfeed(new_feed
, '');
219 if (keycode
== 75) { // k
220 var feed
= getActiveFeedId();
221 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
222 if (new_feed
) viewfeed(new_feed
, '');
225 if (!is_safari() && (keycode
== 78 || keycode
== 40)) { // n, down
226 if (typeof moveToPost
!= 'undefined') {
227 return moveToPost('next');
231 if (!is_safari() && (keycode
== 80 || keycode
== 38)) { // p, up
232 if (typeof moveToPost
!= 'undefined') {
233 return moveToPost('prev');
237 if (keycode
== 68 && shift_key
) { // d
238 if (!debug_mode_enabled
) {
239 document
.getElementById('debug_output').style
.display
= 'block';
240 debug('debug mode activated');
242 document
.getElementById('debug_output').style
.display
= 'none';
245 debug_mode_enabled
= !debug_mode_enabled
;
248 if (keycode
== 190 && shift_key
) { // >
252 if (keycode
== 188 && shift_key
) { // <
256 if (keycode
== 191 && shift_key
) { // ?
260 if (keycode
== 69 && shift_key
) {
261 return editFeedDlg(getActiveFeedId());
264 if (keycode
== 67) { // c
265 if (getActiveFeedId()) {
266 return catchupCurrentFeed();
270 if (keycode
== 90) { // z
271 if (getActiveFeedId()) {
272 return catchupPage();
276 if (typeof localHotkeyHandler
!= 'undefined') {
278 return localHotkeyHandler(e
);
280 exception_error("hotkey_handler, local:", e
);
284 debug("KP=" + keycode
);
286 exception_error("hotkey_handler", e
);
290 function cleanSelectedList(element
) {
291 var content
= document
.getElementById(element
);
293 if (!document
.getElementById("feedCatHolder")) {
294 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
295 var child
= content
.childNodes
[i
];
297 child
.className
= child
.className
.replace("Selected", "");
303 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
304 var child
= content
.childNodes
[i
];
305 if (child
.id
== "feedCatHolder") {
307 var fcat
= child
.lastChild
;
308 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
309 var feed
= fcat
.childNodes
[j
];
310 feed
.className
= feed
.className
.replace("Selected", "");
318 function cleanSelected(element
) {
319 var content
= document
.getElementById(element
);
321 for (i
= 0; i
< content
.rows
.length
; i
++) {
322 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
326 function getVisibleUnreadHeadlines() {
327 var content
= document
.getElementById("headlinesList");
329 var rows
= new Array();
331 for (i
= 0; i
< content
.rows
.length
; i
++) {
332 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
333 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
340 function getVisibleHeadlineIds() {
342 var content
= document
.getElementById("headlinesList");
344 var rows
= new Array();
346 for (i
= 0; i
< content
.rows
.length
; i
++) {
347 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
348 if (row_id
.length
> 0) {
355 function getFirstVisibleHeadlineId() {
356 var rows
= getVisibleHeadlineIds();
360 function getLastVisibleHeadlineId() {
361 var rows
= getVisibleHeadlineIds();
362 return rows
[rows
.length
-1];
365 function markHeadline(id
) {
366 var row
= document
.getElementById("RROW-" + id
);
368 var is_active
= false;
370 if (row
.className
.match("Active")) {
373 row
.className
= row
.className
.replace("Selected", "");
374 row
.className
= row
.className
.replace("Active", "");
375 row
.className
= row
.className
.replace("Insensitive", "");
378 row
.className
= row
.className
= "Active";
381 var check
= document
.getElementById("RCHK-" + id
);
384 check
.checked
= true;
387 row
.className
= row
.className
+ "Selected";
392 function getFeedIds() {
393 var content
= document
.getElementById("feedsList");
395 var rows
= new Array();
397 for (i
= 0; i
< content
.rows
.length
; i
++) {
398 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
407 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
413 d
.setTime(lifetime
* 1000);
416 int_setCookie(name
, value
, d
, path
, domain
, secure
);
420 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
421 document
.cookie
= name
+ "=" + escape(value
) +
422 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
423 ((path
) ? "; path=" + path
: "") +
424 ((domain
) ? "; domain=" + domain
: "") +
425 ((secure
) ? "; secure" : "");
428 function delCookie(name
, path
, domain
) {
429 if (getCookie(name
)) {
430 document
.cookie
= name
+ "=" +
431 ((path
) ? ";path=" + path
: "") +
432 ((domain
) ? ";domain=" + domain
: "" ) +
433 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
438 function getCookie(name
) {
440 var dc
= document
.cookie
;
441 var prefix
= name
+ "=";
442 var begin
= dc
.indexOf("; " + prefix
);
444 begin
= dc
.indexOf(prefix
);
445 if (begin
!= 0) return null;
450 var end
= document
.cookie
.indexOf(";", begin
);
454 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
457 function disableContainerChildren(id
, disable
, doc
) {
459 if (!doc
) doc
= document
;
461 var container
= doc
.getElementById(id
);
464 //alert("disableContainerChildren: element " + id + " not found");
468 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
469 var child
= container
.childNodes
[i
];
472 child
.disabled
= disable
;
478 if (child
.className
&& child
.className
.match("button")) {
479 child
.className
= "disabledButton";
482 if (child
.className
&& child
.className
.match("disabledButton")) {
483 child
.className
= "button";
490 function gotoPreferences() {
491 document
.location
.href
= "prefs.php";
494 function gotoMain() {
495 document
.location
.href
= "tt-rss.php";
498 function gotoExportOpml() {
499 document
.location
.href
= "opml.php?op=Export";
502 function getActiveFeedId() {
503 // return getCookie("ttrss_vf_actfeed");
505 debug("gAFID: " + active_feed_id
);
506 return active_feed_id
;
508 exception_error("getActiveFeedId", e
);
512 function activeFeedIsCat() {
513 return active_feed_is_cat
;
516 function setActiveFeedId(id
) {
517 // return setCookie("ttrss_vf_actfeed", id);
519 debug("sAFID(" + id
+ ")");
522 exception_error("setActiveFeedId", e
);
526 function parse_counters(reply
, scheduled_call
) {
531 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
532 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
533 reply
= reply
.firstChild
;
536 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
537 if (!reply
.childNodes
[l
] ||
538 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
539 // where did this come from?
543 var id
= reply
.childNodes
[l
].getAttribute("id");
544 var t
= reply
.childNodes
[l
].getAttribute("type");
545 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
546 var error
= reply
.childNodes
[l
].getAttribute("error");
547 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
548 var updated
= reply
.childNodes
[l
].getAttribute("updated");
550 if (id
== "global-unread") {
556 if (id
== "subscribed-feeds") {
561 if (t
== "category") {
562 var catctr
= document
.getElementById("FCATCTR-" + id
);
564 catctr
.innerHTML
= "(" + ctr
+ ")";
566 catctr
.className
= "catCtrHasUnread";
568 catctr
.className
= "catCtrNoUnread";
574 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
575 var feedu
= document
.getElementById("FEEDU-" + id
);
576 var feedr
= document
.getElementById("FEEDR-" + id
);
577 var feed_img
= document
.getElementById("FIMG-" + id
);
578 var feedlink
= document
.getElementById("FEEDL-" + id
);
579 var feedupd
= document
.getElementById("FLUPD-" + id
);
581 if (updated
&& feedlink
) {
583 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
585 feedlink
.title
= "Updated: " + updated
;
589 if (updated
&& feedupd
) {
591 feedupd
.innerHTML
= updated
+ " (Error)";
593 feedupd
.innerHTML
= updated
;
597 if (feedctr
&& feedu
&& feedr
) {
599 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
603 feedu
.innerHTML
= ctr
;
606 feedr
.className
= feedr
.className
.replace("feed", "error");
608 feedr
.className
= feedr
.className
.replace("error", "feed");
612 feedctr
.className
= "odd";
613 if (!feedr
.className
.match("Unread")) {
614 var is_selected
= feedr
.className
.match("Selected");
616 feedr
.className
= feedr
.className
.replace("Selected", "");
617 feedr
.className
= feedr
.className
.replace("Unread", "");
619 feedr
.className
= feedr
.className
+ "Unread";
622 feedr
.className
= feedr
.className
+ "Selected";
627 feedctr
.className
= "invisible";
628 feedr
.className
= feedr
.className
.replace("Unread", "");
633 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
635 var feeds_stored
= number_of_feeds
;
637 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
639 if (feeds_stored
!= feeds_found
) {
640 number_of_feeds
= feeds_found
;
642 if (feeds_stored
!= 0) {
643 debug("Subscribed feed number changed, refreshing feedlist");
644 setTimeout('updateFeedList(false, false)', 50);
649 exception_error("parse_counters", e
);
653 function parse_counters_reply(xmlhttp
, scheduled_call
) {
655 if (!xmlhttp
.responseXML
) {
656 notify("refetch_callback: backend did not return valid XML", true, true);
660 var reply
= xmlhttp
.responseXML
.firstChild
;
663 notify("refetch_callback: backend did not return expected XML object", true, true);
668 var error_code
= false;
669 var error_msg
= false;
671 if (reply
.firstChild
) {
672 error_code
= reply
.firstChild
.getAttribute("error-code");
673 error_msg
= reply
.firstChild
.getAttribute("error-msg");
677 error_code
= reply
.getAttribute("error-code");
678 error_msg
= reply
.getAttribute("error-msg");
681 if (error_code
&& error_code
!= 0) {
682 debug("refetch_callback: got error code " + error_code
);
683 return fatalError(error_code
, error_msg
);
686 var counters
= reply
.firstChild
;
688 parse_counters(counters
, scheduled_call
);
690 var runtime_info
= counters
.nextSibling
;
692 parse_runtime_info(runtime_info
);
694 if (getInitParam("feeds_sort_by_unread") == 1) {
698 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
702 function all_counters_callback() {
703 if (xmlhttp_rpc
.readyState
== 4) {
705 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
706 debug("[all_counters_callback] backend did not return valid XML");
710 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
712 var reply = xmlhttp_rpc.responseXML.firstChild;
714 var counters = reply.firstChild;
716 parse_counters(counters);
718 var runtime = counters.nextSibling;
721 parse_runtime_info(runtime);
724 if (getInitParam("feeds_sort_by_unread") == 1) {
728 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
730 debug("in all_counters_callback");
732 parse_counters_reply(xmlhttp_rpc
);
735 exception_error("all_counters_callback", e
);
740 function get_feed_entry_unread(doc
, elem
) {
742 var id
= elem
.id
.replace("FEEDR-", "");
749 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
755 function resort_category(doc
, node
) {
756 debug("resort_category: " + node
);
758 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
759 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
760 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
762 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
766 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
767 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
769 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
770 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
772 if (cur_val
> tmp_val
) {
773 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
774 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
775 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
776 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
785 function resort_feedlist() {
786 debug("resort_feedlist");
790 if (fd
.getElementById("feedCatHolder")) {
792 var feeds
= fd
.getElementById("feedList");
793 var child
= feeds
.firstChild
;
797 if (child
.id
== "feedCatHolder") {
798 resort_category(fd
, child
.firstChild
);
801 child
= child
.nextSibling
;
805 resort_category(fd
, fd
.getElementById("feedList"));
809 function update_all_counters(feed
) {
810 if (xmlhttp_ready(xmlhttp_rpc
)) {
811 var query
= "backend.php?op=rpc&subop=getAllCounters";
814 query
= query
+ "&aid=" + feed
;
817 if (tagsAreDisplayed()) {
818 query
= query
+ "&omode=lt";
820 query
= query
+ "&omode=flc";
823 debug("update_all_counters QUERY: " + query
);
825 var date
= new Date();
826 var timestamp
= Math
.round(date
.getTime() / 1000);
827 query
= query
+ "&ts=" + timestamp
829 xmlhttp_rpc
.open("GET", query
, true);
830 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
831 xmlhttp_rpc
.send(null);
835 function popupHelp(tid
) {
836 var w
= window
.open("backend.php?op=help&tid=" + tid
,
838 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
841 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
842 * * @author Sundar Dorai-Raj
843 * * Email: sdoraira@vt.edu
844 * * This program is free software; you can redistribute it and/or
845 * * modify it under the terms of the GNU General Public License
846 * * as published by the Free Software Foundation; either version 2
847 * * of the License, or (at your option) any later version,
848 * * provided that any use properly credits the author.
849 * * This program is distributed in the hope that it will be useful,
850 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
851 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
852 * * GNU General Public License for more details at http://www.gnu.org * * */
854 var numbers
=".0123456789";
855 function isNumeric(x
) {
856 // is x a String or a character?
858 // remove negative sign
860 for(j
=0;j
<x
.length
;j
++) {
861 // call isNumeric recursively for each character
862 number
=isNumeric(x
.substring(j
,j
+1));
863 if(!number
) return number
;
868 // if x is number return true
869 if(numbers
.indexOf(x
)>=0) return true;
875 function hideOrShowFeeds(doc
, hide
) {
877 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
881 var list
= fd
.getElementById("feedList");
883 if (fd
.getElementById("feedCatHolder")) {
885 var feeds
= fd
.getElementById("feedList");
886 var child
= feeds
.firstChild
;
890 if (child
.id
== "feedCatHolder") {
891 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
894 child
= child
.nextSibling
;
898 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
902 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
904 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
909 debug("hideOrShowFeeds: passed node is null, aborting");
913 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
914 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
915 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
917 if (node
.childNodes
[i
].style
!= undefined) {
919 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
921 // debug(node.childNodes[i].id + " --> " + has_unread);
923 if (hide
&& !has_unread
) {
924 node
.childNodes
[i
].style
.display
= "none";
928 node
.childNodes
[i
].style
.display
= "list-item";
932 node
.childNodes
[i
].style
.display
= "list-item";
939 if (cat_unread
== 0) {
940 if (cat_node
.style
== undefined) {
941 debug("ERROR: supplied cat_node " + cat_node
+
942 " has no styles. WTF?");
946 cat_node
.style
.display
= "none";
948 cat_node
.style
.display
= "list-item";
952 cat_node
.style
.display
= "list-item";
958 // debug("unread for category: " + cat_unread);
961 function selectTableRow(r
, do_select
) {
962 r
.className
= r
.className
.replace("Selected", "");
965 r
.className
= r
.className
+ "Selected";
969 function selectTableRowById(elem_id
, check_id
, do_select
) {
973 var row
= document
.getElementById(elem_id
);
976 selectTableRow(row
, do_select
);
979 var check
= document
.getElementById(check_id
);
982 check
.checked
= do_select
;
985 exception_error("selectTableRowById", e
);
989 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
990 classcheck
, reset_others
) {
992 var content
= document
.getElementById(content_id
);
995 alert("[selectTableRows] Element " + content_id
+ " not found.");
999 for (i
= 0; i
< content
.rows
.length
; i
++) {
1000 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
1002 if (content
.rows
[i
].id
.match(prefix
)) {
1003 selectTableRow(content
.rows
[i
], do_select
);
1005 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1006 var check
= document
.getElementById(check_prefix
+ row_id
);
1009 check
.checked
= do_select
;
1011 } else if (reset_others
) {
1012 selectTableRow(content
.rows
[i
], false);
1014 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1015 var check
= document
.getElementById(check_prefix
+ row_id
);
1018 check
.checked
= false;
1022 } else if (reset_others
) {
1023 selectTableRow(content
.rows
[i
], false);
1025 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1026 var check
= document
.getElementById(check_prefix
+ row_id
);
1029 check
.checked
= false;
1036 function getSelectedTableRowIds(content_id
, prefix
) {
1038 var content
= document
.getElementById(content_id
);
1041 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1045 var sel_rows
= new Array();
1047 for (i
= 0; i
< content
.rows
.length
; i
++) {
1048 if (content
.rows
[i
].id
.match(prefix
) &&
1049 content
.rows
[i
].className
.match("Selected")) {
1051 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1052 sel_rows
.push(row_id
);
1060 function toggleSelectRowById(sender
, id
) {
1061 var row
= document
.getElementById(id
);
1063 if (sender
.checked
) {
1064 if (!row
.className
.match("Selected")) {
1065 row
.className
= row
.className
+ "Selected";
1068 if (row
.className
.match("Selected")) {
1069 row
.className
= row
.className
.replace("Selected", "");
1074 function toggleSelectListRow(sender
) {
1075 var parent_row
= sender
.parentNode
;
1077 if (sender
.checked
) {
1078 if (!parent_row
.className
.match("Selected")) {
1079 parent_row
.className
= parent_row
.className
+ "Selected";
1082 if (parent_row
.className
.match("Selected")) {
1083 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1089 function toggleSelectRow(sender
) {
1090 var parent_row
= sender
.parentNode
.parentNode
;
1092 if (sender
.checked
) {
1093 if (!parent_row
.className
.match("Selected")) {
1094 parent_row
.className
= parent_row
.className
+ "Selected";
1097 if (parent_row
.className
.match("Selected")) {
1098 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1103 function openExternalUrl(url
) {
1104 var w
= window
.open(url
);
1107 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1109 if (direction
== "next") {
1110 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1111 var child
= list
.childNodes
[i
];
1112 if (child
.id
&& child
.id
== "feedCatHolder") {
1113 if (child
.lastChild
) {
1114 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1117 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1118 return child
.id
.replace('FEEDR-', '');
1123 // FIXME select last feed doesn't work when only unread feeds are visible
1125 if (direction
== "prev") {
1126 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1127 var child
= list
.childNodes
[i
];
1128 if (child
.id
== "feedCatHolder") {
1129 if (child
.firstChild
) {
1130 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1133 } else if (child
.id
.match("FEEDR-")) {
1135 if (getInitParam("hide_read_feeds") == 1) {
1136 if (child
.className
!= "feed") {
1137 alert(child
.className
);
1138 return child
.id
.replace('FEEDR-', '');
1141 return child
.id
.replace('FEEDR-', '');
1148 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1150 if (getInitParam("hide_read_feeds") == 1) {
1154 if (direction
== "next") {
1160 if (e
.nextSibling
) {
1164 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1166 var this_cat
= e
.parentNode
.parentNode
;
1170 if (this_cat
&& this_cat
.nextSibling
) {
1171 while (!e
&& this_cat
.nextSibling
) {
1172 this_cat
= this_cat
.nextSibling
;
1173 if (this_cat
.id
== "feedCatHolder") {
1174 e
= this_cat
.firstChild
.firstChild
;
1184 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1185 e
.className
.match("feed"))) {
1186 return e
.id
.replace("FEEDR-", "");
1191 } else if (direction
== "prev") {
1197 if (e
.previousSibling
) {
1199 e
= e
.previousSibling
;
1201 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1203 var this_cat
= e
.parentNode
.parentNode
;
1207 if (this_cat
&& this_cat
.previousSibling
) {
1208 while (!e
&& this_cat
.previousSibling
) {
1209 this_cat
= this_cat
.previousSibling
;
1210 if (this_cat
.id
== "feedCatHolder") {
1211 e
= this_cat
.firstChild
.lastChild
;
1221 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1222 e
.className
.match("feed"))) {
1223 return e
.id
.replace("FEEDR-", "");
1231 function showBlockElement(id
) {
1232 var elem
= document
.getElementById(id
);
1235 elem
.style
.display
= "block";
1237 alert("[showBlockElement] can't find element with id " + id
);
1241 function hideParentElement(e
) {
1242 e
.parentNode
.style
.display
= "none";
1245 function dropboxSelect(e
, v
) {
1246 for (i
= 0; i
< e
.length
; i
++) {
1247 if (e
[i
].value
== v
) {
1248 e
.selectedIndex
= i
;
1254 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1255 // bugfixed just a little bit :-)
1256 function getURLParam(strParamName
){
1258 var strHref
= window
.location
.href
;
1260 if (strHref
.indexOf("#") == strHref
.length
-1) {
1261 strHref
= strHref
.substring(0, strHref
.length
-1);
1264 if ( strHref
.indexOf("?") > -1 ){
1265 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1266 var aQueryString
= strQueryString
.split("&");
1267 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1268 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1269 var aParam
= aQueryString
[iParam
].split("=");
1270 strReturn
= aParam
[1];
1278 function leading_zero(p
) {
1280 if (s
.length
== 1) s
= "0" + s
;
1284 function closeInfoBox(cleanup
) {
1285 var box
= document
.getElementById('infoBox');
1286 var shadow
= document
.getElementById('infoBoxShadow');
1289 shadow
.style
.display
= "none";
1291 box
.style
.display
= "none";
1294 if (cleanup
) box
.innerHTML
= " ";
1302 function displayDlg(id
, param
) {
1304 if (!xmlhttp_ready(xmlhttp
)) {
1305 printLockingError();
1311 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1312 param_escape(id
) + "¶m=" + param_escape(param
), true);
1313 xmlhttp
.onreadystatechange
=infobox_callback
;
1321 function infobox_submit_callback() {
1322 if (xmlhttp
.readyState
== 4) {
1326 // called from prefs, reload tab
1328 selectTab(active_tab
, false);
1332 notify(xmlhttp
.responseText
);
1337 function infobox_callback() {
1338 if (xmlhttp
.readyState
== 4) {
1339 var box
= document
.getElementById('infoBox');
1340 var shadow
= document
.getElementById('infoBoxShadow');
1342 box
.innerHTML
=xmlhttp
.responseText
;
1344 shadow
.style
.display
= "block";
1346 box
.style
.display
= "block";
1353 function qaddFilter() {
1355 if (!xmlhttp_ready(xmlhttp
)) {
1356 printLockingError();
1360 var form
= document
.forms
['filter_add_form'];
1361 var reg_exp
= form
.reg_exp
.value
;
1363 if (reg_exp
== "") {
1364 alert("Can't add filter: nothing to match on.");
1368 var query
= Form
.serialize("filter_add_form");
1370 xmlhttp
.open("GET", "backend.php?" + query
, true);
1371 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1377 function toggleSubmitNotEmpty(e
, submit_id
) {
1379 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1381 exception_error("toggleSubmitNotEmpty", e
);
1385 function isValidURL(s
) {
1386 return s
.match("http://") != null || s
.match("https://") != null;
1391 if (!xmlhttp_ready(xmlhttp
)) {
1392 printLockingError();
1396 var form
= document
.forms
['feed_add_form'];
1397 var feed_url
= form
.feed_url
.value
;
1399 if (feed_url
== "") {
1400 alert("Can't subscribe: no feed URL given.");
1404 notify("Adding feed...", true);
1408 var feeds_doc
= document
;
1410 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1412 var query
= Form
.serialize("feed_add_form");
1414 xmlhttp
.open("GET", "backend.php?" + query
, true);
1415 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1421 function filterCR(e
, f
)
1426 key
= window
.event
.keyCode
; //IE
1428 key
= e
.which
; //firefox
1431 if (typeof f
!= 'undefined') {
1442 function getMainContext() {
1446 function getFeedsContext() {
1450 function getContentContext() {
1454 function getHeadlinesContext() {
1458 var debug_last_class
= "even";
1460 function debug(msg
) {
1462 if (debug_last_class
== "even") {
1463 debug_last_class
= "odd";
1465 debug_last_class
= "even";
1468 var c
= document
.getElementById('debug_output');
1469 if (c
&& c
.style
.display
== "block") {
1470 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1471 c
.removeChild(c
.lastChild
);
1475 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1476 ":" + leading_zero(d
.getSeconds());
1477 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1478 msg
+ "</li>" + c
.innerHTML
;
1482 function getInitParam(key
) {
1483 return getMainContext().init_params
[key
];
1486 function storeInitParam(key
, value
, is_client
) {
1489 if (getMainContext().init_params
[key
] != value
) {
1490 debug("storeInitParam: " + key
+ " => " + value
);
1491 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1492 // param_escape(key) + "&value=" + param_escape(value));
1493 var f
= getMainContext().document
.getElementById("backReqBox");
1494 f
.src
= "backend.php?op=rpc&subop=storeParam&key=" +
1495 param_escape(key
) + "&value=" + param_escape(value
);
1498 getMainContext().init_params
[key
] = value
;
1500 exception_error("storeInitParam", e
);
1505 function storeInitParams(params, is_client) {
1510 if (getMainContext().init_params[k] != params[k]) {
1511 s += k + "=" + params[k] + ";";
1512 getMainContext().init_params[k] = params[k];
1516 debug("storeInitParams: " + s);
1519 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1522 exception_error("storeInitParams", e);
1526 function fatalError(code
, message
) {
1531 var fe
= document
.getElementById("fatal_error");
1532 var fc
= document
.getElementById("fatal_error_msg");
1534 fc
.innerHTML
= "Code " + code
+ ": " + message
;
1536 fe
.style
.display
= "block";
1538 window
.location
.href
= "login.php?rt=none";
1542 exception_error("fatalError", e
);
1546 function getFeedName(id
, is_cat
) {
1547 var d
= getFeedsContext().document
;
1552 e
= d
.getElementById("FCATN-" + id
);
1554 e
= d
.getElementById("FEEDN-" + id
);
1557 return e
.innerHTML
.stripTags();
1563 function viewContentUrl(url
) {
1564 getContentContext().location
= url
;
1567 function filterDlgCheckAction(sender
) {
1571 var action
= sender
[sender
.selectedIndex
].value
;
1573 var form
= document
.forms
["filter_add_form"];
1576 form
= document
.forms
["filter_edit_form"];
1580 debug("filterDlgCheckAction: can't find form!");
1584 var action_param
= form
.action_param
;
1586 if (!action_param
) {
1587 debug("filterDlgCheckAction: can't find action param!");
1591 // if selected action supports parameters, enable params field
1593 action_param
.disabled
= false;
1595 action_param
.disabled
= true;
1599 exception_error(e
, "filterDlgCheckAction");
1604 function explainError(code
) {
1605 return displayDlg("explainError", code
);