]>
git.wh0rd.org - tt-rss.git/blob - functions.js
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 logout_callback() {
56 var container
= document
.getElementById('notify');
57 if (xmlhttp
.readyState
== 4) {
59 window
.location
.reload(true);
61 exception_error("logout_callback", e
);
66 function notify_callback() {
67 var container
= document
.getElementById('notify');
68 if (xmlhttp
.readyState
== 4) {
69 container
.innerHTML
=xmlhttp
.responseText
;
73 function rpc_notify_callback() {
74 var container
= document
.getElementById('notify');
75 if (xmlhttp_rpc
.readyState
== 4) {
76 container
.innerHTML
=xmlhttp_rpc
.responseText
;
80 function param_escape(arg
) {
81 if (typeof encodeURIComponent
!= 'undefined')
82 return encodeURIComponent(arg
);
87 function param_unescape(arg
) {
88 if (typeof decodeURIComponent
!= 'undefined')
89 return decodeURIComponent(arg
);
96 then
=new Date().getTime();
98 while((now
-then
)<gap
) {
99 now
=new Date().getTime();
103 var notify_hide_timerid
= false;
104 var notify_last_doc
= false;
106 var notify_effect
= false;
108 function hide_notify() {
109 if (notify_last_doc
) {
110 var n
= notify_last_doc
.getElementById("notify");
111 n
.style
.display
= "none";
113 /* if (browser_has_opacity()) {
114 if (notify_opacity >= 0) {
115 notify_opacity = notify_opacity - 0.1;
116 n.style.opacity = notify_opacity;
117 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
119 n.style.display = "none";
123 n.style.display = "none";
128 function notify_real(msg
, doc
, no_hide
, is_err
) {
130 var n
= doc
.getElementById("notify");
131 var nb
= doc
.getElementById("notify_body");
133 if (!n
|| !nb
) return;
135 if (notify_hide_timerid
) {
136 window
.clearTimeout(notify_hide_timerid
);
139 notify_last_doc
= doc
;
143 if (n
.style
.display
== "block") {
144 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
148 n
.style
.display
= "block";
152 n
.className
= "notifyError";
153 // n.style.backgroundColor = "#ffcccc";
154 // n.style.color = "black";
155 // n.style.borderColor = "#ff0000";
157 n
.className
= "notify";
158 // n.style.backgroundColor = "#fff7d5";
159 // n.style.borderColor = "#d7c47a";
160 // n.style.color = "black";
163 // msg = "<img src='images/live_com_loading.gif'> " + msg;
168 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
172 function p_notify(msg
, no_hide
, is_err
) {
173 notify_real(msg
, document
, no_hide
, is_err
);
176 function notify(msg
, no_hide
, is_err
) {
177 notify_real(msg
, document
, no_hide
, is_err
);
180 function printLockingError() {
181 notify("Please wait until operation finishes");}
183 function hotkey_handler(e
) {
188 var shift_key
= false;
191 shift_key
= e
.shiftKey
;
196 if (!hotkeys_enabled
) return;
199 keycode
= window
.event
.keyCode
;
204 if (keycode
== 82) { // r
205 return scheduleFeedUpdate(true);
208 if (keycode
== 83) { // s
209 return displayDlg("search", getActiveFeedId());
212 if (keycode
== 85) { // u
213 if (getActiveFeedId()) {
214 return viewfeed(getActiveFeedId(), "ForceUpdate");
218 if (keycode
== 65) { // a
219 return toggleDispRead();
222 var feedlist
= document
.getElementById('feedList');
224 if (keycode
== 74) { // j
225 var feed
= getActiveFeedId();
226 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
227 if (new_feed
) viewfeed(new_feed
, '');
230 if (keycode
== 75) { // k
231 var feed
= getActiveFeedId();
232 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
233 if (new_feed
) viewfeed(new_feed
, '');
236 if (!is_safari() && (keycode
== 78 || keycode
== 40)) { // n, down
237 if (typeof moveToPost
!= 'undefined') {
238 return moveToPost('next');
242 if (!is_safari() && (keycode
== 80 || keycode
== 38)) { // p, up
243 if (typeof moveToPost
!= 'undefined') {
244 return moveToPost('prev');
248 if (keycode
== 68 && shift_key
) { // d
249 if (!debug_mode_enabled
) {
250 document
.getElementById('debug_output').style
.display
= 'block';
251 debug('debug mode activated');
253 document
.getElementById('debug_output').style
.display
= 'none';
256 debug_mode_enabled
= !debug_mode_enabled
;
259 if (keycode
== 190 && shift_key
) { // >
263 if (keycode
== 188 && shift_key
) { // <
267 if (keycode
== 191 && shift_key
) { // ?
271 if (keycode
== 69 && shift_key
) { // e
272 return editFeedDlg(getActiveFeedId());
275 if (keycode
== 70 && shift_key
) { // f
276 if (getActiveFeedId()) {
277 return catchupCurrentFeed();
281 if (keycode
== 80 && shift_key
) { // p
282 if (getActiveFeedId()) {
283 return catchupPage();
287 if (typeof localHotkeyHandler
!= 'undefined') {
289 return localHotkeyHandler(e
);
291 exception_error("hotkey_handler, local:", e
);
295 debug("KP=" + keycode
);
297 exception_error("hotkey_handler", e
);
301 function cleanSelectedList(element
) {
302 var content
= document
.getElementById(element
);
304 if (!document
.getElementById("feedCatHolder")) {
305 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
306 var child
= content
.childNodes
[i
];
308 child
.className
= child
.className
.replace("Selected", "");
314 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
315 var child
= content
.childNodes
[i
];
316 if (child
.id
== "feedCatHolder") {
318 var fcat
= child
.lastChild
;
319 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
320 var feed
= fcat
.childNodes
[j
];
321 feed
.className
= feed
.className
.replace("Selected", "");
329 function cleanSelected(element
) {
330 var content
= document
.getElementById(element
);
332 for (i
= 0; i
< content
.rows
.length
; i
++) {
333 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
337 function getVisibleUnreadHeadlines() {
338 var content
= document
.getElementById("headlinesList");
340 var rows
= new Array();
342 for (i
= 0; i
< content
.rows
.length
; i
++) {
343 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
344 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
351 function getVisibleHeadlineIds() {
353 var content
= document
.getElementById("headlinesList");
355 var rows
= new Array();
357 for (i
= 0; i
< content
.rows
.length
; i
++) {
358 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
359 if (row_id
.length
> 0) {
366 function getFirstVisibleHeadlineId() {
367 var rows
= getVisibleHeadlineIds();
371 function getLastVisibleHeadlineId() {
372 var rows
= getVisibleHeadlineIds();
373 return rows
[rows
.length
-1];
376 function markHeadline(id
) {
377 var row
= document
.getElementById("RROW-" + id
);
379 var is_active
= false;
381 if (row
.className
.match("Active")) {
384 row
.className
= row
.className
.replace("Selected", "");
385 row
.className
= row
.className
.replace("Active", "");
386 row
.className
= row
.className
.replace("Insensitive", "");
389 row
.className
= row
.className
= "Active";
392 var check
= document
.getElementById("RCHK-" + id
);
395 check
.checked
= true;
398 row
.className
= row
.className
+ "Selected";
403 function getFeedIds() {
404 var content
= document
.getElementById("feedsList");
406 var rows
= new Array();
408 for (i
= 0; i
< content
.rows
.length
; i
++) {
409 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
418 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
424 d
.setTime(lifetime
* 1000);
427 int_setCookie(name
, value
, d
, path
, domain
, secure
);
431 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
432 document
.cookie
= name
+ "=" + escape(value
) +
433 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
434 ((path
) ? "; path=" + path
: "") +
435 ((domain
) ? "; domain=" + domain
: "") +
436 ((secure
) ? "; secure" : "");
439 function delCookie(name
, path
, domain
) {
440 if (getCookie(name
)) {
441 document
.cookie
= name
+ "=" +
442 ((path
) ? ";path=" + path
: "") +
443 ((domain
) ? ";domain=" + domain
: "" ) +
444 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
449 function getCookie(name
) {
451 var dc
= document
.cookie
;
452 var prefix
= name
+ "=";
453 var begin
= dc
.indexOf("; " + prefix
);
455 begin
= dc
.indexOf(prefix
);
456 if (begin
!= 0) return null;
461 var end
= document
.cookie
.indexOf(";", begin
);
465 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
468 function disableContainerChildren(id
, disable
, doc
) {
470 if (!doc
) doc
= document
;
472 var container
= doc
.getElementById(id
);
475 //alert("disableContainerChildren: element " + id + " not found");
479 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
480 var child
= container
.childNodes
[i
];
483 child
.disabled
= disable
;
489 if (child
.className
&& child
.className
.match("button")) {
490 child
.className
= "disabledButton";
493 if (child
.className
&& child
.className
.match("disabledButton")) {
494 child
.className
= "button";
501 function gotoPreferences() {
502 document
.location
.href
= "prefs.php";
505 function gotoMain() {
506 document
.location
.href
= "tt-rss.php";
509 function gotoExportOpml() {
510 document
.location
.href
= "opml.php?op=Export";
513 function getActiveFeedId() {
514 // return getCookie("ttrss_vf_actfeed");
516 debug("gAFID: " + active_feed_id
);
517 return active_feed_id
;
519 exception_error("getActiveFeedId", e
);
523 function activeFeedIsCat() {
524 return active_feed_is_cat
;
527 function setActiveFeedId(id
) {
528 // return setCookie("ttrss_vf_actfeed", id);
530 debug("sAFID(" + id
+ ")");
533 exception_error("setActiveFeedId", e
);
537 function parse_counters(reply
, scheduled_call
) {
542 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
543 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
544 reply
= reply
.firstChild
;
547 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
548 if (!reply
.childNodes
[l
] ||
549 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
550 // where did this come from?
554 var id
= reply
.childNodes
[l
].getAttribute("id");
555 var t
= reply
.childNodes
[l
].getAttribute("type");
556 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
557 var error
= reply
.childNodes
[l
].getAttribute("error");
558 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
559 var updated
= reply
.childNodes
[l
].getAttribute("updated");
561 if (id
== "global-unread") {
567 if (id
== "subscribed-feeds") {
572 if (t
== "category") {
573 var catctr
= document
.getElementById("FCATCTR-" + id
);
575 catctr
.innerHTML
= "(" + ctr
+ ")";
577 catctr
.className
= "catCtrHasUnread";
579 catctr
.className
= "catCtrNoUnread";
585 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
586 var feedu
= document
.getElementById("FEEDU-" + id
);
587 var feedr
= document
.getElementById("FEEDR-" + id
);
588 var feed_img
= document
.getElementById("FIMG-" + id
);
589 var feedlink
= document
.getElementById("FEEDL-" + id
);
590 var feedupd
= document
.getElementById("FLUPD-" + id
);
592 if (updated
&& feedlink
) {
594 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
596 feedlink
.title
= "Updated: " + updated
;
600 if (updated
&& feedupd
) {
602 feedupd
.innerHTML
= updated
+ " (Error)";
604 feedupd
.innerHTML
= updated
;
608 if (feedctr
&& feedu
&& feedr
) {
610 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
614 feedu
.innerHTML
= ctr
;
617 feedr
.className
= feedr
.className
.replace("feed", "error");
619 feedr
.className
= feedr
.className
.replace("error", "feed");
623 feedctr
.className
= "odd";
624 if (!feedr
.className
.match("Unread")) {
625 var is_selected
= feedr
.className
.match("Selected");
627 feedr
.className
= feedr
.className
.replace("Selected", "");
628 feedr
.className
= feedr
.className
.replace("Unread", "");
630 feedr
.className
= feedr
.className
+ "Unread";
633 feedr
.className
= feedr
.className
+ "Selected";
638 feedctr
.className
= "invisible";
639 feedr
.className
= feedr
.className
.replace("Unread", "");
644 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
646 var feeds_stored
= number_of_feeds
;
648 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
650 if (feeds_stored
!= feeds_found
) {
651 number_of_feeds
= feeds_found
;
653 if (feeds_stored
!= 0) {
654 debug("Subscribed feed number changed, refreshing feedlist");
655 setTimeout('updateFeedList(false, false)', 50);
660 exception_error("parse_counters", e
);
664 function parse_counters_reply(xmlhttp
, scheduled_call
) {
666 if (!xmlhttp
.responseXML
) {
667 notify("refetch_callback: backend did not return valid XML", true, true);
671 var reply
= xmlhttp
.responseXML
.firstChild
;
674 notify("refetch_callback: backend did not return expected XML object", true, true);
679 var error_code
= false;
680 var error_msg
= false;
682 if (reply
.firstChild
) {
683 error_code
= reply
.firstChild
.getAttribute("error-code");
684 error_msg
= reply
.firstChild
.getAttribute("error-msg");
688 error_code
= reply
.getAttribute("error-code");
689 error_msg
= reply
.getAttribute("error-msg");
692 if (error_code
&& error_code
!= 0) {
693 debug("refetch_callback: got error code " + error_code
);
694 return fatalError(error_code
, error_msg
);
697 var counters
= reply
.firstChild
;
699 parse_counters(counters
, scheduled_call
);
701 var runtime_info
= counters
.nextSibling
;
703 parse_runtime_info(runtime_info
);
705 if (getInitParam("feeds_sort_by_unread") == 1) {
709 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
713 function all_counters_callback() {
714 if (xmlhttp_rpc
.readyState
== 4) {
716 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
717 debug("[all_counters_callback] backend did not return valid XML");
721 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
723 var reply = xmlhttp_rpc.responseXML.firstChild;
725 var counters = reply.firstChild;
727 parse_counters(counters);
729 var runtime = counters.nextSibling;
732 parse_runtime_info(runtime);
735 if (getInitParam("feeds_sort_by_unread") == 1) {
739 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
741 debug("in all_counters_callback");
743 parse_counters_reply(xmlhttp_rpc
);
746 exception_error("all_counters_callback", e
);
751 function get_feed_entry_unread(doc
, elem
) {
753 var id
= elem
.id
.replace("FEEDR-", "");
760 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
766 function resort_category(doc
, node
) {
767 debug("resort_category: " + node
);
769 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
770 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
771 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
773 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
777 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
778 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
780 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
781 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
783 if (cur_val
> tmp_val
) {
784 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
785 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
786 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
787 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
796 function resort_feedlist() {
797 debug("resort_feedlist");
801 if (fd
.getElementById("feedCatHolder")) {
803 var feeds
= fd
.getElementById("feedList");
804 var child
= feeds
.firstChild
;
808 if (child
.id
== "feedCatHolder") {
809 resort_category(fd
, child
.firstChild
);
812 child
= child
.nextSibling
;
816 resort_category(fd
, fd
.getElementById("feedList"));
820 function update_all_counters(feed
) {
821 if (xmlhttp_ready(xmlhttp_rpc
)) {
822 var query
= "backend.php?op=rpc&subop=getAllCounters";
825 query
= query
+ "&aid=" + feed
;
828 if (tagsAreDisplayed()) {
829 query
= query
+ "&omode=lt";
831 query
= query
+ "&omode=flc";
834 debug("update_all_counters QUERY: " + query
);
836 var date
= new Date();
837 var timestamp
= Math
.round(date
.getTime() / 1000);
838 query
= query
+ "&ts=" + timestamp
840 xmlhttp_rpc
.open("GET", query
, true);
841 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
842 xmlhttp_rpc
.send(null);
846 function popupHelp(tid
) {
847 var w
= window
.open("backend.php?op=help&tid=" + tid
,
849 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
852 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
853 * * @author Sundar Dorai-Raj
854 * * Email: sdoraira@vt.edu
855 * * This program is free software; you can redistribute it and/or
856 * * modify it under the terms of the GNU General Public License
857 * * as published by the Free Software Foundation; either version 2
858 * * of the License, or (at your option) any later version,
859 * * provided that any use properly credits the author.
860 * * This program is distributed in the hope that it will be useful,
861 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
862 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
863 * * GNU General Public License for more details at http://www.gnu.org * * */
865 var numbers
=".0123456789";
866 function isNumeric(x
) {
867 // is x a String or a character?
869 // remove negative sign
871 for(j
=0;j
<x
.length
;j
++) {
872 // call isNumeric recursively for each character
873 number
=isNumeric(x
.substring(j
,j
+1));
874 if(!number
) return number
;
879 // if x is number return true
880 if(numbers
.indexOf(x
)>=0) return true;
886 function hideOrShowFeeds(doc
, hide
) {
888 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
892 var list
= fd
.getElementById("feedList");
894 if (fd
.getElementById("feedCatHolder")) {
896 var feeds
= fd
.getElementById("feedList");
897 var child
= feeds
.firstChild
;
901 if (child
.id
== "feedCatHolder") {
902 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
905 child
= child
.nextSibling
;
909 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
913 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
915 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
920 debug("hideOrShowFeeds: passed node is null, aborting");
924 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
925 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
926 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
928 if (node
.childNodes
[i
].style
!= undefined) {
930 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
932 // debug(node.childNodes[i].id + " --> " + has_unread);
934 if (hide
&& !has_unread
) {
935 node
.childNodes
[i
].style
.display
= "none";
939 node
.childNodes
[i
].style
.display
= "list-item";
943 node
.childNodes
[i
].style
.display
= "list-item";
950 if (cat_unread
== 0) {
951 if (cat_node
.style
== undefined) {
952 debug("ERROR: supplied cat_node " + cat_node
+
953 " has no styles. WTF?");
957 cat_node
.style
.display
= "none";
959 cat_node
.style
.display
= "list-item";
963 cat_node
.style
.display
= "list-item";
969 // debug("unread for category: " + cat_unread);
972 function selectTableRow(r
, do_select
) {
973 r
.className
= r
.className
.replace("Selected", "");
976 r
.className
= r
.className
+ "Selected";
980 function selectTableRowById(elem_id
, check_id
, do_select
) {
984 var row
= document
.getElementById(elem_id
);
987 selectTableRow(row
, do_select
);
990 var check
= document
.getElementById(check_id
);
993 check
.checked
= do_select
;
996 exception_error("selectTableRowById", e
);
1000 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
1001 classcheck
, reset_others
) {
1003 var content
= document
.getElementById(content_id
);
1006 alert("[selectTableRows] Element " + content_id
+ " not found.");
1010 for (i
= 0; i
< content
.rows
.length
; i
++) {
1011 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
1013 if (content
.rows
[i
].id
.match(prefix
)) {
1014 selectTableRow(content
.rows
[i
], do_select
);
1016 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1017 var check
= document
.getElementById(check_prefix
+ row_id
);
1020 check
.checked
= do_select
;
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;
1033 } else if (reset_others
) {
1034 selectTableRow(content
.rows
[i
], false);
1036 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1037 var check
= document
.getElementById(check_prefix
+ row_id
);
1040 check
.checked
= false;
1047 function getSelectedTableRowIds(content_id
, prefix
) {
1049 var content
= document
.getElementById(content_id
);
1052 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1056 var sel_rows
= new Array();
1058 for (i
= 0; i
< content
.rows
.length
; i
++) {
1059 if (content
.rows
[i
].id
.match(prefix
) &&
1060 content
.rows
[i
].className
.match("Selected")) {
1062 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1063 sel_rows
.push(row_id
);
1071 function toggleSelectRowById(sender
, id
) {
1072 var row
= document
.getElementById(id
);
1074 if (sender
.checked
) {
1075 if (!row
.className
.match("Selected")) {
1076 row
.className
= row
.className
+ "Selected";
1079 if (row
.className
.match("Selected")) {
1080 row
.className
= row
.className
.replace("Selected", "");
1085 function toggleSelectListRow(sender
) {
1086 var parent_row
= sender
.parentNode
;
1088 if (sender
.checked
) {
1089 if (!parent_row
.className
.match("Selected")) {
1090 parent_row
.className
= parent_row
.className
+ "Selected";
1093 if (parent_row
.className
.match("Selected")) {
1094 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1100 function toggleSelectRow(sender
) {
1101 var parent_row
= sender
.parentNode
.parentNode
;
1103 if (sender
.checked
) {
1104 if (!parent_row
.className
.match("Selected")) {
1105 parent_row
.className
= parent_row
.className
+ "Selected";
1108 if (parent_row
.className
.match("Selected")) {
1109 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1114 function openExternalUrl(url
) {
1115 var w
= window
.open(url
);
1118 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1120 if (direction
== "next") {
1121 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1122 var child
= list
.childNodes
[i
];
1123 if (child
.id
&& child
.id
== "feedCatHolder") {
1124 if (child
.lastChild
) {
1125 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1128 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1129 return child
.id
.replace('FEEDR-', '');
1134 // FIXME select last feed doesn't work when only unread feeds are visible
1136 if (direction
== "prev") {
1137 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1138 var child
= list
.childNodes
[i
];
1139 if (child
.id
== "feedCatHolder") {
1140 if (child
.firstChild
) {
1141 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1144 } else if (child
.id
.match("FEEDR-")) {
1146 if (getInitParam("hide_read_feeds") == 1) {
1147 if (child
.className
!= "feed") {
1148 alert(child
.className
);
1149 return child
.id
.replace('FEEDR-', '');
1152 return child
.id
.replace('FEEDR-', '');
1159 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1161 if (getInitParam("hide_read_feeds") == 1) {
1165 if (direction
== "next") {
1171 if (e
.nextSibling
) {
1175 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1177 var this_cat
= e
.parentNode
.parentNode
;
1181 if (this_cat
&& this_cat
.nextSibling
) {
1182 while (!e
&& this_cat
.nextSibling
) {
1183 this_cat
= this_cat
.nextSibling
;
1184 if (this_cat
.id
== "feedCatHolder") {
1185 e
= this_cat
.firstChild
.firstChild
;
1195 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1196 e
.className
.match("feed"))) {
1197 return e
.id
.replace("FEEDR-", "");
1202 } else if (direction
== "prev") {
1208 if (e
.previousSibling
) {
1210 e
= e
.previousSibling
;
1212 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1214 var this_cat
= e
.parentNode
.parentNode
;
1218 if (this_cat
&& this_cat
.previousSibling
) {
1219 while (!e
&& this_cat
.previousSibling
) {
1220 this_cat
= this_cat
.previousSibling
;
1221 if (this_cat
.id
== "feedCatHolder") {
1222 e
= this_cat
.firstChild
.lastChild
;
1232 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1233 e
.className
.match("feed"))) {
1234 return e
.id
.replace("FEEDR-", "");
1242 function showBlockElement(id
) {
1243 var elem
= document
.getElementById(id
);
1246 elem
.style
.display
= "block";
1248 alert("[showBlockElement] can't find element with id " + id
);
1252 function hideParentElement(e
) {
1253 e
.parentNode
.style
.display
= "none";
1256 function dropboxSelect(e
, v
) {
1257 for (i
= 0; i
< e
.length
; i
++) {
1258 if (e
[i
].value
== v
) {
1259 e
.selectedIndex
= i
;
1265 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1266 // bugfixed just a little bit :-)
1267 function getURLParam(strParamName
){
1269 var strHref
= window
.location
.href
;
1271 if (strHref
.indexOf("#") == strHref
.length
-1) {
1272 strHref
= strHref
.substring(0, strHref
.length
-1);
1275 if ( strHref
.indexOf("?") > -1 ){
1276 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1277 var aQueryString
= strQueryString
.split("&");
1278 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1279 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1280 var aParam
= aQueryString
[iParam
].split("=");
1281 strReturn
= aParam
[1];
1289 function leading_zero(p
) {
1291 if (s
.length
== 1) s
= "0" + s
;
1295 function closeInfoBox(cleanup
) {
1296 var box
= document
.getElementById('infoBox');
1297 var shadow
= document
.getElementById('infoBoxShadow');
1300 shadow
.style
.display
= "none";
1302 box
.style
.display
= "none";
1305 if (cleanup
) box
.innerHTML
= " ";
1313 function displayDlg(id
, param
) {
1315 if (!xmlhttp_ready(xmlhttp
)) {
1316 printLockingError();
1322 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1323 param_escape(id
) + "¶m=" + param_escape(param
), true);
1324 xmlhttp
.onreadystatechange
=infobox_callback
;
1332 function infobox_submit_callback() {
1333 if (xmlhttp
.readyState
== 4) {
1337 // called from prefs, reload tab
1339 selectTab(active_tab
, false);
1343 notify(xmlhttp
.responseText
);
1348 function infobox_callback() {
1349 if (xmlhttp
.readyState
== 4) {
1350 var box
= document
.getElementById('infoBox');
1351 var shadow
= document
.getElementById('infoBoxShadow');
1353 box
.innerHTML
=xmlhttp
.responseText
;
1355 shadow
.style
.display
= "block";
1357 box
.style
.display
= "block";
1364 function qaddFilter() {
1366 if (!xmlhttp_ready(xmlhttp
)) {
1367 printLockingError();
1371 var form
= document
.forms
['filter_add_form'];
1372 var reg_exp
= form
.reg_exp
.value
;
1374 if (reg_exp
== "") {
1375 alert("Can't add filter: nothing to match on.");
1379 var query
= Form
.serialize("filter_add_form");
1381 xmlhttp
.open("GET", "backend.php?" + query
, true);
1382 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1388 function toggleSubmitNotEmpty(e
, submit_id
) {
1390 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1392 exception_error("toggleSubmitNotEmpty", e
);
1396 function isValidURL(s
) {
1397 return s
.match("http://") != null || s
.match("https://") != null;
1402 if (!xmlhttp_ready(xmlhttp
)) {
1403 printLockingError();
1407 var form
= document
.forms
['feed_add_form'];
1408 var feed_url
= form
.feed_url
.value
;
1410 if (feed_url
== "") {
1411 alert("Can't subscribe: no feed URL given.");
1415 notify("Adding feed...", true);
1419 var feeds_doc
= document
;
1421 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1423 var query
= Form
.serialize("feed_add_form");
1425 xmlhttp
.open("GET", "backend.php?" + query
, true);
1426 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1432 function filterCR(e
, f
)
1437 key
= window
.event
.keyCode
; //IE
1439 key
= e
.which
; //firefox
1442 if (typeof f
!= 'undefined') {
1453 function getMainContext() {
1457 function getFeedsContext() {
1461 function getContentContext() {
1465 function getHeadlinesContext() {
1469 var debug_last_class
= "even";
1471 function debug(msg
) {
1473 if (debug_last_class
== "even") {
1474 debug_last_class
= "odd";
1476 debug_last_class
= "even";
1479 var c
= document
.getElementById('debug_output');
1480 if (c
&& c
.style
.display
== "block") {
1481 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1482 c
.removeChild(c
.lastChild
);
1486 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1487 ":" + leading_zero(d
.getSeconds());
1488 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1489 msg
+ "</li>" + c
.innerHTML
;
1493 function getInitParam(key
) {
1494 return getMainContext().init_params
[key
];
1497 function storeInitParam(key
, value
, is_client
) {
1500 if (getMainContext().init_params
[key
] != value
) {
1501 debug("storeInitParam: " + key
+ " => " + value
);
1502 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1503 // param_escape(key) + "&value=" + param_escape(value));
1504 var f
= getMainContext().document
.getElementById("backReqBox");
1505 f
.src
= "backend.php?op=rpc&subop=storeParam&key=" +
1506 param_escape(key
) + "&value=" + param_escape(value
);
1509 getMainContext().init_params
[key
] = value
;
1511 exception_error("storeInitParam", e
);
1516 function storeInitParams(params, is_client) {
1521 if (getMainContext().init_params[k] != params[k]) {
1522 s += k + "=" + params[k] + ";";
1523 getMainContext().init_params[k] = params[k];
1527 debug("storeInitParams: " + s);
1530 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1533 exception_error("storeInitParams", e);
1537 function fatalError(code
, message
) {
1541 //window.location.href = "login.php?rt=none";
1542 } else if (code
== 5) {
1543 window
.location
.href
= "update.php";
1545 var fe
= document
.getElementById("fatal_error");
1546 var fc
= document
.getElementById("fatal_error_msg");
1548 fc
.innerHTML
= "Code " + code
+ ": " + message
;
1550 fe
.style
.display
= "block";
1554 exception_error("fatalError", e
);
1558 function getFeedName(id
, is_cat
) {
1559 var d
= getFeedsContext().document
;
1564 e
= d
.getElementById("FCATN-" + id
);
1566 e
= d
.getElementById("FEEDN-" + id
);
1569 return e
.innerHTML
.stripTags();
1575 function viewContentUrl(url
) {
1576 getContentContext().location
= url
;
1579 function filterDlgCheckAction(sender
) {
1583 var action
= sender
[sender
.selectedIndex
].value
;
1585 var form
= document
.forms
["filter_add_form"];
1588 form
= document
.forms
["filter_edit_form"];
1592 debug("filterDlgCheckAction: can't find form!");
1596 var action_param
= form
.action_param
;
1598 if (!action_param
) {
1599 debug("filterDlgCheckAction: can't find action param!");
1603 // if selected action supports parameters, enable params field
1605 action_param
.disabled
= false;
1607 action_param
.disabled
= true;
1611 exception_error(e
, "filterDlgCheckAction");
1616 function explainError(code
) {
1617 return displayDlg("explainError", code
);
1620 function logoutUser() {
1622 if (xmlhttp_ready(xmlhttp_rpc
)) {
1623 xmlhttp_rpc
.open("GET", "backend.php?op=rpc&subop=logout", true);
1624 xmlhttp_rpc
.onreadystatechange
=logout_callback
;
1625 xmlhttp_rpc
.send(null);
1627 printLockingError();
1630 exception_error("logoutUser", e
);