]>
git.wh0rd.org - tt-rss.git/blob - functions.js
a6aa133efaa3865c4750cea95860f3edaeddac7c
1 var hotkeys_enabled
= true;
2 var debug_mode_enabled
= false;
3 var xmlhttp_rpc
= Ajax
.getTransport();
5 /* add method to remove element from array */
7 Array
.prototype.remove = function(s
) {
8 for (var i
=0; i
< this.length
; i
++) {
9 if (s
== this[i
]) this.splice(i
, 1);
13 function browser_has_opacity() {
14 return navigator
.userAgent
.match("Gecko") != null ||
15 navigator
.userAgent
.match("Opera") != null;
19 return navigator
.userAgent
.match("MSIE");
23 return navigator
.userAgent
.match("Opera");
27 return navigator
.userAgent
.match("KHTML");
30 function is_safari() {
31 return navigator
.userAgent
.match("Safari");
34 function exception_error(location
, e
, silent
) {
38 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
40 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
41 "\nFunction: " + location
+ "()" +
42 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
45 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
48 debug("<b>EXCEPTION: " + msg
+ "</b>");
55 function disableHotkeys() {
56 hotkeys_enabled
= false;
59 function enableHotkeys() {
60 hotkeys_enabled
= true;
63 function xmlhttp_ready(obj
) {
64 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
67 function open_article_callback() {
68 if (xmlhttp_rpc
.readyState
== 4) {
71 if (xmlhttp_rpc
.responseXML
) {
72 var link
= xmlhttp_rpc
.responseXML
.getElementsByTagName("link")[0];
73 var id
= xmlhttp_rpc
.responseXML
.getElementsByTagName("id")[0];
76 window
.open(link
.firstChild
.nodeValue
, "_blank");
79 id
= id
.firstChild
.nodeValue
;
80 if (!document
.getElementById("headlinesList")) {
81 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
88 exception_error("open_article_callback", e
);
93 function logout_callback() {
94 var container
= document
.getElementById('notify');
95 if (xmlhttp
.readyState
== 4) {
97 var date
= new Date();
98 var timestamp
= Math
.round(date
.getTime() / 1000);
99 window
.location
.href
= "tt-rss.php";
101 exception_error("logout_callback", e
);
106 function notify_callback() {
107 var container
= document
.getElementById('notify');
108 if (xmlhttp
.readyState
== 4) {
109 container
.innerHTML
=xmlhttp
.responseText
;
113 function rpc_notify_callback() {
114 var container
= document
.getElementById('notify');
115 if (xmlhttp_rpc
.readyState
== 4) {
116 container
.innerHTML
=xmlhttp_rpc
.responseText
;
120 function param_escape(arg
) {
121 if (typeof encodeURIComponent
!= 'undefined')
122 return encodeURIComponent(arg
);
127 function param_unescape(arg
) {
128 if (typeof decodeURIComponent
!= 'undefined')
129 return decodeURIComponent(arg
);
131 return unescape(arg
);
134 function delay(gap
) {
136 then
=new Date().getTime();
138 while((now
-then
)<gap
) {
139 now
=new Date().getTime();
143 var notify_hide_timerid
= false;
145 function hide_notify() {
146 var n
= document
.getElementById("notify");
148 n
.style
.display
= "none";
152 function notify_real(msg
, no_hide
, n_type
) {
154 var n
= document
.getElementById("notify");
155 var nb
= document
.getElementById("notify_body");
157 if (!n
|| !nb
) return;
159 if (notify_hide_timerid
) {
160 window
.clearTimeout(notify_hide_timerid
);
164 if (n
.style
.display
== "block") {
165 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
169 n
.style
.display
= "block";
181 if (typeof __
!= 'undefined') {
186 n
.className
= "notify";
187 } else if (n_type
== 2) {
188 n
.className
= "notifyProgress";
189 msg
= "<img src='images/indicator_white.gif'> " + msg
;
190 } else if (n_type
== 3) {
191 n
.className
= "notifyError";
192 msg
= "<img src='images/sign_excl.png'> " + msg
;
193 } else if (n_type
== 4) {
194 n
.className
= "notifyInfo";
195 msg
= "<img src='images/sign_info.png'> " + msg
;
198 // msg = "<img src='images/live_com_loading.gif'> " + msg;
203 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
207 function notify(msg
, no_hide
) {
208 notify_real(msg
, no_hide
, 1);
211 function notify_progress(msg
, no_hide
) {
212 notify_real(msg
, no_hide
, 2);
215 function notify_error(msg
, no_hide
) {
216 notify_real(msg
, no_hide
, 3);
220 function notify_info(msg
, no_hide
) {
221 notify_real(msg
, no_hide
, 4);
224 function printLockingError() {
225 notify_info("Please wait until operation finishes.");
228 function hotkey_handler(e
) {
233 var shift_key
= false;
236 shift_key
= e
.shiftKey
;
241 if (!hotkeys_enabled
) return;
244 keycode
= window
.event
.keyCode
;
249 if (keycode
== 82) { // r
250 return scheduleFeedUpdate(true);
253 if (keycode
== 83) { // s
254 return displayDlg("search", getActiveFeedId());
257 if (keycode
== 85) { // u
258 if (getActiveFeedId()) {
259 return viewfeed(getActiveFeedId(), "ForceUpdate");
263 if (keycode
== 65) { // a
264 return toggleDispRead();
267 var feedlist
= document
.getElementById('feedList');
269 if (keycode
== 74) { // j
270 var feed
= getActiveFeedId();
271 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
272 if (new_feed
) viewfeed(new_feed
, '');
275 if (keycode
== 75) { // k
276 var feed
= getActiveFeedId();
277 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
278 if (new_feed
) viewfeed(new_feed
, '');
281 if (keycode
== 78 || keycode
== 40) { // n, down
282 if (typeof moveToPost
!= 'undefined') {
283 return moveToPost('next');
287 if (keycode
== 80 || keycode
== 38) { // p, up
288 if (typeof moveToPost
!= 'undefined') {
289 return moveToPost('prev');
293 if (keycode
== 68 && shift_key
) { // d
294 if (!debug_mode_enabled
) {
295 document
.getElementById('debug_output').style
.display
= 'block';
296 debug('debug mode activated');
298 document
.getElementById('debug_output').style
.display
= 'none';
301 debug_mode_enabled
= !debug_mode_enabled
;
304 if (keycode
== 190 && shift_key
) { // >
308 if (keycode
== 188 && shift_key
) { // <
312 if (keycode
== 191 && shift_key
) { // ?
316 if (keycode
== 69 && shift_key
) { // e
317 return editFeedDlg(getActiveFeedId());
320 if (keycode
== 70 && shift_key
) { // f
321 if (getActiveFeedId()) {
322 return catchupCurrentFeed();
326 if (keycode
== 80 && shift_key
) { // p
327 if (getActiveFeedId()) {
328 return catchupPage();
332 if (keycode
== 86) { // v
333 if (getActiveArticleId()) {
334 openArticleInNewWindow(getActiveArticleId());
338 if (typeof localHotkeyHandler
!= 'undefined') {
340 return localHotkeyHandler(e
);
342 exception_error("hotkey_handler, local:", e
);
346 debug("KP=" + keycode
);
348 exception_error("hotkey_handler", e
);
352 function cleanSelectedList(element
) {
353 var content
= document
.getElementById(element
);
355 if (!document
.getElementById("feedCatHolder")) {
356 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
357 var child
= content
.childNodes
[i
];
359 child
.className
= child
.className
.replace("Selected", "");
365 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
366 var child
= content
.childNodes
[i
];
367 if (child
.id
== "feedCatHolder") {
369 var fcat
= child
.lastChild
;
370 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
371 var feed
= fcat
.childNodes
[j
];
372 feed
.className
= feed
.className
.replace("Selected", "");
380 function cleanSelected(element
) {
381 var content
= document
.getElementById(element
);
383 for (i
= 0; i
< content
.rows
.length
; i
++) {
384 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
388 function getVisibleUnreadHeadlines() {
389 var content
= document
.getElementById("headlinesList");
391 var rows
= new Array();
393 for (i
= 0; i
< content
.rows
.length
; i
++) {
394 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
395 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
402 function getVisibleHeadlineIds() {
404 var content
= document
.getElementById("headlinesList");
406 var rows
= new Array();
408 for (i
= 0; i
< content
.rows
.length
; i
++) {
409 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
410 if (row_id
.length
> 0) {
417 function getFirstVisibleHeadlineId() {
418 var rows
= getVisibleHeadlineIds();
422 function getLastVisibleHeadlineId() {
423 var rows
= getVisibleHeadlineIds();
424 return rows
[rows
.length
-1];
427 function markHeadline(id
) {
428 var row
= document
.getElementById("RROW-" + id
);
430 var is_active
= false;
432 if (row
.className
.match("Active")) {
435 row
.className
= row
.className
.replace("Selected", "");
436 row
.className
= row
.className
.replace("Active", "");
437 row
.className
= row
.className
.replace("Insensitive", "");
440 row
.className
= row
.className
= "Active";
443 var check
= document
.getElementById("RCHK-" + id
);
446 check
.checked
= true;
449 row
.className
= row
.className
+ "Selected";
454 function getFeedIds() {
455 var content
= document
.getElementById("feedsList");
457 var rows
= new Array();
459 for (i
= 0; i
< content
.rows
.length
; i
++) {
460 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
469 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
475 d
.setTime(d
.getTime() + (lifetime
* 1000));
478 debug("setCookie: " + name
+ " => " + value
+ ": " + d
);
480 int_setCookie(name
, value
, d
, path
, domain
, secure
);
484 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
485 document
.cookie
= name
+ "=" + escape(value
) +
486 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
487 ((path
) ? "; path=" + path
: "") +
488 ((domain
) ? "; domain=" + domain
: "") +
489 ((secure
) ? "; secure" : "");
492 function delCookie(name
, path
, domain
) {
493 if (getCookie(name
)) {
494 document
.cookie
= name
+ "=" +
495 ((path
) ? ";path=" + path
: "") +
496 ((domain
) ? ";domain=" + domain
: "" ) +
497 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
502 function getCookie(name
) {
504 var dc
= document
.cookie
;
505 var prefix
= name
+ "=";
506 var begin
= dc
.indexOf("; " + prefix
);
508 begin
= dc
.indexOf(prefix
);
509 if (begin
!= 0) return null;
514 var end
= document
.cookie
.indexOf(";", begin
);
518 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
521 function disableContainerChildren(id
, disable
, doc
) {
523 if (!doc
) doc
= document
;
525 var container
= doc
.getElementById(id
);
528 //alert("disableContainerChildren: element " + id + " not found");
532 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
533 var child
= container
.childNodes
[i
];
536 child
.disabled
= disable
;
542 if (child
.className
&& child
.className
.match("button")) {
543 child
.className
= "disabledButton";
546 if (child
.className
&& child
.className
.match("disabledButton")) {
547 child
.className
= "button";
554 function gotoPreferences() {
555 document
.location
.href
= "prefs.php";
558 function gotoMain() {
559 document
.location
.href
= "tt-rss.php";
562 function gotoExportOpml() {
563 document
.location
.href
= "opml.php?op=Export";
566 function getActiveFeedId() {
567 // return getCookie("ttrss_vf_actfeed");
569 debug("gAFID: " + active_feed_id
);
570 return active_feed_id
;
572 exception_error("getActiveFeedId", e
);
576 function activeFeedIsCat() {
577 return active_feed_is_cat
;
580 function setActiveFeedId(id
) {
581 // return setCookie("ttrss_vf_actfeed", id);
583 debug("sAFID(" + id
+ ")");
586 exception_error("setActiveFeedId", e
);
590 function parse_counters(reply
, scheduled_call
) {
595 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
596 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
597 reply
= reply
.firstChild
;
600 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
601 if (!reply
.childNodes
[l
] ||
602 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
603 // where did this come from?
607 var id
= reply
.childNodes
[l
].getAttribute("id");
608 var t
= reply
.childNodes
[l
].getAttribute("type");
609 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
610 var error
= reply
.childNodes
[l
].getAttribute("error");
611 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
612 var updated
= reply
.childNodes
[l
].getAttribute("updated");
614 if (id
== "global-unread") {
620 if (id
== "subscribed-feeds") {
625 if (t
== "category") {
626 var catctr
= document
.getElementById("FCATCTR-" + id
);
628 catctr
.innerHTML
= "(" + ctr
+ ")";
630 catctr
.className
= "catCtrHasUnread";
632 catctr
.className
= "catCtrNoUnread";
638 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
639 var feedu
= document
.getElementById("FEEDU-" + id
);
640 var feedr
= document
.getElementById("FEEDR-" + id
);
641 var feed_img
= document
.getElementById("FIMG-" + id
);
642 var feedlink
= document
.getElementById("FEEDL-" + id
);
643 var feedupd
= document
.getElementById("FLUPD-" + id
);
645 if (updated
&& feedlink
) {
647 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
649 feedlink
.title
= "Updated: " + updated
;
653 if (updated
&& feedupd
) {
655 feedupd
.innerHTML
= updated
+ " (Error)";
657 feedupd
.innerHTML
= updated
;
661 if (feedctr
&& feedu
&& feedr
) {
663 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
667 feedu
.innerHTML
= ctr
;
670 feedr
.className
= feedr
.className
.replace("feed", "error");
672 feedr
.className
= feedr
.className
.replace("error", "feed");
676 feedctr
.className
= "odd";
677 if (!feedr
.className
.match("Unread")) {
678 var is_selected
= feedr
.className
.match("Selected");
680 feedr
.className
= feedr
.className
.replace("Selected", "");
681 feedr
.className
= feedr
.className
.replace("Unread", "");
683 feedr
.className
= feedr
.className
+ "Unread";
686 feedr
.className
= feedr
.className
+ "Selected";
691 feedctr
.className
= "invisible";
692 feedr
.className
= feedr
.className
.replace("Unread", "");
697 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
699 var feeds_stored
= number_of_feeds
;
701 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
703 if (feeds_stored
!= feeds_found
) {
704 number_of_feeds
= feeds_found
;
706 if (feeds_stored
!= 0) {
707 debug("Subscribed feed number changed, refreshing feedlist");
708 setTimeout('updateFeedList(false, false)', 50);
713 exception_error("parse_counters", e
);
717 function parse_counters_reply(xmlhttp
, scheduled_call
) {
719 if (!xmlhttp
.responseXML
) {
720 notify_error("Backend did not return valid XML", true);
724 var reply
= xmlhttp
.responseXML
.firstChild
;
727 notify_error("Backend did not return expected XML object", true);
732 var error_code
= false;
733 var error_msg
= false;
735 if (reply
.firstChild
) {
736 error_code
= reply
.firstChild
.getAttribute("error-code");
737 error_msg
= reply
.firstChild
.getAttribute("error-msg");
741 error_code
= reply
.getAttribute("error-code");
742 error_msg
= reply
.getAttribute("error-msg");
745 if (error_code
&& error_code
!= 0) {
746 debug("refetch_callback: got error code " + error_code
);
747 return fatalError(error_code
, error_msg
);
750 var counters
= reply
.firstChild
;
752 parse_counters(counters
, scheduled_call
);
754 var runtime_info
= counters
.nextSibling
;
756 parse_runtime_info(runtime_info
);
758 if (getInitParam("feeds_sort_by_unread") == 1) {
762 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
766 function all_counters_callback() {
767 if (xmlhttp_rpc
.readyState
== 4) {
769 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
770 debug("[all_counters_callback] backend did not return valid XML");
774 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
776 var reply = xmlhttp_rpc.responseXML.firstChild;
778 var counters = reply.firstChild;
780 parse_counters(counters);
782 var runtime = counters.nextSibling;
785 parse_runtime_info(runtime);
788 if (getInitParam("feeds_sort_by_unread") == 1) {
792 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
794 debug("in all_counters_callback");
796 parse_counters_reply(xmlhttp_rpc
);
799 exception_error("all_counters_callback", e
);
804 function get_feed_entry_unread(doc
, elem
) {
806 var id
= elem
.id
.replace("FEEDR-", "");
813 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
819 function resort_category(doc
, node
) {
820 debug("resort_category: " + node
);
822 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
823 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
824 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
826 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
830 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
831 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
833 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
834 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
836 if (cur_val
> tmp_val
) {
837 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
838 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
839 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
840 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
849 function resort_feedlist() {
850 debug("resort_feedlist");
854 if (fd
.getElementById("feedCatHolder")) {
856 var feeds
= fd
.getElementById("feedList");
857 var child
= feeds
.firstChild
;
861 if (child
.id
== "feedCatHolder") {
862 resort_category(fd
, child
.firstChild
);
865 child
= child
.nextSibling
;
869 resort_category(fd
, fd
.getElementById("feedList"));
873 function update_all_counters(feed
) {
874 if (xmlhttp_ready(xmlhttp_rpc
)) {
875 var query
= "backend.php?op=rpc&subop=getAllCounters";
878 query
= query
+ "&aid=" + feed
;
881 if (tagsAreDisplayed()) {
882 query
= query
+ "&omode=lt";
884 query
= query
+ "&omode=flc";
887 debug("update_all_counters QUERY: " + query
);
889 var date
= new Date();
890 var timestamp
= Math
.round(date
.getTime() / 1000);
891 query
= query
+ "&ts=" + timestamp
893 xmlhttp_rpc
.open("GET", query
, true);
894 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
895 xmlhttp_rpc
.send(null);
899 function popupHelp(tid
) {
900 var w
= window
.open("backend.php?op=help&tid=" + tid
,
902 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
905 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
906 * * @author Sundar Dorai-Raj
907 * * Email: sdoraira@vt.edu
908 * * This program is free software; you can redistribute it and/or
909 * * modify it under the terms of the GNU General Public License
910 * * as published by the Free Software Foundation; either version 2
911 * * of the License, or (at your option) any later version,
912 * * provided that any use properly credits the author.
913 * * This program is distributed in the hope that it will be useful,
914 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
915 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
916 * * GNU General Public License for more details at http://www.gnu.org * * */
918 var numbers
=".0123456789";
919 function isNumeric(x
) {
920 // is x a String or a character?
922 // remove negative sign
924 for(j
=0;j
<x
.length
;j
++) {
925 // call isNumeric recursively for each character
926 number
=isNumeric(x
.substring(j
,j
+1));
927 if(!number
) return number
;
932 // if x is number return true
933 if(numbers
.indexOf(x
)>=0) return true;
939 function hideOrShowFeeds(doc
, hide
) {
941 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
945 var list
= fd
.getElementById("feedList");
947 if (fd
.getElementById("feedCatHolder")) {
949 var feeds
= fd
.getElementById("feedList");
950 var child
= feeds
.firstChild
;
954 if (child
.id
== "feedCatHolder") {
955 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
958 child
= child
.nextSibling
;
962 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
966 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
968 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
973 debug("hideOrShowFeeds: passed node is null, aborting");
977 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
978 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
979 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
981 if (node
.childNodes
[i
].style
!= undefined) {
983 var has_unread
= (node
.childNodes
[i
].className
!= "feed" &&
984 node
.childNodes
[i
].className
!= "tag");
986 // debug(node.childNodes[i].id + " --> " + has_unread);
988 if (hide
&& !has_unread
) {
989 node
.childNodes
[i
].style
.display
= "none";
993 node
.childNodes
[i
].style
.display
= "list-item";
997 node
.childNodes
[i
].style
.display
= "list-item";
1004 if (cat_unread
== 0) {
1005 if (cat_node
.style
== undefined) {
1006 debug("ERROR: supplied cat_node " + cat_node
+
1007 " has no styles. WTF?");
1011 cat_node
.style
.display
= "none";
1013 cat_node
.style
.display
= "list-item";
1017 cat_node
.style
.display
= "list-item";
1023 // debug("unread for category: " + cat_unread);
1026 function selectTableRow(r
, do_select
) {
1027 r
.className
= r
.className
.replace("Selected", "");
1030 r
.className
= r
.className
+ "Selected";
1034 function selectTableRowById(elem_id
, check_id
, do_select
) {
1038 var row
= document
.getElementById(elem_id
);
1041 selectTableRow(row
, do_select
);
1044 var check
= document
.getElementById(check_id
);
1047 check
.checked
= do_select
;
1050 exception_error("selectTableRowById", e
);
1054 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
1055 classcheck
, reset_others
) {
1057 var content
= document
.getElementById(content_id
);
1060 alert("[selectTableRows] Element " + content_id
+ " not found.");
1064 for (i
= 0; i
< content
.rows
.length
; i
++) {
1065 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
1067 if (content
.rows
[i
].id
.match(prefix
)) {
1068 selectTableRow(content
.rows
[i
], do_select
);
1070 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1071 var check
= document
.getElementById(check_prefix
+ row_id
);
1074 check
.checked
= do_select
;
1076 } else if (reset_others
) {
1077 selectTableRow(content
.rows
[i
], false);
1079 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1080 var check
= document
.getElementById(check_prefix
+ row_id
);
1083 check
.checked
= false;
1087 } else if (reset_others
) {
1088 selectTableRow(content
.rows
[i
], false);
1090 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1091 var check
= document
.getElementById(check_prefix
+ row_id
);
1094 check
.checked
= false;
1101 function getSelectedTableRowIds(content_id
, prefix
) {
1103 var content
= document
.getElementById(content_id
);
1106 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1110 var sel_rows
= new Array();
1112 for (i
= 0; i
< content
.rows
.length
; i
++) {
1113 if (content
.rows
[i
].id
.match(prefix
) &&
1114 content
.rows
[i
].className
.match("Selected")) {
1116 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1117 sel_rows
.push(row_id
);
1125 function toggleSelectRowById(sender
, id
) {
1126 var row
= document
.getElementById(id
);
1128 if (sender
.checked
) {
1129 if (!row
.className
.match("Selected")) {
1130 row
.className
= row
.className
+ "Selected";
1133 if (row
.className
.match("Selected")) {
1134 row
.className
= row
.className
.replace("Selected", "");
1139 function toggleSelectListRow(sender
) {
1140 var parent_row
= sender
.parentNode
;
1142 if (sender
.checked
) {
1143 if (!parent_row
.className
.match("Selected")) {
1144 parent_row
.className
= parent_row
.className
+ "Selected";
1147 if (parent_row
.className
.match("Selected")) {
1148 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1153 function tSR(sender
) {
1154 return toggleSelectRow(sender
);
1157 function toggleSelectRow(sender
) {
1158 var parent_row
= sender
.parentNode
.parentNode
;
1160 if (sender
.checked
) {
1161 if (!parent_row
.className
.match("Selected")) {
1162 parent_row
.className
= parent_row
.className
+ "Selected";
1165 if (parent_row
.className
.match("Selected")) {
1166 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1171 function openExternalUrl(url
) {
1172 var w
= window
.open(url
);
1175 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1177 if (direction
== "next") {
1178 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1179 var child
= list
.childNodes
[i
];
1180 if (child
.id
&& child
.id
== "feedCatHolder") {
1181 if (child
.lastChild
) {
1182 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
, unread_only
);
1185 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
1186 return child
.id
.replace('FEEDR-', '');
1191 // FIXME select last feed doesn't work when only unread feeds are visible
1193 if (direction
== "prev") {
1194 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
1195 var child
= list
.childNodes
[i
];
1196 if (child
.id
== "feedCatHolder" && child
.className
!= "invisible") {
1197 if (child
.firstChild
) {
1198 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
1201 } else if (child
.id
.match("FEEDR-")) {
1203 if (getInitParam("hide_read_feeds") == 1) {
1204 if (child
.className
!= "feed") {
1205 // alert(child.className);
1206 return child
.id
.replace('FEEDR-', '');
1209 return child
.id
.replace('FEEDR-', '');
1216 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + id
);
1218 if (getInitParam("hide_read_feeds") == 1) {
1222 if (direction
== "next") {
1228 if (e
.nextSibling
) {
1232 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1234 var this_cat
= e
.parentNode
.parentNode
;
1238 if (this_cat
&& this_cat
.nextSibling
) {
1239 while (!e
&& this_cat
.nextSibling
) {
1240 this_cat
= this_cat
.nextSibling
;
1241 if (this_cat
.id
== "feedCatHolder") {
1242 e
= this_cat
.firstChild
.firstChild
;
1252 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1253 e
.className
.match("feed"))) {
1254 if (e
.parentNode
.parentNode
&& e
.parentNode
.parentNode
.className
1256 return e
.id
.replace("FEEDR-", "");
1262 } else if (direction
== "prev") {
1268 if (e
.previousSibling
) {
1270 e
= e
.previousSibling
;
1272 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1274 var this_cat
= e
.parentNode
.parentNode
;
1278 if (this_cat
&& this_cat
.previousSibling
) {
1279 while (!e
&& this_cat
.previousSibling
) {
1280 this_cat
= this_cat
.previousSibling
;
1281 if (this_cat
.id
== "feedCatHolder") {
1282 e
= this_cat
.firstChild
.lastChild
;
1292 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1293 e
.className
.match("feed"))) {
1294 if (e
.parentNode
.parentNode
&& e
.parentNode
.parentNode
.className
1296 return e
.id
.replace("FEEDR-", "");
1305 function showBlockElement(id
, h_id
) {
1306 var elem
= document
.getElementById(id
);
1309 elem
.style
.display
= "block";
1312 elem
= document
.getElementById(h_id
);
1314 elem
.style
.display
= "none";
1318 alert("[showBlockElement] can't find element with id " + id
);
1322 function hideParentElement(e
) {
1323 e
.parentNode
.style
.display
= "none";
1326 function dropboxSelect(e
, v
) {
1327 for (i
= 0; i
< e
.length
; i
++) {
1328 if (e
[i
].value
== v
) {
1329 e
.selectedIndex
= i
;
1335 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1336 // bugfixed just a little bit :-)
1337 function getURLParam(strParamName
){
1339 var strHref
= window
.location
.href
;
1341 if (strHref
.indexOf("#") == strHref
.length
-1) {
1342 strHref
= strHref
.substring(0, strHref
.length
-1);
1345 if ( strHref
.indexOf("?") > -1 ){
1346 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1347 var aQueryString
= strQueryString
.split("&");
1348 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1349 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1350 var aParam
= aQueryString
[iParam
].split("=");
1351 strReturn
= aParam
[1];
1359 function leading_zero(p
) {
1361 if (s
.length
== 1) s
= "0" + s
;
1365 function closeInfoBox(cleanup
) {
1367 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1368 var overlay
= document
.getElementById("dialog_overlay");
1370 overlay
.style
.display
= "none";
1374 var box
= document
.getElementById('infoBox');
1375 var shadow
= document
.getElementById('infoBoxShadow');
1378 shadow
.style
.display
= "none";
1380 box
.style
.display
= "none";
1383 if (cleanup
) box
.innerHTML
= " ";
1391 function displayDlg(id
, param
) {
1393 if (!xmlhttp_ready(xmlhttp
)) {
1394 printLockingError();
1398 notify_progress("Loading, please wait...", true);
1400 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1401 param_escape(id
) + "¶m=" + param_escape(param
), true);
1402 xmlhttp
.onreadystatechange
=infobox_callback
;
1410 function infobox_submit_callback() {
1411 if (xmlhttp
.readyState
== 4) {
1415 // called from prefs, reload tab
1417 selectTab(active_tab
, false);
1421 if (xmlhttp
.responseText
) {
1422 notify_info(xmlhttp
.responseText
);
1428 function infobox_callback() {
1429 if (xmlhttp
.readyState
== 4) {
1433 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1434 var overlay
= document
.getElementById("dialog_overlay");
1436 overlay
.style
.display
= "block";
1440 var box
= document
.getElementById('infoBox');
1441 var shadow
= document
.getElementById('infoBoxShadow');
1443 box
.innerHTML
=xmlhttp
.responseText
;
1445 shadow
.style
.display
= "block";
1447 box
.style
.display
= "block";
1452 exception_error("infobox_callback", e
);
1457 function helpbox_callback() {
1458 if (xmlhttp
.readyState
== 4) {
1459 var box
= document
.getElementById('helpBox');
1460 var shadow
= document
.getElementById('helpBoxShadow');
1462 box
.innerHTML
=xmlhttp
.responseText
;
1464 shadow
.style
.display
= "block";
1466 box
.style
.display
= "block";
1473 function addFilter() {
1475 if (!xmlhttp_ready(xmlhttp
)) {
1476 printLockingError();
1480 var form
= document
.forms
['filter_add_form'];
1481 var reg_exp
= form
.reg_exp
.value
;
1483 if (reg_exp
== "") {
1484 alert("Can't add filter: nothing to match on.");
1488 var query
= Form
.serialize("filter_add_form");
1490 xmlhttp
.open("GET", "backend.php?" + query
, true);
1491 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1497 function toggleSubmitNotEmpty(e
, submit_id
) {
1499 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1501 exception_error("toggleSubmitNotEmpty", e
);
1505 function isValidURL(s
) {
1506 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1509 function qaddFeed() {
1511 if (!xmlhttp_ready(xmlhttp
)) {
1512 printLockingError();
1516 var form
= document
.forms
['feed_add_form'];
1517 var feed_url
= form
.feed_url
.value
;
1519 if (feed_url
== "") {
1520 alert("Can't subscribe: no feed URL given.");
1524 notify_progress(__("Subscribing to feed..."), true);
1528 var feeds_doc
= document
;
1530 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1532 var query
= Form
.serialize("feed_add_form");
1534 debug("subscribe q: " + query
);
1536 /* xmlhttp.open("GET", "backend.php?" + query, true);
1537 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1538 xmlhttp.send(null); */
1540 xmlhttp
.open("POST", "backend.php", true);
1541 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1542 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1543 xmlhttp
.send(query
);
1548 function filterCR(e
, f
)
1553 key
= window
.event
.keyCode
; //IE
1555 key
= e
.which
; //firefox
1558 if (typeof f
!= 'undefined') {
1569 function getMainContext() {
1573 function getFeedsContext() {
1577 function getContentContext() {
1581 function getHeadlinesContext() {
1585 var debug_last_class
= "even";
1587 function debug(msg
) {
1589 if (debug_last_class
== "even") {
1590 debug_last_class
= "odd";
1592 debug_last_class
= "even";
1595 var c
= document
.getElementById('debug_output');
1596 if (c
&& c
.style
.display
== "block") {
1597 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1598 c
.removeChild(c
.lastChild
);
1602 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1603 ":" + leading_zero(d
.getSeconds());
1604 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1605 msg
+ "</li>" + c
.innerHTML
;
1609 function getInitParam(key
) {
1610 return init_params
[key
];
1613 function storeInitParam(key
, value
) {
1614 debug("<b>storeInitParam is OBSOLETE: " + key
+ " => " + value
+ "</b>");
1615 init_params
[key
] = value
;
1618 function fatalError(code
, message
) {
1622 window
.location
.href
= "tt-rss.php";
1623 } else if (code
== 5) {
1624 window
.location
.href
= "update.php";
1626 var fe
= document
.getElementById("fatal_error");
1627 var fc
= document
.getElementById("fatal_error_msg");
1629 if (message
== "") message
= "Unknown error";
1631 fc
.innerHTML
= "<img src='images/sign_excl.png'> " + message
+ " (Code " + code
+ ")";
1633 fe
.style
.display
= "block";
1637 exception_error("fatalError", e
);
1641 function getFeedName(id
, is_cat
) {
1642 var d
= getFeedsContext().document
;
1647 e
= d
.getElementById("FCATN-" + id
);
1649 e
= d
.getElementById("FEEDN-" + id
);
1652 return e
.innerHTML
.stripTags();
1658 function viewContentUrl(url
) {
1659 getContentContext().location
= url
;
1662 function filterDlgCheckAction(sender
) {
1666 var action
= sender
[sender
.selectedIndex
].value
;
1668 var form
= document
.forms
["filter_add_form"];
1671 form
= document
.forms
["filter_edit_form"];
1675 debug("filterDlgCheckAction: can't find form!");
1679 var action_param
= form
.action_param
;
1681 if (!action_param
) {
1682 debug("filterDlgCheckAction: can't find action param!");
1686 // if selected action supports parameters, enable params field
1688 action_param
.disabled
= false;
1690 action_param
.disabled
= true;
1694 exception_error(e
, "filterDlgCheckAction");
1699 function explainError(code
) {
1700 return displayDlg("explainError", code
);
1703 function logoutUser() {
1705 if (xmlhttp_ready(xmlhttp_rpc
)) {
1707 notify_progress("Logging out, please wait...", true);
1709 xmlhttp_rpc
.open("GET", "backend.php?op=rpc&subop=logout", true);
1710 xmlhttp_rpc
.onreadystatechange
=logout_callback
;
1711 xmlhttp_rpc
.send(null);
1713 printLockingError();
1716 exception_error("logoutUser", e
);
1720 // this only searches loaded headlines list, not in CDM
1721 function getRelativePostIds(id
) {
1723 debug("getRelativePostIds: " + id
);
1725 var ids
= new Array();
1726 var container
= document
.getElementById("headlinesList");
1729 var rows
= container
.rows
;
1731 for (var i
= 0; i
< rows
.length
; i
++) {
1732 var r_id
= rows
[i
].id
.replace("RROW-", "");
1735 if (i
> 0) ids
.push(rows
[i
-1].id
.replace("RROW-", ""));
1736 if (i
> 1) ids
.push(rows
[i
-2].id
.replace("RROW-", ""));
1737 if (i
> 2) ids
.push(rows
[i
-3].id
.replace("RROW-", ""));
1739 if (i
< rows
.length
-1) ids
.push(rows
[i
+1].id
.replace("RROW-", ""));
1740 if (i
< rows
.length
-2) ids
.push(rows
[i
+2].id
.replace("RROW-", ""));
1741 if (i
< rows
.length
-3) ids
.push(rows
[i
+3].id
.replace("RROW-", ""));
1751 function openArticleInNewWindow(id
) {
1754 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1755 printLockingError();
1759 debug("openArticleInNewWindow: " + id
);
1761 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1765 xmlhttp_rpc
.open("GET", query
, true);
1766 xmlhttp_rpc
.onreadystatechange
=open_article_callback
;
1767 xmlhttp_rpc
.send(null);
1770 exception_error("openArticleInNewWindow", e
);