]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var hotkeys_enabled
= true;
2 var debug_mode_enabled
= false;
3 var xmlhttp_rpc
= Ajax
.getTransport();
5 function browser_has_opacity() {
6 return navigator
.userAgent
.match("Gecko") != null ||
7 navigator
.userAgent
.match("Opera") != null;
11 return navigator
.userAgent
.match("Opera");
15 return navigator
.userAgent
.match("KHTML");
18 function is_safari() {
19 return navigator
.userAgent
.match("Safari");
22 function exception_error(location
, e
, silent
) {
26 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
28 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
29 "\nFunction: " + location
+ "()" +
30 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
33 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
36 debug("<b>EXCEPTION: " + msg
+ "</b>");
43 function disableHotkeys() {
44 hotkeys_enabled
= false;
47 function enableHotkeys() {
48 hotkeys_enabled
= true;
51 function xmlhttp_ready(obj
) {
52 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
55 function logout_callback() {
56 var container
= document
.getElementById('notify');
57 if (xmlhttp
.readyState
== 4) {
59 var date
= new Date();
60 var timestamp
= Math
.round(date
.getTime() / 1000);
61 window
.location
.href
= "tt-rss.php";
63 exception_error("logout_callback", e
);
68 function notify_callback() {
69 var container
= document
.getElementById('notify');
70 if (xmlhttp
.readyState
== 4) {
71 container
.innerHTML
=xmlhttp
.responseText
;
75 function rpc_notify_callback() {
76 var container
= document
.getElementById('notify');
77 if (xmlhttp_rpc
.readyState
== 4) {
78 container
.innerHTML
=xmlhttp_rpc
.responseText
;
82 function param_escape(arg
) {
83 if (typeof encodeURIComponent
!= 'undefined')
84 return encodeURIComponent(arg
);
89 function param_unescape(arg
) {
90 if (typeof decodeURIComponent
!= 'undefined')
91 return decodeURIComponent(arg
);
98 then
=new Date().getTime();
100 while((now
-then
)<gap
) {
101 now
=new Date().getTime();
105 var notify_hide_timerid
= false;
106 var notify_last_doc
= false;
108 var notify_effect
= false;
110 function hide_notify() {
111 if (notify_last_doc
) {
112 var n
= notify_last_doc
.getElementById("notify");
113 n
.style
.display
= "none";
115 /* if (browser_has_opacity()) {
116 if (notify_opacity >= 0) {
117 notify_opacity = notify_opacity - 0.1;
118 n.style.opacity = notify_opacity;
119 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
121 n.style.display = "none";
125 n.style.display = "none";
130 function notify_real(msg
, doc
, no_hide
, is_err
) {
132 var n
= doc
.getElementById("notify");
133 var nb
= doc
.getElementById("notify_body");
135 if (!n
|| !nb
) return;
137 if (notify_hide_timerid
) {
138 window
.clearTimeout(notify_hide_timerid
);
141 notify_last_doc
= doc
;
145 if (n
.style
.display
== "block") {
146 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
150 n
.style
.display
= "block";
154 n
.className
= "notifyError";
155 // n.style.backgroundColor = "#ffcccc";
156 // n.style.color = "black";
157 // n.style.borderColor = "#ff0000";
158 msg
= "<img src='images/sign_excl.png'> " + msg
;
160 n
.className
= "notify";
161 // n.style.backgroundColor = "#fff7d5";
162 // n.style.borderColor = "#d7c47a";
163 // n.style.color = "black";
164 msg
= "<img src='images/sign_info.png'> " + msg
;
167 // msg = "<img src='images/live_com_loading.gif'> " + msg;
172 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
176 function p_notify(msg
, no_hide
, is_err
) {
177 notify_real(msg
, document
, no_hide
, is_err
);
180 function notify(msg
, no_hide
, is_err
) {
181 notify_real(msg
, document
, no_hide
, is_err
);
184 function printLockingError() {
185 notify("Please wait until operation finishes");}
187 function hotkey_handler(e
) {
192 var shift_key
= false;
195 shift_key
= e
.shiftKey
;
200 if (!hotkeys_enabled
) return;
203 keycode
= window
.event
.keyCode
;
208 if (keycode
== 82) { // r
209 return scheduleFeedUpdate(true);
212 if (keycode
== 83) { // s
213 return displayDlg("search", getActiveFeedId());
216 if (keycode
== 85) { // u
217 if (getActiveFeedId()) {
218 return viewfeed(getActiveFeedId(), "ForceUpdate");
222 if (keycode
== 65) { // a
223 return toggleDispRead();
226 var feedlist
= document
.getElementById('feedList');
228 if (keycode
== 74) { // j
229 var feed
= getActiveFeedId();
230 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
231 if (new_feed
) viewfeed(new_feed
, '');
234 if (keycode
== 75) { // k
235 var feed
= getActiveFeedId();
236 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
237 if (new_feed
) viewfeed(new_feed
, '');
240 if (!is_safari() && (keycode
== 78 || keycode
== 40)) { // n, down
241 if (typeof moveToPost
!= 'undefined') {
242 return moveToPost('next');
246 if (!is_safari() && (keycode
== 80 || keycode
== 38)) { // p, up
247 if (typeof moveToPost
!= 'undefined') {
248 return moveToPost('prev');
252 if (keycode
== 68 && shift_key
) { // d
253 if (!debug_mode_enabled
) {
254 document
.getElementById('debug_output').style
.display
= 'block';
255 debug('debug mode activated');
257 document
.getElementById('debug_output').style
.display
= 'none';
260 debug_mode_enabled
= !debug_mode_enabled
;
263 if (keycode
== 190 && shift_key
) { // >
267 if (keycode
== 188 && shift_key
) { // <
271 if (keycode
== 191 && shift_key
) { // ?
275 if (keycode
== 69 && shift_key
) { // e
276 return editFeedDlg(getActiveFeedId());
279 if (keycode
== 70 && shift_key
) { // f
280 if (getActiveFeedId()) {
281 return catchupCurrentFeed();
285 if (keycode
== 80 && shift_key
) { // p
286 if (getActiveFeedId()) {
287 return catchupPage();
291 if (typeof localHotkeyHandler
!= 'undefined') {
293 return localHotkeyHandler(e
);
295 exception_error("hotkey_handler, local:", e
);
299 debug("KP=" + keycode
);
301 exception_error("hotkey_handler", e
);
305 function cleanSelectedList(element
) {
306 var content
= document
.getElementById(element
);
308 if (!document
.getElementById("feedCatHolder")) {
309 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
310 var child
= content
.childNodes
[i
];
312 child
.className
= child
.className
.replace("Selected", "");
318 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
319 var child
= content
.childNodes
[i
];
320 if (child
.id
== "feedCatHolder") {
322 var fcat
= child
.lastChild
;
323 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
324 var feed
= fcat
.childNodes
[j
];
325 feed
.className
= feed
.className
.replace("Selected", "");
333 function cleanSelected(element
) {
334 var content
= document
.getElementById(element
);
336 for (i
= 0; i
< content
.rows
.length
; i
++) {
337 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
341 function getVisibleUnreadHeadlines() {
342 var content
= document
.getElementById("headlinesList");
344 var rows
= new Array();
346 for (i
= 0; i
< content
.rows
.length
; i
++) {
347 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
348 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
355 function getVisibleHeadlineIds() {
357 var content
= document
.getElementById("headlinesList");
359 var rows
= new Array();
361 for (i
= 0; i
< content
.rows
.length
; i
++) {
362 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
363 if (row_id
.length
> 0) {
370 function getFirstVisibleHeadlineId() {
371 var rows
= getVisibleHeadlineIds();
375 function getLastVisibleHeadlineId() {
376 var rows
= getVisibleHeadlineIds();
377 return rows
[rows
.length
-1];
380 function markHeadline(id
) {
381 var row
= document
.getElementById("RROW-" + id
);
383 var is_active
= false;
385 if (row
.className
.match("Active")) {
388 row
.className
= row
.className
.replace("Selected", "");
389 row
.className
= row
.className
.replace("Active", "");
390 row
.className
= row
.className
.replace("Insensitive", "");
393 row
.className
= row
.className
= "Active";
396 var check
= document
.getElementById("RCHK-" + id
);
399 check
.checked
= true;
402 row
.className
= row
.className
+ "Selected";
407 function getFeedIds() {
408 var content
= document
.getElementById("feedsList");
410 var rows
= new Array();
412 for (i
= 0; i
< content
.rows
.length
; i
++) {
413 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
422 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
428 d
.setTime(lifetime
* 1000);
431 int_setCookie(name
, value
, d
, path
, domain
, secure
);
435 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
436 document
.cookie
= name
+ "=" + escape(value
) +
437 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
438 ((path
) ? "; path=" + path
: "") +
439 ((domain
) ? "; domain=" + domain
: "") +
440 ((secure
) ? "; secure" : "");
443 function delCookie(name
, path
, domain
) {
444 if (getCookie(name
)) {
445 document
.cookie
= name
+ "=" +
446 ((path
) ? ";path=" + path
: "") +
447 ((domain
) ? ";domain=" + domain
: "" ) +
448 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
453 function getCookie(name
) {
455 var dc
= document
.cookie
;
456 var prefix
= name
+ "=";
457 var begin
= dc
.indexOf("; " + prefix
);
459 begin
= dc
.indexOf(prefix
);
460 if (begin
!= 0) return null;
465 var end
= document
.cookie
.indexOf(";", begin
);
469 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
472 function disableContainerChildren(id
, disable
, doc
) {
474 if (!doc
) doc
= document
;
476 var container
= doc
.getElementById(id
);
479 //alert("disableContainerChildren: element " + id + " not found");
483 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
484 var child
= container
.childNodes
[i
];
487 child
.disabled
= disable
;
493 if (child
.className
&& child
.className
.match("button")) {
494 child
.className
= "disabledButton";
497 if (child
.className
&& child
.className
.match("disabledButton")) {
498 child
.className
= "button";
505 function gotoPreferences() {
506 document
.location
.href
= "prefs.php";
509 function gotoMain() {
510 document
.location
.href
= "tt-rss.php";
513 function gotoExportOpml() {
514 document
.location
.href
= "opml.php?op=Export";
517 function getActiveFeedId() {
518 // return getCookie("ttrss_vf_actfeed");
520 debug("gAFID: " + active_feed_id
);
521 return active_feed_id
;
523 exception_error("getActiveFeedId", e
);
527 function activeFeedIsCat() {
528 return active_feed_is_cat
;
531 function setActiveFeedId(id
) {
532 // return setCookie("ttrss_vf_actfeed", id);
534 debug("sAFID(" + id
+ ")");
537 exception_error("setActiveFeedId", e
);
541 function parse_counters(reply
, scheduled_call
) {
546 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
547 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
548 reply
= reply
.firstChild
;
551 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
552 if (!reply
.childNodes
[l
] ||
553 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
554 // where did this come from?
558 var id
= reply
.childNodes
[l
].getAttribute("id");
559 var t
= reply
.childNodes
[l
].getAttribute("type");
560 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
561 var error
= reply
.childNodes
[l
].getAttribute("error");
562 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
563 var updated
= reply
.childNodes
[l
].getAttribute("updated");
565 if (id
== "global-unread") {
571 if (id
== "subscribed-feeds") {
576 if (t
== "category") {
577 var catctr
= document
.getElementById("FCATCTR-" + id
);
579 catctr
.innerHTML
= "(" + ctr
+ ")";
581 catctr
.className
= "catCtrHasUnread";
583 catctr
.className
= "catCtrNoUnread";
589 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
590 var feedu
= document
.getElementById("FEEDU-" + id
);
591 var feedr
= document
.getElementById("FEEDR-" + id
);
592 var feed_img
= document
.getElementById("FIMG-" + id
);
593 var feedlink
= document
.getElementById("FEEDL-" + id
);
594 var feedupd
= document
.getElementById("FLUPD-" + id
);
596 if (updated
&& feedlink
) {
598 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
600 feedlink
.title
= "Updated: " + updated
;
604 if (updated
&& feedupd
) {
606 feedupd
.innerHTML
= updated
+ " (Error)";
608 feedupd
.innerHTML
= updated
;
612 if (feedctr
&& feedu
&& feedr
) {
614 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
618 feedu
.innerHTML
= ctr
;
621 feedr
.className
= feedr
.className
.replace("feed", "error");
623 feedr
.className
= feedr
.className
.replace("error", "feed");
627 feedctr
.className
= "odd";
628 if (!feedr
.className
.match("Unread")) {
629 var is_selected
= feedr
.className
.match("Selected");
631 feedr
.className
= feedr
.className
.replace("Selected", "");
632 feedr
.className
= feedr
.className
.replace("Unread", "");
634 feedr
.className
= feedr
.className
+ "Unread";
637 feedr
.className
= feedr
.className
+ "Selected";
642 feedctr
.className
= "invisible";
643 feedr
.className
= feedr
.className
.replace("Unread", "");
648 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
650 var feeds_stored
= number_of_feeds
;
652 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
654 if (feeds_stored
!= feeds_found
) {
655 number_of_feeds
= feeds_found
;
657 if (feeds_stored
!= 0) {
658 debug("Subscribed feed number changed, refreshing feedlist");
659 setTimeout('updateFeedList(false, false)', 50);
664 exception_error("parse_counters", e
);
668 function parse_counters_reply(xmlhttp
, scheduled_call
) {
670 if (!xmlhttp
.responseXML
) {
671 notify("refetch_callback: backend did not return valid XML", true, true);
675 var reply
= xmlhttp
.responseXML
.firstChild
;
678 notify("refetch_callback: backend did not return expected XML object", true, true);
683 var error_code
= false;
684 var error_msg
= false;
686 if (reply
.firstChild
) {
687 error_code
= reply
.firstChild
.getAttribute("error-code");
688 error_msg
= reply
.firstChild
.getAttribute("error-msg");
692 error_code
= reply
.getAttribute("error-code");
693 error_msg
= reply
.getAttribute("error-msg");
696 if (error_code
&& error_code
!= 0) {
697 debug("refetch_callback: got error code " + error_code
);
698 return fatalError(error_code
, error_msg
);
701 var counters
= reply
.firstChild
;
703 parse_counters(counters
, scheduled_call
);
705 var runtime_info
= counters
.nextSibling
;
707 parse_runtime_info(runtime_info
);
709 if (getInitParam("feeds_sort_by_unread") == 1) {
713 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
717 function all_counters_callback() {
718 if (xmlhttp_rpc
.readyState
== 4) {
720 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
721 debug("[all_counters_callback] backend did not return valid XML");
725 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
727 var reply = xmlhttp_rpc.responseXML.firstChild;
729 var counters = reply.firstChild;
731 parse_counters(counters);
733 var runtime = counters.nextSibling;
736 parse_runtime_info(runtime);
739 if (getInitParam("feeds_sort_by_unread") == 1) {
743 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
745 debug("in all_counters_callback");
747 parse_counters_reply(xmlhttp_rpc
);
750 exception_error("all_counters_callback", e
);
755 function get_feed_entry_unread(doc
, elem
) {
757 var id
= elem
.id
.replace("FEEDR-", "");
764 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
770 function resort_category(doc
, node
) {
771 debug("resort_category: " + node
);
773 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
774 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
775 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
777 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
781 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
782 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
784 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
785 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
787 if (cur_val
> tmp_val
) {
788 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
789 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
790 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
791 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
800 function resort_feedlist() {
801 debug("resort_feedlist");
805 if (fd
.getElementById("feedCatHolder")) {
807 var feeds
= fd
.getElementById("feedList");
808 var child
= feeds
.firstChild
;
812 if (child
.id
== "feedCatHolder") {
813 resort_category(fd
, child
.firstChild
);
816 child
= child
.nextSibling
;
820 resort_category(fd
, fd
.getElementById("feedList"));
824 function update_all_counters(feed
) {
825 if (xmlhttp_ready(xmlhttp_rpc
)) {
826 var query
= "backend.php?op=rpc&subop=getAllCounters";
829 query
= query
+ "&aid=" + feed
;
832 if (tagsAreDisplayed()) {
833 query
= query
+ "&omode=lt";
835 query
= query
+ "&omode=flc";
838 debug("update_all_counters QUERY: " + query
);
840 var date
= new Date();
841 var timestamp
= Math
.round(date
.getTime() / 1000);
842 query
= query
+ "&ts=" + timestamp
844 xmlhttp_rpc
.open("GET", query
, true);
845 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
846 xmlhttp_rpc
.send(null);
850 function popupHelp(tid
) {
851 var w
= window
.open("backend.php?op=help&tid=" + tid
,
853 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
856 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
857 * * @author Sundar Dorai-Raj
858 * * Email: sdoraira@vt.edu
859 * * This program is free software; you can redistribute it and/or
860 * * modify it under the terms of the GNU General Public License
861 * * as published by the Free Software Foundation; either version 2
862 * * of the License, or (at your option) any later version,
863 * * provided that any use properly credits the author.
864 * * This program is distributed in the hope that it will be useful,
865 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
866 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
867 * * GNU General Public License for more details at http://www.gnu.org * * */
869 var numbers
=".0123456789";
870 function isNumeric(x
) {
871 // is x a String or a character?
873 // remove negative sign
875 for(j
=0;j
<x
.length
;j
++) {
876 // call isNumeric recursively for each character
877 number
=isNumeric(x
.substring(j
,j
+1));
878 if(!number
) return number
;
883 // if x is number return true
884 if(numbers
.indexOf(x
)>=0) return true;
890 function hideOrShowFeeds(doc
, hide
) {
892 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
896 var list
= fd
.getElementById("feedList");
898 if (fd
.getElementById("feedCatHolder")) {
900 var feeds
= fd
.getElementById("feedList");
901 var child
= feeds
.firstChild
;
905 if (child
.id
== "feedCatHolder") {
906 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
909 child
= child
.nextSibling
;
913 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
917 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
919 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
924 debug("hideOrShowFeeds: passed node is null, aborting");
928 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
929 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
930 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
932 if (node
.childNodes
[i
].style
!= undefined) {
934 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
936 // debug(node.childNodes[i].id + " --> " + has_unread);
938 if (hide
&& !has_unread
) {
939 node
.childNodes
[i
].style
.display
= "none";
943 node
.childNodes
[i
].style
.display
= "list-item";
947 node
.childNodes
[i
].style
.display
= "list-item";
954 if (cat_unread
== 0) {
955 if (cat_node
.style
== undefined) {
956 debug("ERROR: supplied cat_node " + cat_node
+
957 " has no styles. WTF?");
961 cat_node
.style
.display
= "none";
963 cat_node
.style
.display
= "list-item";
967 cat_node
.style
.display
= "list-item";
973 // debug("unread for category: " + cat_unread);
976 function selectTableRow(r
, do_select
) {
977 r
.className
= r
.className
.replace("Selected", "");
980 r
.className
= r
.className
+ "Selected";
984 function selectTableRowById(elem_id
, check_id
, do_select
) {
988 var row
= document
.getElementById(elem_id
);
991 selectTableRow(row
, do_select
);
994 var check
= document
.getElementById(check_id
);
997 check
.checked
= do_select
;
1000 exception_error("selectTableRowById", e
);
1004 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
1005 classcheck
, reset_others
) {
1007 var content
= document
.getElementById(content_id
);
1010 alert("[selectTableRows] Element " + content_id
+ " not found.");
1014 for (i
= 0; i
< content
.rows
.length
; i
++) {
1015 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
1017 if (content
.rows
[i
].id
.match(prefix
)) {
1018 selectTableRow(content
.rows
[i
], do_select
);
1020 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1021 var check
= document
.getElementById(check_prefix
+ row_id
);
1024 check
.checked
= do_select
;
1026 } else if (reset_others
) {
1027 selectTableRow(content
.rows
[i
], false);
1029 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1030 var check
= document
.getElementById(check_prefix
+ row_id
);
1033 check
.checked
= false;
1037 } else if (reset_others
) {
1038 selectTableRow(content
.rows
[i
], false);
1040 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1041 var check
= document
.getElementById(check_prefix
+ row_id
);
1044 check
.checked
= false;
1051 function getSelectedTableRowIds(content_id
, prefix
) {
1053 var content
= document
.getElementById(content_id
);
1056 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1060 var sel_rows
= new Array();
1062 for (i
= 0; i
< content
.rows
.length
; i
++) {
1063 if (content
.rows
[i
].id
.match(prefix
) &&
1064 content
.rows
[i
].className
.match("Selected")) {
1066 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1067 sel_rows
.push(row_id
);
1075 function toggleSelectRowById(sender
, id
) {
1076 var row
= document
.getElementById(id
);
1078 if (sender
.checked
) {
1079 if (!row
.className
.match("Selected")) {
1080 row
.className
= row
.className
+ "Selected";
1083 if (row
.className
.match("Selected")) {
1084 row
.className
= row
.className
.replace("Selected", "");
1089 function toggleSelectListRow(sender
) {
1090 var parent_row
= sender
.parentNode
;
1092 if (sender
.checked
) {
1093 if (!parent_row
.className
.match("Selected")) {
1094 parent_row
.className
= parent_row
.className
+ "Selected";
1097 if (parent_row
.className
.match("Selected")) {
1098 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1104 function toggleSelectRow(sender
) {
1105 var parent_row
= sender
.parentNode
.parentNode
;
1107 if (sender
.checked
) {
1108 if (!parent_row
.className
.match("Selected")) {
1109 parent_row
.className
= parent_row
.className
+ "Selected";
1112 if (parent_row
.className
.match("Selected")) {
1113 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1118 function openExternalUrl(url
) {
1119 var w
= window
.open(url
);
1122 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1124 if (direction
== "next") {
1125 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1126 var child
= list
.childNodes
[i
];
1127 if (child
.id
&& child
.id
== "feedCatHolder") {
1128 if (child
.lastChild
) {
1129 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1132 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1133 return child
.id
.replace('FEEDR-', '');
1138 // FIXME select last feed doesn't work when only unread feeds are visible
1140 if (direction
== "prev") {
1141 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1142 var child
= list
.childNodes
[i
];
1143 if (child
.id
== "feedCatHolder") {
1144 if (child
.firstChild
) {
1145 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1148 } else if (child
.id
.match("FEEDR-")) {
1150 if (getInitParam("hide_read_feeds") == 1) {
1151 if (child
.className
!= "feed") {
1152 alert(child
.className
);
1153 return child
.id
.replace('FEEDR-', '');
1156 return child
.id
.replace('FEEDR-', '');
1163 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1165 if (getInitParam("hide_read_feeds") == 1) {
1169 if (direction
== "next") {
1175 if (e
.nextSibling
) {
1179 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1181 var this_cat
= e
.parentNode
.parentNode
;
1185 if (this_cat
&& this_cat
.nextSibling
) {
1186 while (!e
&& this_cat
.nextSibling
) {
1187 this_cat
= this_cat
.nextSibling
;
1188 if (this_cat
.id
== "feedCatHolder") {
1189 e
= this_cat
.firstChild
.firstChild
;
1199 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1200 e
.className
.match("feed"))) {
1201 return e
.id
.replace("FEEDR-", "");
1206 } else if (direction
== "prev") {
1212 if (e
.previousSibling
) {
1214 e
= e
.previousSibling
;
1216 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1218 var this_cat
= e
.parentNode
.parentNode
;
1222 if (this_cat
&& this_cat
.previousSibling
) {
1223 while (!e
&& this_cat
.previousSibling
) {
1224 this_cat
= this_cat
.previousSibling
;
1225 if (this_cat
.id
== "feedCatHolder") {
1226 e
= this_cat
.firstChild
.lastChild
;
1236 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1237 e
.className
.match("feed"))) {
1238 return e
.id
.replace("FEEDR-", "");
1246 function showBlockElement(id
) {
1247 var elem
= document
.getElementById(id
);
1250 elem
.style
.display
= "block";
1252 alert("[showBlockElement] can't find element with id " + id
);
1256 function hideParentElement(e
) {
1257 e
.parentNode
.style
.display
= "none";
1260 function dropboxSelect(e
, v
) {
1261 for (i
= 0; i
< e
.length
; i
++) {
1262 if (e
[i
].value
== v
) {
1263 e
.selectedIndex
= i
;
1269 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1270 // bugfixed just a little bit :-)
1271 function getURLParam(strParamName
){
1273 var strHref
= window
.location
.href
;
1275 if (strHref
.indexOf("#") == strHref
.length
-1) {
1276 strHref
= strHref
.substring(0, strHref
.length
-1);
1279 if ( strHref
.indexOf("?") > -1 ){
1280 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1281 var aQueryString
= strQueryString
.split("&");
1282 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1283 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1284 var aParam
= aQueryString
[iParam
].split("=");
1285 strReturn
= aParam
[1];
1293 function leading_zero(p
) {
1295 if (s
.length
== 1) s
= "0" + s
;
1299 function closeInfoBox(cleanup
) {
1300 var box
= document
.getElementById('infoBox');
1301 var shadow
= document
.getElementById('infoBoxShadow');
1304 shadow
.style
.display
= "none";
1306 box
.style
.display
= "none";
1309 if (cleanup
) box
.innerHTML
= " ";
1317 function displayDlg(id
, param
) {
1319 if (!xmlhttp_ready(xmlhttp
)) {
1320 printLockingError();
1326 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1327 param_escape(id
) + "¶m=" + param_escape(param
), true);
1328 xmlhttp
.onreadystatechange
=infobox_callback
;
1336 function infobox_submit_callback() {
1337 if (xmlhttp
.readyState
== 4) {
1341 // called from prefs, reload tab
1343 selectTab(active_tab
, false);
1347 notify(xmlhttp
.responseText
);
1352 function infobox_callback() {
1353 if (xmlhttp
.readyState
== 4) {
1354 var box
= document
.getElementById('infoBox');
1355 var shadow
= document
.getElementById('infoBoxShadow');
1357 box
.innerHTML
=xmlhttp
.responseText
;
1359 shadow
.style
.display
= "block";
1361 box
.style
.display
= "block";
1368 function qaddFilter() {
1370 if (!xmlhttp_ready(xmlhttp
)) {
1371 printLockingError();
1375 var form
= document
.forms
['filter_add_form'];
1376 var reg_exp
= form
.reg_exp
.value
;
1378 if (reg_exp
== "") {
1379 alert("Can't add filter: nothing to match on.");
1383 var query
= Form
.serialize("filter_add_form");
1385 xmlhttp
.open("GET", "backend.php?" + query
, true);
1386 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1392 function toggleSubmitNotEmpty(e
, submit_id
) {
1394 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1396 exception_error("toggleSubmitNotEmpty", e
);
1400 function isValidURL(s
) {
1401 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1406 if (!xmlhttp_ready(xmlhttp
)) {
1407 printLockingError();
1411 var form
= document
.forms
['feed_add_form'];
1412 var feed_url
= form
.feed_url
.value
;
1414 if (feed_url
== "") {
1415 alert("Can't subscribe: no feed URL given.");
1419 notify("Adding feed...", true);
1423 var feeds_doc
= document
;
1425 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1427 var query
= Form
.serialize("feed_add_form");
1429 xmlhttp
.open("GET", "backend.php?" + query
, true);
1430 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1436 function filterCR(e
, f
)
1441 key
= window
.event
.keyCode
; //IE
1443 key
= e
.which
; //firefox
1446 if (typeof f
!= 'undefined') {
1457 function getMainContext() {
1461 function getFeedsContext() {
1465 function getContentContext() {
1469 function getHeadlinesContext() {
1473 var debug_last_class
= "even";
1475 function debug(msg
) {
1477 if (debug_last_class
== "even") {
1478 debug_last_class
= "odd";
1480 debug_last_class
= "even";
1483 var c
= document
.getElementById('debug_output');
1484 if (c
&& c
.style
.display
== "block") {
1485 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1486 c
.removeChild(c
.lastChild
);
1490 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1491 ":" + leading_zero(d
.getSeconds());
1492 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1493 msg
+ "</li>" + c
.innerHTML
;
1497 function getInitParam(key
) {
1498 return getMainContext().init_params
[key
];
1501 function storeInitParam(key
, value
, is_client
) {
1504 if (getMainContext().init_params
[key
] != value
) {
1505 debug("storeInitParam: " + key
+ " => " + value
);
1506 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1507 // param_escape(key) + "&value=" + param_escape(value));
1508 var f
= getMainContext().document
.getElementById("backReqBox");
1509 f
.src
= "backend.php?op=rpc&subop=storeParam&key=" +
1510 param_escape(key
) + "&value=" + param_escape(value
);
1513 getMainContext().init_params
[key
] = value
;
1515 exception_error("storeInitParam", e
);
1520 function storeInitParams(params, is_client) {
1525 if (getMainContext().init_params[k] != params[k]) {
1526 s += k + "=" + params[k] + ";";
1527 getMainContext().init_params[k] = params[k];
1531 debug("storeInitParams: " + s);
1534 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1537 exception_error("storeInitParams", e);
1541 function fatalError(code
, message
) {
1545 window
.location
.href
= "tt-rss.php";
1546 } else if (code
== 5) {
1547 window
.location
.href
= "update.php";
1549 var fe
= document
.getElementById("fatal_error");
1550 var fc
= document
.getElementById("fatal_error_msg");
1552 fc
.innerHTML
= "Code " + code
+ ": " + message
;
1554 fe
.style
.display
= "block";
1558 exception_error("fatalError", e
);
1562 function getFeedName(id
, is_cat
) {
1563 var d
= getFeedsContext().document
;
1568 e
= d
.getElementById("FCATN-" + id
);
1570 e
= d
.getElementById("FEEDN-" + id
);
1573 return e
.innerHTML
.stripTags();
1579 function viewContentUrl(url
) {
1580 getContentContext().location
= url
;
1583 function filterDlgCheckAction(sender
) {
1587 var action
= sender
[sender
.selectedIndex
].value
;
1589 var form
= document
.forms
["filter_add_form"];
1592 form
= document
.forms
["filter_edit_form"];
1596 debug("filterDlgCheckAction: can't find form!");
1600 var action_param
= form
.action_param
;
1602 if (!action_param
) {
1603 debug("filterDlgCheckAction: can't find action param!");
1607 // if selected action supports parameters, enable params field
1609 action_param
.disabled
= false;
1611 action_param
.disabled
= true;
1615 exception_error(e
, "filterDlgCheckAction");
1620 function explainError(code
) {
1621 return displayDlg("explainError", code
);
1624 function logoutUser() {
1626 if (xmlhttp_ready(xmlhttp_rpc
)) {
1628 notify("Logging out, please wait...");
1630 xmlhttp_rpc
.open("GET", "backend.php?op=rpc&subop=logout", true);
1631 xmlhttp_rpc
.onreadystatechange
=logout_callback
;
1632 xmlhttp_rpc
.send(null);
1634 printLockingError();
1637 exception_error("logoutUser", e
);