]>
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;
107 function hide_notify() {
108 var n
= document
.getElementById("notify");
110 n
.style
.display
= "none";
114 function notify_real(msg
, no_hide
, n_type
) {
116 var n
= document
.getElementById("notify");
117 var nb
= document
.getElementById("notify_body");
119 if (!n
|| !nb
) return;
121 if (notify_hide_timerid
) {
122 window
.clearTimeout(notify_hide_timerid
);
126 if (n
.style
.display
== "block") {
127 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
131 n
.style
.display
= "block";
143 if (typeof __
!= 'undefined') {
148 n
.className
= "notify";
149 } else if (n_type
== 2) {
150 n
.className
= "notifyProgress";
151 msg
= "<img src='images/indicator_white.gif'> " + msg
;
152 } else if (n_type
== 3) {
153 n
.className
= "notifyError";
154 msg
= "<img src='images/sign_excl.png'> " + msg
;
155 } else if (n_type
== 4) {
156 n
.className
= "notifyInfo";
157 msg
= "<img src='images/sign_info.png'> " + msg
;
160 // msg = "<img src='images/live_com_loading.gif'> " + msg;
165 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
169 function notify(msg
, no_hide
) {
170 notify_real(msg
, no_hide
, 1);
173 function notify_progress(msg
, no_hide
) {
174 notify_real(msg
, no_hide
, 2);
177 function notify_error(msg
, no_hide
) {
178 notify_real(msg
, no_hide
, 3);
182 function notify_info(msg
, no_hide
) {
183 notify_real(msg
, no_hide
, 4);
186 function printLockingError() {
187 notify_info("Please wait until operation finishes.");
190 function hotkey_handler(e
) {
195 var shift_key
= false;
198 shift_key
= e
.shiftKey
;
203 if (!hotkeys_enabled
) return;
206 keycode
= window
.event
.keyCode
;
211 if (keycode
== 82) { // r
212 return scheduleFeedUpdate(true);
215 if (keycode
== 83) { // s
216 return displayDlg("search", getActiveFeedId());
219 if (keycode
== 85) { // u
220 if (getActiveFeedId()) {
221 return viewfeed(getActiveFeedId(), "ForceUpdate");
225 if (keycode
== 65) { // a
226 return toggleDispRead();
229 var feedlist
= document
.getElementById('feedList');
231 if (keycode
== 74) { // j
232 var feed
= getActiveFeedId();
233 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
234 if (new_feed
) viewfeed(new_feed
, '');
237 if (keycode
== 75) { // k
238 var feed
= getActiveFeedId();
239 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
240 if (new_feed
) viewfeed(new_feed
, '');
243 if (!is_safari() && (keycode
== 78 || keycode
== 40)) { // n, down
244 if (typeof moveToPost
!= 'undefined') {
245 return moveToPost('next');
249 if (!is_safari() && (keycode
== 80 || keycode
== 38)) { // p, up
250 if (typeof moveToPost
!= 'undefined') {
251 return moveToPost('prev');
255 if (keycode
== 68 && shift_key
) { // d
256 if (!debug_mode_enabled
) {
257 document
.getElementById('debug_output').style
.display
= 'block';
258 debug('debug mode activated');
260 document
.getElementById('debug_output').style
.display
= 'none';
263 debug_mode_enabled
= !debug_mode_enabled
;
266 if (keycode
== 190 && shift_key
) { // >
270 if (keycode
== 188 && shift_key
) { // <
274 if (keycode
== 191 && shift_key
) { // ?
278 if (keycode
== 69 && shift_key
) { // e
279 return editFeedDlg(getActiveFeedId());
282 if (keycode
== 70 && shift_key
) { // f
283 if (getActiveFeedId()) {
284 return catchupCurrentFeed();
288 if (keycode
== 80 && shift_key
) { // p
289 if (getActiveFeedId()) {
290 return catchupPage();
294 if (typeof localHotkeyHandler
!= 'undefined') {
296 return localHotkeyHandler(e
);
298 exception_error("hotkey_handler, local:", e
);
302 debug("KP=" + keycode
);
304 exception_error("hotkey_handler", e
);
308 function cleanSelectedList(element
) {
309 var content
= document
.getElementById(element
);
311 if (!document
.getElementById("feedCatHolder")) {
312 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
313 var child
= content
.childNodes
[i
];
315 child
.className
= child
.className
.replace("Selected", "");
321 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
322 var child
= content
.childNodes
[i
];
323 if (child
.id
== "feedCatHolder") {
325 var fcat
= child
.lastChild
;
326 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
327 var feed
= fcat
.childNodes
[j
];
328 feed
.className
= feed
.className
.replace("Selected", "");
336 function cleanSelected(element
) {
337 var content
= document
.getElementById(element
);
339 for (i
= 0; i
< content
.rows
.length
; i
++) {
340 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
344 function getVisibleUnreadHeadlines() {
345 var content
= document
.getElementById("headlinesList");
347 var rows
= new Array();
349 for (i
= 0; i
< content
.rows
.length
; i
++) {
350 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
351 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
358 function getVisibleHeadlineIds() {
360 var content
= document
.getElementById("headlinesList");
362 var rows
= new Array();
364 for (i
= 0; i
< content
.rows
.length
; i
++) {
365 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
366 if (row_id
.length
> 0) {
373 function getFirstVisibleHeadlineId() {
374 var rows
= getVisibleHeadlineIds();
378 function getLastVisibleHeadlineId() {
379 var rows
= getVisibleHeadlineIds();
380 return rows
[rows
.length
-1];
383 function markHeadline(id
) {
384 var row
= document
.getElementById("RROW-" + id
);
386 var is_active
= false;
388 if (row
.className
.match("Active")) {
391 row
.className
= row
.className
.replace("Selected", "");
392 row
.className
= row
.className
.replace("Active", "");
393 row
.className
= row
.className
.replace("Insensitive", "");
396 row
.className
= row
.className
= "Active";
399 var check
= document
.getElementById("RCHK-" + id
);
402 check
.checked
= true;
405 row
.className
= row
.className
+ "Selected";
410 function getFeedIds() {
411 var content
= document
.getElementById("feedsList");
413 var rows
= new Array();
415 for (i
= 0; i
< content
.rows
.length
; i
++) {
416 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
425 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
431 d
.setTime(d
.getTime() + (lifetime
* 1000));
434 int_setCookie(name
, value
, d
, path
, domain
, secure
);
438 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
439 document
.cookie
= name
+ "=" + escape(value
) +
440 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
441 ((path
) ? "; path=" + path
: "") +
442 ((domain
) ? "; domain=" + domain
: "") +
443 ((secure
) ? "; secure" : "");
446 function delCookie(name
, path
, domain
) {
447 if (getCookie(name
)) {
448 document
.cookie
= name
+ "=" +
449 ((path
) ? ";path=" + path
: "") +
450 ((domain
) ? ";domain=" + domain
: "" ) +
451 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
456 function getCookie(name
) {
458 var dc
= document
.cookie
;
459 var prefix
= name
+ "=";
460 var begin
= dc
.indexOf("; " + prefix
);
462 begin
= dc
.indexOf(prefix
);
463 if (begin
!= 0) return null;
468 var end
= document
.cookie
.indexOf(";", begin
);
472 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
475 function disableContainerChildren(id
, disable
, doc
) {
477 if (!doc
) doc
= document
;
479 var container
= doc
.getElementById(id
);
482 //alert("disableContainerChildren: element " + id + " not found");
486 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
487 var child
= container
.childNodes
[i
];
490 child
.disabled
= disable
;
496 if (child
.className
&& child
.className
.match("button")) {
497 child
.className
= "disabledButton";
500 if (child
.className
&& child
.className
.match("disabledButton")) {
501 child
.className
= "button";
508 function gotoPreferences() {
509 document
.location
.href
= "prefs.php";
512 function gotoMain() {
513 document
.location
.href
= "tt-rss.php";
516 function gotoExportOpml() {
517 document
.location
.href
= "opml.php?op=Export";
520 function getActiveFeedId() {
521 // return getCookie("ttrss_vf_actfeed");
523 debug("gAFID: " + active_feed_id
);
524 return active_feed_id
;
526 exception_error("getActiveFeedId", e
);
530 function activeFeedIsCat() {
531 return active_feed_is_cat
;
534 function setActiveFeedId(id
) {
535 // return setCookie("ttrss_vf_actfeed", id);
537 debug("sAFID(" + id
+ ")");
540 exception_error("setActiveFeedId", e
);
544 function parse_counters(reply
, scheduled_call
) {
549 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
550 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
551 reply
= reply
.firstChild
;
554 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
555 if (!reply
.childNodes
[l
] ||
556 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
557 // where did this come from?
561 var id
= reply
.childNodes
[l
].getAttribute("id");
562 var t
= reply
.childNodes
[l
].getAttribute("type");
563 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
564 var error
= reply
.childNodes
[l
].getAttribute("error");
565 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
566 var updated
= reply
.childNodes
[l
].getAttribute("updated");
568 if (id
== "global-unread") {
574 if (id
== "subscribed-feeds") {
579 if (t
== "category") {
580 var catctr
= document
.getElementById("FCATCTR-" + id
);
582 catctr
.innerHTML
= "(" + ctr
+ ")";
584 catctr
.className
= "catCtrHasUnread";
586 catctr
.className
= "catCtrNoUnread";
592 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
593 var feedu
= document
.getElementById("FEEDU-" + id
);
594 var feedr
= document
.getElementById("FEEDR-" + id
);
595 var feed_img
= document
.getElementById("FIMG-" + id
);
596 var feedlink
= document
.getElementById("FEEDL-" + id
);
597 var feedupd
= document
.getElementById("FLUPD-" + id
);
599 if (updated
&& feedlink
) {
601 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
603 feedlink
.title
= "Updated: " + updated
;
607 if (updated
&& feedupd
) {
609 feedupd
.innerHTML
= updated
+ " (Error)";
611 feedupd
.innerHTML
= updated
;
615 if (feedctr
&& feedu
&& feedr
) {
617 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
621 feedu
.innerHTML
= ctr
;
624 feedr
.className
= feedr
.className
.replace("feed", "error");
626 feedr
.className
= feedr
.className
.replace("error", "feed");
630 feedctr
.className
= "odd";
631 if (!feedr
.className
.match("Unread")) {
632 var is_selected
= feedr
.className
.match("Selected");
634 feedr
.className
= feedr
.className
.replace("Selected", "");
635 feedr
.className
= feedr
.className
.replace("Unread", "");
637 feedr
.className
= feedr
.className
+ "Unread";
640 feedr
.className
= feedr
.className
+ "Selected";
645 feedctr
.className
= "invisible";
646 feedr
.className
= feedr
.className
.replace("Unread", "");
651 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
653 var feeds_stored
= number_of_feeds
;
655 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
657 if (feeds_stored
!= feeds_found
) {
658 number_of_feeds
= feeds_found
;
660 if (feeds_stored
!= 0) {
661 debug("Subscribed feed number changed, refreshing feedlist");
662 setTimeout('updateFeedList(false, false)', 50);
667 exception_error("parse_counters", e
);
671 function parse_counters_reply(xmlhttp
, scheduled_call
) {
673 if (!xmlhttp
.responseXML
) {
674 notify_error("Backend did not return valid XML", true);
678 var reply
= xmlhttp
.responseXML
.firstChild
;
681 notify_error("Backend did not return expected XML object", true);
686 var error_code
= false;
687 var error_msg
= false;
689 if (reply
.firstChild
) {
690 error_code
= reply
.firstChild
.getAttribute("error-code");
691 error_msg
= reply
.firstChild
.getAttribute("error-msg");
695 error_code
= reply
.getAttribute("error-code");
696 error_msg
= reply
.getAttribute("error-msg");
699 if (error_code
&& error_code
!= 0) {
700 debug("refetch_callback: got error code " + error_code
);
701 return fatalError(error_code
, error_msg
);
704 var counters
= reply
.firstChild
;
706 parse_counters(counters
, scheduled_call
);
708 var runtime_info
= counters
.nextSibling
;
710 parse_runtime_info(runtime_info
);
712 if (getInitParam("feeds_sort_by_unread") == 1) {
716 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
720 function all_counters_callback() {
721 if (xmlhttp_rpc
.readyState
== 4) {
723 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
724 debug("[all_counters_callback] backend did not return valid XML");
728 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
730 var reply = xmlhttp_rpc.responseXML.firstChild;
732 var counters = reply.firstChild;
734 parse_counters(counters);
736 var runtime = counters.nextSibling;
739 parse_runtime_info(runtime);
742 if (getInitParam("feeds_sort_by_unread") == 1) {
746 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
748 debug("in all_counters_callback");
750 parse_counters_reply(xmlhttp_rpc
);
753 exception_error("all_counters_callback", e
);
758 function get_feed_entry_unread(doc
, elem
) {
760 var id
= elem
.id
.replace("FEEDR-", "");
767 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
773 function resort_category(doc
, node
) {
774 debug("resort_category: " + node
);
776 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
777 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
778 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
780 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
784 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
785 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
787 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
788 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
790 if (cur_val
> tmp_val
) {
791 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
792 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
793 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
794 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
803 function resort_feedlist() {
804 debug("resort_feedlist");
808 if (fd
.getElementById("feedCatHolder")) {
810 var feeds
= fd
.getElementById("feedList");
811 var child
= feeds
.firstChild
;
815 if (child
.id
== "feedCatHolder") {
816 resort_category(fd
, child
.firstChild
);
819 child
= child
.nextSibling
;
823 resort_category(fd
, fd
.getElementById("feedList"));
827 function update_all_counters(feed
) {
828 if (xmlhttp_ready(xmlhttp_rpc
)) {
829 var query
= "backend.php?op=rpc&subop=getAllCounters";
832 query
= query
+ "&aid=" + feed
;
835 if (tagsAreDisplayed()) {
836 query
= query
+ "&omode=lt";
838 query
= query
+ "&omode=flc";
841 debug("update_all_counters QUERY: " + query
);
843 var date
= new Date();
844 var timestamp
= Math
.round(date
.getTime() / 1000);
845 query
= query
+ "&ts=" + timestamp
847 xmlhttp_rpc
.open("GET", query
, true);
848 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
849 xmlhttp_rpc
.send(null);
853 function popupHelp(tid
) {
854 var w
= window
.open("backend.php?op=help&tid=" + tid
,
856 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
859 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
860 * * @author Sundar Dorai-Raj
861 * * Email: sdoraira@vt.edu
862 * * This program is free software; you can redistribute it and/or
863 * * modify it under the terms of the GNU General Public License
864 * * as published by the Free Software Foundation; either version 2
865 * * of the License, or (at your option) any later version,
866 * * provided that any use properly credits the author.
867 * * This program is distributed in the hope that it will be useful,
868 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
869 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
870 * * GNU General Public License for more details at http://www.gnu.org * * */
872 var numbers
=".0123456789";
873 function isNumeric(x
) {
874 // is x a String or a character?
876 // remove negative sign
878 for(j
=0;j
<x
.length
;j
++) {
879 // call isNumeric recursively for each character
880 number
=isNumeric(x
.substring(j
,j
+1));
881 if(!number
) return number
;
886 // if x is number return true
887 if(numbers
.indexOf(x
)>=0) return true;
893 function hideOrShowFeeds(doc
, hide
) {
895 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
899 var list
= fd
.getElementById("feedList");
901 if (fd
.getElementById("feedCatHolder")) {
903 var feeds
= fd
.getElementById("feedList");
904 var child
= feeds
.firstChild
;
908 if (child
.id
== "feedCatHolder") {
909 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
912 child
= child
.nextSibling
;
916 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
920 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
922 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
927 debug("hideOrShowFeeds: passed node is null, aborting");
931 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
932 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
933 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
935 if (node
.childNodes
[i
].style
!= undefined) {
937 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
939 // debug(node.childNodes[i].id + " --> " + has_unread);
941 if (hide
&& !has_unread
) {
942 node
.childNodes
[i
].style
.display
= "none";
946 node
.childNodes
[i
].style
.display
= "list-item";
950 node
.childNodes
[i
].style
.display
= "list-item";
957 if (cat_unread
== 0) {
958 if (cat_node
.style
== undefined) {
959 debug("ERROR: supplied cat_node " + cat_node
+
960 " has no styles. WTF?");
964 cat_node
.style
.display
= "none";
966 cat_node
.style
.display
= "list-item";
970 cat_node
.style
.display
= "list-item";
976 // debug("unread for category: " + cat_unread);
979 function selectTableRow(r
, do_select
) {
980 r
.className
= r
.className
.replace("Selected", "");
983 r
.className
= r
.className
+ "Selected";
987 function selectTableRowById(elem_id
, check_id
, do_select
) {
991 var row
= document
.getElementById(elem_id
);
994 selectTableRow(row
, do_select
);
997 var check
= document
.getElementById(check_id
);
1000 check
.checked
= do_select
;
1003 exception_error("selectTableRowById", e
);
1007 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
1008 classcheck
, reset_others
) {
1010 var content
= document
.getElementById(content_id
);
1013 alert("[selectTableRows] Element " + content_id
+ " not found.");
1017 for (i
= 0; i
< content
.rows
.length
; i
++) {
1018 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
1020 if (content
.rows
[i
].id
.match(prefix
)) {
1021 selectTableRow(content
.rows
[i
], do_select
);
1023 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1024 var check
= document
.getElementById(check_prefix
+ row_id
);
1027 check
.checked
= do_select
;
1029 } else if (reset_others
) {
1030 selectTableRow(content
.rows
[i
], false);
1032 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1033 var check
= document
.getElementById(check_prefix
+ row_id
);
1036 check
.checked
= false;
1040 } else if (reset_others
) {
1041 selectTableRow(content
.rows
[i
], false);
1043 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1044 var check
= document
.getElementById(check_prefix
+ row_id
);
1047 check
.checked
= false;
1054 function getSelectedTableRowIds(content_id
, prefix
) {
1056 var content
= document
.getElementById(content_id
);
1059 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1063 var sel_rows
= new Array();
1065 for (i
= 0; i
< content
.rows
.length
; i
++) {
1066 if (content
.rows
[i
].id
.match(prefix
) &&
1067 content
.rows
[i
].className
.match("Selected")) {
1069 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1070 sel_rows
.push(row_id
);
1078 function toggleSelectRowById(sender
, id
) {
1079 var row
= document
.getElementById(id
);
1081 if (sender
.checked
) {
1082 if (!row
.className
.match("Selected")) {
1083 row
.className
= row
.className
+ "Selected";
1086 if (row
.className
.match("Selected")) {
1087 row
.className
= row
.className
.replace("Selected", "");
1092 function toggleSelectListRow(sender
) {
1093 var parent_row
= sender
.parentNode
;
1095 if (sender
.checked
) {
1096 if (!parent_row
.className
.match("Selected")) {
1097 parent_row
.className
= parent_row
.className
+ "Selected";
1100 if (parent_row
.className
.match("Selected")) {
1101 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1107 function toggleSelectRow(sender
) {
1108 var parent_row
= sender
.parentNode
.parentNode
;
1110 if (sender
.checked
) {
1111 if (!parent_row
.className
.match("Selected")) {
1112 parent_row
.className
= parent_row
.className
+ "Selected";
1115 if (parent_row
.className
.match("Selected")) {
1116 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1121 function openExternalUrl(url
) {
1122 var w
= window
.open(url
);
1125 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1127 if (direction
== "next") {
1128 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1129 var child
= list
.childNodes
[i
];
1130 if (child
.id
&& child
.id
== "feedCatHolder") {
1131 if (child
.lastChild
) {
1132 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1135 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1136 return child
.id
.replace('FEEDR-', '');
1141 // FIXME select last feed doesn't work when only unread feeds are visible
1143 if (direction
== "prev") {
1144 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1145 var child
= list
.childNodes
[i
];
1146 if (child
.id
== "feedCatHolder") {
1147 if (child
.firstChild
) {
1148 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1151 } else if (child
.id
.match("FEEDR-")) {
1153 if (getInitParam("hide_read_feeds") == 1) {
1154 if (child
.className
!= "feed") {
1155 alert(child
.className
);
1156 return child
.id
.replace('FEEDR-', '');
1159 return child
.id
.replace('FEEDR-', '');
1166 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1168 if (getInitParam("hide_read_feeds") == 1) {
1172 if (direction
== "next") {
1178 if (e
.nextSibling
) {
1182 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1184 var this_cat
= e
.parentNode
.parentNode
;
1188 if (this_cat
&& this_cat
.nextSibling
) {
1189 while (!e
&& this_cat
.nextSibling
) {
1190 this_cat
= this_cat
.nextSibling
;
1191 if (this_cat
.id
== "feedCatHolder") {
1192 e
= this_cat
.firstChild
.firstChild
;
1202 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1203 e
.className
.match("feed"))) {
1204 return e
.id
.replace("FEEDR-", "");
1209 } else if (direction
== "prev") {
1215 if (e
.previousSibling
) {
1217 e
= e
.previousSibling
;
1219 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1221 var this_cat
= e
.parentNode
.parentNode
;
1225 if (this_cat
&& this_cat
.previousSibling
) {
1226 while (!e
&& this_cat
.previousSibling
) {
1227 this_cat
= this_cat
.previousSibling
;
1228 if (this_cat
.id
== "feedCatHolder") {
1229 e
= this_cat
.firstChild
.lastChild
;
1239 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1240 e
.className
.match("feed"))) {
1241 return e
.id
.replace("FEEDR-", "");
1249 function showBlockElement(id
) {
1250 var elem
= document
.getElementById(id
);
1253 elem
.style
.display
= "block";
1255 alert("[showBlockElement] can't find element with id " + id
);
1259 function hideParentElement(e
) {
1260 e
.parentNode
.style
.display
= "none";
1263 function dropboxSelect(e
, v
) {
1264 for (i
= 0; i
< e
.length
; i
++) {
1265 if (e
[i
].value
== v
) {
1266 e
.selectedIndex
= i
;
1272 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1273 // bugfixed just a little bit :-)
1274 function getURLParam(strParamName
){
1276 var strHref
= window
.location
.href
;
1278 if (strHref
.indexOf("#") == strHref
.length
-1) {
1279 strHref
= strHref
.substring(0, strHref
.length
-1);
1282 if ( strHref
.indexOf("?") > -1 ){
1283 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1284 var aQueryString
= strQueryString
.split("&");
1285 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1286 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1287 var aParam
= aQueryString
[iParam
].split("=");
1288 strReturn
= aParam
[1];
1296 function leading_zero(p
) {
1298 if (s
.length
== 1) s
= "0" + s
;
1302 function closeInfoBox(cleanup
) {
1303 var box
= document
.getElementById('infoBox');
1304 var shadow
= document
.getElementById('infoBoxShadow');
1307 shadow
.style
.display
= "none";
1309 box
.style
.display
= "none";
1312 if (cleanup
) box
.innerHTML
= " ";
1320 function displayDlg(id
, param
) {
1322 if (!xmlhttp_ready(xmlhttp
)) {
1323 printLockingError();
1327 notify_progress("Loading, please wait...");
1329 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1330 param_escape(id
) + "¶m=" + param_escape(param
), true);
1331 xmlhttp
.onreadystatechange
=infobox_callback
;
1339 function infobox_submit_callback() {
1340 if (xmlhttp
.readyState
== 4) {
1344 // called from prefs, reload tab
1346 selectTab(active_tab
, false);
1350 if (xmlhttp
.responseText
) {
1351 notify_info(xmlhttp
.responseText
);
1357 function infobox_callback() {
1358 if (xmlhttp
.readyState
== 4) {
1359 var box
= document
.getElementById('infoBox');
1360 var shadow
= document
.getElementById('infoBoxShadow');
1362 box
.innerHTML
=xmlhttp
.responseText
;
1364 shadow
.style
.display
= "block";
1366 box
.style
.display
= "block";
1373 function addFilter() {
1375 if (!xmlhttp_ready(xmlhttp
)) {
1376 printLockingError();
1380 var form
= document
.forms
['filter_add_form'];
1381 var reg_exp
= form
.reg_exp
.value
;
1383 if (reg_exp
== "") {
1384 alert("Can't add filter: nothing to match on.");
1388 var query
= Form
.serialize("filter_add_form");
1390 xmlhttp
.open("GET", "backend.php?" + query
, true);
1391 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1397 function toggleSubmitNotEmpty(e
, submit_id
) {
1399 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1401 exception_error("toggleSubmitNotEmpty", e
);
1405 function isValidURL(s
) {
1406 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1409 function qaddFeed() {
1411 if (!xmlhttp_ready(xmlhttp
)) {
1412 printLockingError();
1416 var form
= document
.forms
['feed_add_form'];
1417 var feed_url
= form
.feed_url
.value
;
1419 if (feed_url
== "") {
1420 alert("Can't subscribe: no feed URL given.");
1424 notify_progress("Adding feed...");
1428 var feeds_doc
= document
;
1430 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1432 var query
= Form
.serialize("feed_add_form");
1434 xmlhttp
.open("GET", "backend.php?" + query
, true);
1435 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1441 function filterCR(e
, f
)
1446 key
= window
.event
.keyCode
; //IE
1448 key
= e
.which
; //firefox
1451 if (typeof f
!= 'undefined') {
1462 function getMainContext() {
1466 function getFeedsContext() {
1470 function getContentContext() {
1474 function getHeadlinesContext() {
1478 var debug_last_class
= "even";
1480 function debug(msg
) {
1482 if (debug_last_class
== "even") {
1483 debug_last_class
= "odd";
1485 debug_last_class
= "even";
1488 var c
= document
.getElementById('debug_output');
1489 if (c
&& c
.style
.display
== "block") {
1490 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1491 c
.removeChild(c
.lastChild
);
1495 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1496 ":" + leading_zero(d
.getSeconds());
1497 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1498 msg
+ "</li>" + c
.innerHTML
;
1502 function getInitParam(key
) {
1503 var c
= getCookie("TTIP:" + key
);
1507 return getMainContext().init_params
[key
];
1511 function storeInitParam(key
, value
) {
1513 init_params
[key
] = value
;
1514 debug("storeInitParam: " + key
+ " => " + value
+
1515 " (" + getInitParam("cookie_lifetime") + ")");
1516 if (getInitParam("cookie_lifetime") > 0) {
1517 setCookie("TTIP:" + key
, value
, getInitParam("cookie_lifetime"));
1519 setCookie("TTIP:" + key
, value
);
1522 exception_error("storeInitParam", e
);
1528 function storeInitParam(key, value, is_client) {
1531 if (getMainContext().init_params[key] != value) {
1532 debug("storeInitParam: " + key + " => " + value);
1533 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1534 // param_escape(key) + "&value=" + param_escape(value));
1535 var f = getMainContext().document.getElementById("backReqBox");
1536 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1537 param_escape(key) + "&value=" + param_escape(value);
1540 getMainContext().init_params[key] = value;
1542 exception_error("storeInitParam", e);
1547 function storeInitParams(params, is_client) {
1552 if (getMainContext().init_params[k] != params[k]) {
1553 s += k + "=" + params[k] + ";";
1554 getMainContext().init_params[k] = params[k];
1558 debug("storeInitParams: " + s);
1561 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1564 exception_error("storeInitParams", e);
1568 function fatalError(code
, message
) {
1572 window
.location
.href
= "tt-rss.php";
1573 } else if (code
== 5) {
1574 window
.location
.href
= "update.php";
1576 var fe
= document
.getElementById("fatal_error");
1577 var fc
= document
.getElementById("fatal_error_msg");
1579 if (message
== "") message
= "Unknown error";
1581 fc
.innerHTML
= "<img src='images/sign_excl.png'> " + message
+ " (Code " + code
+ ")";
1583 fe
.style
.display
= "block";
1587 exception_error("fatalError", e
);
1591 function getFeedName(id
, is_cat
) {
1592 var d
= getFeedsContext().document
;
1597 e
= d
.getElementById("FCATN-" + id
);
1599 e
= d
.getElementById("FEEDN-" + id
);
1602 return e
.innerHTML
.stripTags();
1608 function viewContentUrl(url
) {
1609 getContentContext().location
= url
;
1612 function filterDlgCheckAction(sender
) {
1616 var action
= sender
[sender
.selectedIndex
].value
;
1618 var form
= document
.forms
["filter_add_form"];
1621 form
= document
.forms
["filter_edit_form"];
1625 debug("filterDlgCheckAction: can't find form!");
1629 var action_param
= form
.action_param
;
1631 if (!action_param
) {
1632 debug("filterDlgCheckAction: can't find action param!");
1636 // if selected action supports parameters, enable params field
1638 action_param
.disabled
= false;
1640 action_param
.disabled
= true;
1644 exception_error(e
, "filterDlgCheckAction");
1649 function explainError(code
) {
1650 return displayDlg("explainError", code
);
1653 function logoutUser() {
1655 if (xmlhttp_ready(xmlhttp_rpc
)) {
1657 notify_progress("Logging out, please wait...", true);
1659 xmlhttp_rpc
.open("GET", "backend.php?op=rpc&subop=logout", true);
1660 xmlhttp_rpc
.onreadystatechange
=logout_callback
;
1661 xmlhttp_rpc
.send(null);
1663 printLockingError();
1666 exception_error("logoutUser", e
);