]>
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();
6 /* add method to remove element from array */
8 Array
.prototype.remove = function(s
) {
9 for (var i
=0; i
< this.length
; i
++) {
10 if (s
== this[i
]) this.splice(i
, 1);
14 function browser_has_opacity() {
15 return navigator
.userAgent
.match("Gecko") != null ||
16 navigator
.userAgent
.match("Opera") != null;
20 return navigator
.userAgent
.match("MSIE");
24 return navigator
.userAgent
.match("Opera");
28 return navigator
.userAgent
.match("KHTML");
31 function is_safari() {
32 return navigator
.userAgent
.match("Safari");
35 function exception_error(location
, e
, silent
) {
39 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
41 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
42 "\nFunction: " + location
+ "()" +
43 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
46 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
49 debug("<b>EXCEPTION: " + msg
+ "</b>");
56 function disableHotkeys() {
57 hotkeys_enabled
= false;
60 function enableHotkeys() {
61 hotkeys_enabled
= true;
64 function xmlhttp_ready(obj
) {
65 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
68 function open_article_callback(transport
) {
71 if (transport
.responseXML
) {
73 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
74 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
76 debug("open_article_callback, received link: " + link
);
79 debug("link url: " + link
.firstChild
.nodeValue
);
81 var w
= window
.open(link
.firstChild
.nodeValue
, "_blank");
83 if (!w
) { notify_error("Failed to load article in new window"); }
86 id
= id
.firstChild
.nodeValue
;
87 if (!document
.getElementById("headlinesList")) {
88 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
92 notify_error("Can't open article: received invalid article link");
95 notify_error("Can't open article: received invalid XML");
99 exception_error("open_article_callback", e
);
103 function param_escape(arg
) {
104 if (typeof encodeURIComponent
!= 'undefined')
105 return encodeURIComponent(arg
);
110 function param_unescape(arg
) {
111 if (typeof decodeURIComponent
!= 'undefined')
112 return decodeURIComponent(arg
);
114 return unescape(arg
);
117 function delay(gap
) {
119 then
=new Date().getTime();
121 while((now
-then
)<gap
) {
122 now
=new Date().getTime();
126 var notify_hide_timerid
= false;
128 function hide_notify() {
129 var n
= document
.getElementById("notify");
131 n
.style
.display
= "none";
135 function notify_real(msg
, no_hide
, n_type
) {
137 var n
= document
.getElementById("notify");
138 var nb
= document
.getElementById("notify_body");
140 if (!n
|| !nb
) return;
142 if (notify_hide_timerid
) {
143 window
.clearTimeout(notify_hide_timerid
);
147 if (n
.style
.display
== "block") {
148 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
152 n
.style
.display
= "block";
164 if (typeof __
!= 'undefined') {
169 n
.className
= "notify";
170 } else if (n_type
== 2) {
171 n
.className
= "notifyProgress";
172 msg
= "<img src='images/indicator_white.gif'> " + msg
;
173 } else if (n_type
== 3) {
174 n
.className
= "notifyError";
175 msg
= "<img src='images/sign_excl.gif'> " + msg
;
176 } else if (n_type
== 4) {
177 n
.className
= "notifyInfo";
178 msg
= "<img src='images/sign_info.gif'> " + msg
;
181 // msg = "<img src='images/live_com_loading.gif'> " + msg;
186 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
190 function notify(msg
, no_hide
) {
191 notify_real(msg
, no_hide
, 1);
194 function notify_progress(msg
, no_hide
) {
195 notify_real(msg
, no_hide
, 2);
198 function notify_error(msg
, no_hide
) {
199 notify_real(msg
, no_hide
, 3);
203 function notify_info(msg
, no_hide
) {
204 notify_real(msg
, no_hide
, 4);
207 function printLockingError() {
208 notify_info("Please wait until operation finishes.");
211 function cleanSelectedList(element
) {
212 var content
= document
.getElementById(element
);
214 if (!document
.getElementById("feedCatHolder")) {
215 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
216 var child
= content
.childNodes
[i
];
218 child
.className
= child
.className
.replace("Selected", "");
224 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
225 var child
= content
.childNodes
[i
];
226 if (child
.id
== "feedCatHolder") {
228 var fcat
= child
.lastChild
;
229 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
230 var feed
= fcat
.childNodes
[j
];
231 feed
.className
= feed
.className
.replace("Selected", "");
239 function cleanSelected(element
) {
240 var content
= document
.getElementById(element
);
242 for (i
= 0; i
< content
.rows
.length
; i
++) {
243 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
247 function getVisibleUnreadHeadlines() {
248 var content
= document
.getElementById("headlinesList");
250 var rows
= new Array();
252 for (i
= 0; i
< content
.rows
.length
; i
++) {
253 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
254 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
261 function getVisibleHeadlineIds() {
263 var content
= document
.getElementById("headlinesList");
265 var rows
= new Array();
267 for (i
= 0; i
< content
.rows
.length
; i
++) {
268 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
269 if (row_id
.length
> 0) {
276 function getFirstVisibleHeadlineId() {
278 var rows
= cdmGetVisibleArticles();
281 var rows
= getVisibleHeadlineIds();
286 function getLastVisibleHeadlineId() {
288 var rows
= cdmGetVisibleArticles();
289 return rows
[rows
.length
-1];
291 var rows
= getVisibleHeadlineIds();
292 return rows
[rows
.length
-1];
296 function markHeadline(id
) {
297 var row
= document
.getElementById("RROW-" + id
);
299 var is_active
= false;
301 if (row
.className
.match("Active")) {
304 row
.className
= row
.className
.replace("Selected", "");
305 row
.className
= row
.className
.replace("Active", "");
306 row
.className
= row
.className
.replace("Insensitive", "");
309 row
.className
= row
.className
= "Active";
312 var check
= document
.getElementById("RCHK-" + id
);
315 check
.checked
= true;
318 row
.className
= row
.className
+ "Selected";
323 function getFeedIds() {
324 var content
= document
.getElementById("feedsList");
326 var rows
= new Array();
328 for (i
= 0; i
< content
.rows
.length
; i
++) {
329 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
338 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
344 d
.setTime(d
.getTime() + (lifetime
* 1000));
347 debug("setCookie: " + name
+ " => " + value
+ ": " + d
);
349 int_setCookie(name
, value
, d
, path
, domain
, secure
);
353 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
354 document
.cookie
= name
+ "=" + escape(value
) +
355 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
356 ((path
) ? "; path=" + path
: "") +
357 ((domain
) ? "; domain=" + domain
: "") +
358 ((secure
) ? "; secure" : "");
361 function delCookie(name
, path
, domain
) {
362 if (getCookie(name
)) {
363 document
.cookie
= name
+ "=" +
364 ((path
) ? ";path=" + path
: "") +
365 ((domain
) ? ";domain=" + domain
: "" ) +
366 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
371 function getCookie(name
) {
373 var dc
= document
.cookie
;
374 var prefix
= name
+ "=";
375 var begin
= dc
.indexOf("; " + prefix
);
377 begin
= dc
.indexOf(prefix
);
378 if (begin
!= 0) return null;
383 var end
= document
.cookie
.indexOf(";", begin
);
387 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
390 function disableContainerChildren(id
, disable
, doc
) {
392 if (!doc
) doc
= document
;
394 var container
= doc
.getElementById(id
);
397 //alert("disableContainerChildren: element " + id + " not found");
401 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
402 var child
= container
.childNodes
[i
];
405 child
.disabled
= disable
;
411 if (child
.className
&& child
.className
.match("button")) {
412 child
.className
= "disabledButton";
415 if (child
.className
&& child
.className
.match("disabledButton")) {
416 child
.className
= "button";
423 function gotoPreferences() {
424 document
.location
.href
= "prefs.php";
427 function gotoMain() {
428 document
.location
.href
= "tt-rss.php";
431 function gotoExportOpml() {
432 document
.location
.href
= "opml.php?op=Export";
435 function getActiveFeedId() {
436 // return getCookie("ttrss_vf_actfeed");
438 debug("gAFID: " + active_feed_id
);
439 return active_feed_id
;
441 exception_error("getActiveFeedId", e
);
445 function activeFeedIsCat() {
446 return active_feed_is_cat
;
449 function setActiveFeedId(id
) {
450 // return setCookie("ttrss_vf_actfeed", id);
452 debug("sAFID(" + id
+ ")");
455 exception_error("setActiveFeedId", e
);
459 function parse_counters(reply
, scheduled_call
) {
464 var elems
= reply
.getElementsByTagName("counter");
466 for (var l
= 0; l
< elems
.length
; l
++) {
468 var id
= elems
[l
].getAttribute("id");
469 var t
= elems
[l
].getAttribute("type");
470 var ctr
= elems
[l
].getAttribute("counter");
471 var error
= elems
[l
].getAttribute("error");
472 var has_img
= elems
[l
].getAttribute("hi");
473 var updated
= elems
[l
].getAttribute("updated");
474 var title
= elems
[l
].getAttribute("title");
476 if (id
== "global-unread") {
482 if (id
== "subscribed-feeds") {
487 if (t
== "category") {
488 var catctr
= document
.getElementById("FCATCTR-" + id
);
490 catctr
.innerHTML
= "(" + ctr
+ ")";
492 catctr
.className
= "catCtrHasUnread";
494 catctr
.className
= "catCtrNoUnread";
500 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
501 var feedu
= document
.getElementById("FEEDU-" + id
);
502 var feedr
= document
.getElementById("FEEDR-" + id
);
503 var feed_img
= document
.getElementById("FIMG-" + id
);
504 var feedlink
= document
.getElementById("FEEDL-" + id
);
505 var feedupd
= document
.getElementById("FLUPD-" + id
);
507 if (updated
&& feedlink
) {
509 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
511 feedlink
.title
= "Updated: " + updated
;
515 if (updated
&& feedupd
) {
517 feedupd
.innerHTML
= updated
+ " (Error)";
519 feedupd
.innerHTML
= updated
;
523 if (has_img
&& feed_img
&& !is_msie()) {
524 if (!feed_img
.src
.match(id
+ ".ico")) {
525 feed_img
.src
= getInitParam("icons_location") + "/" + id
+ ".ico";
529 if (feedlink
&& title
) {
530 feedlink
.innerHTML
= title
;
533 if (feedctr
&& feedu
&& feedr
) {
535 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
539 var row_needs_hl
= (ctr
> 0 && ctr
> parseInt(feedu
.innerHTML
));
541 feedu
.innerHTML
= ctr
;
544 feedr
.className
= feedr
.className
.replace("feed", "error");
546 feedr
.className
= feedr
.className
.replace("error", "feed");
550 feedctr
.className
= "odd";
551 if (!feedr
.className
.match("Unread")) {
552 var is_selected
= feedr
.className
.match("Selected");
554 feedr
.className
= feedr
.className
.replace("Selected", "");
555 feedr
.className
= feedr
.className
.replace("Unread", "");
557 feedr
.className
= feedr
.className
+ "Unread";
560 feedr
.className
= feedr
.className
+ "Selected";
566 new Effect
.Highlight(feedr
, {duration
: 1, startcolor
: "#fff7d5",
567 queue
: { position
:'end', scope
: 'EFQ-' + id
, limit
: 1 } } );
570 feedctr
.className
= "invisible";
571 feedr
.className
= feedr
.className
.replace("Unread", "");
576 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
578 var feeds_stored
= number_of_feeds
;
580 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
582 if (feeds_stored
!= feeds_found
) {
583 number_of_feeds
= feeds_found
;
585 if (feeds_stored
!= 0 && feeds_found
!= 0) {
586 debug("Subscribed feed number changed, refreshing feedlist");
587 setTimeout('updateFeedList(false, false)', 50);
592 exception_error("parse_counters", e
);
596 function parse_counters_reply(transport
, scheduled_call
) {
598 if (!transport
.responseXML
) {
599 notify_error("Backend did not return valid XML", true);
603 var reply
= transport
.responseXML
.firstChild
;
606 notify_error("Backend did not return expected XML object", true);
611 var error_code
= false;
612 var error_msg
= false;
614 if (reply
.firstChild
) {
615 error_code
= reply
.firstChild
.getAttribute("error-code");
616 error_msg
= reply
.firstChild
.getAttribute("error-msg");
620 error_code
= reply
.getAttribute("error-code");
621 error_msg
= reply
.getAttribute("error-msg");
624 if (error_code
&& error_code
!= 0) {
625 debug("refetch_callback: got error code " + error_code
);
626 return fatalError(error_code
, error_msg
);
629 var counters
= reply
.getElementsByTagName("counters")[0];
631 parse_counters(counters
, scheduled_call
);
633 var runtime_info
= reply
.getElementsByTagName("runtime-info")[0];
635 parse_runtime_info(runtime_info
);
637 if (getInitParam("feeds_sort_by_unread") == 1) {
641 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
645 function all_counters_callback2(transport
) {
647 debug("<b>all_counters_callback2 IN: " + transport
+ "</b>");
648 parse_counters_reply(transport
);
649 debug("<b>all_counters_callback2 OUT: " + transport
+ "</b>");
652 exception_error("all_counters_callback2", e
);
656 function get_feed_unread(id
) {
658 return parseInt(document
.getElementById("FEEDU-" + id
).innerHTML
);
660 exception_error("get_feed_unread", e
, true);
665 function get_feed_entry_unread(doc
, elem
) {
667 var id
= elem
.id
.replace("FEEDR-", "");
674 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
680 function resort_category(doc
, node
) {
681 debug("resort_category: " + node
);
683 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
684 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
685 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
687 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
691 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
692 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
694 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
695 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
697 if (cur_val
> tmp_val
) {
698 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
699 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
700 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
701 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
710 function resort_feedlist() {
711 debug("resort_feedlist");
715 if (fd
.getElementById("feedCatHolder")) {
717 var feeds
= fd
.getElementById("feedList");
718 var child
= feeds
.firstChild
;
722 if (child
.id
== "feedCatHolder") {
723 resort_category(fd
, child
.firstChild
);
726 child
= child
.nextSibling
;
730 resort_category(fd
, fd
.getElementById("feedList"));
734 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
735 * * @author Sundar Dorai-Raj
736 * * Email: sdoraira@vt.edu
737 * * This program is free software; you can redistribute it and/or
738 * * modify it under the terms of the GNU General Public License
739 * * as published by the Free Software Foundation; either version 2
740 * * of the License, or (at your option) any later version,
741 * * provided that any use properly credits the author.
742 * * This program is distributed in the hope that it will be useful,
743 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
744 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
745 * * GNU General Public License for more details at http://www.gnu.org * * */
747 var numbers
=".0123456789";
748 function isNumeric(x
) {
749 // is x a String or a character?
751 // remove negative sign
753 for(j
=0;j
<x
.length
;j
++) {
754 // call isNumeric recursively for each character
755 number
=isNumeric(x
.substring(j
,j
+1));
756 if(!number
) return number
;
761 // if x is number return true
762 if(numbers
.indexOf(x
)>=0) return true;
768 function hideOrShowFeeds(doc
, hide
) {
770 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
774 var list
= fd
.getElementById("feedList");
776 if (fd
.getElementById("feedCatHolder")) {
778 var feeds
= fd
.getElementById("feedList");
779 var child
= feeds
.firstChild
;
783 if (child
.id
== "feedCatHolder") {
784 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
787 child
= child
.nextSibling
;
791 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
795 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
797 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
802 debug("hideOrShowFeeds: passed node is null, aborting");
806 // debug("cat: " + node.id);
808 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
809 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
810 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
812 if (node
.childNodes
[i
].style
!= undefined) {
814 var has_unread
= (node
.childNodes
[i
].className
!= "feed" &&
815 node
.childNodes
[i
].className
!= "label" &&
816 !(!getInitParam("hide_read_shows_special") &&
817 node
.childNodes
[i
].className
== "virt") &&
818 node
.childNodes
[i
].className
!= "error" &&
819 node
.childNodes
[i
].className
!= "tag");
821 // debug(node.childNodes[i].id + " --> " + has_unread);
823 if (hide
&& !has_unread
) {
824 //node.childNodes[i].style.display = "none";
825 var id
= node
.childNodes
[i
].id
;
826 Effect
.Fade(node
.childNodes
[i
], {duration
: 0.3,
827 queue
: { position
: 'end', scope
: 'FFADE-' + id
, limit
: 1 }});
831 node
.childNodes
[i
].style
.display
= "list-item";
832 //Effect.Appear(node.childNodes[i], {duration : 0.3});
836 node
.childNodes
[i
].style
.display
= "list-item";
838 //Effect.Appear(node.childNodes[i], {duration : 0.3});
839 //Effect.Highlight(node.childNodes[i]);
845 // debug("end cat: " + node.id + " unread " + cat_unread);
847 if (cat_unread
== 0) {
848 if (cat_node
.style
== undefined) {
849 debug("ERROR: supplied cat_node " + cat_node
+
850 " has no styles. WTF?");
854 //cat_node.style.display = "none";
855 Effect
.Fade(cat_node
, {duration
: 0.3,
856 queue
: { position
: 'end', scope
: 'CFADE-' + node
.id
, limit
: 1 }});
858 cat_node
.style
.display
= "list-item";
862 cat_node
.style
.display
= "list-item";
868 // debug("unread for category: " + cat_unread);
871 function selectTableRow(r
, do_select
) {
872 r
.className
= r
.className
.replace("Selected", "");
875 r
.className
= r
.className
+ "Selected";
879 function selectTableRowById(elem_id
, check_id
, do_select
) {
883 var row
= document
.getElementById(elem_id
);
886 selectTableRow(row
, do_select
);
889 var check
= document
.getElementById(check_id
);
892 check
.checked
= do_select
;
895 exception_error("selectTableRowById", e
);
899 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
900 classcheck
, reset_others
) {
902 var content
= document
.getElementById(content_id
);
905 alert("[selectTableRows] Element " + content_id
+ " not found.");
909 for (i
= 0; i
< content
.rows
.length
; i
++) {
910 if (Element
.visible(content
.rows
[i
])) {
911 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
913 if (content
.rows
[i
].id
.match(prefix
)) {
914 selectTableRow(content
.rows
[i
], do_select
);
916 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
917 var check
= document
.getElementById(check_prefix
+ row_id
);
920 check
.checked
= do_select
;
922 } else if (reset_others
) {
923 selectTableRow(content
.rows
[i
], false);
925 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
926 var check
= document
.getElementById(check_prefix
+ row_id
);
929 check
.checked
= false;
933 } else if (reset_others
) {
934 selectTableRow(content
.rows
[i
], false);
936 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
937 var check
= document
.getElementById(check_prefix
+ row_id
);
940 check
.checked
= false;
948 function getSelectedTableRowIds(content_id
, prefix
) {
950 var content
= document
.getElementById(content_id
);
953 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
957 var sel_rows
= new Array();
959 for (i
= 0; i
< content
.rows
.length
; i
++) {
960 if (content
.rows
[i
].id
.match(prefix
) &&
961 content
.rows
[i
].className
.match("Selected")) {
963 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
964 sel_rows
.push(row_id
);
972 function toggleSelectRowById(sender
, id
) {
973 var row
= document
.getElementById(id
);
975 if (sender
.checked
) {
976 if (!row
.className
.match("Selected")) {
977 row
.className
= row
.className
+ "Selected";
980 if (row
.className
.match("Selected")) {
981 row
.className
= row
.className
.replace("Selected", "");
986 function toggleSelectListRow(sender
) {
987 var parent_row
= sender
.parentNode
;
989 if (sender
.checked
) {
990 if (!parent_row
.className
.match("Selected")) {
991 parent_row
.className
= parent_row
.className
+ "Selected";
994 if (parent_row
.className
.match("Selected")) {
995 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1000 function tSR(sender
) {
1001 return toggleSelectRow(sender
);
1004 function toggleSelectRow(sender
) {
1005 var parent_row
= sender
.parentNode
.parentNode
;
1007 if (sender
.checked
) {
1008 if (!parent_row
.className
.match("Selected")) {
1009 parent_row
.className
= parent_row
.className
+ "Selected";
1012 if (parent_row
.className
.match("Selected")) {
1013 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1018 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1019 var rows
= list
.getElementsByTagName("LI");
1020 var feeds
= new Array();
1022 for (var i
= 0; i
< rows
.length
; i
++) {
1023 if (rows
[i
].id
.match("FEEDR-")) {
1025 if (rows
[i
].id
== "FEEDR-" + id
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1028 (rows
[i
].className
.match("Unread") || rows
[i
].id
== "FEEDR-" + id
)) {
1029 feeds
.push(rows
[i
].id
.replace("FEEDR-", ""));
1036 if (direction
== "next") {
1037 return feeds
.shift();
1042 if (direction
== "next") {
1043 var idx
= feeds
.indexOf(id
);
1044 if (idx
!= -1 && idx
< feeds
.length
) {
1045 return feeds
[idx
+1];
1047 return getRelativeFeedId(list
, false, direction
, unread_only
);
1050 var idx
= feeds
.indexOf(id
);
1052 return feeds
[idx
-1];
1054 return getRelativeFeedId(list
, false, direction
, unread_only
);
1061 function showBlockElement(id
, h_id
) {
1062 var elem
= document
.getElementById(id
);
1065 elem
.style
.display
= "block";
1068 elem
= document
.getElementById(h_id
);
1070 elem
.style
.display
= "none";
1074 alert("[showBlockElement] can't find element with id " + id
);
1078 function appearBlockElement_afh(effect
) {
1082 function checkboxToggleElement(elem
, id
) {
1084 Effect
.SlideDown(id
, {duration
: 0.5});
1086 Effect
.SlideUp(id
, {duration
: 0.5});
1090 function appearBlockElement(id
, h_id
) {
1096 Effect
.SlideDown(id
, {duration
: 1.0, afterFinish
: appearBlockElement_afh
});
1098 exception_error("appearBlockElement", e
);
1103 function hideParentElement(e
) {
1104 e
.parentNode
.style
.display
= "none";
1107 function dropboxSelect(e
, v
) {
1108 for (i
= 0; i
< e
.length
; i
++) {
1109 if (e
[i
].value
== v
) {
1110 e
.selectedIndex
= i
;
1116 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1117 // bugfixed just a little bit :-)
1118 function getURLParam(strParamName
){
1120 var strHref
= window
.location
.href
;
1122 if (strHref
.indexOf("#") == strHref
.length
-1) {
1123 strHref
= strHref
.substring(0, strHref
.length
-1);
1126 if ( strHref
.indexOf("?") > -1 ){
1127 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1128 var aQueryString
= strQueryString
.split("&");
1129 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1130 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1131 var aParam
= aQueryString
[iParam
].split("=");
1132 strReturn
= aParam
[1];
1140 function leading_zero(p
) {
1142 if (s
.length
== 1) s
= "0" + s
;
1146 function closeInfoBox(cleanup
) {
1148 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1149 var overlay
= document
.getElementById("dialog_overlay");
1151 overlay
.style
.display
= "none";
1155 var box
= document
.getElementById('infoBox');
1156 var shadow
= document
.getElementById('infoBoxShadow');
1159 shadow
.style
.display
= "none";
1161 box
.style
.display
= "none";
1164 if (cleanup
) box
.innerHTML
= " ";
1172 function displayDlg(id
, param
) {
1174 notify_progress("Loading, please wait...", true);
1178 var query
= "backend.php?op=dlg&id=" +
1179 param_escape(id
) + "¶m=" + param_escape(param
);
1181 new Ajax
.Request(query
, {
1182 onComplete: function (transport
) {
1183 infobox_callback2(transport
);
1189 function infobox_submit_callback2(transport
) {
1193 // called from prefs, reload tab
1195 selectTab(active_tab
, false);
1199 if (transport
.responseText
) {
1200 notify_info(transport
.responseText
);
1204 function infobox_callback2(transport
) {
1207 debug("infobox_callback2");
1209 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1210 var overlay
= document
.getElementById("dialog_overlay");
1212 overlay
.style
.display
= "block";
1216 var box
= document
.getElementById('infoBox');
1217 var shadow
= document
.getElementById('infoBoxShadow');
1220 /* if (!is_safari()) {
1221 new Draggable(shadow);
1224 box
.innerHTML
=transport
.responseText
;
1226 shadow
.style
.display
= "block";
1228 box
.style
.display
= "block";
1232 /* FIXME this needs to be moved out somewhere */
1234 if (document
.getElementById("tags_choices")) {
1235 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1236 "backend.php?op=rpc&subop=completeTags",
1237 { tokens
: ',', paramName
: "search" });
1244 exception_error("infobox_callback2", e
);
1248 function createFilter() {
1250 var form
= document
.forms
['filter_add_form'];
1251 var reg_exp
= form
.reg_exp
.value
;
1253 if (reg_exp
== "") {
1254 alert(__("Can't add filter: nothing to match on."));
1258 var query
= Form
.serialize("filter_add_form");
1260 // we can be called from some other tab in Prefs
1261 if (active_tab
) active_tab
= "filterConfig";
1263 new Ajax
.Request("backend.php?" + query
, {
1264 onComplete: function (transport
) {
1265 infobox_submit_callback2(transport
);
1271 function toggleSubmitNotEmpty(e
, submit_id
) {
1273 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1275 exception_error("toggleSubmitNotEmpty", e
);
1279 function isValidURL(s
) {
1280 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1283 function subscribeToFeed() {
1285 var form
= document
.forms
['feed_add_form'];
1286 var feed_url
= form
.feed_url
.value
;
1288 if (feed_url
== "") {
1289 alert(__("Can't subscribe: no feed URL given."));
1293 notify_progress(__("Subscribing to feed..."), true);
1297 var feeds_doc
= document
;
1299 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1301 var query
= Form
.serialize("feed_add_form");
1303 debug("subscribe q: " + query
);
1305 new Ajax
.Request("backend.php", {
1307 onComplete: function(transport
) {
1308 dlg_frefresh_callback(transport
);
1314 function filterCR(e
, f
)
1319 key
= window
.event
.keyCode
; //IE
1321 key
= e
.which
; //firefox
1324 if (typeof f
!= 'undefined') {
1335 function getMainContext() {
1339 function getFeedsContext() {
1343 function getContentContext() {
1347 function getHeadlinesContext() {
1351 var debug_last_class
= "even";
1353 function debug(msg
) {
1355 if (debug_last_class
== "even") {
1356 debug_last_class
= "odd";
1358 debug_last_class
= "even";
1361 var c
= document
.getElementById('debug_output');
1362 if (c
&& c
.style
.display
== "block") {
1363 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1364 c
.removeChild(c
.lastChild
);
1368 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1369 ":" + leading_zero(d
.getSeconds());
1370 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1371 msg
+ "</li>" + c
.innerHTML
;
1375 function getInitParam(key
) {
1376 return init_params
[key
];
1379 function storeInitParam(key
, value
) {
1380 debug("<b>storeInitParam is OBSOLETE: " + key
+ " => " + value
+ "</b>");
1381 init_params
[key
] = value
;
1384 function fatalError(code
, message
) {
1388 window
.location
.href
= "tt-rss.php";
1389 } else if (code
== 5) {
1390 window
.location
.href
= "update.php";
1392 var fe
= document
.getElementById("fatal_error");
1393 var fc
= document
.getElementById("fatal_error_msg");
1395 if (message
== "") message
= "Unknown error";
1397 fc
.innerHTML
= "<img src='images/sign_excl.gif'> " + message
+ " (Code " + code
+ ")";
1399 fe
.style
.display
= "block";
1403 exception_error("fatalError", e
);
1407 function getFeedName(id
, is_cat
) {
1408 var d
= getFeedsContext().document
;
1413 e
= d
.getElementById("FCATN-" + id
);
1415 e
= d
.getElementById("FEEDN-" + id
);
1418 return e
.innerHTML
.stripTags();
1424 function viewContentUrl(url
) {
1425 getContentContext().location
= url
;
1428 function filterDlgCheckAction(sender
) {
1432 var action
= sender
[sender
.selectedIndex
].value
;
1434 var form
= document
.forms
["filter_add_form"];
1437 form
= document
.forms
["filter_edit_form"];
1441 debug("filterDlgCheckAction: can't find form!");
1445 var action_param
= form
.action_param
;
1447 if (!action_param
) {
1448 debug("filterDlgCheckAction: can't find action param!");
1452 // if selected action supports parameters, enable params field
1453 if (action
== 4 || action
== 6) {
1454 action_param
.disabled
= false;
1456 action_param
.disabled
= true;
1460 exception_error(e
, "filterDlgCheckAction");
1465 function explainError(code
) {
1466 return displayDlg("explainError", code
);
1469 // this only searches loaded headlines list, not in CDM
1470 function getRelativePostIds(id
) {
1472 debug("getRelativePostIds: " + id
);
1474 var ids
= new Array();
1475 var container
= document
.getElementById("headlinesList");
1478 var rows
= container
.rows
;
1480 for (var i
= 0; i
< rows
.length
; i
++) {
1481 var r_id
= rows
[i
].id
.replace("RROW-", "");
1484 if (i
> 0) ids
.push(rows
[i
-1].id
.replace("RROW-", ""));
1485 if (i
> 1) ids
.push(rows
[i
-2].id
.replace("RROW-", ""));
1486 if (i
> 2) ids
.push(rows
[i
-3].id
.replace("RROW-", ""));
1488 if (i
< rows
.length
-1) ids
.push(rows
[i
+1].id
.replace("RROW-", ""));
1489 if (i
< rows
.length
-2) ids
.push(rows
[i
+2].id
.replace("RROW-", ""));
1490 if (i
< rows
.length
-3) ids
.push(rows
[i
+3].id
.replace("RROW-", ""));
1500 function openArticleInNewWindow(id
) {
1502 debug("openArticleInNewWindow: " + id
);
1504 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1508 new Ajax
.Request(query
, {
1509 onComplete: function(transport
) {
1510 open_article_callback(transport
);
1515 exception_error("openArticleInNewWindow", e
);
1519 /* http://textsnippets.com/posts/show/835 */
1521 Position
.GetWindowSize = function(w
) {
1523 var width
= w
.innerWidth
|| (w
.document
.documentElement
.clientWidth
|| w
.document
.body
.clientWidth
);
1524 var height
= w
.innerHeight
|| (w
.document
.documentElement
.clientHeight
|| w
.document
.body
.clientHeight
);
1525 return [width
, height
]
1528 /* http://textsnippets.com/posts/show/836 */
1530 Position
.Center = function(element
, parent
) {
1532 var d
= Element
.getDimensions(element
);
1537 var ws
= Position
.GetWindowSize();
1541 pw
= parent
.offsetWidth
;
1542 ph
= parent
.offsetHeight
;
1544 element
.style
.top
= (ph
/2) - (h/2) - Position
.deltaY
+ "px";
1545 element
.style
.left
= (pw
/2) - (w/2) - Position
.deltaX
+ "px";
1549 function labeltest_callback(transport
) {
1551 var container
= document
.getElementById('label_test_result');
1553 container
.innerHTML
= transport
.responseText
;
1554 if (!Element
.visible(container
)) {
1555 Effect
.SlideDown(container
, { duration
: 0.5 });
1560 exception_error("labeltest_callback", e
);
1564 function labelTest() {
1567 var container
= document
.getElementById('label_test_result');
1569 var form
= document
.forms
['label_edit_form'];
1571 var sql_exp
= form
.sql_exp
.value
;
1572 var description
= form
.description
.value
;
1574 notify_progress("Loading, please wait...");
1576 var query
= "backend.php?op=pref-labels&subop=test&expr=" +
1577 param_escape(sql_exp
) + "&descr=" + param_escape(description
);
1579 new Ajax
.Request(query
, {
1580 onComplete: function (transport
) {
1581 labeltest_callback(transport
);
1587 exception_error("labelTest", e
);
1591 function isCdmMode() {
1592 return !document
.getElementById("headlinesList");
1595 function getSelectedArticleIds2() {
1596 var rows
= new Array();
1597 var cdm_mode
= isCdmMode();
1600 rows
= cdmGetSelectedArticles();
1602 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1605 var ids
= new Array();
1607 for (var i
= 0; i
< rows
.length
; i
++) {
1608 var chk
= document
.getElementById("RCHK-" + rows
[i
]);
1609 if (chk
&& chk
.checked
) {
1617 function displayHelpInfobox(topic_id
) {
1619 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
1621 var w
= window
.open(url
, "ttrss_help",
1622 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1627 var _border_color_normal
= "#88b0f0";
1628 var _border_color_highlight
= "#72eda8";
1629 var _border_color_flash
= "#f0fff0";
1631 function highlightHotkeyZone(zone
) {
1633 var feeds
= document
.getElementById("feeds-holder");
1634 var headlines
= document
.getElementById("headlines-frame");
1635 var content
= document
.getElementById("content-frame");
1637 feeds
.style
.borderColor
= _border_color_normal
;
1638 headlines
.style
.borderColor
= _border_color_normal
;
1639 content
.style
.borderColor
= _border_color_normal
;
1642 feeds
.style
.borderColor
= _border_color_highlight
;
1644 new Effect
.Highlight(feeds
, {duration
: 0.5, startcolor
:
1645 _border_color_flash
,
1646 queue
: { position
:'end', scope
: 'EFCHL-Q', limit
: 1 } } );
1650 headlines
.style
.borderColor
= _border_color_highlight
;
1652 new Effect
.Highlight(headlines
, {duration
: 0.5, startcolor
:
1653 _border_color_flash
,
1654 queue
: { position
:'end', scope
: 'EFCHL-Q', limit
: 1 } } );
1657 if (zone
== 3 && content
) {
1658 content
.style
.borderColor
= _border_color_highlight
;
1660 new Effect
.Highlight(content
, {duration
: 0.5, startcolor
:
1661 _border_color_flash
,
1662 queue
: { position
:'end', scope
: 'EFCHL-Q', limit
: 1 } } );
1666 exception_error("highlightHotkeyZone", e
);
1671 function setHotkeyZone(zone
) {
1675 highlightHotkeyZone(zone
);
1679 exception_error("setHotkeyZone", e
);