]>
git.wh0rd.org - tt-rss.git/blob - functions.js
26f3f4bfb1e972255913626d5d80e429b26e3cb1
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
== 190 && shift_key
) { // >
244 if (keycode
== 188 && shift_key
) { // <
248 if (keycode
== 191 && shift_key
) { // ?
252 if (keycode
== 69 && shift_key
) {
253 return editFeedDlg(getActiveFeedId());
256 if (typeof localHotkeyHandler
!= 'undefined') {
258 return localHotkeyHandler(e
);
260 exception_error("hotkey_handler, local:", e
);
264 debug("KP=" + keycode
);
266 exception_error("hotkey_handler", e
);
270 function cleanSelectedList(element
) {
271 var content
= document
.getElementById(element
);
273 if (!document
.getElementById("feedCatHolder")) {
274 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
275 var child
= content
.childNodes
[i
];
277 child
.className
= child
.className
.replace("Selected", "");
283 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
284 var child
= content
.childNodes
[i
];
285 if (child
.id
== "feedCatHolder") {
287 var fcat
= child
.lastChild
;
288 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
289 var feed
= fcat
.childNodes
[j
];
290 feed
.className
= feed
.className
.replace("Selected", "");
298 function cleanSelected(element
) {
299 var content
= document
.getElementById(element
);
301 for (i
= 0; i
< content
.rows
.length
; i
++) {
302 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
306 function getVisibleUnreadHeadlines() {
307 var content
= document
.getElementById("headlinesList");
309 var rows
= new Array();
311 for (i
= 0; i
< content
.rows
.length
; i
++) {
312 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
313 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
320 function getVisibleHeadlineIds() {
322 var content
= document
.getElementById("headlinesList");
324 var rows
= new Array();
326 for (i
= 0; i
< content
.rows
.length
; i
++) {
327 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
328 if (row_id
.length
> 0) {
335 function getFirstVisibleHeadlineId() {
336 var rows
= getVisibleHeadlineIds();
340 function getLastVisibleHeadlineId() {
341 var rows
= getVisibleHeadlineIds();
342 return rows
[rows
.length
-1];
345 function markHeadline(id
) {
346 var row
= document
.getElementById("RROW-" + id
);
348 var is_active
= false;
350 if (row
.className
.match("Active")) {
353 row
.className
= row
.className
.replace("Selected", "");
354 row
.className
= row
.className
.replace("Active", "");
355 row
.className
= row
.className
.replace("Insensitive", "");
358 row
.className
= row
.className
= "Active";
361 var check
= document
.getElementById("RCHK-" + id
);
364 check
.checked
= true;
367 row
.className
= row
.className
+ "Selected";
372 function getFeedIds() {
373 var content
= document
.getElementById("feedsList");
375 var rows
= new Array();
377 for (i
= 0; i
< content
.rows
.length
; i
++) {
378 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
387 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
393 d
.setTime(lifetime
* 1000);
396 int_setCookie(name
, value
, d
, path
, domain
, secure
);
400 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
401 document
.cookie
= name
+ "=" + escape(value
) +
402 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
403 ((path
) ? "; path=" + path
: "") +
404 ((domain
) ? "; domain=" + domain
: "") +
405 ((secure
) ? "; secure" : "");
408 function delCookie(name
, path
, domain
) {
409 if (getCookie(name
)) {
410 document
.cookie
= name
+ "=" +
411 ((path
) ? ";path=" + path
: "") +
412 ((domain
) ? ";domain=" + domain
: "" ) +
413 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
418 function getCookie(name
) {
420 var dc
= document
.cookie
;
421 var prefix
= name
+ "=";
422 var begin
= dc
.indexOf("; " + prefix
);
424 begin
= dc
.indexOf(prefix
);
425 if (begin
!= 0) return null;
430 var end
= document
.cookie
.indexOf(";", begin
);
434 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
437 function disableContainerChildren(id
, disable
, doc
) {
439 if (!doc
) doc
= document
;
441 var container
= doc
.getElementById(id
);
444 //alert("disableContainerChildren: element " + id + " not found");
448 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
449 var child
= container
.childNodes
[i
];
452 child
.disabled
= disable
;
458 if (child
.className
&& child
.className
.match("button")) {
459 child
.className
= "disabledButton";
462 if (child
.className
&& child
.className
.match("disabledButton")) {
463 child
.className
= "button";
470 function gotoPreferences() {
471 document
.location
.href
= "prefs.php";
474 function gotoMain() {
475 document
.location
.href
= "tt-rss.php";
478 function gotoExportOpml() {
479 document
.location
.href
= "opml.php?op=Export";
482 function getActiveFeedId() {
483 // return getCookie("ttrss_vf_actfeed");
485 debug("gAFID: " + active_feed_id
);
486 return active_feed_id
;
488 exception_error("getActiveFeedId", e
);
492 function activeFeedIsCat() {
493 return active_feed_is_cat
;
496 function setActiveFeedId(id
) {
497 // return setCookie("ttrss_vf_actfeed", id);
499 debug("sAFID(" + id
+ ")");
502 exception_error("setActiveFeedId", e
);
506 function parse_counters(reply
, scheduled_call
) {
511 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
512 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
513 reply
= reply
.firstChild
;
516 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
517 if (!reply
.childNodes
[l
] ||
518 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
519 // where did this come from?
523 var id
= reply
.childNodes
[l
].getAttribute("id");
524 var t
= reply
.childNodes
[l
].getAttribute("type");
525 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
526 var error
= reply
.childNodes
[l
].getAttribute("error");
527 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
528 var updated
= reply
.childNodes
[l
].getAttribute("updated");
530 if (id
== "global-unread") {
536 if (id
== "subscribed-feeds") {
541 if (t
== "category") {
542 var catctr
= document
.getElementById("FCATCTR-" + id
);
544 catctr
.innerHTML
= "(" + ctr
+ ")";
546 catctr
.className
= "catCtrHasUnread";
548 catctr
.className
= "catCtrNoUnread";
554 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
555 var feedu
= document
.getElementById("FEEDU-" + id
);
556 var feedr
= document
.getElementById("FEEDR-" + id
);
557 var feed_img
= document
.getElementById("FIMG-" + id
);
558 var feedlink
= document
.getElementById("FEEDL-" + id
);
559 var feedupd
= document
.getElementById("FLUPD-" + id
);
561 if (updated
&& feedlink
) {
563 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
565 feedlink
.title
= "Updated: " + updated
;
569 if (updated
&& feedupd
) {
571 feedupd
.innerHTML
= updated
+ " (Error)";
573 feedupd
.innerHTML
= updated
;
577 if (feedctr
&& feedu
&& feedr
) {
579 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
583 feedu
.innerHTML
= ctr
;
586 feedr
.className
= feedr
.className
.replace("feed", "error");
588 feedr
.className
= feedr
.className
.replace("error", "feed");
592 feedctr
.className
= "odd";
593 if (!feedr
.className
.match("Unread")) {
594 var is_selected
= feedr
.className
.match("Selected");
596 feedr
.className
= feedr
.className
.replace("Selected", "");
597 feedr
.className
= feedr
.className
.replace("Unread", "");
599 feedr
.className
= feedr
.className
+ "Unread";
602 feedr
.className
= feedr
.className
+ "Selected";
607 feedctr
.className
= "invisible";
608 feedr
.className
= feedr
.className
.replace("Unread", "");
613 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
615 var feeds_stored
= number_of_feeds
;
617 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
619 if (feeds_stored
!= feeds_found
) {
620 number_of_feeds
= feeds_found
;
622 if (feeds_stored
!= 0) {
623 debug("Subscribed feed number changed, refreshing feedlist");
624 setTimeout('updateFeedList(false, false)', 50);
629 exception_error("parse_counters", e
);
633 function parse_counters_reply(xmlhttp
, scheduled_call
) {
635 if (!xmlhttp
.responseXML
) {
636 notify("refetch_callback: backend did not return valid XML", true, true);
640 var reply
= xmlhttp
.responseXML
.firstChild
;
643 notify("refetch_callback: backend did not return expected XML object", true, true);
648 var error_code
= false;
649 var error_msg
= false;
651 if (reply
.firstChild
) {
652 error_code
= reply
.firstChild
.getAttribute("error-code");
653 error_msg
= reply
.firstChild
.getAttribute("error-msg");
657 error_code
= reply
.getAttribute("error-code");
658 error_msg
= reply
.getAttribute("error-msg");
661 if (error_code
&& error_code
!= 0) {
662 debug("refetch_callback: got error code " + error_code
);
663 return fatalError(error_code
, error_msg
);
666 var counters
= reply
.firstChild
;
668 parse_counters(counters
, scheduled_call
);
670 var runtime_info
= counters
.nextSibling
;
672 parse_runtime_info(runtime_info
);
674 if (getInitParam("feeds_sort_by_unread") == 1) {
678 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
682 function all_counters_callback() {
683 if (xmlhttp_rpc
.readyState
== 4) {
685 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
686 debug("[all_counters_callback] backend did not return valid XML");
690 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
692 var reply = xmlhttp_rpc.responseXML.firstChild;
694 var counters = reply.firstChild;
696 parse_counters(counters);
698 var runtime = counters.nextSibling;
701 parse_runtime_info(runtime);
704 if (getInitParam("feeds_sort_by_unread") == 1) {
708 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
710 debug("in all_counters_callback");
712 parse_counters_reply(xmlhttp_rpc
);
715 exception_error("all_counters_callback", e
);
720 function get_feed_entry_unread(doc
, elem
) {
722 var id
= elem
.id
.replace("FEEDR-", "");
729 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
735 function resort_category(doc
, node
) {
736 debug("resort_category: " + node
);
738 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
739 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
740 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
742 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
746 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
747 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
749 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
750 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
752 if (cur_val
> tmp_val
) {
753 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
754 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
755 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
756 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
765 function resort_feedlist() {
766 debug("resort_feedlist");
770 if (fd
.getElementById("feedCatHolder")) {
772 var feeds
= fd
.getElementById("feedList");
773 var child
= feeds
.firstChild
;
777 if (child
.id
== "feedCatHolder") {
778 resort_category(fd
, child
.firstChild
);
781 child
= child
.nextSibling
;
785 resort_category(fd
, fd
.getElementById("feedList"));
789 function update_all_counters(feed
) {
790 if (xmlhttp_ready(xmlhttp_rpc
)) {
791 var query
= "backend.php?op=rpc&subop=getAllCounters";
794 query
= query
+ "&aid=" + feed
;
797 if (tagsAreDisplayed()) {
798 query
= query
+ "&omode=lt";
800 query
= query
+ "&omode=flc";
803 debug("update_all_counters QUERY: " + query
);
805 xmlhttp_rpc
.open("GET", query
, true);
806 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
807 xmlhttp_rpc
.send(null);
811 function popupHelp(tid
) {
812 var w
= window
.open("backend.php?op=help&tid=" + tid
,
814 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
817 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
818 * * @author Sundar Dorai-Raj
819 * * Email: sdoraira@vt.edu
820 * * This program is free software; you can redistribute it and/or
821 * * modify it under the terms of the GNU General Public License
822 * * as published by the Free Software Foundation; either version 2
823 * * of the License, or (at your option) any later version,
824 * * provided that any use properly credits the author.
825 * * This program is distributed in the hope that it will be useful,
826 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
827 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
828 * * GNU General Public License for more details at http://www.gnu.org * * */
830 var numbers
=".0123456789";
831 function isNumeric(x
) {
832 // is x a String or a character?
834 // remove negative sign
836 for(j
=0;j
<x
.length
;j
++) {
837 // call isNumeric recursively for each character
838 number
=isNumeric(x
.substring(j
,j
+1));
839 if(!number
) return number
;
844 // if x is number return true
845 if(numbers
.indexOf(x
)>=0) return true;
851 function hideOrShowFeeds(doc
, hide
) {
853 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
857 var list
= fd
.getElementById("feedList");
859 if (fd
.getElementById("feedCatHolder")) {
861 var feeds
= fd
.getElementById("feedList");
862 var child
= feeds
.firstChild
;
866 if (child
.id
== "feedCatHolder") {
867 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
870 child
= child
.nextSibling
;
874 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
878 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
880 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
885 debug("hideOrShowFeeds: passed node is null, aborting");
889 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
890 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
891 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
893 if (node
.childNodes
[i
].style
!= undefined) {
895 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
897 // debug(node.childNodes[i].id + " --> " + has_unread);
899 if (hide
&& !has_unread
) {
900 node
.childNodes
[i
].style
.display
= "none";
904 node
.childNodes
[i
].style
.display
= "list-item";
908 node
.childNodes
[i
].style
.display
= "list-item";
915 if (cat_unread
== 0) {
916 if (cat_node
.style
== undefined) {
917 debug("ERROR: supplied cat_node " + cat_node
+
918 " has no styles. WTF?");
922 cat_node
.style
.display
= "none";
924 cat_node
.style
.display
= "list-item";
928 cat_node
.style
.display
= "list-item";
934 // debug("unread for category: " + cat_unread);
937 function selectTableRow(r
, do_select
) {
938 r
.className
= r
.className
.replace("Selected", "");
941 r
.className
= r
.className
+ "Selected";
945 function selectTableRowById(elem_id
, check_id
, do_select
) {
949 var row
= document
.getElementById(elem_id
);
952 selectTableRow(row
, do_select
);
955 var check
= document
.getElementById(check_id
);
958 check
.checked
= do_select
;
961 exception_error("selectTableRowById", e
);
965 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
966 classcheck
, reset_others
) {
968 var content
= document
.getElementById(content_id
);
971 alert("[selectTableRows] Element " + content_id
+ " not found.");
975 for (i
= 0; i
< content
.rows
.length
; i
++) {
976 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
978 if (content
.rows
[i
].id
.match(prefix
)) {
979 selectTableRow(content
.rows
[i
], do_select
);
981 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
982 var check
= document
.getElementById(check_prefix
+ row_id
);
985 check
.checked
= do_select
;
987 } else if (reset_others
) {
988 selectTableRow(content
.rows
[i
], false);
990 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
991 var check
= document
.getElementById(check_prefix
+ row_id
);
994 check
.checked
= false;
998 } else if (reset_others
) {
999 selectTableRow(content
.rows
[i
], false);
1001 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1002 var check
= document
.getElementById(check_prefix
+ row_id
);
1005 check
.checked
= false;
1012 function getSelectedTableRowIds(content_id
, prefix
) {
1014 var content
= document
.getElementById(content_id
);
1017 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1021 var sel_rows
= new Array();
1023 for (i
= 0; i
< content
.rows
.length
; i
++) {
1024 if (content
.rows
[i
].id
.match(prefix
) &&
1025 content
.rows
[i
].className
.match("Selected")) {
1027 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1028 sel_rows
.push(row_id
);
1036 function toggleSelectRowById(sender
, id
) {
1037 var row
= document
.getElementById(id
);
1039 if (sender
.checked
) {
1040 if (!row
.className
.match("Selected")) {
1041 row
.className
= row
.className
+ "Selected";
1044 if (row
.className
.match("Selected")) {
1045 row
.className
= row
.className
.replace("Selected", "");
1050 function toggleSelectListRow(sender
) {
1051 var parent_row
= sender
.parentNode
;
1053 if (sender
.checked
) {
1054 if (!parent_row
.className
.match("Selected")) {
1055 parent_row
.className
= parent_row
.className
+ "Selected";
1058 if (parent_row
.className
.match("Selected")) {
1059 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1065 function toggleSelectRow(sender
) {
1066 var parent_row
= sender
.parentNode
.parentNode
;
1068 if (sender
.checked
) {
1069 if (!parent_row
.className
.match("Selected")) {
1070 parent_row
.className
= parent_row
.className
+ "Selected";
1073 if (parent_row
.className
.match("Selected")) {
1074 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1079 function openExternalUrl(url
) {
1080 var w
= window
.open(url
);
1083 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1085 if (direction
== "next") {
1086 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1087 var child
= list
.childNodes
[i
];
1088 if (child
.id
&& child
.id
== "feedCatHolder") {
1089 if (child
.lastChild
) {
1090 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1093 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1094 return child
.id
.replace('FEEDR-', '');
1099 // FIXME select last feed doesn't work when only unread feeds are visible
1101 if (direction
== "prev") {
1102 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1103 var child
= list
.childNodes
[i
];
1104 if (child
.id
== "feedCatHolder") {
1105 if (child
.firstChild
) {
1106 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1109 } else if (child
.id
.match("FEEDR-")) {
1111 if (getInitParam("hide_read_feeds") == 1) {
1112 if (child
.className
!= "feed") {
1113 alert(child
.className
);
1114 return child
.id
.replace('FEEDR-', '');
1117 return child
.id
.replace('FEEDR-', '');
1124 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1126 if (getInitParam("hide_read_feeds") == 1) {
1130 if (direction
== "next") {
1136 if (e
.nextSibling
) {
1140 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1142 var this_cat
= e
.parentNode
.parentNode
;
1146 if (this_cat
&& this_cat
.nextSibling
) {
1147 while (!e
&& this_cat
.nextSibling
) {
1148 this_cat
= this_cat
.nextSibling
;
1149 if (this_cat
.id
== "feedCatHolder") {
1150 e
= this_cat
.firstChild
.firstChild
;
1160 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1161 e
.className
.match("feed"))) {
1162 return e
.id
.replace("FEEDR-", "");
1167 } else if (direction
== "prev") {
1173 if (e
.previousSibling
) {
1175 e
= e
.previousSibling
;
1177 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1179 var this_cat
= e
.parentNode
.parentNode
;
1183 if (this_cat
&& this_cat
.previousSibling
) {
1184 while (!e
&& this_cat
.previousSibling
) {
1185 this_cat
= this_cat
.previousSibling
;
1186 if (this_cat
.id
== "feedCatHolder") {
1187 e
= this_cat
.firstChild
.lastChild
;
1197 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1198 e
.className
.match("feed"))) {
1199 return e
.id
.replace("FEEDR-", "");
1207 function showBlockElement(id
) {
1208 var elem
= document
.getElementById(id
);
1211 elem
.style
.display
= "block";
1213 alert("[showBlockElement] can't find element with id " + id
);
1217 function hideParentElement(e
) {
1218 e
.parentNode
.style
.display
= "none";
1221 function dropboxSelect(e
, v
) {
1222 for (i
= 0; i
< e
.length
; i
++) {
1223 if (e
[i
].value
== v
) {
1224 e
.selectedIndex
= i
;
1230 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1231 // bugfixed just a little bit :-)
1232 function getURLParam(strParamName
){
1234 var strHref
= window
.location
.href
;
1236 if (strHref
.indexOf("#") == strHref
.length
-1) {
1237 strHref
= strHref
.substring(0, strHref
.length
-1);
1240 if ( strHref
.indexOf("?") > -1 ){
1241 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1242 var aQueryString
= strQueryString
.split("&");
1243 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1244 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1245 var aParam
= aQueryString
[iParam
].split("=");
1246 strReturn
= aParam
[1];
1254 function leading_zero(p
) {
1256 if (s
.length
== 1) s
= "0" + s
;
1260 function closeInfoBox(cleanup
) {
1261 var box
= document
.getElementById('infoBox');
1262 var shadow
= document
.getElementById('infoBoxShadow');
1265 shadow
.style
.display
= "none";
1267 box
.style
.display
= "none";
1270 if (cleanup
) box
.innerHTML
= " ";
1278 function displayDlg(id
, param
) {
1280 if (!xmlhttp_ready(xmlhttp
)) {
1281 printLockingError();
1287 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1288 param_escape(id
) + "¶m=" + param_escape(param
), true);
1289 xmlhttp
.onreadystatechange
=infobox_callback
;
1297 function infobox_submit_callback() {
1298 if (xmlhttp
.readyState
== 4) {
1302 // called from prefs, reload tab
1304 selectTab(active_tab
, false);
1308 notify(xmlhttp
.responseText
);
1313 function infobox_callback() {
1314 if (xmlhttp
.readyState
== 4) {
1315 var box
= document
.getElementById('infoBox');
1316 var shadow
= document
.getElementById('infoBoxShadow');
1318 box
.innerHTML
=xmlhttp
.responseText
;
1320 shadow
.style
.display
= "block";
1322 box
.style
.display
= "block";
1329 function qaddFilter() {
1331 if (!xmlhttp_ready(xmlhttp
)) {
1332 printLockingError();
1336 var form
= document
.forms
['filter_add_form'];
1337 var reg_exp
= form
.reg_exp
.value
;
1339 if (reg_exp
== "") {
1340 alert("Can't add filter: nothing to match on.");
1344 var query
= Form
.serialize("filter_add_form");
1346 xmlhttp
.open("GET", "backend.php?" + query
, true);
1347 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1353 function toggleSubmitNotEmpty(e
, submit_id
) {
1355 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1357 exception_error("toggleSubmitNotEmpty", e
);
1361 function isValidURL(s
) {
1362 return s
.match("http://") != null || s
.match("https://") != null;
1367 if (!xmlhttp_ready(xmlhttp
)) {
1368 printLockingError();
1372 var form
= document
.forms
['feed_add_form'];
1373 var feed_url
= form
.feed_url
.value
;
1375 if (feed_url
== "") {
1376 alert("Can't subscribe: no feed URL given.");
1380 notify("Adding feed...", true);
1384 var feeds_doc
= document
;
1386 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1388 var query
= Form
.serialize("feed_add_form");
1390 xmlhttp
.open("GET", "backend.php?" + query
, true);
1391 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1397 function filterCR(e
, f
)
1402 key
= window
.event
.keyCode
; //IE
1404 key
= e
.which
; //firefox
1407 if (typeof f
!= 'undefined') {
1418 function getMainContext() {
1422 function getFeedsContext() {
1426 function getContentContext() {
1430 function getHeadlinesContext() {
1434 var debug_last_class
= "even";
1436 function debug(msg
) {
1438 if (debug_last_class
== "even") {
1439 debug_last_class
= "odd";
1441 debug_last_class
= "even";
1444 var c
= document
.getElementById('debug_output');
1445 if (c
&& c
.style
.display
== "block") {
1446 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1447 c
.removeChild(c
.lastChild
);
1451 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1452 ":" + leading_zero(d
.getSeconds());
1453 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1454 msg
+ "</li>" + c
.innerHTML
;
1458 function getInitParam(key
) {
1459 return getMainContext().init_params
[key
];
1462 function storeInitParam(key
, value
, is_client
) {
1465 if (getMainContext().init_params
[key
] != value
) {
1466 debug("storeInitParam: " + key
+ " => " + value
);
1467 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1468 // param_escape(key) + "&value=" + param_escape(value));
1469 var f
= getMainContext().document
.getElementById("backReqBox");
1470 f
.src
= "backend.php?op=rpc&subop=storeParam&key=" +
1471 param_escape(key
) + "&value=" + param_escape(value
);
1474 getMainContext().init_params
[key
] = value
;
1476 exception_error("storeInitParam", e
);
1481 function storeInitParams(params, is_client) {
1486 if (getMainContext().init_params[k] != params[k]) {
1487 s += k + "=" + params[k] + ";";
1488 getMainContext().init_params[k] = params[k];
1492 debug("storeInitParams: " + s);
1495 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1498 exception_error("storeInitParams", e);
1502 function fatalError(code
, message
) {
1507 var fe
= document
.getElementById("fatal_error");
1508 var fc
= document
.getElementById("fatal_error_msg");
1510 fc
.innerHTML
= "Code " + code
+ ": " + message
;
1512 fe
.style
.display
= "block";
1514 window
.location
.href
= "login.php?rt=none";
1518 exception_error("fatalError", e
);
1522 function getFeedName(id
, is_cat
) {
1523 var d
= getFeedsContext().document
;
1528 e
= d
.getElementById("FCATN-" + id
);
1530 e
= d
.getElementById("FEEDN-" + id
);
1533 return e
.innerHTML
.stripTags();
1539 function viewContentUrl(url
) {
1540 getContentContext().location
= url
;
1543 function filterDlgCheckAction(sender
) {
1547 var action
= sender
[sender
.selectedIndex
].value
;
1549 var form
= document
.forms
["filter_add_form"];
1552 form
= document
.forms
["filter_edit_form"];
1556 debug("filterDlgCheckAction: can't find form!");
1560 var action_param
= form
.action_param
;
1562 if (!action_param
) {
1563 debug("filterDlgCheckAction: can't find action param!");
1567 // if selected action supports parameters, enable params field
1569 action_param
.disabled
= false;
1571 action_param
.disabled
= true;
1575 exception_error(e
, "filterDlgCheckAction");