]>
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 notify_callback() {
56 var container
= document
.getElementById('notify');
57 if (xmlhttp
.readyState
== 4) {
58 container
.innerHTML
=xmlhttp
.responseText
;
62 function rpc_notify_callback() {
63 var container
= document
.getElementById('notify');
64 if (xmlhttp_rpc
.readyState
== 4) {
65 container
.innerHTML
=xmlhttp_rpc
.responseText
;
69 function param_escape(arg
) {
70 if (typeof encodeURIComponent
!= 'undefined')
71 return encodeURIComponent(arg
);
76 function param_unescape(arg
) {
77 if (typeof decodeURIComponent
!= 'undefined')
78 return decodeURIComponent(arg
);
85 then
=new Date().getTime();
87 while((now
-then
)<gap
) {
88 now
=new Date().getTime();
92 var notify_hide_timerid
= false;
93 var notify_last_doc
= false;
95 var notify_effect
= false;
97 function hide_notify() {
98 if (notify_last_doc
) {
99 var n
= notify_last_doc
.getElementById("notify");
100 n
.style
.display
= "none";
102 /* if (browser_has_opacity()) {
103 if (notify_opacity >= 0) {
104 notify_opacity = notify_opacity - 0.1;
105 n.style.opacity = notify_opacity;
106 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
108 n.style.display = "none";
112 n.style.display = "none";
117 function notify_real(msg
, doc
, no_hide
, is_err
) {
119 var n
= doc
.getElementById("notify");
120 var nb
= doc
.getElementById("notify_body");
122 if (!n
|| !nb
) return;
124 if (notify_hide_timerid
) {
125 window
.clearTimeout(notify_hide_timerid
);
128 notify_last_doc
= doc
;
132 if (n
.style
.display
== "block") {
133 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
137 n
.style
.display
= "block";
141 n
.className
= "notifyError";
142 // n.style.backgroundColor = "#ffcccc";
143 // n.style.color = "black";
144 // n.style.borderColor = "#ff0000";
146 n
.className
= "notify";
147 // n.style.backgroundColor = "#fff7d5";
148 // n.style.borderColor = "#d7c47a";
149 // n.style.color = "black";
152 // msg = "<img src='images/live_com_loading.gif'> " + msg;
157 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
161 function p_notify(msg
, no_hide
, is_err
) {
162 notify_real(msg
, document
, no_hide
, is_err
);
165 function notify(msg
, no_hide
, is_err
) {
166 notify_real(msg
, document
, no_hide
, is_err
);
169 function printLockingError() {
170 notify("Please wait until operation finishes");}
172 function hotkey_handler(e
) {
177 var shift_key
= false;
180 shift_key
= e
.shiftKey
;
185 if (!hotkeys_enabled
) return;
188 keycode
= window
.event
.keyCode
;
193 if (keycode
== 82) { // r
194 return scheduleFeedUpdate(true);
197 if (keycode
== 83) { // s
198 return displayDlg("search", getActiveFeedId());
201 if (keycode
== 85) { // u
202 if (getActiveFeedId()) {
203 return viewfeed(getActiveFeedId(), "ForceUpdate");
207 if (keycode
== 65) { // a
208 return toggleDispRead();
211 var feedlist
= document
.getElementById('feedList');
213 if (keycode
== 74) { // j
214 var feed
= getActiveFeedId();
215 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
216 if (new_feed
) viewfeed(new_feed
, '');
219 if (keycode
== 75) { // k
220 var feed
= getActiveFeedId();
221 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
222 if (new_feed
) viewfeed(new_feed
, '');
225 if (!is_safari() && (keycode
== 78 || keycode
== 40)) { // n, down
226 if (typeof moveToPost
!= 'undefined') {
227 return moveToPost('next');
231 if (!is_safari() && (keycode
== 80 || keycode
== 38)) { // p, up
232 if (typeof moveToPost
!= 'undefined') {
233 return moveToPost('prev');
237 if (keycode
== 68 && shift_key
) { // d
238 if (!debug_mode_enabled
) {
239 document
.getElementById('debug_output').style
.display
= 'block';
240 debug('debug mode activated');
242 document
.getElementById('debug_output').style
.display
= 'none';
245 debug_mode_enabled
= !debug_mode_enabled
;
248 if (keycode
== 190 && shift_key
) { // >
252 if (keycode
== 188 && shift_key
) { // <
256 if (keycode
== 191 && shift_key
) { // ?
260 if (keycode
== 69 && shift_key
) {
261 return editFeedDlg(getActiveFeedId());
264 if (typeof localHotkeyHandler
!= 'undefined') {
266 return localHotkeyHandler(e
);
268 exception_error("hotkey_handler, local:", e
);
272 debug("KP=" + keycode
);
274 exception_error("hotkey_handler", e
);
278 function cleanSelectedList(element
) {
279 var content
= document
.getElementById(element
);
281 if (!document
.getElementById("feedCatHolder")) {
282 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
283 var child
= content
.childNodes
[i
];
285 child
.className
= child
.className
.replace("Selected", "");
291 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
292 var child
= content
.childNodes
[i
];
293 if (child
.id
== "feedCatHolder") {
295 var fcat
= child
.lastChild
;
296 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
297 var feed
= fcat
.childNodes
[j
];
298 feed
.className
= feed
.className
.replace("Selected", "");
306 function cleanSelected(element
) {
307 var content
= document
.getElementById(element
);
309 for (i
= 0; i
< content
.rows
.length
; i
++) {
310 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
314 function getVisibleUnreadHeadlines() {
315 var content
= document
.getElementById("headlinesList");
317 var rows
= new Array();
319 for (i
= 0; i
< content
.rows
.length
; i
++) {
320 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
321 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
328 function getVisibleHeadlineIds() {
330 var content
= document
.getElementById("headlinesList");
332 var rows
= new Array();
334 for (i
= 0; i
< content
.rows
.length
; i
++) {
335 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
336 if (row_id
.length
> 0) {
343 function getFirstVisibleHeadlineId() {
344 var rows
= getVisibleHeadlineIds();
348 function getLastVisibleHeadlineId() {
349 var rows
= getVisibleHeadlineIds();
350 return rows
[rows
.length
-1];
353 function markHeadline(id
) {
354 var row
= document
.getElementById("RROW-" + id
);
356 var is_active
= false;
358 if (row
.className
.match("Active")) {
361 row
.className
= row
.className
.replace("Selected", "");
362 row
.className
= row
.className
.replace("Active", "");
363 row
.className
= row
.className
.replace("Insensitive", "");
366 row
.className
= row
.className
= "Active";
369 var check
= document
.getElementById("RCHK-" + id
);
372 check
.checked
= true;
375 row
.className
= row
.className
+ "Selected";
380 function getFeedIds() {
381 var content
= document
.getElementById("feedsList");
383 var rows
= new Array();
385 for (i
= 0; i
< content
.rows
.length
; i
++) {
386 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
395 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
401 d
.setTime(lifetime
* 1000);
404 int_setCookie(name
, value
, d
, path
, domain
, secure
);
408 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
409 document
.cookie
= name
+ "=" + escape(value
) +
410 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
411 ((path
) ? "; path=" + path
: "") +
412 ((domain
) ? "; domain=" + domain
: "") +
413 ((secure
) ? "; secure" : "");
416 function delCookie(name
, path
, domain
) {
417 if (getCookie(name
)) {
418 document
.cookie
= name
+ "=" +
419 ((path
) ? ";path=" + path
: "") +
420 ((domain
) ? ";domain=" + domain
: "" ) +
421 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
426 function getCookie(name
) {
428 var dc
= document
.cookie
;
429 var prefix
= name
+ "=";
430 var begin
= dc
.indexOf("; " + prefix
);
432 begin
= dc
.indexOf(prefix
);
433 if (begin
!= 0) return null;
438 var end
= document
.cookie
.indexOf(";", begin
);
442 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
445 function disableContainerChildren(id
, disable
, doc
) {
447 if (!doc
) doc
= document
;
449 var container
= doc
.getElementById(id
);
452 //alert("disableContainerChildren: element " + id + " not found");
456 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
457 var child
= container
.childNodes
[i
];
460 child
.disabled
= disable
;
466 if (child
.className
&& child
.className
.match("button")) {
467 child
.className
= "disabledButton";
470 if (child
.className
&& child
.className
.match("disabledButton")) {
471 child
.className
= "button";
478 function gotoPreferences() {
479 document
.location
.href
= "prefs.php";
482 function gotoMain() {
483 document
.location
.href
= "tt-rss.php";
486 function gotoExportOpml() {
487 document
.location
.href
= "opml.php?op=Export";
490 function getActiveFeedId() {
491 // return getCookie("ttrss_vf_actfeed");
493 debug("gAFID: " + active_feed_id
);
494 return active_feed_id
;
496 exception_error("getActiveFeedId", e
);
500 function activeFeedIsCat() {
501 return active_feed_is_cat
;
504 function setActiveFeedId(id
) {
505 // return setCookie("ttrss_vf_actfeed", id);
507 debug("sAFID(" + id
+ ")");
510 exception_error("setActiveFeedId", e
);
514 function parse_counters(reply
, scheduled_call
) {
519 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
520 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
521 reply
= reply
.firstChild
;
524 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
525 if (!reply
.childNodes
[l
] ||
526 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
527 // where did this come from?
531 var id
= reply
.childNodes
[l
].getAttribute("id");
532 var t
= reply
.childNodes
[l
].getAttribute("type");
533 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
534 var error
= reply
.childNodes
[l
].getAttribute("error");
535 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
536 var updated
= reply
.childNodes
[l
].getAttribute("updated");
538 if (id
== "global-unread") {
544 if (id
== "subscribed-feeds") {
549 if (t
== "category") {
550 var catctr
= document
.getElementById("FCATCTR-" + id
);
552 catctr
.innerHTML
= "(" + ctr
+ ")";
554 catctr
.className
= "catCtrHasUnread";
556 catctr
.className
= "catCtrNoUnread";
562 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
563 var feedu
= document
.getElementById("FEEDU-" + id
);
564 var feedr
= document
.getElementById("FEEDR-" + id
);
565 var feed_img
= document
.getElementById("FIMG-" + id
);
566 var feedlink
= document
.getElementById("FEEDL-" + id
);
567 var feedupd
= document
.getElementById("FLUPD-" + id
);
569 if (updated
&& feedlink
) {
571 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
573 feedlink
.title
= "Updated: " + updated
;
577 if (updated
&& feedupd
) {
579 feedupd
.innerHTML
= updated
+ " (Error)";
581 feedupd
.innerHTML
= updated
;
585 if (feedctr
&& feedu
&& feedr
) {
587 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
591 feedu
.innerHTML
= ctr
;
594 feedr
.className
= feedr
.className
.replace("feed", "error");
596 feedr
.className
= feedr
.className
.replace("error", "feed");
600 feedctr
.className
= "odd";
601 if (!feedr
.className
.match("Unread")) {
602 var is_selected
= feedr
.className
.match("Selected");
604 feedr
.className
= feedr
.className
.replace("Selected", "");
605 feedr
.className
= feedr
.className
.replace("Unread", "");
607 feedr
.className
= feedr
.className
+ "Unread";
610 feedr
.className
= feedr
.className
+ "Selected";
615 feedctr
.className
= "invisible";
616 feedr
.className
= feedr
.className
.replace("Unread", "");
621 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
623 var feeds_stored
= number_of_feeds
;
625 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
627 if (feeds_stored
!= feeds_found
) {
628 number_of_feeds
= feeds_found
;
630 if (feeds_stored
!= 0) {
631 debug("Subscribed feed number changed, refreshing feedlist");
632 setTimeout('updateFeedList(false, false)', 50);
637 exception_error("parse_counters", e
);
641 function parse_counters_reply(xmlhttp
, scheduled_call
) {
643 if (!xmlhttp
.responseXML
) {
644 notify("refetch_callback: backend did not return valid XML", true, true);
648 var reply
= xmlhttp
.responseXML
.firstChild
;
651 notify("refetch_callback: backend did not return expected XML object", true, true);
656 var error_code
= false;
657 var error_msg
= false;
659 if (reply
.firstChild
) {
660 error_code
= reply
.firstChild
.getAttribute("error-code");
661 error_msg
= reply
.firstChild
.getAttribute("error-msg");
665 error_code
= reply
.getAttribute("error-code");
666 error_msg
= reply
.getAttribute("error-msg");
669 if (error_code
&& error_code
!= 0) {
670 debug("refetch_callback: got error code " + error_code
);
671 return fatalError(error_code
, error_msg
);
674 var counters
= reply
.firstChild
;
676 parse_counters(counters
, scheduled_call
);
678 var runtime_info
= counters
.nextSibling
;
680 parse_runtime_info(runtime_info
);
682 if (getInitParam("feeds_sort_by_unread") == 1) {
686 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
690 function all_counters_callback() {
691 if (xmlhttp_rpc
.readyState
== 4) {
693 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
694 debug("[all_counters_callback] backend did not return valid XML");
698 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
700 var reply = xmlhttp_rpc.responseXML.firstChild;
702 var counters = reply.firstChild;
704 parse_counters(counters);
706 var runtime = counters.nextSibling;
709 parse_runtime_info(runtime);
712 if (getInitParam("feeds_sort_by_unread") == 1) {
716 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
718 debug("in all_counters_callback");
720 parse_counters_reply(xmlhttp_rpc
);
723 exception_error("all_counters_callback", e
);
728 function get_feed_entry_unread(doc
, elem
) {
730 var id
= elem
.id
.replace("FEEDR-", "");
737 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
743 function resort_category(doc
, node
) {
744 debug("resort_category: " + node
);
746 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
747 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
748 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
750 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
754 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
755 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
757 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
758 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
760 if (cur_val
> tmp_val
) {
761 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
762 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
763 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
764 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
773 function resort_feedlist() {
774 debug("resort_feedlist");
778 if (fd
.getElementById("feedCatHolder")) {
780 var feeds
= fd
.getElementById("feedList");
781 var child
= feeds
.firstChild
;
785 if (child
.id
== "feedCatHolder") {
786 resort_category(fd
, child
.firstChild
);
789 child
= child
.nextSibling
;
793 resort_category(fd
, fd
.getElementById("feedList"));
797 function update_all_counters(feed
) {
798 if (xmlhttp_ready(xmlhttp_rpc
)) {
799 var query
= "backend.php?op=rpc&subop=getAllCounters";
802 query
= query
+ "&aid=" + feed
;
805 if (tagsAreDisplayed()) {
806 query
= query
+ "&omode=lt";
808 query
= query
+ "&omode=flc";
811 debug("update_all_counters QUERY: " + query
);
813 var date
= new Date();
814 var timestamp
= Math
.round(date
.getTime() / 1000);
815 query
= query
+ "&ts=" + timestamp
817 xmlhttp_rpc
.open("GET", query
, true);
818 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
819 xmlhttp_rpc
.send(null);
823 function popupHelp(tid
) {
824 var w
= window
.open("backend.php?op=help&tid=" + tid
,
826 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
829 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
830 * * @author Sundar Dorai-Raj
831 * * Email: sdoraira@vt.edu
832 * * This program is free software; you can redistribute it and/or
833 * * modify it under the terms of the GNU General Public License
834 * * as published by the Free Software Foundation; either version 2
835 * * of the License, or (at your option) any later version,
836 * * provided that any use properly credits the author.
837 * * This program is distributed in the hope that it will be useful,
838 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
839 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
840 * * GNU General Public License for more details at http://www.gnu.org * * */
842 var numbers
=".0123456789";
843 function isNumeric(x
) {
844 // is x a String or a character?
846 // remove negative sign
848 for(j
=0;j
<x
.length
;j
++) {
849 // call isNumeric recursively for each character
850 number
=isNumeric(x
.substring(j
,j
+1));
851 if(!number
) return number
;
856 // if x is number return true
857 if(numbers
.indexOf(x
)>=0) return true;
863 function hideOrShowFeeds(doc
, hide
) {
865 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
869 var list
= fd
.getElementById("feedList");
871 if (fd
.getElementById("feedCatHolder")) {
873 var feeds
= fd
.getElementById("feedList");
874 var child
= feeds
.firstChild
;
878 if (child
.id
== "feedCatHolder") {
879 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
882 child
= child
.nextSibling
;
886 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
890 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
892 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
897 debug("hideOrShowFeeds: passed node is null, aborting");
901 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
902 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
903 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
905 if (node
.childNodes
[i
].style
!= undefined) {
907 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
909 // debug(node.childNodes[i].id + " --> " + has_unread);
911 if (hide
&& !has_unread
) {
912 node
.childNodes
[i
].style
.display
= "none";
916 node
.childNodes
[i
].style
.display
= "list-item";
920 node
.childNodes
[i
].style
.display
= "list-item";
927 if (cat_unread
== 0) {
928 if (cat_node
.style
== undefined) {
929 debug("ERROR: supplied cat_node " + cat_node
+
930 " has no styles. WTF?");
934 cat_node
.style
.display
= "none";
936 cat_node
.style
.display
= "list-item";
940 cat_node
.style
.display
= "list-item";
946 // debug("unread for category: " + cat_unread);
949 function selectTableRow(r
, do_select
) {
950 r
.className
= r
.className
.replace("Selected", "");
953 r
.className
= r
.className
+ "Selected";
957 function selectTableRowById(elem_id
, check_id
, do_select
) {
961 var row
= document
.getElementById(elem_id
);
964 selectTableRow(row
, do_select
);
967 var check
= document
.getElementById(check_id
);
970 check
.checked
= do_select
;
973 exception_error("selectTableRowById", e
);
977 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
978 classcheck
, reset_others
) {
980 var content
= document
.getElementById(content_id
);
983 alert("[selectTableRows] Element " + content_id
+ " not found.");
987 for (i
= 0; i
< content
.rows
.length
; i
++) {
988 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
990 if (content
.rows
[i
].id
.match(prefix
)) {
991 selectTableRow(content
.rows
[i
], do_select
);
993 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
994 var check
= document
.getElementById(check_prefix
+ row_id
);
997 check
.checked
= do_select
;
999 } else if (reset_others
) {
1000 selectTableRow(content
.rows
[i
], false);
1002 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1003 var check
= document
.getElementById(check_prefix
+ row_id
);
1006 check
.checked
= false;
1010 } else if (reset_others
) {
1011 selectTableRow(content
.rows
[i
], false);
1013 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1014 var check
= document
.getElementById(check_prefix
+ row_id
);
1017 check
.checked
= false;
1024 function getSelectedTableRowIds(content_id
, prefix
) {
1026 var content
= document
.getElementById(content_id
);
1029 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1033 var sel_rows
= new Array();
1035 for (i
= 0; i
< content
.rows
.length
; i
++) {
1036 if (content
.rows
[i
].id
.match(prefix
) &&
1037 content
.rows
[i
].className
.match("Selected")) {
1039 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1040 sel_rows
.push(row_id
);
1048 function toggleSelectRowById(sender
, id
) {
1049 var row
= document
.getElementById(id
);
1051 if (sender
.checked
) {
1052 if (!row
.className
.match("Selected")) {
1053 row
.className
= row
.className
+ "Selected";
1056 if (row
.className
.match("Selected")) {
1057 row
.className
= row
.className
.replace("Selected", "");
1062 function toggleSelectListRow(sender
) {
1063 var parent_row
= sender
.parentNode
;
1065 if (sender
.checked
) {
1066 if (!parent_row
.className
.match("Selected")) {
1067 parent_row
.className
= parent_row
.className
+ "Selected";
1070 if (parent_row
.className
.match("Selected")) {
1071 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1077 function toggleSelectRow(sender
) {
1078 var parent_row
= sender
.parentNode
.parentNode
;
1080 if (sender
.checked
) {
1081 if (!parent_row
.className
.match("Selected")) {
1082 parent_row
.className
= parent_row
.className
+ "Selected";
1085 if (parent_row
.className
.match("Selected")) {
1086 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1091 function openExternalUrl(url
) {
1092 var w
= window
.open(url
);
1095 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1097 if (direction
== "next") {
1098 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1099 var child
= list
.childNodes
[i
];
1100 if (child
.id
&& child
.id
== "feedCatHolder") {
1101 if (child
.lastChild
) {
1102 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1105 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1106 return child
.id
.replace('FEEDR-', '');
1111 // FIXME select last feed doesn't work when only unread feeds are visible
1113 if (direction
== "prev") {
1114 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1115 var child
= list
.childNodes
[i
];
1116 if (child
.id
== "feedCatHolder") {
1117 if (child
.firstChild
) {
1118 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1121 } else if (child
.id
.match("FEEDR-")) {
1123 if (getInitParam("hide_read_feeds") == 1) {
1124 if (child
.className
!= "feed") {
1125 alert(child
.className
);
1126 return child
.id
.replace('FEEDR-', '');
1129 return child
.id
.replace('FEEDR-', '');
1136 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1138 if (getInitParam("hide_read_feeds") == 1) {
1142 if (direction
== "next") {
1148 if (e
.nextSibling
) {
1152 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1154 var this_cat
= e
.parentNode
.parentNode
;
1158 if (this_cat
&& this_cat
.nextSibling
) {
1159 while (!e
&& this_cat
.nextSibling
) {
1160 this_cat
= this_cat
.nextSibling
;
1161 if (this_cat
.id
== "feedCatHolder") {
1162 e
= this_cat
.firstChild
.firstChild
;
1172 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1173 e
.className
.match("feed"))) {
1174 return e
.id
.replace("FEEDR-", "");
1179 } else if (direction
== "prev") {
1185 if (e
.previousSibling
) {
1187 e
= e
.previousSibling
;
1189 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1191 var this_cat
= e
.parentNode
.parentNode
;
1195 if (this_cat
&& this_cat
.previousSibling
) {
1196 while (!e
&& this_cat
.previousSibling
) {
1197 this_cat
= this_cat
.previousSibling
;
1198 if (this_cat
.id
== "feedCatHolder") {
1199 e
= this_cat
.firstChild
.lastChild
;
1209 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1210 e
.className
.match("feed"))) {
1211 return e
.id
.replace("FEEDR-", "");
1219 function showBlockElement(id
) {
1220 var elem
= document
.getElementById(id
);
1223 elem
.style
.display
= "block";
1225 alert("[showBlockElement] can't find element with id " + id
);
1229 function hideParentElement(e
) {
1230 e
.parentNode
.style
.display
= "none";
1233 function dropboxSelect(e
, v
) {
1234 for (i
= 0; i
< e
.length
; i
++) {
1235 if (e
[i
].value
== v
) {
1236 e
.selectedIndex
= i
;
1242 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1243 // bugfixed just a little bit :-)
1244 function getURLParam(strParamName
){
1246 var strHref
= window
.location
.href
;
1248 if (strHref
.indexOf("#") == strHref
.length
-1) {
1249 strHref
= strHref
.substring(0, strHref
.length
-1);
1252 if ( strHref
.indexOf("?") > -1 ){
1253 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1254 var aQueryString
= strQueryString
.split("&");
1255 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1256 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1257 var aParam
= aQueryString
[iParam
].split("=");
1258 strReturn
= aParam
[1];
1266 function leading_zero(p
) {
1268 if (s
.length
== 1) s
= "0" + s
;
1272 function closeInfoBox(cleanup
) {
1273 var box
= document
.getElementById('infoBox');
1274 var shadow
= document
.getElementById('infoBoxShadow');
1277 shadow
.style
.display
= "none";
1279 box
.style
.display
= "none";
1282 if (cleanup
) box
.innerHTML
= " ";
1290 function displayDlg(id
, param
) {
1292 if (!xmlhttp_ready(xmlhttp
)) {
1293 printLockingError();
1299 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1300 param_escape(id
) + "¶m=" + param_escape(param
), true);
1301 xmlhttp
.onreadystatechange
=infobox_callback
;
1309 function infobox_submit_callback() {
1310 if (xmlhttp
.readyState
== 4) {
1314 // called from prefs, reload tab
1316 selectTab(active_tab
, false);
1320 notify(xmlhttp
.responseText
);
1325 function infobox_callback() {
1326 if (xmlhttp
.readyState
== 4) {
1327 var box
= document
.getElementById('infoBox');
1328 var shadow
= document
.getElementById('infoBoxShadow');
1330 box
.innerHTML
=xmlhttp
.responseText
;
1332 shadow
.style
.display
= "block";
1334 box
.style
.display
= "block";
1341 function qaddFilter() {
1343 if (!xmlhttp_ready(xmlhttp
)) {
1344 printLockingError();
1348 var form
= document
.forms
['filter_add_form'];
1349 var reg_exp
= form
.reg_exp
.value
;
1351 if (reg_exp
== "") {
1352 alert("Can't add filter: nothing to match on.");
1356 var query
= Form
.serialize("filter_add_form");
1358 xmlhttp
.open("GET", "backend.php?" + query
, true);
1359 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1365 function toggleSubmitNotEmpty(e
, submit_id
) {
1367 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1369 exception_error("toggleSubmitNotEmpty", e
);
1373 function isValidURL(s
) {
1374 return s
.match("http://") != null || s
.match("https://") != null;
1379 if (!xmlhttp_ready(xmlhttp
)) {
1380 printLockingError();
1384 var form
= document
.forms
['feed_add_form'];
1385 var feed_url
= form
.feed_url
.value
;
1387 if (feed_url
== "") {
1388 alert("Can't subscribe: no feed URL given.");
1392 notify("Adding feed...", true);
1396 var feeds_doc
= document
;
1398 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1400 var query
= Form
.serialize("feed_add_form");
1402 xmlhttp
.open("GET", "backend.php?" + query
, true);
1403 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1409 function filterCR(e
, f
)
1414 key
= window
.event
.keyCode
; //IE
1416 key
= e
.which
; //firefox
1419 if (typeof f
!= 'undefined') {
1430 function getMainContext() {
1434 function getFeedsContext() {
1438 function getContentContext() {
1442 function getHeadlinesContext() {
1446 var debug_last_class
= "even";
1448 function debug(msg
) {
1450 if (debug_last_class
== "even") {
1451 debug_last_class
= "odd";
1453 debug_last_class
= "even";
1456 var c
= document
.getElementById('debug_output');
1457 if (c
&& c
.style
.display
== "block") {
1458 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1459 c
.removeChild(c
.lastChild
);
1463 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1464 ":" + leading_zero(d
.getSeconds());
1465 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1466 msg
+ "</li>" + c
.innerHTML
;
1470 function getInitParam(key
) {
1471 return getMainContext().init_params
[key
];
1474 function storeInitParam(key
, value
, is_client
) {
1477 if (getMainContext().init_params
[key
] != value
) {
1478 debug("storeInitParam: " + key
+ " => " + value
);
1479 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1480 // param_escape(key) + "&value=" + param_escape(value));
1481 var f
= getMainContext().document
.getElementById("backReqBox");
1482 f
.src
= "backend.php?op=rpc&subop=storeParam&key=" +
1483 param_escape(key
) + "&value=" + param_escape(value
);
1486 getMainContext().init_params
[key
] = value
;
1488 exception_error("storeInitParam", e
);
1493 function storeInitParams(params, is_client) {
1498 if (getMainContext().init_params[k] != params[k]) {
1499 s += k + "=" + params[k] + ";";
1500 getMainContext().init_params[k] = params[k];
1504 debug("storeInitParams: " + s);
1507 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1510 exception_error("storeInitParams", e);
1514 function fatalError(code
, message
) {
1519 var fe
= document
.getElementById("fatal_error");
1520 var fc
= document
.getElementById("fatal_error_msg");
1522 fc
.innerHTML
= "Code " + code
+ ": " + message
;
1524 fe
.style
.display
= "block";
1526 window
.location
.href
= "login.php?rt=none";
1530 exception_error("fatalError", e
);
1534 function getFeedName(id
, is_cat
) {
1535 var d
= getFeedsContext().document
;
1540 e
= d
.getElementById("FCATN-" + id
);
1542 e
= d
.getElementById("FEEDN-" + id
);
1545 return e
.innerHTML
.stripTags();
1551 function viewContentUrl(url
) {
1552 getContentContext().location
= url
;
1555 function filterDlgCheckAction(sender
) {
1559 var action
= sender
[sender
.selectedIndex
].value
;
1561 var form
= document
.forms
["filter_add_form"];
1564 form
= document
.forms
["filter_edit_form"];
1568 debug("filterDlgCheckAction: can't find form!");
1572 var action_param
= form
.action_param
;
1574 if (!action_param
) {
1575 debug("filterDlgCheckAction: can't find action param!");
1579 // if selected action supports parameters, enable params field
1581 action_param
.disabled
= false;
1583 action_param
.disabled
= true;
1587 exception_error(e
, "filterDlgCheckAction");
1592 function explainError(code
) {
1593 return displayDlg("explainError", code
);