]>
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");
14 function exception_error(location
, e
, silent
) {
18 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
20 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
21 "\nFunction: " + location
+ "()" +
22 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
25 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
28 debug("<b>EXCEPTION: " + msg
+ "</b>");
35 function disableHotkeys() {
36 hotkeys_enabled
= false;
39 function enableHotkeys() {
40 hotkeys_enabled
= true;
43 function xmlhttp_ready(obj
) {
44 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
47 function notify_callback() {
48 var container
= document
.getElementById('notify');
49 if (xmlhttp
.readyState
== 4) {
50 container
.innerHTML
=xmlhttp
.responseText
;
54 function rpc_notify_callback() {
55 var container
= document
.getElementById('notify');
56 if (xmlhttp_rpc
.readyState
== 4) {
57 container
.innerHTML
=xmlhttp_rpc
.responseText
;
61 function param_escape(arg
) {
62 if (typeof encodeURIComponent
!= 'undefined')
63 return encodeURIComponent(arg
);
68 function param_unescape(arg
) {
69 if (typeof decodeURIComponent
!= 'undefined')
70 return decodeURIComponent(arg
);
77 then
=new Date().getTime();
79 while((now
-then
)<gap
) {
80 now
=new Date().getTime();
84 var notify_hide_timerid
= false;
85 var notify_last_doc
= false;
87 var notify_effect
= false;
89 function hide_notify() {
90 if (notify_last_doc
) {
91 var n
= notify_last_doc
.getElementById("notify");
92 n
.style
.display
= "none";
94 /* if (browser_has_opacity()) {
95 if (notify_opacity >= 0) {
96 notify_opacity = notify_opacity - 0.1;
97 n.style.opacity = notify_opacity;
98 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
100 n.style.display = "none";
104 n.style.display = "none";
109 function notify_real(msg
, doc
, no_hide
, is_err
) {
111 var n
= doc
.getElementById("notify");
112 var nb
= doc
.getElementById("notify_body");
114 if (!n
|| !nb
) return;
116 if (notify_hide_timerid
) {
117 window
.clearTimeout(notify_hide_timerid
);
120 notify_last_doc
= doc
;
124 if (n
.style
.display
== "block") {
125 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
129 n
.style
.display
= "block";
133 n
.className
= "notifyError";
134 // n.style.backgroundColor = "#ffcccc";
135 // n.style.color = "black";
136 // n.style.borderColor = "#ff0000";
138 n
.className
= "notify";
139 // n.style.backgroundColor = "#fff7d5";
140 // n.style.borderColor = "#d7c47a";
141 // n.style.color = "black";
144 // msg = "<img src='images/live_com_loading.gif'> " + msg;
149 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
153 function p_notify(msg
, no_hide
, is_err
) {
154 notify_real(msg
, document
, no_hide
, is_err
);
157 function notify(msg
, no_hide
, is_err
) {
158 notify_real(msg
, document
, no_hide
, is_err
);
161 function printLockingError() {
162 notify("Please wait until operation finishes");}
164 function hotkey_handler(e
) {
169 var shift_key
= false;
172 shift_key
= e
.shiftKey
;
177 if (!hotkeys_enabled
) return;
180 keycode
= window
.event
.keyCode
;
185 if (keycode
== 82) { // r
186 return scheduleFeedUpdate(true);
189 if (keycode
== 83) { // s
190 return displayDlg("search", getActiveFeedId());
193 if (keycode
== 85) { // u
194 if (getActiveFeedId()) {
195 return viewfeed(getActiveFeedId(), "ForceUpdate");
199 if (keycode
== 65) { // a
200 return toggleDispRead();
203 var feedlist
= document
.getElementById('feedList');
205 if (keycode
== 74) { // j
206 var feed
= getActiveFeedId();
207 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
208 if (new_feed
) viewfeed(new_feed
, '');
211 if (keycode
== 75) { // k
212 var feed
= getActiveFeedId();
213 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
214 if (new_feed
) viewfeed(new_feed
, '');
217 if (keycode
== 78 || keycode
== 40) { // n, down
218 if (typeof moveToPost
!= 'undefined') {
219 return moveToPost('next');
223 if (keycode
== 80 || keycode
== 38) { // p, up
224 if (typeof moveToPost
!= 'undefined') {
225 return moveToPost('prev');
229 if (keycode
== 68 && shift_key
) { // d
230 if (!debug_mode_enabled
) {
231 document
.getElementById('debug_output').style
.display
= 'block';
232 debug('debug mode activated');
234 document
.getElementById('debug_output').style
.display
= 'none';
237 debug_mode_enabled
= !debug_mode_enabled
;
240 if (keycode
== 69 && shift_key
) {
241 return editFeedDlg(getActiveFeedId());
244 if (typeof localHotkeyHandler
!= 'undefined') {
246 return localHotkeyHandler(e
);
248 exception_error("hotkey_handler, local:", e
);
252 debug("KP=" + keycode
);
254 exception_error("hotkey_handler", e
);
258 function cleanSelectedList(element
) {
259 var content
= document
.getElementById(element
);
261 if (!document
.getElementById("feedCatHolder")) {
262 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
263 var child
= content
.childNodes
[i
];
265 child
.className
= child
.className
.replace("Selected", "");
271 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
272 var child
= content
.childNodes
[i
];
273 if (child
.id
== "feedCatHolder") {
275 var fcat
= child
.lastChild
;
276 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
277 var feed
= fcat
.childNodes
[j
];
278 feed
.className
= feed
.className
.replace("Selected", "");
286 function cleanSelected(element
) {
287 var content
= document
.getElementById(element
);
289 for (i
= 0; i
< content
.rows
.length
; i
++) {
290 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
294 function getVisibleUnreadHeadlines() {
295 var content
= document
.getElementById("headlinesList");
297 var rows
= new Array();
299 for (i
= 0; i
< content
.rows
.length
; i
++) {
300 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
301 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
308 function getVisibleHeadlineIds() {
310 var content
= document
.getElementById("headlinesList");
312 var rows
= new Array();
314 for (i
= 0; i
< content
.rows
.length
; i
++) {
315 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
316 if (row_id
.length
> 0) {
323 function getFirstVisibleHeadlineId() {
324 var rows
= getVisibleHeadlineIds();
328 function getLastVisibleHeadlineId() {
329 var rows
= getVisibleHeadlineIds();
330 return rows
[rows
.length
-1];
333 function markHeadline(id
) {
334 var row
= document
.getElementById("RROW-" + id
);
336 var is_active
= false;
338 if (row
.className
.match("Active")) {
341 row
.className
= row
.className
.replace("Selected", "");
342 row
.className
= row
.className
.replace("Active", "");
343 row
.className
= row
.className
.replace("Insensitive", "");
346 row
.className
= row
.className
= "Active";
349 var check
= document
.getElementById("RCHK-" + id
);
352 check
.checked
= true;
355 row
.className
= row
.className
+ "Selected";
360 function getFeedIds() {
361 var content
= document
.getElementById("feedsList");
363 var rows
= new Array();
365 for (i
= 0; i
< content
.rows
.length
; i
++) {
366 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
375 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
381 d
.setTime(lifetime
* 1000);
384 int_setCookie(name
, value
, d
, path
, domain
, secure
);
388 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
389 document
.cookie
= name
+ "=" + escape(value
) +
390 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
391 ((path
) ? "; path=" + path
: "") +
392 ((domain
) ? "; domain=" + domain
: "") +
393 ((secure
) ? "; secure" : "");
396 function delCookie(name
, path
, domain
) {
397 if (getCookie(name
)) {
398 document
.cookie
= name
+ "=" +
399 ((path
) ? ";path=" + path
: "") +
400 ((domain
) ? ";domain=" + domain
: "" ) +
401 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
406 function getCookie(name
) {
408 var dc
= document
.cookie
;
409 var prefix
= name
+ "=";
410 var begin
= dc
.indexOf("; " + prefix
);
412 begin
= dc
.indexOf(prefix
);
413 if (begin
!= 0) return null;
418 var end
= document
.cookie
.indexOf(";", begin
);
422 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
425 function disableContainerChildren(id
, disable
, doc
) {
427 if (!doc
) doc
= document
;
429 var container
= doc
.getElementById(id
);
432 //alert("disableContainerChildren: element " + id + " not found");
436 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
437 var child
= container
.childNodes
[i
];
440 child
.disabled
= disable
;
446 if (child
.className
&& child
.className
.match("button")) {
447 child
.className
= "disabledButton";
450 if (child
.className
&& child
.className
.match("disabledButton")) {
451 child
.className
= "button";
458 function gotoPreferences() {
459 document
.location
.href
= "prefs.php";
462 function gotoMain() {
463 document
.location
.href
= "tt-rss.php";
466 function gotoExportOpml() {
467 document
.location
.href
= "opml.php?op=Export";
470 function getActiveFeedId() {
471 // return getCookie("ttrss_vf_actfeed");
473 debug("gAFID: " + active_feed_id
);
474 return active_feed_id
;
476 exception_error("getActiveFeedId", e
);
480 function activeFeedIsCat() {
481 return active_feed_is_cat
;
484 function setActiveFeedId(id
) {
485 // return setCookie("ttrss_vf_actfeed", id);
487 debug("sAFID(" + id
+ ")");
490 exception_error("setActiveFeedId", e
);
494 function parse_counters(reply
, scheduled_call
) {
499 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
500 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
501 reply
= reply
.firstChild
;
504 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
505 if (!reply
.childNodes
[l
] ||
506 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
507 // where did this come from?
511 var id
= reply
.childNodes
[l
].getAttribute("id");
512 var t
= reply
.childNodes
[l
].getAttribute("type");
513 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
514 var error
= reply
.childNodes
[l
].getAttribute("error");
515 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
516 var updated
= reply
.childNodes
[l
].getAttribute("updated");
518 if (id
== "global-unread") {
524 if (id
== "subscribed-feeds") {
529 if (t
== "category") {
530 var catctr
= document
.getElementById("FCATCTR-" + id
);
532 catctr
.innerHTML
= "(" + ctr
+ " unread)";
537 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
538 var feedu
= document
.getElementById("FEEDU-" + id
);
539 var feedr
= document
.getElementById("FEEDR-" + id
);
540 var feed_img
= document
.getElementById("FIMG-" + id
);
541 var feedlink
= document
.getElementById("FEEDL-" + id
);
542 var feedupd
= document
.getElementById("FLUPD-" + id
);
544 if (updated
&& feedlink
) {
546 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
548 feedlink
.title
= "Updated: " + updated
;
552 if (updated
&& feedupd
) {
554 feedupd
.innerHTML
= updated
+ " (Error)";
556 feedupd
.innerHTML
= updated
;
560 if (feedctr
&& feedu
&& feedr
) {
562 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
566 feedu
.innerHTML
= ctr
;
569 feedr
.className
= feedr
.className
.replace("feed", "error");
571 feedr
.className
= feedr
.className
.replace("error", "feed");
575 feedctr
.className
= "odd";
576 if (!feedr
.className
.match("Unread")) {
577 var is_selected
= feedr
.className
.match("Selected");
579 feedr
.className
= feedr
.className
.replace("Selected", "");
580 feedr
.className
= feedr
.className
.replace("Unread", "");
582 feedr
.className
= feedr
.className
+ "Unread";
585 feedr
.className
= feedr
.className
+ "Selected";
590 feedctr
.className
= "invisible";
591 feedr
.className
= feedr
.className
.replace("Unread", "");
596 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
598 var feeds_stored
= number_of_feeds
;
600 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
602 if (feeds_stored
!= feeds_found
) {
603 number_of_feeds
= feeds_found
;
605 if (feeds_stored
!= 0) {
606 debug("Subscribed feed number changed, refreshing feedlist");
607 setTimeout('updateFeedList(false, false)', 50);
612 exception_error("parse_counters", e
);
616 function parse_counters_reply(xmlhttp
, scheduled_call
) {
618 if (!xmlhttp
.responseXML
) {
619 notify("refetch_callback: backend did not return valid XML", true, true);
623 var reply
= xmlhttp
.responseXML
.firstChild
;
626 notify("refetch_callback: backend did not return expected XML object", true, true);
631 var error_code
= false;
632 var error_msg
= false;
634 if (reply
.firstChild
) {
635 error_code
= reply
.firstChild
.getAttribute("error-code");
636 error_msg
= reply
.firstChild
.getAttribute("error-msg");
640 error_code
= reply
.getAttribute("error-code");
641 error_msg
= reply
.getAttribute("error-msg");
644 if (error_code
&& error_code
!= 0) {
645 debug("refetch_callback: got error code " + error_code
);
646 return fatalError(error_code
, error_msg
);
649 var counters
= reply
.firstChild
;
651 parse_counters(counters
, scheduled_call
);
653 var runtime_info
= counters
.nextSibling
;
655 parse_runtime_info(runtime_info
);
657 if (getInitParam("feeds_sort_by_unread") == 1) {
661 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
665 function all_counters_callback() {
666 if (xmlhttp_rpc
.readyState
== 4) {
668 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
669 debug("[all_counters_callback] backend did not return valid XML");
673 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
675 var reply = xmlhttp_rpc.responseXML.firstChild;
677 var counters = reply.firstChild;
679 parse_counters(counters);
681 var runtime = counters.nextSibling;
684 parse_runtime_info(runtime);
687 if (getInitParam("feeds_sort_by_unread") == 1) {
691 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
693 debug("in all_counters_callback");
695 parse_counters_reply(xmlhttp_rpc
);
698 exception_error("all_counters_callback", e
);
703 function get_feed_entry_unread(doc
, elem
) {
705 var id
= elem
.id
.replace("FEEDR-", "");
712 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
718 function resort_category(doc
, node
) {
719 debug("resort_category: " + node
);
721 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
722 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
723 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
725 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
729 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
730 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
732 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
733 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
735 if (cur_val
> tmp_val
) {
736 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
737 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
738 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
739 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
748 function resort_feedlist() {
749 debug("resort_feedlist");
753 if (fd
.getElementById("feedCatHolder")) {
755 var feeds
= fd
.getElementById("feedList");
756 var child
= feeds
.firstChild
;
760 if (child
.id
== "feedCatHolder") {
761 resort_category(fd
, child
.firstChild
);
764 child
= child
.nextSibling
;
768 resort_category(fd
, fd
.getElementById("feedList"));
772 function update_all_counters(feed
) {
773 if (xmlhttp_ready(xmlhttp_rpc
)) {
774 var query
= "backend.php?op=rpc&subop=getAllCounters";
777 query
= query
+ "&aid=" + feed
;
780 xmlhttp_rpc
.open("GET", query
, true);
781 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
782 xmlhttp_rpc
.send(null);
786 function popupHelp(tid
) {
787 var w
= window
.open("backend.php?op=help&tid=" + tid
,
789 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
792 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
793 * * @author Sundar Dorai-Raj
794 * * Email: sdoraira@vt.edu
795 * * This program is free software; you can redistribute it and/or
796 * * modify it under the terms of the GNU General Public License
797 * * as published by the Free Software Foundation; either version 2
798 * * of the License, or (at your option) any later version,
799 * * provided that any use properly credits the author.
800 * * This program is distributed in the hope that it will be useful,
801 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
802 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
803 * * GNU General Public License for more details at http://www.gnu.org * * */
805 var numbers
=".0123456789";
806 function isNumeric(x
) {
807 // is x a String or a character?
809 // remove negative sign
811 for(j
=0;j
<x
.length
;j
++) {
812 // call isNumeric recursively for each character
813 number
=isNumeric(x
.substring(j
,j
+1));
814 if(!number
) return number
;
819 // if x is number return true
820 if(numbers
.indexOf(x
)>=0) return true;
826 function hideOrShowFeeds(doc
, hide
) {
828 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
832 var list
= fd
.getElementById("feedList");
834 if (fd
.getElementById("feedCatHolder")) {
836 var feeds
= fd
.getElementById("feedList");
837 var child
= feeds
.firstChild
;
841 if (child
.id
== "feedCatHolder") {
842 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
845 child
= child
.nextSibling
;
849 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
853 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
855 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
860 debug("hideOrShowFeeds: passed node is null, aborting");
864 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
865 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
866 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
868 if (node
.childNodes
[i
].style
!= undefined) {
870 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
872 // debug(node.childNodes[i].id + " --> " + has_unread);
874 if (hide
&& !has_unread
) {
875 node
.childNodes
[i
].style
.display
= "none";
879 node
.childNodes
[i
].style
.display
= "list-item";
883 node
.childNodes
[i
].style
.display
= "list-item";
890 if (cat_unread
== 0) {
891 if (cat_node
.style
== undefined) {
892 debug("ERROR: supplied cat_node " + cat_node
+
893 " has no styles. WTF?");
897 cat_node
.style
.display
= "none";
899 cat_node
.style
.display
= "list-item";
903 cat_node
.style
.display
= "list-item";
909 // debug("unread for category: " + cat_unread);
912 function selectTableRow(r
, do_select
) {
913 r
.className
= r
.className
.replace("Selected", "");
916 r
.className
= r
.className
+ "Selected";
920 function selectTableRowById(elem_id
, check_id
, do_select
) {
924 var row
= document
.getElementById(elem_id
);
927 selectTableRow(row
, do_select
);
930 var check
= document
.getElementById(check_id
);
933 check
.checked
= do_select
;
936 exception_error("selectTableRowById", e
);
940 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
941 classcheck
, reset_others
) {
943 var content
= document
.getElementById(content_id
);
946 alert("[selectTableRows] Element " + content_id
+ " not found.");
950 for (i
= 0; i
< content
.rows
.length
; i
++) {
951 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
953 if (content
.rows
[i
].id
.match(prefix
)) {
954 selectTableRow(content
.rows
[i
], do_select
);
956 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
957 var check
= document
.getElementById(check_prefix
+ row_id
);
960 check
.checked
= do_select
;
962 } else if (reset_others
) {
963 selectTableRow(content
.rows
[i
], false);
965 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
966 var check
= document
.getElementById(check_prefix
+ row_id
);
969 check
.checked
= false;
973 } else if (reset_others
) {
974 selectTableRow(content
.rows
[i
], false);
976 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
977 var check
= document
.getElementById(check_prefix
+ row_id
);
980 check
.checked
= false;
987 function getSelectedTableRowIds(content_id
, prefix
) {
989 var content
= document
.getElementById(content_id
);
992 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
996 var sel_rows
= new Array();
998 for (i
= 0; i
< content
.rows
.length
; i
++) {
999 if (content
.rows
[i
].id
.match(prefix
) &&
1000 content
.rows
[i
].className
.match("Selected")) {
1002 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1003 sel_rows
.push(row_id
);
1011 function toggleSelectRowById(sender
, id
) {
1012 var row
= document
.getElementById(id
);
1014 if (sender
.checked
) {
1015 if (!row
.className
.match("Selected")) {
1016 row
.className
= row
.className
+ "Selected";
1019 if (row
.className
.match("Selected")) {
1020 row
.className
= row
.className
.replace("Selected", "");
1025 function toggleSelectListRow(sender
) {
1026 var parent_row
= sender
.parentNode
;
1028 if (sender
.checked
) {
1029 if (!parent_row
.className
.match("Selected")) {
1030 parent_row
.className
= parent_row
.className
+ "Selected";
1033 if (parent_row
.className
.match("Selected")) {
1034 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1040 function toggleSelectRow(sender
) {
1041 var parent_row
= sender
.parentNode
.parentNode
;
1043 if (sender
.checked
) {
1044 if (!parent_row
.className
.match("Selected")) {
1045 parent_row
.className
= parent_row
.className
+ "Selected";
1048 if (parent_row
.className
.match("Selected")) {
1049 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1054 function openExternalUrl(url
) {
1055 var w
= window
.open(url
);
1058 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1060 if (direction
== "next") {
1061 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1062 var child
= list
.childNodes
[i
];
1063 if (child
.id
&& child
.id
== "feedCatHolder") {
1064 if (child
.lastChild
) {
1065 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1068 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1069 return child
.id
.replace('FEEDR-', '');
1074 // FIXME select last feed doesn't work when only unread feeds are visible
1076 if (direction
== "prev") {
1077 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1078 var child
= list
.childNodes
[i
];
1079 if (child
.id
== "feedCatHolder") {
1080 if (child
.firstChild
) {
1081 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1084 } else if (child
.id
.match("FEEDR-")) {
1086 if (getInitParam("hide_read_feeds") == 1) {
1087 if (child
.className
!= "feed") {
1088 alert(child
.className
);
1089 return child
.id
.replace('FEEDR-', '');
1092 return child
.id
.replace('FEEDR-', '');
1099 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1101 if (getInitParam("hide_read_feeds") == 1) {
1105 if (direction
== "next") {
1111 if (e
.nextSibling
) {
1115 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1117 var this_cat
= e
.parentNode
.parentNode
;
1121 if (this_cat
&& this_cat
.nextSibling
) {
1122 while (!e
&& this_cat
.nextSibling
) {
1123 this_cat
= this_cat
.nextSibling
;
1124 if (this_cat
.id
== "feedCatHolder") {
1125 e
= this_cat
.firstChild
.firstChild
;
1135 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1136 e
.className
.match("feed"))) {
1137 return e
.id
.replace("FEEDR-", "");
1142 } else if (direction
== "prev") {
1148 if (e
.previousSibling
) {
1150 e
= e
.previousSibling
;
1152 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1154 var this_cat
= e
.parentNode
.parentNode
;
1158 if (this_cat
&& this_cat
.previousSibling
) {
1159 while (!e
&& this_cat
.previousSibling
) {
1160 this_cat
= this_cat
.previousSibling
;
1161 if (this_cat
.id
== "feedCatHolder") {
1162 e
= this_cat
.firstChild
.lastChild
;
1172 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1173 e
.className
.match("feed"))) {
1174 return e
.id
.replace("FEEDR-", "");
1182 function showBlockElement(id
) {
1183 var elem
= document
.getElementById(id
);
1186 elem
.style
.display
= "block";
1188 alert("[showBlockElement] can't find element with id " + id
);
1192 function hideParentElement(e
) {
1193 e
.parentNode
.style
.display
= "none";
1196 function dropboxSelect(e
, v
) {
1197 for (i
= 0; i
< e
.length
; i
++) {
1198 if (e
[i
].value
== v
) {
1199 e
.selectedIndex
= i
;
1205 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1206 // bugfixed just a little bit :-)
1207 function getURLParam(strParamName
){
1209 var strHref
= window
.location
.href
;
1211 if (strHref
.indexOf("#") == strHref
.length
-1) {
1212 strHref
= strHref
.substring(0, strHref
.length
-1);
1215 if ( strHref
.indexOf("?") > -1 ){
1216 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1217 var aQueryString
= strQueryString
.split("&");
1218 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1219 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1220 var aParam
= aQueryString
[iParam
].split("=");
1221 strReturn
= aParam
[1];
1229 function leading_zero(p
) {
1231 if (s
.length
== 1) s
= "0" + s
;
1235 function closeInfoBox(cleanup
) {
1236 var box
= document
.getElementById('infoBox');
1237 var shadow
= document
.getElementById('infoBoxShadow');
1240 shadow
.style
.display
= "none";
1242 box
.style
.display
= "none";
1245 if (cleanup
) box
.innerHTML
= " ";
1253 function displayDlg(id
, param
) {
1255 if (!xmlhttp_ready(xmlhttp
)) {
1256 printLockingError();
1262 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1263 param_escape(id
) + "¶m=" + param_escape(param
), true);
1264 xmlhttp
.onreadystatechange
=infobox_callback
;
1272 function infobox_submit_callback() {
1273 if (xmlhttp
.readyState
== 4) {
1277 // called from prefs, reload tab
1279 selectTab(active_tab
, false);
1283 notify(xmlhttp
.responseText
);
1288 function infobox_callback() {
1289 if (xmlhttp
.readyState
== 4) {
1290 var box
= document
.getElementById('infoBox');
1291 var shadow
= document
.getElementById('infoBoxShadow');
1293 box
.innerHTML
=xmlhttp
.responseText
;
1295 shadow
.style
.display
= "block";
1297 box
.style
.display
= "block";
1304 function qaddFilter() {
1306 if (!xmlhttp_ready(xmlhttp
)) {
1307 printLockingError();
1311 var form
= document
.forms
['filter_add_form'];
1312 var reg_exp
= form
.reg_exp
.value
;
1314 if (reg_exp
== "") {
1315 alert("Can't add filter: nothing to match on.");
1319 var query
= Form
.serialize("filter_add_form");
1321 xmlhttp
.open("GET", "backend.php?" + query
, true);
1322 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1328 function toggleSubmitNotEmpty(e
, submit_id
) {
1330 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1332 exception_error("toggleSubmitNotEmpty", e
);
1336 function isValidURL(s
) {
1337 return s
.match("http://") != null || s
.match("https://") != null;
1342 if (!xmlhttp_ready(xmlhttp
)) {
1343 printLockingError();
1347 var form
= document
.forms
['feed_add_form'];
1348 var feed_url
= form
.feed_url
.value
;
1350 if (feed_url
== "") {
1351 alert("Can't subscribe: no feed URL given.");
1355 notify("Adding feed...", true);
1359 var feeds_doc
= document
;
1361 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1363 var query
= Form
.serialize("feed_add_form");
1365 xmlhttp
.open("GET", "backend.php?" + query
, true);
1366 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1372 function filterCR(e
, f
)
1377 key
= window
.event
.keyCode
; //IE
1379 key
= e
.which
; //firefox
1382 if (typeof f
!= 'undefined') {
1393 function getMainContext() {
1397 function getFeedsContext() {
1401 function getContentContext() {
1405 function getHeadlinesContext() {
1409 var debug_last_class
= "even";
1411 function debug(msg
) {
1413 if (debug_last_class
== "even") {
1414 debug_last_class
= "odd";
1416 debug_last_class
= "even";
1419 var c
= document
.getElementById('debug_output');
1420 if (c
&& c
.style
.display
== "block") {
1421 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1422 c
.removeChild(c
.lastChild
);
1426 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1427 ":" + leading_zero(d
.getSeconds());
1428 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1429 msg
+ "</li>" + c
.innerHTML
;
1433 function getInitParam(key
) {
1434 return getMainContext().init_params
[key
];
1437 function storeInitParam(key
, value
, is_client
) {
1440 if (getMainContext().init_params
[key
] != value
) {
1441 debug("storeInitParam: " + key
+ " => " + value
);
1442 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1443 // param_escape(key) + "&value=" + param_escape(value));
1444 var f
= getMainContext().document
.getElementById("backReqBox");
1445 f
.src
= "backend.php?op=rpc&subop=storeParam&key=" +
1446 param_escape(key
) + "&value=" + param_escape(value
);
1449 getMainContext().init_params
[key
] = value
;
1451 exception_error("storeInitParam", e
);
1456 function storeInitParams(params, is_client) {
1461 if (getMainContext().init_params[k] != params[k]) {
1462 s += k + "=" + params[k] + ";";
1463 getMainContext().init_params[k] = params[k];
1467 debug("storeInitParams: " + s);
1470 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1473 exception_error("storeInitParams", e);
1477 function fatalError(code
, message
) {
1482 var fe
= document
.getElementById("fatal_error");
1483 var fc
= document
.getElementById("fatal_error_msg");
1485 fc
.innerHTML
= "Code " + code
+ ": " + message
;
1487 fe
.style
.display
= "block";
1489 window
.location
.href
= "login.php?rt=none";
1493 exception_error("fatalError", e
);
1497 function getFeedName(id
, is_cat
) {
1498 var d
= getFeedsContext().document
;
1503 e
= d
.getElementById("FCATN-" + id
);
1505 e
= d
.getElementById("FEEDN-" + id
);
1508 return e
.innerHTML
.stripTags();
1514 function viewContentUrl(url
) {
1515 getContentContext().location
= url
;