]>
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";
144 n
.className
= "notify";
145 } else if (n_type
== 2) {
146 n
.className
= "notifyProgress";
147 msg
= "<img src='images/indicator_white.gif'> " + msg
;
148 } else if (n_type
== 3) {
149 n
.className
= "notifyError";
150 msg
= "<img src='images/sign_excl.png'> " + msg
;
151 } else if (n_type
== 4) {
152 n
.className
= "notifyInfo";
153 msg
= "<img src='images/sign_info.png'> " + msg
;
156 // msg = "<img src='images/live_com_loading.gif'> " + msg;
161 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
165 function notify(msg
, no_hide
) {
166 notify_real(msg
, no_hide
, 1);
169 function notify_progress(msg
, no_hide
) {
170 notify_real(msg
, no_hide
, 2);
173 function notify_error(msg
, no_hide
) {
174 notify_real(msg
, no_hide
, 3);
178 function notify_info(msg
, no_hide
) {
179 notify_real(msg
, no_hide
, 4);
182 function printLockingError() {
183 notify_info("Please wait until operation finishes.");
186 function hotkey_handler(e
) {
191 var shift_key
= false;
194 shift_key
= e
.shiftKey
;
199 if (!hotkeys_enabled
) return;
202 keycode
= window
.event
.keyCode
;
207 if (keycode
== 82) { // r
208 return scheduleFeedUpdate(true);
211 if (keycode
== 83) { // s
212 return displayDlg("search", getActiveFeedId());
215 if (keycode
== 85) { // u
216 if (getActiveFeedId()) {
217 return viewfeed(getActiveFeedId(), "ForceUpdate");
221 if (keycode
== 65) { // a
222 return toggleDispRead();
225 var feedlist
= document
.getElementById('feedList');
227 if (keycode
== 74) { // j
228 var feed
= getActiveFeedId();
229 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
230 if (new_feed
) viewfeed(new_feed
, '');
233 if (keycode
== 75) { // k
234 var feed
= getActiveFeedId();
235 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
236 if (new_feed
) viewfeed(new_feed
, '');
239 if (!is_safari() && (keycode
== 78 || keycode
== 40)) { // n, down
240 if (typeof moveToPost
!= 'undefined') {
241 return moveToPost('next');
245 if (!is_safari() && (keycode
== 80 || keycode
== 38)) { // p, up
246 if (typeof moveToPost
!= 'undefined') {
247 return moveToPost('prev');
251 if (keycode
== 68 && shift_key
) { // d
252 if (!debug_mode_enabled
) {
253 document
.getElementById('debug_output').style
.display
= 'block';
254 debug('debug mode activated');
256 document
.getElementById('debug_output').style
.display
= 'none';
259 debug_mode_enabled
= !debug_mode_enabled
;
262 if (keycode
== 190 && shift_key
) { // >
266 if (keycode
== 188 && shift_key
) { // <
270 if (keycode
== 191 && shift_key
) { // ?
274 if (keycode
== 69 && shift_key
) { // e
275 return editFeedDlg(getActiveFeedId());
278 if (keycode
== 70 && shift_key
) { // f
279 if (getActiveFeedId()) {
280 return catchupCurrentFeed();
284 if (keycode
== 80 && shift_key
) { // p
285 if (getActiveFeedId()) {
286 return catchupPage();
290 if (typeof localHotkeyHandler
!= 'undefined') {
292 return localHotkeyHandler(e
);
294 exception_error("hotkey_handler, local:", e
);
298 debug("KP=" + keycode
);
300 exception_error("hotkey_handler", e
);
304 function cleanSelectedList(element
) {
305 var content
= document
.getElementById(element
);
307 if (!document
.getElementById("feedCatHolder")) {
308 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
309 var child
= content
.childNodes
[i
];
311 child
.className
= child
.className
.replace("Selected", "");
317 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
318 var child
= content
.childNodes
[i
];
319 if (child
.id
== "feedCatHolder") {
321 var fcat
= child
.lastChild
;
322 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
323 var feed
= fcat
.childNodes
[j
];
324 feed
.className
= feed
.className
.replace("Selected", "");
332 function cleanSelected(element
) {
333 var content
= document
.getElementById(element
);
335 for (i
= 0; i
< content
.rows
.length
; i
++) {
336 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
340 function getVisibleUnreadHeadlines() {
341 var content
= document
.getElementById("headlinesList");
343 var rows
= new Array();
345 for (i
= 0; i
< content
.rows
.length
; i
++) {
346 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
347 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
354 function getVisibleHeadlineIds() {
356 var content
= document
.getElementById("headlinesList");
358 var rows
= new Array();
360 for (i
= 0; i
< content
.rows
.length
; i
++) {
361 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
362 if (row_id
.length
> 0) {
369 function getFirstVisibleHeadlineId() {
370 var rows
= getVisibleHeadlineIds();
374 function getLastVisibleHeadlineId() {
375 var rows
= getVisibleHeadlineIds();
376 return rows
[rows
.length
-1];
379 function markHeadline(id
) {
380 var row
= document
.getElementById("RROW-" + id
);
382 var is_active
= false;
384 if (row
.className
.match("Active")) {
387 row
.className
= row
.className
.replace("Selected", "");
388 row
.className
= row
.className
.replace("Active", "");
389 row
.className
= row
.className
.replace("Insensitive", "");
392 row
.className
= row
.className
= "Active";
395 var check
= document
.getElementById("RCHK-" + id
);
398 check
.checked
= true;
401 row
.className
= row
.className
+ "Selected";
406 function getFeedIds() {
407 var content
= document
.getElementById("feedsList");
409 var rows
= new Array();
411 for (i
= 0; i
< content
.rows
.length
; i
++) {
412 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
421 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
427 d
.setTime(lifetime
* 1000);
430 int_setCookie(name
, value
, d
, path
, domain
, secure
);
434 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
435 document
.cookie
= name
+ "=" + escape(value
) +
436 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
437 ((path
) ? "; path=" + path
: "") +
438 ((domain
) ? "; domain=" + domain
: "") +
439 ((secure
) ? "; secure" : "");
442 function delCookie(name
, path
, domain
) {
443 if (getCookie(name
)) {
444 document
.cookie
= name
+ "=" +
445 ((path
) ? ";path=" + path
: "") +
446 ((domain
) ? ";domain=" + domain
: "" ) +
447 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
452 function getCookie(name
) {
454 var dc
= document
.cookie
;
455 var prefix
= name
+ "=";
456 var begin
= dc
.indexOf("; " + prefix
);
458 begin
= dc
.indexOf(prefix
);
459 if (begin
!= 0) return null;
464 var end
= document
.cookie
.indexOf(";", begin
);
468 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
471 function disableContainerChildren(id
, disable
, doc
) {
473 if (!doc
) doc
= document
;
475 var container
= doc
.getElementById(id
);
478 //alert("disableContainerChildren: element " + id + " not found");
482 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
483 var child
= container
.childNodes
[i
];
486 child
.disabled
= disable
;
492 if (child
.className
&& child
.className
.match("button")) {
493 child
.className
= "disabledButton";
496 if (child
.className
&& child
.className
.match("disabledButton")) {
497 child
.className
= "button";
504 function gotoPreferences() {
505 document
.location
.href
= "prefs.php";
508 function gotoMain() {
509 document
.location
.href
= "tt-rss.php";
512 function gotoExportOpml() {
513 document
.location
.href
= "opml.php?op=Export";
516 function getActiveFeedId() {
517 // return getCookie("ttrss_vf_actfeed");
519 debug("gAFID: " + active_feed_id
);
520 return active_feed_id
;
522 exception_error("getActiveFeedId", e
);
526 function activeFeedIsCat() {
527 return active_feed_is_cat
;
530 function setActiveFeedId(id
) {
531 // return setCookie("ttrss_vf_actfeed", id);
533 debug("sAFID(" + id
+ ")");
536 exception_error("setActiveFeedId", e
);
540 function parse_counters(reply
, scheduled_call
) {
545 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
546 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
547 reply
= reply
.firstChild
;
550 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
551 if (!reply
.childNodes
[l
] ||
552 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
553 // where did this come from?
557 var id
= reply
.childNodes
[l
].getAttribute("id");
558 var t
= reply
.childNodes
[l
].getAttribute("type");
559 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
560 var error
= reply
.childNodes
[l
].getAttribute("error");
561 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
562 var updated
= reply
.childNodes
[l
].getAttribute("updated");
564 if (id
== "global-unread") {
570 if (id
== "subscribed-feeds") {
575 if (t
== "category") {
576 var catctr
= document
.getElementById("FCATCTR-" + id
);
578 catctr
.innerHTML
= "(" + ctr
+ ")";
580 catctr
.className
= "catCtrHasUnread";
582 catctr
.className
= "catCtrNoUnread";
588 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
589 var feedu
= document
.getElementById("FEEDU-" + id
);
590 var feedr
= document
.getElementById("FEEDR-" + id
);
591 var feed_img
= document
.getElementById("FIMG-" + id
);
592 var feedlink
= document
.getElementById("FEEDL-" + id
);
593 var feedupd
= document
.getElementById("FLUPD-" + id
);
595 if (updated
&& feedlink
) {
597 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
599 feedlink
.title
= "Updated: " + updated
;
603 if (updated
&& feedupd
) {
605 feedupd
.innerHTML
= updated
+ " (Error)";
607 feedupd
.innerHTML
= updated
;
611 if (feedctr
&& feedu
&& feedr
) {
613 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
617 feedu
.innerHTML
= ctr
;
620 feedr
.className
= feedr
.className
.replace("feed", "error");
622 feedr
.className
= feedr
.className
.replace("error", "feed");
626 feedctr
.className
= "odd";
627 if (!feedr
.className
.match("Unread")) {
628 var is_selected
= feedr
.className
.match("Selected");
630 feedr
.className
= feedr
.className
.replace("Selected", "");
631 feedr
.className
= feedr
.className
.replace("Unread", "");
633 feedr
.className
= feedr
.className
+ "Unread";
636 feedr
.className
= feedr
.className
+ "Selected";
641 feedctr
.className
= "invisible";
642 feedr
.className
= feedr
.className
.replace("Unread", "");
647 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
649 var feeds_stored
= number_of_feeds
;
651 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
653 if (feeds_stored
!= feeds_found
) {
654 number_of_feeds
= feeds_found
;
656 if (feeds_stored
!= 0) {
657 debug("Subscribed feed number changed, refreshing feedlist");
658 setTimeout('updateFeedList(false, false)', 50);
663 exception_error("parse_counters", e
);
667 function parse_counters_reply(xmlhttp
, scheduled_call
) {
669 if (!xmlhttp
.responseXML
) {
670 notify_error("Backend did not return valid XML", true);
674 var reply
= xmlhttp
.responseXML
.firstChild
;
677 notify_error("Backend did not return expected XML object", true);
682 var error_code
= false;
683 var error_msg
= false;
685 if (reply
.firstChild
) {
686 error_code
= reply
.firstChild
.getAttribute("error-code");
687 error_msg
= reply
.firstChild
.getAttribute("error-msg");
691 error_code
= reply
.getAttribute("error-code");
692 error_msg
= reply
.getAttribute("error-msg");
695 if (error_code
&& error_code
!= 0) {
696 debug("refetch_callback: got error code " + error_code
);
697 return fatalError(error_code
, error_msg
);
700 var counters
= reply
.firstChild
;
702 parse_counters(counters
, scheduled_call
);
704 var runtime_info
= counters
.nextSibling
;
706 parse_runtime_info(runtime_info
);
708 if (getInitParam("feeds_sort_by_unread") == 1) {
712 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
716 function all_counters_callback() {
717 if (xmlhttp_rpc
.readyState
== 4) {
719 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
720 debug("[all_counters_callback] backend did not return valid XML");
724 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
726 var reply = xmlhttp_rpc.responseXML.firstChild;
728 var counters = reply.firstChild;
730 parse_counters(counters);
732 var runtime = counters.nextSibling;
735 parse_runtime_info(runtime);
738 if (getInitParam("feeds_sort_by_unread") == 1) {
742 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
744 debug("in all_counters_callback");
746 parse_counters_reply(xmlhttp_rpc
);
749 exception_error("all_counters_callback", e
);
754 function get_feed_entry_unread(doc
, elem
) {
756 var id
= elem
.id
.replace("FEEDR-", "");
763 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
769 function resort_category(doc
, node
) {
770 debug("resort_category: " + node
);
772 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
773 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
774 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
776 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
780 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
781 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
783 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
784 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
786 if (cur_val
> tmp_val
) {
787 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
788 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
789 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
790 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
799 function resort_feedlist() {
800 debug("resort_feedlist");
804 if (fd
.getElementById("feedCatHolder")) {
806 var feeds
= fd
.getElementById("feedList");
807 var child
= feeds
.firstChild
;
811 if (child
.id
== "feedCatHolder") {
812 resort_category(fd
, child
.firstChild
);
815 child
= child
.nextSibling
;
819 resort_category(fd
, fd
.getElementById("feedList"));
823 function update_all_counters(feed
) {
824 if (xmlhttp_ready(xmlhttp_rpc
)) {
825 var query
= "backend.php?op=rpc&subop=getAllCounters";
828 query
= query
+ "&aid=" + feed
;
831 if (tagsAreDisplayed()) {
832 query
= query
+ "&omode=lt";
834 query
= query
+ "&omode=flc";
837 debug("update_all_counters QUERY: " + query
);
839 var date
= new Date();
840 var timestamp
= Math
.round(date
.getTime() / 1000);
841 query
= query
+ "&ts=" + timestamp
843 xmlhttp_rpc
.open("GET", query
, true);
844 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
845 xmlhttp_rpc
.send(null);
849 function popupHelp(tid
) {
850 var w
= window
.open("backend.php?op=help&tid=" + tid
,
852 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
855 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
856 * * @author Sundar Dorai-Raj
857 * * Email: sdoraira@vt.edu
858 * * This program is free software; you can redistribute it and/or
859 * * modify it under the terms of the GNU General Public License
860 * * as published by the Free Software Foundation; either version 2
861 * * of the License, or (at your option) any later version,
862 * * provided that any use properly credits the author.
863 * * This program is distributed in the hope that it will be useful,
864 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
865 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
866 * * GNU General Public License for more details at http://www.gnu.org * * */
868 var numbers
=".0123456789";
869 function isNumeric(x
) {
870 // is x a String or a character?
872 // remove negative sign
874 for(j
=0;j
<x
.length
;j
++) {
875 // call isNumeric recursively for each character
876 number
=isNumeric(x
.substring(j
,j
+1));
877 if(!number
) return number
;
882 // if x is number return true
883 if(numbers
.indexOf(x
)>=0) return true;
889 function hideOrShowFeeds(doc
, hide
) {
891 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
895 var list
= fd
.getElementById("feedList");
897 if (fd
.getElementById("feedCatHolder")) {
899 var feeds
= fd
.getElementById("feedList");
900 var child
= feeds
.firstChild
;
904 if (child
.id
== "feedCatHolder") {
905 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
908 child
= child
.nextSibling
;
912 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
916 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
918 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
923 debug("hideOrShowFeeds: passed node is null, aborting");
927 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
928 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
929 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
931 if (node
.childNodes
[i
].style
!= undefined) {
933 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
935 // debug(node.childNodes[i].id + " --> " + has_unread);
937 if (hide
&& !has_unread
) {
938 node
.childNodes
[i
].style
.display
= "none";
942 node
.childNodes
[i
].style
.display
= "list-item";
946 node
.childNodes
[i
].style
.display
= "list-item";
953 if (cat_unread
== 0) {
954 if (cat_node
.style
== undefined) {
955 debug("ERROR: supplied cat_node " + cat_node
+
956 " has no styles. WTF?");
960 cat_node
.style
.display
= "none";
962 cat_node
.style
.display
= "list-item";
966 cat_node
.style
.display
= "list-item";
972 // debug("unread for category: " + cat_unread);
975 function selectTableRow(r
, do_select
) {
976 r
.className
= r
.className
.replace("Selected", "");
979 r
.className
= r
.className
+ "Selected";
983 function selectTableRowById(elem_id
, check_id
, do_select
) {
987 var row
= document
.getElementById(elem_id
);
990 selectTableRow(row
, do_select
);
993 var check
= document
.getElementById(check_id
);
996 check
.checked
= do_select
;
999 exception_error("selectTableRowById", e
);
1003 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
1004 classcheck
, reset_others
) {
1006 var content
= document
.getElementById(content_id
);
1009 alert("[selectTableRows] Element " + content_id
+ " not found.");
1013 for (i
= 0; i
< content
.rows
.length
; i
++) {
1014 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
1016 if (content
.rows
[i
].id
.match(prefix
)) {
1017 selectTableRow(content
.rows
[i
], do_select
);
1019 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1020 var check
= document
.getElementById(check_prefix
+ row_id
);
1023 check
.checked
= do_select
;
1025 } else if (reset_others
) {
1026 selectTableRow(content
.rows
[i
], false);
1028 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1029 var check
= document
.getElementById(check_prefix
+ row_id
);
1032 check
.checked
= false;
1036 } else if (reset_others
) {
1037 selectTableRow(content
.rows
[i
], false);
1039 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1040 var check
= document
.getElementById(check_prefix
+ row_id
);
1043 check
.checked
= false;
1050 function getSelectedTableRowIds(content_id
, prefix
) {
1052 var content
= document
.getElementById(content_id
);
1055 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1059 var sel_rows
= new Array();
1061 for (i
= 0; i
< content
.rows
.length
; i
++) {
1062 if (content
.rows
[i
].id
.match(prefix
) &&
1063 content
.rows
[i
].className
.match("Selected")) {
1065 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1066 sel_rows
.push(row_id
);
1074 function toggleSelectRowById(sender
, id
) {
1075 var row
= document
.getElementById(id
);
1077 if (sender
.checked
) {
1078 if (!row
.className
.match("Selected")) {
1079 row
.className
= row
.className
+ "Selected";
1082 if (row
.className
.match("Selected")) {
1083 row
.className
= row
.className
.replace("Selected", "");
1088 function toggleSelectListRow(sender
) {
1089 var parent_row
= sender
.parentNode
;
1091 if (sender
.checked
) {
1092 if (!parent_row
.className
.match("Selected")) {
1093 parent_row
.className
= parent_row
.className
+ "Selected";
1096 if (parent_row
.className
.match("Selected")) {
1097 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1103 function toggleSelectRow(sender
) {
1104 var parent_row
= sender
.parentNode
.parentNode
;
1106 if (sender
.checked
) {
1107 if (!parent_row
.className
.match("Selected")) {
1108 parent_row
.className
= parent_row
.className
+ "Selected";
1111 if (parent_row
.className
.match("Selected")) {
1112 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1117 function openExternalUrl(url
) {
1118 var w
= window
.open(url
);
1121 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1123 if (direction
== "next") {
1124 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1125 var child
= list
.childNodes
[i
];
1126 if (child
.id
&& child
.id
== "feedCatHolder") {
1127 if (child
.lastChild
) {
1128 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1131 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1132 return child
.id
.replace('FEEDR-', '');
1137 // FIXME select last feed doesn't work when only unread feeds are visible
1139 if (direction
== "prev") {
1140 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1141 var child
= list
.childNodes
[i
];
1142 if (child
.id
== "feedCatHolder") {
1143 if (child
.firstChild
) {
1144 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1147 } else if (child
.id
.match("FEEDR-")) {
1149 if (getInitParam("hide_read_feeds") == 1) {
1150 if (child
.className
!= "feed") {
1151 alert(child
.className
);
1152 return child
.id
.replace('FEEDR-', '');
1155 return child
.id
.replace('FEEDR-', '');
1162 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1164 if (getInitParam("hide_read_feeds") == 1) {
1168 if (direction
== "next") {
1174 if (e
.nextSibling
) {
1178 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1180 var this_cat
= e
.parentNode
.parentNode
;
1184 if (this_cat
&& this_cat
.nextSibling
) {
1185 while (!e
&& this_cat
.nextSibling
) {
1186 this_cat
= this_cat
.nextSibling
;
1187 if (this_cat
.id
== "feedCatHolder") {
1188 e
= this_cat
.firstChild
.firstChild
;
1198 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1199 e
.className
.match("feed"))) {
1200 return e
.id
.replace("FEEDR-", "");
1205 } else if (direction
== "prev") {
1211 if (e
.previousSibling
) {
1213 e
= e
.previousSibling
;
1215 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1217 var this_cat
= e
.parentNode
.parentNode
;
1221 if (this_cat
&& this_cat
.previousSibling
) {
1222 while (!e
&& this_cat
.previousSibling
) {
1223 this_cat
= this_cat
.previousSibling
;
1224 if (this_cat
.id
== "feedCatHolder") {
1225 e
= this_cat
.firstChild
.lastChild
;
1235 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1236 e
.className
.match("feed"))) {
1237 return e
.id
.replace("FEEDR-", "");
1245 function showBlockElement(id
) {
1246 var elem
= document
.getElementById(id
);
1249 elem
.style
.display
= "block";
1251 alert("[showBlockElement] can't find element with id " + id
);
1255 function hideParentElement(e
) {
1256 e
.parentNode
.style
.display
= "none";
1259 function dropboxSelect(e
, v
) {
1260 for (i
= 0; i
< e
.length
; i
++) {
1261 if (e
[i
].value
== v
) {
1262 e
.selectedIndex
= i
;
1268 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1269 // bugfixed just a little bit :-)
1270 function getURLParam(strParamName
){
1272 var strHref
= window
.location
.href
;
1274 if (strHref
.indexOf("#") == strHref
.length
-1) {
1275 strHref
= strHref
.substring(0, strHref
.length
-1);
1278 if ( strHref
.indexOf("?") > -1 ){
1279 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1280 var aQueryString
= strQueryString
.split("&");
1281 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1282 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1283 var aParam
= aQueryString
[iParam
].split("=");
1284 strReturn
= aParam
[1];
1292 function leading_zero(p
) {
1294 if (s
.length
== 1) s
= "0" + s
;
1298 function closeInfoBox(cleanup
) {
1299 var box
= document
.getElementById('infoBox');
1300 var shadow
= document
.getElementById('infoBoxShadow');
1303 shadow
.style
.display
= "none";
1305 box
.style
.display
= "none";
1308 if (cleanup
) box
.innerHTML
= " ";
1316 function displayDlg(id
, param
) {
1318 if (!xmlhttp_ready(xmlhttp
)) {
1319 printLockingError();
1323 notify_progress("Loading, please wait...");
1325 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1326 param_escape(id
) + "¶m=" + param_escape(param
), true);
1327 xmlhttp
.onreadystatechange
=infobox_callback
;
1335 function infobox_submit_callback() {
1336 if (xmlhttp
.readyState
== 4) {
1340 // called from prefs, reload tab
1342 selectTab(active_tab
, false);
1346 // notify_info(xmlhttp.responseText);
1351 function infobox_callback() {
1352 if (xmlhttp
.readyState
== 4) {
1353 var box
= document
.getElementById('infoBox');
1354 var shadow
= document
.getElementById('infoBoxShadow');
1356 box
.innerHTML
=xmlhttp
.responseText
;
1358 shadow
.style
.display
= "block";
1360 box
.style
.display
= "block";
1367 function qaddFilter() {
1369 if (!xmlhttp_ready(xmlhttp
)) {
1370 printLockingError();
1374 var form
= document
.forms
['filter_add_form'];
1375 var reg_exp
= form
.reg_exp
.value
;
1377 if (reg_exp
== "") {
1378 alert("Can't add filter: nothing to match on.");
1382 var query
= Form
.serialize("filter_add_form");
1384 xmlhttp
.open("GET", "backend.php?" + query
, true);
1385 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1391 function toggleSubmitNotEmpty(e
, submit_id
) {
1393 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1395 exception_error("toggleSubmitNotEmpty", e
);
1399 function isValidURL(s
) {
1400 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1405 if (!xmlhttp_ready(xmlhttp
)) {
1406 printLockingError();
1410 var form
= document
.forms
['feed_add_form'];
1411 var feed_url
= form
.feed_url
.value
;
1413 if (feed_url
== "") {
1414 alert("Can't subscribe: no feed URL given.");
1418 notify_progress("Adding feed...");
1422 var feeds_doc
= document
;
1424 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1426 var query
= Form
.serialize("feed_add_form");
1428 xmlhttp
.open("GET", "backend.php?" + query
, true);
1429 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1435 function filterCR(e
, f
)
1440 key
= window
.event
.keyCode
; //IE
1442 key
= e
.which
; //firefox
1445 if (typeof f
!= 'undefined') {
1456 function getMainContext() {
1460 function getFeedsContext() {
1464 function getContentContext() {
1468 function getHeadlinesContext() {
1472 var debug_last_class
= "even";
1474 function debug(msg
) {
1476 if (debug_last_class
== "even") {
1477 debug_last_class
= "odd";
1479 debug_last_class
= "even";
1482 var c
= document
.getElementById('debug_output');
1483 if (c
&& c
.style
.display
== "block") {
1484 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1485 c
.removeChild(c
.lastChild
);
1489 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1490 ":" + leading_zero(d
.getSeconds());
1491 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1492 msg
+ "</li>" + c
.innerHTML
;
1496 function getInitParam(key
) {
1497 return getMainContext().init_params
[key
];
1500 function storeInitParam(key
, value
, is_client
) {
1503 if (getMainContext().init_params
[key
] != value
) {
1504 debug("storeInitParam: " + key
+ " => " + value
);
1505 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1506 // param_escape(key) + "&value=" + param_escape(value));
1507 var f
= getMainContext().document
.getElementById("backReqBox");
1508 f
.src
= "backend.php?op=rpc&subop=storeParam&key=" +
1509 param_escape(key
) + "&value=" + param_escape(value
);
1512 getMainContext().init_params
[key
] = value
;
1514 exception_error("storeInitParam", e
);
1519 function storeInitParams(params, is_client) {
1524 if (getMainContext().init_params[k] != params[k]) {
1525 s += k + "=" + params[k] + ";";
1526 getMainContext().init_params[k] = params[k];
1530 debug("storeInitParams: " + s);
1533 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1536 exception_error("storeInitParams", e);
1540 function fatalError(code
, message
) {
1544 window
.location
.href
= "tt-rss.php";
1545 } else if (code
== 5) {
1546 window
.location
.href
= "update.php";
1548 var fe
= document
.getElementById("fatal_error");
1549 var fc
= document
.getElementById("fatal_error_msg");
1551 if (message
== "") message
= "Unknown error";
1553 fc
.innerHTML
= "<img src='images/sign_excl.png'> " + message
+ " (Code " + code
+ ")";
1555 fe
.style
.display
= "block";
1559 exception_error("fatalError", e
);
1563 function getFeedName(id
, is_cat
) {
1564 var d
= getFeedsContext().document
;
1569 e
= d
.getElementById("FCATN-" + id
);
1571 e
= d
.getElementById("FEEDN-" + id
);
1574 return e
.innerHTML
.stripTags();
1580 function viewContentUrl(url
) {
1581 getContentContext().location
= url
;
1584 function filterDlgCheckAction(sender
) {
1588 var action
= sender
[sender
.selectedIndex
].value
;
1590 var form
= document
.forms
["filter_add_form"];
1593 form
= document
.forms
["filter_edit_form"];
1597 debug("filterDlgCheckAction: can't find form!");
1601 var action_param
= form
.action_param
;
1603 if (!action_param
) {
1604 debug("filterDlgCheckAction: can't find action param!");
1608 // if selected action supports parameters, enable params field
1610 action_param
.disabled
= false;
1612 action_param
.disabled
= true;
1616 exception_error(e
, "filterDlgCheckAction");
1621 function explainError(code
) {
1622 return displayDlg("explainError", code
);
1625 function logoutUser() {
1627 if (xmlhttp_ready(xmlhttp_rpc
)) {
1629 notify_progress("Logging out, please wait...", true);
1631 xmlhttp_rpc
.open("GET", "backend.php?op=rpc&subop=logout", true);
1632 xmlhttp_rpc
.onreadystatechange
=logout_callback
;
1633 xmlhttp_rpc
.send(null);
1635 printLockingError();
1638 exception_error("logoutUser", e
);