]>
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 /* 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 (keycode
== 84) { // t
340 var id
= getActiveArticleId();
344 var cb
= document
.getElementById("RCHK-" + id
);
347 cb
.checked
= !cb
.checked
;
348 toggleSelectRowById(cb
, "RROW-" + id
);
353 if (keycode
== 67) { // c
354 var id
= getActiveArticleId();
361 if (typeof localHotkeyHandler
!= 'undefined') {
363 return localHotkeyHandler(e
);
365 exception_error("hotkey_handler, local:", e
);
369 debug("KP=" + keycode
);
371 exception_error("hotkey_handler", e
);
375 function cleanSelectedList(element
) {
376 var content
= document
.getElementById(element
);
378 if (!document
.getElementById("feedCatHolder")) {
379 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
380 var child
= content
.childNodes
[i
];
382 child
.className
= child
.className
.replace("Selected", "");
388 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
389 var child
= content
.childNodes
[i
];
390 if (child
.id
== "feedCatHolder") {
392 var fcat
= child
.lastChild
;
393 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
394 var feed
= fcat
.childNodes
[j
];
395 feed
.className
= feed
.className
.replace("Selected", "");
403 function cleanSelected(element
) {
404 var content
= document
.getElementById(element
);
406 for (i
= 0; i
< content
.rows
.length
; i
++) {
407 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
411 function getVisibleUnreadHeadlines() {
412 var content
= document
.getElementById("headlinesList");
414 var rows
= new Array();
416 for (i
= 0; i
< content
.rows
.length
; i
++) {
417 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
418 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
425 function getVisibleHeadlineIds() {
427 var content
= document
.getElementById("headlinesList");
429 var rows
= new Array();
431 for (i
= 0; i
< content
.rows
.length
; i
++) {
432 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
433 if (row_id
.length
> 0) {
440 function getFirstVisibleHeadlineId() {
441 var rows
= getVisibleHeadlineIds();
445 function getLastVisibleHeadlineId() {
446 var rows
= getVisibleHeadlineIds();
447 return rows
[rows
.length
-1];
450 function markHeadline(id
) {
451 var row
= document
.getElementById("RROW-" + id
);
453 var is_active
= false;
455 if (row
.className
.match("Active")) {
458 row
.className
= row
.className
.replace("Selected", "");
459 row
.className
= row
.className
.replace("Active", "");
460 row
.className
= row
.className
.replace("Insensitive", "");
463 row
.className
= row
.className
= "Active";
466 var check
= document
.getElementById("RCHK-" + id
);
469 check
.checked
= true;
472 row
.className
= row
.className
+ "Selected";
477 function getFeedIds() {
478 var content
= document
.getElementById("feedsList");
480 var rows
= new Array();
482 for (i
= 0; i
< content
.rows
.length
; i
++) {
483 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
492 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
498 d
.setTime(d
.getTime() + (lifetime
* 1000));
501 debug("setCookie: " + name
+ " => " + value
+ ": " + d
);
503 int_setCookie(name
, value
, d
, path
, domain
, secure
);
507 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
508 document
.cookie
= name
+ "=" + escape(value
) +
509 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
510 ((path
) ? "; path=" + path
: "") +
511 ((domain
) ? "; domain=" + domain
: "") +
512 ((secure
) ? "; secure" : "");
515 function delCookie(name
, path
, domain
) {
516 if (getCookie(name
)) {
517 document
.cookie
= name
+ "=" +
518 ((path
) ? ";path=" + path
: "") +
519 ((domain
) ? ";domain=" + domain
: "" ) +
520 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
525 function getCookie(name
) {
527 var dc
= document
.cookie
;
528 var prefix
= name
+ "=";
529 var begin
= dc
.indexOf("; " + prefix
);
531 begin
= dc
.indexOf(prefix
);
532 if (begin
!= 0) return null;
537 var end
= document
.cookie
.indexOf(";", begin
);
541 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
544 function disableContainerChildren(id
, disable
, doc
) {
546 if (!doc
) doc
= document
;
548 var container
= doc
.getElementById(id
);
551 //alert("disableContainerChildren: element " + id + " not found");
555 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
556 var child
= container
.childNodes
[i
];
559 child
.disabled
= disable
;
565 if (child
.className
&& child
.className
.match("button")) {
566 child
.className
= "disabledButton";
569 if (child
.className
&& child
.className
.match("disabledButton")) {
570 child
.className
= "button";
577 function gotoPreferences() {
578 document
.location
.href
= "prefs.php";
581 function gotoMain() {
582 document
.location
.href
= "tt-rss.php";
585 function gotoExportOpml() {
586 document
.location
.href
= "opml.php?op=Export";
589 function getActiveFeedId() {
590 // return getCookie("ttrss_vf_actfeed");
592 debug("gAFID: " + active_feed_id
);
593 return active_feed_id
;
595 exception_error("getActiveFeedId", e
);
599 function activeFeedIsCat() {
600 return active_feed_is_cat
;
603 function setActiveFeedId(id
) {
604 // return setCookie("ttrss_vf_actfeed", id);
606 debug("sAFID(" + id
+ ")");
609 exception_error("setActiveFeedId", e
);
613 function parse_counters(reply
, scheduled_call
) {
618 var elems
= reply
.getElementsByTagName("counter");
620 for (var l
= 0; l
< elems
.length
; l
++) {
622 var id
= elems
[l
].getAttribute("id");
623 var t
= elems
[l
].getAttribute("type");
624 var ctr
= elems
[l
].getAttribute("counter");
625 var error
= elems
[l
].getAttribute("error");
626 var has_img
= elems
[l
].getAttribute("hi");
627 var updated
= elems
[l
].getAttribute("updated");
629 if (id
== "global-unread") {
635 if (id
== "subscribed-feeds") {
640 if (t
== "category") {
641 var catctr
= document
.getElementById("FCATCTR-" + id
);
643 catctr
.innerHTML
= "(" + ctr
+ ")";
645 catctr
.className
= "catCtrHasUnread";
647 catctr
.className
= "catCtrNoUnread";
653 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
654 var feedu
= document
.getElementById("FEEDU-" + id
);
655 var feedr
= document
.getElementById("FEEDR-" + id
);
656 var feed_img
= document
.getElementById("FIMG-" + id
);
657 var feedlink
= document
.getElementById("FEEDL-" + id
);
658 var feedupd
= document
.getElementById("FLUPD-" + id
);
660 if (updated
&& feedlink
) {
662 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
664 feedlink
.title
= "Updated: " + updated
;
668 if (updated
&& feedupd
) {
670 feedupd
.innerHTML
= updated
+ " (Error)";
672 feedupd
.innerHTML
= updated
;
676 if (has_img
&& feed_img
&& !is_msie()) {
677 if (!feed_img
.src
.match(id
+ ".ico")) {
678 feed_img
.src
= getInitParam("icons_location") + "/" + id
+ ".ico";
682 if (feedctr
&& feedu
&& feedr
) {
684 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
688 var row_needs_hl
= (ctr
> 0 && ctr
> parseInt(feedu
.innerHTML
));
690 feedu
.innerHTML
= ctr
;
693 feedr
.className
= feedr
.className
.replace("feed", "error");
695 feedr
.className
= feedr
.className
.replace("error", "feed");
699 feedctr
.className
= "odd";
700 if (!feedr
.className
.match("Unread")) {
701 var is_selected
= feedr
.className
.match("Selected");
703 feedr
.className
= feedr
.className
.replace("Selected", "");
704 feedr
.className
= feedr
.className
.replace("Unread", "");
706 feedr
.className
= feedr
.className
+ "Unread";
709 feedr
.className
= feedr
.className
+ "Selected";
715 new Effect
.Highlight(feedr
, {duration
: 1, startcolor
: "#fff7d5"});
718 feedctr
.className
= "invisible";
719 feedr
.className
= feedr
.className
.replace("Unread", "");
724 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
726 var feeds_stored
= number_of_feeds
;
728 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
730 if (feeds_stored
!= feeds_found
) {
731 number_of_feeds
= feeds_found
;
733 if (feeds_stored
!= 0 && feeds_found
!= 0) {
734 debug("Subscribed feed number changed, refreshing feedlist");
735 setTimeout('updateFeedList(false, false)', 50);
740 exception_error("parse_counters", e
);
744 function parse_counters_reply(xmlhttp
, scheduled_call
) {
746 if (!xmlhttp
.responseXML
) {
747 notify_error("Backend did not return valid XML", true);
751 var reply
= xmlhttp
.responseXML
.firstChild
;
754 notify_error("Backend did not return expected XML object", true);
759 var error_code
= false;
760 var error_msg
= false;
762 if (reply
.firstChild
) {
763 error_code
= reply
.firstChild
.getAttribute("error-code");
764 error_msg
= reply
.firstChild
.getAttribute("error-msg");
768 error_code
= reply
.getAttribute("error-code");
769 error_msg
= reply
.getAttribute("error-msg");
772 if (error_code
&& error_code
!= 0) {
773 debug("refetch_callback: got error code " + error_code
);
774 return fatalError(error_code
, error_msg
);
777 var counters
= reply
.getElementsByTagName("counters")[0];
779 parse_counters(counters
, scheduled_call
);
781 var runtime_info
= reply
.getElementsByTagName("runtime-info")[0];
783 parse_runtime_info(runtime_info
);
785 if (getInitParam("feeds_sort_by_unread") == 1) {
789 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
793 function all_counters_callback() {
794 if (xmlhttp_rpc
.readyState
== 4) {
796 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
797 debug("[all_counters_callback] backend did not return valid XML");
801 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
803 var reply = xmlhttp_rpc.responseXML.firstChild;
805 var counters = reply.firstChild;
807 parse_counters(counters);
809 var runtime = counters.nextSibling;
812 parse_runtime_info(runtime);
815 if (getInitParam("feeds_sort_by_unread") == 1) {
819 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
821 debug("in all_counters_callback");
823 parse_counters_reply(xmlhttp_rpc
);
826 exception_error("all_counters_callback", e
);
831 function get_feed_entry_unread(doc
, elem
) {
833 var id
= elem
.id
.replace("FEEDR-", "");
840 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
846 function resort_category(doc
, node
) {
847 debug("resort_category: " + node
);
849 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
850 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
851 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
853 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
857 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
858 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
860 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
861 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
863 if (cur_val
> tmp_val
) {
864 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
865 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
866 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
867 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
876 function resort_feedlist() {
877 debug("resort_feedlist");
881 if (fd
.getElementById("feedCatHolder")) {
883 var feeds
= fd
.getElementById("feedList");
884 var child
= feeds
.firstChild
;
888 if (child
.id
== "feedCatHolder") {
889 resort_category(fd
, child
.firstChild
);
892 child
= child
.nextSibling
;
896 resort_category(fd
, fd
.getElementById("feedList"));
900 function update_all_counters(feed
) {
901 if (xmlhttp_ready(xmlhttp_rpc
)) {
902 var query
= "backend.php?op=rpc&subop=getAllCounters";
905 query
= query
+ "&aid=" + feed
;
908 if (tagsAreDisplayed()) {
909 query
= query
+ "&omode=lt";
911 query
= query
+ "&omode=flc";
914 debug("update_all_counters QUERY: " + query
);
916 var date
= new Date();
917 var timestamp
= Math
.round(date
.getTime() / 1000);
918 query
= query
+ "&ts=" + timestamp
920 xmlhttp_rpc
.open("GET", query
, true);
921 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
922 xmlhttp_rpc
.send(null);
926 function popupHelp(tid
) {
927 var w
= window
.open("backend.php?op=help&tid=" + tid
,
929 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
932 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
933 * * @author Sundar Dorai-Raj
934 * * Email: sdoraira@vt.edu
935 * * This program is free software; you can redistribute it and/or
936 * * modify it under the terms of the GNU General Public License
937 * * as published by the Free Software Foundation; either version 2
938 * * of the License, or (at your option) any later version,
939 * * provided that any use properly credits the author.
940 * * This program is distributed in the hope that it will be useful,
941 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
942 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
943 * * GNU General Public License for more details at http://www.gnu.org * * */
945 var numbers
=".0123456789";
946 function isNumeric(x
) {
947 // is x a String or a character?
949 // remove negative sign
951 for(j
=0;j
<x
.length
;j
++) {
952 // call isNumeric recursively for each character
953 number
=isNumeric(x
.substring(j
,j
+1));
954 if(!number
) return number
;
959 // if x is number return true
960 if(numbers
.indexOf(x
)>=0) return true;
966 function hideOrShowFeeds(doc
, hide
) {
968 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
972 var list
= fd
.getElementById("feedList");
974 if (fd
.getElementById("feedCatHolder")) {
976 var feeds
= fd
.getElementById("feedList");
977 var child
= feeds
.firstChild
;
981 if (child
.id
== "feedCatHolder") {
982 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
985 child
= child
.nextSibling
;
989 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
993 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
995 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
1000 debug("hideOrShowFeeds: passed node is null, aborting");
1004 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
1005 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
1006 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
1008 if (node
.childNodes
[i
].style
!= undefined) {
1010 var has_unread
= (node
.childNodes
[i
].className
!= "feed" &&
1011 node
.childNodes
[i
].className
!= "label" &&
1012 node
.childNodes
[i
].className
!= "virt" &&
1013 node
.childNodes
[i
].className
!= "tag");
1015 // debug(node.childNodes[i].id + " --> " + has_unread);
1017 if (hide
&& !has_unread
) {
1018 //node.childNodes[i].style.display = "none";
1019 Effect
.Fade(node
.childNodes
[i
], {duration
: 0.3});
1023 node
.childNodes
[i
].style
.display
= "list-item";
1024 //Effect.Appear(node.childNodes[i], {duration : 0.3});
1028 node
.childNodes
[i
].style
.display
= "list-item";
1030 //Effect.Appear(node.childNodes[i], {duration : 0.3});
1031 //Effect.Highlight(node.childNodes[i]);
1037 if (cat_unread
== 0) {
1038 if (cat_node
.style
== undefined) {
1039 debug("ERROR: supplied cat_node " + cat_node
+
1040 " has no styles. WTF?");
1044 //cat_node.style.display = "none";
1045 Effect
.Fade(cat_node
, {duration
: 0.3});
1047 cat_node
.style
.display
= "list-item";
1051 cat_node
.style
.display
= "list-item";
1057 // debug("unread for category: " + cat_unread);
1060 function selectTableRow(r
, do_select
) {
1061 r
.className
= r
.className
.replace("Selected", "");
1064 r
.className
= r
.className
+ "Selected";
1068 function selectTableRowById(elem_id
, check_id
, do_select
) {
1072 var row
= document
.getElementById(elem_id
);
1075 selectTableRow(row
, do_select
);
1078 var check
= document
.getElementById(check_id
);
1081 check
.checked
= do_select
;
1084 exception_error("selectTableRowById", e
);
1088 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
1089 classcheck
, reset_others
) {
1091 var content
= document
.getElementById(content_id
);
1094 alert("[selectTableRows] Element " + content_id
+ " not found.");
1098 for (i
= 0; i
< content
.rows
.length
; i
++) {
1099 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
1101 if (content
.rows
[i
].id
.match(prefix
)) {
1102 selectTableRow(content
.rows
[i
], do_select
);
1104 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1105 var check
= document
.getElementById(check_prefix
+ row_id
);
1108 check
.checked
= do_select
;
1110 } else if (reset_others
) {
1111 selectTableRow(content
.rows
[i
], false);
1113 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1114 var check
= document
.getElementById(check_prefix
+ row_id
);
1117 check
.checked
= false;
1121 } else if (reset_others
) {
1122 selectTableRow(content
.rows
[i
], false);
1124 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1125 var check
= document
.getElementById(check_prefix
+ row_id
);
1128 check
.checked
= false;
1135 function getSelectedTableRowIds(content_id
, prefix
) {
1137 var content
= document
.getElementById(content_id
);
1140 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1144 var sel_rows
= new Array();
1146 for (i
= 0; i
< content
.rows
.length
; i
++) {
1147 if (content
.rows
[i
].id
.match(prefix
) &&
1148 content
.rows
[i
].className
.match("Selected")) {
1150 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1151 sel_rows
.push(row_id
);
1159 function toggleSelectRowById(sender
, id
) {
1160 var row
= document
.getElementById(id
);
1162 if (sender
.checked
) {
1163 if (!row
.className
.match("Selected")) {
1164 row
.className
= row
.className
+ "Selected";
1167 if (row
.className
.match("Selected")) {
1168 row
.className
= row
.className
.replace("Selected", "");
1173 function toggleSelectListRow(sender
) {
1174 var parent_row
= sender
.parentNode
;
1176 if (sender
.checked
) {
1177 if (!parent_row
.className
.match("Selected")) {
1178 parent_row
.className
= parent_row
.className
+ "Selected";
1181 if (parent_row
.className
.match("Selected")) {
1182 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1187 function tSR(sender
) {
1188 return toggleSelectRow(sender
);
1191 function toggleSelectRow(sender
) {
1192 var parent_row
= sender
.parentNode
.parentNode
;
1194 if (sender
.checked
) {
1195 if (!parent_row
.className
.match("Selected")) {
1196 parent_row
.className
= parent_row
.className
+ "Selected";
1199 if (parent_row
.className
.match("Selected")) {
1200 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1205 function openExternalUrl(url
) {
1206 var w
= window
.open(url
);
1209 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1210 var rows
= list
.getElementsByTagName("LI");
1211 var feeds
= new Array();
1213 for (var i
= 0; i
< rows
.length
; i
++) {
1214 if (rows
[i
].id
.match("FEEDR-")) {
1216 if (rows
[i
].id
== "FEEDR-" + id
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1219 (rows
[i
].className
.match("Unread") || rows
[i
].id
== "FEEDR-" + id
)) {
1220 feeds
.push(rows
[i
].id
.replace("FEEDR-", ""));
1227 if (direction
== "next") {
1228 return feeds
.shift();
1233 if (direction
== "next") {
1234 var idx
= feeds
.indexOf(id
);
1235 if (idx
!= -1 && idx
< feeds
.length
) {
1236 return feeds
[idx
+1];
1238 return getRelativeFeedId(list
, false, direction
, unread_only
);
1241 var idx
= feeds
.indexOf(id
);
1243 return feeds
[idx
-1];
1245 return getRelativeFeedId(list
, false, direction
, unread_only
);
1252 if (direction == "next") {
1253 for (i = 0; i < list.childNodes.length; i++) {
1254 var child = list.childNodes[i];
1255 if (child.id && child.id == "feedCatHolder") {
1256 if (child.lastChild) {
1257 var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only);
1260 } else if (child.id && child.id.match("FEEDR-")) {
1261 return child.id.replace('FEEDR-', '');
1266 // FIXME select last feed doesn't work when only unread feeds are visible
1268 if (direction == "prev") {
1269 for (i = list.childNodes.length-1; i >= 0; i--) {
1270 var child = list.childNodes[i];
1271 if (child.id == "feedCatHolder" && Element.visible(child)) {
1272 if (child.firstChild) {
1273 var cr = getRelativeFeedId(child.firstChild, id, direction);
1276 } else if (child.id.match("FEEDR-")) {
1278 if (getInitParam("hide_read_feeds") == 1) {
1279 if (child.className != "feed") {
1280 // alert(child.className);
1281 return child.id.replace('FEEDR-', '');
1284 return child.id.replace('FEEDR-', '');
1291 var feed = list.ownerDocument.getElementById("FEEDR-" + id);
1293 if (getInitParam("hide_read_feeds") == 1) {
1297 if (direction == "next") {
1303 if (e.nextSibling) {
1307 } else if (e.parentNode.parentNode.nextSibling) {
1309 var this_cat = e.parentNode.parentNode;
1313 if (this_cat && this_cat.nextSibling) {
1314 while (!e && this_cat.nextSibling) {
1315 this_cat = this_cat.nextSibling;
1316 if (this_cat.id == "feedCatHolder") {
1317 e = this_cat.firstChild.firstChild;
1327 if (!unread_only || (unread_only && e.className != "feed" &&
1328 e.className.match("feed"))) {
1329 if (e.parentNode.parentNode &&
1330 Element.visible(e.parentNode.parentNode)) {
1331 return e.id.replace("FEEDR-", "");
1337 } else if (direction == "prev") {
1343 if (e.previousSibling) {
1345 e = e.previousSibling;
1347 } else if (e.parentNode.parentNode.previousSibling) {
1349 var this_cat = e.parentNode.parentNode;
1353 if (this_cat && this_cat.previousSibling) {
1354 while (!e && this_cat.previousSibling) {
1355 this_cat = this_cat.previousSibling;
1356 if (this_cat.id == "feedCatHolder") {
1357 e = this_cat.firstChild.lastChild;
1367 if (!unread_only || (unread_only && e.className != "feed" &&
1368 e.className.match("feed"))) {
1369 if (e.parentNode.parentNode &&
1370 Element.visible(e.parentNode.parentNode)) {
1371 return e.id.replace("FEEDR-", "");
1380 function showBlockElement(id
, h_id
) {
1381 var elem
= document
.getElementById(id
);
1384 elem
.style
.display
= "block";
1387 elem
= document
.getElementById(h_id
);
1389 elem
.style
.display
= "none";
1393 alert("[showBlockElement] can't find element with id " + id
);
1397 function appearBlockElement_afh(effect
) {
1401 function checkboxToggleElement(elem
, id
) {
1403 Effect
.SlideDown(id
, {duration
: 0.5});
1405 Effect
.SlideUp(id
, {duration
: 0.5});
1409 function appearBlockElement(id
, h_id
) {
1413 Effect
.SlideDown(id
, {duration
: 1.0, afterFinish
: appearBlockElement_afh
});
1415 exception_error("appearBlockElement", e
);
1421 function hideParentElement(e
) {
1422 e
.parentNode
.style
.display
= "none";
1425 function dropboxSelect(e
, v
) {
1426 for (i
= 0; i
< e
.length
; i
++) {
1427 if (e
[i
].value
== v
) {
1428 e
.selectedIndex
= i
;
1434 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1435 // bugfixed just a little bit :-)
1436 function getURLParam(strParamName
){
1438 var strHref
= window
.location
.href
;
1440 if (strHref
.indexOf("#") == strHref
.length
-1) {
1441 strHref
= strHref
.substring(0, strHref
.length
-1);
1444 if ( strHref
.indexOf("?") > -1 ){
1445 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1446 var aQueryString
= strQueryString
.split("&");
1447 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1448 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1449 var aParam
= aQueryString
[iParam
].split("=");
1450 strReturn
= aParam
[1];
1458 function leading_zero(p
) {
1460 if (s
.length
== 1) s
= "0" + s
;
1464 function closeInfoBox(cleanup
) {
1466 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1467 var overlay
= document
.getElementById("dialog_overlay");
1469 overlay
.style
.display
= "none";
1473 var box
= document
.getElementById('infoBox');
1474 var shadow
= document
.getElementById('infoBoxShadow');
1477 shadow
.style
.display
= "none";
1479 box
.style
.display
= "none";
1482 if (cleanup
) box
.innerHTML
= " ";
1490 function displayDlg(id
, param
) {
1492 if (!xmlhttp_ready(xmlhttp
)) {
1493 printLockingError();
1497 notify_progress("Loading, please wait...", true);
1499 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1500 param_escape(id
) + "¶m=" + param_escape(param
), true);
1501 xmlhttp
.onreadystatechange
=infobox_callback
;
1509 function infobox_submit_callback() {
1510 if (xmlhttp
.readyState
== 4) {
1514 // called from prefs, reload tab
1516 selectTab(active_tab
, false);
1520 if (xmlhttp
.responseText
) {
1521 notify_info(xmlhttp
.responseText
);
1527 function infobox_callback() {
1528 if (xmlhttp
.readyState
== 4) {
1532 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1533 var overlay
= document
.getElementById("dialog_overlay");
1535 overlay
.style
.display
= "block";
1539 var box
= document
.getElementById('infoBox');
1540 var shadow
= document
.getElementById('infoBoxShadow');
1543 /* if (!is_safari()) {
1544 new Draggable(shadow);
1547 box
.innerHTML
=xmlhttp
.responseText
;
1549 shadow
.style
.display
= "block";
1551 box
.style
.display
= "block";
1555 /* FIXME this needs to be moved out somewhere */
1557 if (document
.getElementById("tags_choices")) {
1558 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1559 "backend.php?op=rpc&subop=completeTags",
1560 { tokens
: ',', paramName
: "search" });
1565 exception_error("infobox_callback", e
);
1570 function helpbox_callback() {
1571 if (xmlhttp
.readyState
== 4) {
1572 var box
= document
.getElementById('helpBox');
1573 var shadow
= document
.getElementById('helpBoxShadow');
1575 box
.innerHTML
=xmlhttp
.responseText
;
1577 shadow
.style
.display
= "block";
1579 box
.style
.display
= "block";
1586 function addFilter() {
1588 if (!xmlhttp_ready(xmlhttp
)) {
1589 printLockingError();
1593 var form
= document
.forms
['filter_add_form'];
1594 var reg_exp
= form
.reg_exp
.value
;
1596 if (reg_exp
== "") {
1597 alert(__("Can't add filter: nothing to match on."));
1601 var query
= Form
.serialize("filter_add_form");
1603 xmlhttp
.open("GET", "backend.php?" + query
, true);
1604 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1610 function toggleSubmitNotEmpty(e
, submit_id
) {
1612 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1614 exception_error("toggleSubmitNotEmpty", e
);
1618 function isValidURL(s
) {
1619 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1622 function qaddFeed() {
1624 if (!xmlhttp_ready(xmlhttp
)) {
1625 printLockingError();
1629 var form
= document
.forms
['feed_add_form'];
1630 var feed_url
= form
.feed_url
.value
;
1632 if (feed_url
== "") {
1633 alert(__("Can't subscribe: no feed URL given."));
1637 notify_progress(__("Subscribing to feed..."), true);
1641 var feeds_doc
= document
;
1643 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1645 var query
= Form
.serialize("feed_add_form");
1647 debug("subscribe q: " + query
);
1649 /* xmlhttp.open("GET", "backend.php?" + query, true);
1650 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1651 xmlhttp.send(null); */
1653 xmlhttp
.open("POST", "backend.php", true);
1654 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1655 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1656 xmlhttp
.send(query
);
1661 function filterCR(e
, f
)
1666 key
= window
.event
.keyCode
; //IE
1668 key
= e
.which
; //firefox
1671 if (typeof f
!= 'undefined') {
1682 function getMainContext() {
1686 function getFeedsContext() {
1690 function getContentContext() {
1694 function getHeadlinesContext() {
1698 var debug_last_class
= "even";
1700 function debug(msg
) {
1702 if (debug_last_class
== "even") {
1703 debug_last_class
= "odd";
1705 debug_last_class
= "even";
1708 var c
= document
.getElementById('debug_output');
1709 if (c
&& c
.style
.display
== "block") {
1710 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1711 c
.removeChild(c
.lastChild
);
1715 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1716 ":" + leading_zero(d
.getSeconds());
1717 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1718 msg
+ "</li>" + c
.innerHTML
;
1722 function getInitParam(key
) {
1723 return init_params
[key
];
1726 function storeInitParam(key
, value
) {
1727 debug("<b>storeInitParam is OBSOLETE: " + key
+ " => " + value
+ "</b>");
1728 init_params
[key
] = value
;
1731 function fatalError(code
, message
) {
1735 window
.location
.href
= "tt-rss.php";
1736 } else if (code
== 5) {
1737 window
.location
.href
= "update.php";
1739 var fe
= document
.getElementById("fatal_error");
1740 var fc
= document
.getElementById("fatal_error_msg");
1742 if (message
== "") message
= "Unknown error";
1744 fc
.innerHTML
= "<img src='images/sign_excl.png'> " + message
+ " (Code " + code
+ ")";
1746 fe
.style
.display
= "block";
1750 exception_error("fatalError", e
);
1754 function getFeedName(id
, is_cat
) {
1755 var d
= getFeedsContext().document
;
1760 e
= d
.getElementById("FCATN-" + id
);
1762 e
= d
.getElementById("FEEDN-" + id
);
1765 return e
.innerHTML
.stripTags();
1771 function viewContentUrl(url
) {
1772 getContentContext().location
= url
;
1775 function filterDlgCheckAction(sender
) {
1779 var action
= sender
[sender
.selectedIndex
].value
;
1781 var form
= document
.forms
["filter_add_form"];
1784 form
= document
.forms
["filter_edit_form"];
1788 debug("filterDlgCheckAction: can't find form!");
1792 var action_param
= form
.action_param
;
1794 if (!action_param
) {
1795 debug("filterDlgCheckAction: can't find action param!");
1799 // if selected action supports parameters, enable params field
1801 action_param
.disabled
= false;
1803 action_param
.disabled
= true;
1807 exception_error(e
, "filterDlgCheckAction");
1812 function explainError(code
) {
1813 return displayDlg("explainError", code
);
1816 function logoutUser() {
1818 if (xmlhttp_ready(xmlhttp_rpc
)) {
1820 notify_progress("Logging out, please wait...", true);
1822 xmlhttp_rpc
.open("GET", "backend.php?op=rpc&subop=logout", true);
1823 xmlhttp_rpc
.onreadystatechange
=logout_callback
;
1824 xmlhttp_rpc
.send(null);
1826 printLockingError();
1829 exception_error("logoutUser", e
);
1833 // this only searches loaded headlines list, not in CDM
1834 function getRelativePostIds(id
) {
1836 debug("getRelativePostIds: " + id
);
1838 var ids
= new Array();
1839 var container
= document
.getElementById("headlinesList");
1842 var rows
= container
.rows
;
1844 for (var i
= 0; i
< rows
.length
; i
++) {
1845 var r_id
= rows
[i
].id
.replace("RROW-", "");
1848 if (i
> 0) ids
.push(rows
[i
-1].id
.replace("RROW-", ""));
1849 if (i
> 1) ids
.push(rows
[i
-2].id
.replace("RROW-", ""));
1850 if (i
> 2) ids
.push(rows
[i
-3].id
.replace("RROW-", ""));
1852 if (i
< rows
.length
-1) ids
.push(rows
[i
+1].id
.replace("RROW-", ""));
1853 if (i
< rows
.length
-2) ids
.push(rows
[i
+2].id
.replace("RROW-", ""));
1854 if (i
< rows
.length
-3) ids
.push(rows
[i
+3].id
.replace("RROW-", ""));
1864 function openArticleInNewWindow(id
) {
1867 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1868 printLockingError();
1872 debug("openArticleInNewWindow: " + id
);
1874 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1878 xmlhttp_rpc
.open("GET", query
, true);
1879 xmlhttp_rpc
.onreadystatechange
=open_article_callback
;
1880 xmlhttp_rpc
.send(null);
1883 exception_error("openArticleInNewWindow", e
);
1887 /* http://textsnippets.com/posts/show/835 */
1889 Position
.GetWindowSize = function(w
) {
1891 var width
= w
.innerWidth
|| (w
.document
.documentElement
.clientWidth
|| w
.document
.body
.clientWidth
);
1892 var height
= w
.innerHeight
|| (w
.document
.documentElement
.clientHeight
|| w
.document
.body
.clientHeight
);
1893 return [width
, height
]
1896 /* http://textsnippets.com/posts/show/836 */
1898 Position
.Center = function(element
, parent
) {
1900 var d
= Element
.getDimensions(element
);
1905 var ws
= Position
.GetWindowSize();
1909 pw
= parent
.offsetWidth
;
1910 ph
= parent
.offsetHeight
;
1912 element
.style
.top
= (ph
/2) - (h/2) - Position
.deltaY
+ "px";
1913 element
.style
.left
= (pw
/2) - (w/2) - Position
.deltaX
+ "px";
1916 function labeltest_callback() {
1917 var container
= document
.getElementById('label_test_result');
1918 if (xmlhttp
.readyState
== 4) {
1920 container
.innerHTML
=xmlhttp
.responseText
;
1921 if (!Element
.visible(container
)) {
1922 Effect
.SlideDown(container
, { duration
: 0.5 });
1928 function labelTest() {
1930 var container
= document
.getElementById('label_test_result');
1932 var form
= document
.forms
['label_edit_form'];
1934 var sql_exp
= form
.sql_exp
.value
;
1935 var description
= form
.description
.value
;
1937 notify_progress("Loading, please wait...");
1939 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
1940 param_escape(sql_exp
) + "&descr=" + param_escape(description
), true);
1942 xmlhttp
.onreadystatechange
=labeltest_callback
;