]>
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() {
277 var rows
= getVisibleHeadlineIds();
281 function getLastVisibleHeadlineId() {
282 var rows
= getVisibleHeadlineIds();
283 return rows
[rows
.length
-1];
286 function markHeadline(id
) {
287 var row
= document
.getElementById("RROW-" + id
);
289 var is_active
= false;
291 if (row
.className
.match("Active")) {
294 row
.className
= row
.className
.replace("Selected", "");
295 row
.className
= row
.className
.replace("Active", "");
296 row
.className
= row
.className
.replace("Insensitive", "");
299 row
.className
= row
.className
= "Active";
302 var check
= document
.getElementById("RCHK-" + id
);
305 check
.checked
= true;
308 row
.className
= row
.className
+ "Selected";
313 function getFeedIds() {
314 var content
= document
.getElementById("feedsList");
316 var rows
= new Array();
318 for (i
= 0; i
< content
.rows
.length
; i
++) {
319 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
328 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
334 d
.setTime(d
.getTime() + (lifetime
* 1000));
337 debug("setCookie: " + name
+ " => " + value
+ ": " + d
);
339 int_setCookie(name
, value
, d
, path
, domain
, secure
);
343 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
344 document
.cookie
= name
+ "=" + escape(value
) +
345 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
346 ((path
) ? "; path=" + path
: "") +
347 ((domain
) ? "; domain=" + domain
: "") +
348 ((secure
) ? "; secure" : "");
351 function delCookie(name
, path
, domain
) {
352 if (getCookie(name
)) {
353 document
.cookie
= name
+ "=" +
354 ((path
) ? ";path=" + path
: "") +
355 ((domain
) ? ";domain=" + domain
: "" ) +
356 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
361 function getCookie(name
) {
363 var dc
= document
.cookie
;
364 var prefix
= name
+ "=";
365 var begin
= dc
.indexOf("; " + prefix
);
367 begin
= dc
.indexOf(prefix
);
368 if (begin
!= 0) return null;
373 var end
= document
.cookie
.indexOf(";", begin
);
377 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
380 function disableContainerChildren(id
, disable
, doc
) {
382 if (!doc
) doc
= document
;
384 var container
= doc
.getElementById(id
);
387 //alert("disableContainerChildren: element " + id + " not found");
391 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
392 var child
= container
.childNodes
[i
];
395 child
.disabled
= disable
;
401 if (child
.className
&& child
.className
.match("button")) {
402 child
.className
= "disabledButton";
405 if (child
.className
&& child
.className
.match("disabledButton")) {
406 child
.className
= "button";
413 function gotoPreferences() {
414 document
.location
.href
= "prefs.php";
417 function gotoMain() {
418 document
.location
.href
= "tt-rss.php";
421 function gotoExportOpml() {
422 document
.location
.href
= "opml.php?op=Export";
425 function getActiveFeedId() {
426 // return getCookie("ttrss_vf_actfeed");
428 debug("gAFID: " + active_feed_id
);
429 return active_feed_id
;
431 exception_error("getActiveFeedId", e
);
435 function activeFeedIsCat() {
436 return active_feed_is_cat
;
439 function setActiveFeedId(id
) {
440 // return setCookie("ttrss_vf_actfeed", id);
442 debug("sAFID(" + id
+ ")");
445 exception_error("setActiveFeedId", e
);
449 function parse_counters(reply
, scheduled_call
) {
454 var elems
= reply
.getElementsByTagName("counter");
456 for (var l
= 0; l
< elems
.length
; l
++) {
458 var id
= elems
[l
].getAttribute("id");
459 var t
= elems
[l
].getAttribute("type");
460 var ctr
= elems
[l
].getAttribute("counter");
461 var error
= elems
[l
].getAttribute("error");
462 var has_img
= elems
[l
].getAttribute("hi");
463 var updated
= elems
[l
].getAttribute("updated");
464 var title
= elems
[l
].getAttribute("title");
466 if (id
== "global-unread") {
472 if (id
== "subscribed-feeds") {
477 if (t
== "category") {
478 var catctr
= document
.getElementById("FCATCTR-" + id
);
480 catctr
.innerHTML
= "(" + ctr
+ ")";
482 catctr
.className
= "catCtrHasUnread";
484 catctr
.className
= "catCtrNoUnread";
490 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
491 var feedu
= document
.getElementById("FEEDU-" + id
);
492 var feedr
= document
.getElementById("FEEDR-" + id
);
493 var feed_img
= document
.getElementById("FIMG-" + id
);
494 var feedlink
= document
.getElementById("FEEDL-" + id
);
495 var feedupd
= document
.getElementById("FLUPD-" + id
);
497 if (updated
&& feedlink
) {
499 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
501 feedlink
.title
= "Updated: " + updated
;
505 if (updated
&& feedupd
) {
507 feedupd
.innerHTML
= updated
+ " (Error)";
509 feedupd
.innerHTML
= updated
;
513 if (has_img
&& feed_img
&& !is_msie()) {
514 if (!feed_img
.src
.match(id
+ ".ico")) {
515 feed_img
.src
= getInitParam("icons_location") + "/" + id
+ ".ico";
519 if (feedlink
&& title
) {
520 feedlink
.innerHTML
= title
;
523 if (feedctr
&& feedu
&& feedr
) {
525 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
529 var row_needs_hl
= (ctr
> 0 && ctr
> parseInt(feedu
.innerHTML
));
531 feedu
.innerHTML
= ctr
;
534 feedr
.className
= feedr
.className
.replace("feed", "error");
536 feedr
.className
= feedr
.className
.replace("error", "feed");
540 feedctr
.className
= "odd";
541 if (!feedr
.className
.match("Unread")) {
542 var is_selected
= feedr
.className
.match("Selected");
544 feedr
.className
= feedr
.className
.replace("Selected", "");
545 feedr
.className
= feedr
.className
.replace("Unread", "");
547 feedr
.className
= feedr
.className
+ "Unread";
550 feedr
.className
= feedr
.className
+ "Selected";
556 new Effect
.Highlight(feedr
, {duration
: 1, startcolor
: "#fff7d5",
557 queue
: { position
:'end', scope
: 'EFQ-' + id
, limit
: 1 } } );
560 feedctr
.className
= "invisible";
561 feedr
.className
= feedr
.className
.replace("Unread", "");
566 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
568 var feeds_stored
= number_of_feeds
;
570 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
572 if (feeds_stored
!= feeds_found
) {
573 number_of_feeds
= feeds_found
;
575 if (feeds_stored
!= 0 && feeds_found
!= 0) {
576 debug("Subscribed feed number changed, refreshing feedlist");
577 setTimeout('updateFeedList(false, false)', 50);
582 exception_error("parse_counters", e
);
586 function parse_counters_reply(transport
, scheduled_call
) {
588 if (!transport
.responseXML
) {
589 notify_error("Backend did not return valid XML", true);
593 var reply
= transport
.responseXML
.firstChild
;
596 notify_error("Backend did not return expected XML object", true);
601 var error_code
= false;
602 var error_msg
= false;
604 if (reply
.firstChild
) {
605 error_code
= reply
.firstChild
.getAttribute("error-code");
606 error_msg
= reply
.firstChild
.getAttribute("error-msg");
610 error_code
= reply
.getAttribute("error-code");
611 error_msg
= reply
.getAttribute("error-msg");
614 if (error_code
&& error_code
!= 0) {
615 debug("refetch_callback: got error code " + error_code
);
616 return fatalError(error_code
, error_msg
);
619 var counters
= reply
.getElementsByTagName("counters")[0];
621 parse_counters(counters
, scheduled_call
);
623 var runtime_info
= reply
.getElementsByTagName("runtime-info")[0];
625 parse_runtime_info(runtime_info
);
627 if (getInitParam("feeds_sort_by_unread") == 1) {
631 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
635 function all_counters_callback2(transport
) {
637 debug("<b>all_counters_callback2 IN: " + transport
+ "</b>");
638 parse_counters_reply(transport
);
639 debug("<b>all_counters_callback2 OUT: " + transport
+ "</b>");
642 exception_error("all_counters_callback2", e
);
646 function get_feed_unread(id
) {
648 return parseInt(document
.getElementById("FEEDU-" + id
).innerHTML
);
650 exception_error("get_feed_unread", e
, true);
655 function get_feed_entry_unread(doc
, elem
) {
657 var id
= elem
.id
.replace("FEEDR-", "");
664 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
670 function resort_category(doc
, node
) {
671 debug("resort_category: " + node
);
673 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
674 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
675 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
677 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
681 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
682 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
684 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
685 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
687 if (cur_val
> tmp_val
) {
688 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
689 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
690 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
691 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
700 function resort_feedlist() {
701 debug("resort_feedlist");
705 if (fd
.getElementById("feedCatHolder")) {
707 var feeds
= fd
.getElementById("feedList");
708 var child
= feeds
.firstChild
;
712 if (child
.id
== "feedCatHolder") {
713 resort_category(fd
, child
.firstChild
);
716 child
= child
.nextSibling
;
720 resort_category(fd
, fd
.getElementById("feedList"));
724 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
725 * * @author Sundar Dorai-Raj
726 * * Email: sdoraira@vt.edu
727 * * This program is free software; you can redistribute it and/or
728 * * modify it under the terms of the GNU General Public License
729 * * as published by the Free Software Foundation; either version 2
730 * * of the License, or (at your option) any later version,
731 * * provided that any use properly credits the author.
732 * * This program is distributed in the hope that it will be useful,
733 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
734 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
735 * * GNU General Public License for more details at http://www.gnu.org * * */
737 var numbers
=".0123456789";
738 function isNumeric(x
) {
739 // is x a String or a character?
741 // remove negative sign
743 for(j
=0;j
<x
.length
;j
++) {
744 // call isNumeric recursively for each character
745 number
=isNumeric(x
.substring(j
,j
+1));
746 if(!number
) return number
;
751 // if x is number return true
752 if(numbers
.indexOf(x
)>=0) return true;
758 function hideOrShowFeeds(doc
, hide
) {
760 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
764 var list
= fd
.getElementById("feedList");
766 if (fd
.getElementById("feedCatHolder")) {
768 var feeds
= fd
.getElementById("feedList");
769 var child
= feeds
.firstChild
;
773 if (child
.id
== "feedCatHolder") {
774 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
777 child
= child
.nextSibling
;
781 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
785 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
787 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
792 debug("hideOrShowFeeds: passed node is null, aborting");
796 // debug("cat: " + node.id);
798 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
799 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
800 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
802 if (node
.childNodes
[i
].style
!= undefined) {
804 var has_unread
= (node
.childNodes
[i
].className
!= "feed" &&
805 node
.childNodes
[i
].className
!= "label" &&
806 !(!getInitParam("hide_read_shows_special") &&
807 node
.childNodes
[i
].className
== "virt") &&
808 node
.childNodes
[i
].className
!= "error" &&
809 node
.childNodes
[i
].className
!= "tag");
811 // debug(node.childNodes[i].id + " --> " + has_unread);
813 if (hide
&& !has_unread
) {
814 //node.childNodes[i].style.display = "none";
815 var id
= node
.childNodes
[i
].id
;
816 Effect
.Fade(node
.childNodes
[i
], {duration
: 0.3,
817 queue
: { position
: 'end', scope
: 'FFADE-' + id
, limit
: 1 }});
821 node
.childNodes
[i
].style
.display
= "list-item";
822 //Effect.Appear(node.childNodes[i], {duration : 0.3});
826 node
.childNodes
[i
].style
.display
= "list-item";
828 //Effect.Appear(node.childNodes[i], {duration : 0.3});
829 //Effect.Highlight(node.childNodes[i]);
835 // debug("end cat: " + node.id + " unread " + cat_unread);
837 if (cat_unread
== 0) {
838 if (cat_node
.style
== undefined) {
839 debug("ERROR: supplied cat_node " + cat_node
+
840 " has no styles. WTF?");
844 //cat_node.style.display = "none";
845 Effect
.Fade(cat_node
, {duration
: 0.3,
846 queue
: { position
: 'end', scope
: 'CFADE-' + node
.id
, limit
: 1 }});
848 cat_node
.style
.display
= "list-item";
852 cat_node
.style
.display
= "list-item";
858 // debug("unread for category: " + cat_unread);
861 function selectTableRow(r
, do_select
) {
862 r
.className
= r
.className
.replace("Selected", "");
865 r
.className
= r
.className
+ "Selected";
869 function selectTableRowById(elem_id
, check_id
, do_select
) {
873 var row
= document
.getElementById(elem_id
);
876 selectTableRow(row
, do_select
);
879 var check
= document
.getElementById(check_id
);
882 check
.checked
= do_select
;
885 exception_error("selectTableRowById", e
);
889 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
890 classcheck
, reset_others
) {
892 var content
= document
.getElementById(content_id
);
895 alert("[selectTableRows] Element " + content_id
+ " not found.");
899 for (i
= 0; i
< content
.rows
.length
; i
++) {
900 if (Element
.visible(content
.rows
[i
])) {
901 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
903 if (content
.rows
[i
].id
.match(prefix
)) {
904 selectTableRow(content
.rows
[i
], do_select
);
906 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
907 var check
= document
.getElementById(check_prefix
+ row_id
);
910 check
.checked
= do_select
;
912 } else if (reset_others
) {
913 selectTableRow(content
.rows
[i
], false);
915 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
916 var check
= document
.getElementById(check_prefix
+ row_id
);
919 check
.checked
= false;
923 } else if (reset_others
) {
924 selectTableRow(content
.rows
[i
], false);
926 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
927 var check
= document
.getElementById(check_prefix
+ row_id
);
930 check
.checked
= false;
938 function getSelectedTableRowIds(content_id
, prefix
) {
940 var content
= document
.getElementById(content_id
);
943 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
947 var sel_rows
= new Array();
949 for (i
= 0; i
< content
.rows
.length
; i
++) {
950 if (content
.rows
[i
].id
.match(prefix
) &&
951 content
.rows
[i
].className
.match("Selected")) {
953 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
954 sel_rows
.push(row_id
);
962 function toggleSelectRowById(sender
, id
) {
963 var row
= document
.getElementById(id
);
965 if (sender
.checked
) {
966 if (!row
.className
.match("Selected")) {
967 row
.className
= row
.className
+ "Selected";
970 if (row
.className
.match("Selected")) {
971 row
.className
= row
.className
.replace("Selected", "");
976 function toggleSelectListRow(sender
) {
977 var parent_row
= sender
.parentNode
;
979 if (sender
.checked
) {
980 if (!parent_row
.className
.match("Selected")) {
981 parent_row
.className
= parent_row
.className
+ "Selected";
984 if (parent_row
.className
.match("Selected")) {
985 parent_row
.className
= parent_row
.className
.replace("Selected", "");
990 function tSR(sender
) {
991 return toggleSelectRow(sender
);
994 function toggleSelectRow(sender
) {
995 var parent_row
= sender
.parentNode
.parentNode
;
997 if (sender
.checked
) {
998 if (!parent_row
.className
.match("Selected")) {
999 parent_row
.className
= parent_row
.className
+ "Selected";
1002 if (parent_row
.className
.match("Selected")) {
1003 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1008 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1009 var rows
= list
.getElementsByTagName("LI");
1010 var feeds
= new Array();
1012 for (var i
= 0; i
< rows
.length
; i
++) {
1013 if (rows
[i
].id
.match("FEEDR-")) {
1015 if (rows
[i
].id
== "FEEDR-" + id
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1018 (rows
[i
].className
.match("Unread") || rows
[i
].id
== "FEEDR-" + id
)) {
1019 feeds
.push(rows
[i
].id
.replace("FEEDR-", ""));
1026 if (direction
== "next") {
1027 return feeds
.shift();
1032 if (direction
== "next") {
1033 var idx
= feeds
.indexOf(id
);
1034 if (idx
!= -1 && idx
< feeds
.length
) {
1035 return feeds
[idx
+1];
1037 return getRelativeFeedId(list
, false, direction
, unread_only
);
1040 var idx
= feeds
.indexOf(id
);
1042 return feeds
[idx
-1];
1044 return getRelativeFeedId(list
, false, direction
, unread_only
);
1051 function showBlockElement(id
, h_id
) {
1052 var elem
= document
.getElementById(id
);
1055 elem
.style
.display
= "block";
1058 elem
= document
.getElementById(h_id
);
1060 elem
.style
.display
= "none";
1064 alert("[showBlockElement] can't find element with id " + id
);
1068 function appearBlockElement_afh(effect
) {
1072 function checkboxToggleElement(elem
, id
) {
1074 Effect
.SlideDown(id
, {duration
: 0.5});
1076 Effect
.SlideUp(id
, {duration
: 0.5});
1080 function appearBlockElement(id
, h_id
) {
1086 Effect
.SlideDown(id
, {duration
: 1.0, afterFinish
: appearBlockElement_afh
});
1088 exception_error("appearBlockElement", e
);
1093 function hideParentElement(e
) {
1094 e
.parentNode
.style
.display
= "none";
1097 function dropboxSelect(e
, v
) {
1098 for (i
= 0; i
< e
.length
; i
++) {
1099 if (e
[i
].value
== v
) {
1100 e
.selectedIndex
= i
;
1106 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1107 // bugfixed just a little bit :-)
1108 function getURLParam(strParamName
){
1110 var strHref
= window
.location
.href
;
1112 if (strHref
.indexOf("#") == strHref
.length
-1) {
1113 strHref
= strHref
.substring(0, strHref
.length
-1);
1116 if ( strHref
.indexOf("?") > -1 ){
1117 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1118 var aQueryString
= strQueryString
.split("&");
1119 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1120 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1121 var aParam
= aQueryString
[iParam
].split("=");
1122 strReturn
= aParam
[1];
1130 function leading_zero(p
) {
1132 if (s
.length
== 1) s
= "0" + s
;
1136 function closeInfoBox(cleanup
) {
1138 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1139 var overlay
= document
.getElementById("dialog_overlay");
1141 overlay
.style
.display
= "none";
1145 var box
= document
.getElementById('infoBox');
1146 var shadow
= document
.getElementById('infoBoxShadow');
1149 shadow
.style
.display
= "none";
1151 box
.style
.display
= "none";
1154 if (cleanup
) box
.innerHTML
= " ";
1162 function displayDlg(id
, param
) {
1164 notify_progress("Loading, please wait...", true);
1168 var query
= "backend.php?op=dlg&id=" +
1169 param_escape(id
) + "¶m=" + param_escape(param
);
1171 new Ajax
.Request(query
, {
1172 onComplete: function (transport
) {
1173 infobox_callback2(transport
);
1179 function infobox_submit_callback2(transport
) {
1183 // called from prefs, reload tab
1185 selectTab(active_tab
, false);
1189 if (transport
.responseText
) {
1190 notify_info(transport
.responseText
);
1194 function infobox_callback2(transport
) {
1197 debug("infobox_callback2");
1199 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1200 var overlay
= document
.getElementById("dialog_overlay");
1202 overlay
.style
.display
= "block";
1206 var box
= document
.getElementById('infoBox');
1207 var shadow
= document
.getElementById('infoBoxShadow');
1210 /* if (!is_safari()) {
1211 new Draggable(shadow);
1214 box
.innerHTML
=transport
.responseText
;
1216 shadow
.style
.display
= "block";
1218 box
.style
.display
= "block";
1222 /* FIXME this needs to be moved out somewhere */
1224 if (document
.getElementById("tags_choices")) {
1225 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1226 "backend.php?op=rpc&subop=completeTags",
1227 { tokens
: ',', paramName
: "search" });
1232 exception_error("infobox_callback2", e
);
1236 function createFilter() {
1238 var form
= document
.forms
['filter_add_form'];
1239 var reg_exp
= form
.reg_exp
.value
;
1241 if (reg_exp
== "") {
1242 alert(__("Can't add filter: nothing to match on."));
1246 var query
= Form
.serialize("filter_add_form");
1248 new Ajax
.Request("backend.php?" + query
, {
1249 onComplete: function (transport
) {
1250 infobox_submit_callback2(transport
);
1256 function toggleSubmitNotEmpty(e
, submit_id
) {
1258 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1260 exception_error("toggleSubmitNotEmpty", e
);
1264 function isValidURL(s
) {
1265 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1268 function subscribeToFeed() {
1270 var form
= document
.forms
['feed_add_form'];
1271 var feed_url
= form
.feed_url
.value
;
1273 if (feed_url
== "") {
1274 alert(__("Can't subscribe: no feed URL given."));
1278 notify_progress(__("Subscribing to feed..."), true);
1282 var feeds_doc
= document
;
1284 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1286 var query
= Form
.serialize("feed_add_form");
1288 debug("subscribe q: " + query
);
1290 new Ajax
.Request("backend.php", {
1292 onComplete: function(transport
) {
1293 dlg_frefresh_callback(transport
);
1299 function filterCR(e
, f
)
1304 key
= window
.event
.keyCode
; //IE
1306 key
= e
.which
; //firefox
1309 if (typeof f
!= 'undefined') {
1320 function getMainContext() {
1324 function getFeedsContext() {
1328 function getContentContext() {
1332 function getHeadlinesContext() {
1336 var debug_last_class
= "even";
1338 function debug(msg
) {
1340 if (debug_last_class
== "even") {
1341 debug_last_class
= "odd";
1343 debug_last_class
= "even";
1346 var c
= document
.getElementById('debug_output');
1347 if (c
&& c
.style
.display
== "block") {
1348 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1349 c
.removeChild(c
.lastChild
);
1353 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1354 ":" + leading_zero(d
.getSeconds());
1355 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1356 msg
+ "</li>" + c
.innerHTML
;
1360 function getInitParam(key
) {
1361 return init_params
[key
];
1364 function storeInitParam(key
, value
) {
1365 debug("<b>storeInitParam is OBSOLETE: " + key
+ " => " + value
+ "</b>");
1366 init_params
[key
] = value
;
1369 function fatalError(code
, message
) {
1373 window
.location
.href
= "tt-rss.php";
1374 } else if (code
== 5) {
1375 window
.location
.href
= "update.php";
1377 var fe
= document
.getElementById("fatal_error");
1378 var fc
= document
.getElementById("fatal_error_msg");
1380 if (message
== "") message
= "Unknown error";
1382 fc
.innerHTML
= "<img src='images/sign_excl.gif'> " + message
+ " (Code " + code
+ ")";
1384 fe
.style
.display
= "block";
1388 exception_error("fatalError", e
);
1392 function getFeedName(id
, is_cat
) {
1393 var d
= getFeedsContext().document
;
1398 e
= d
.getElementById("FCATN-" + id
);
1400 e
= d
.getElementById("FEEDN-" + id
);
1403 return e
.innerHTML
.stripTags();
1409 function viewContentUrl(url
) {
1410 getContentContext().location
= url
;
1413 function filterDlgCheckAction(sender
) {
1417 var action
= sender
[sender
.selectedIndex
].value
;
1419 var form
= document
.forms
["filter_add_form"];
1422 form
= document
.forms
["filter_edit_form"];
1426 debug("filterDlgCheckAction: can't find form!");
1430 var action_param
= form
.action_param
;
1432 if (!action_param
) {
1433 debug("filterDlgCheckAction: can't find action param!");
1437 // if selected action supports parameters, enable params field
1438 if (action
== 4 || action
== 6) {
1439 action_param
.disabled
= false;
1441 action_param
.disabled
= true;
1445 exception_error(e
, "filterDlgCheckAction");
1450 function explainError(code
) {
1451 return displayDlg("explainError", code
);
1454 // this only searches loaded headlines list, not in CDM
1455 function getRelativePostIds(id
) {
1457 debug("getRelativePostIds: " + id
);
1459 var ids
= new Array();
1460 var container
= document
.getElementById("headlinesList");
1463 var rows
= container
.rows
;
1465 for (var i
= 0; i
< rows
.length
; i
++) {
1466 var r_id
= rows
[i
].id
.replace("RROW-", "");
1469 if (i
> 0) ids
.push(rows
[i
-1].id
.replace("RROW-", ""));
1470 if (i
> 1) ids
.push(rows
[i
-2].id
.replace("RROW-", ""));
1471 if (i
> 2) ids
.push(rows
[i
-3].id
.replace("RROW-", ""));
1473 if (i
< rows
.length
-1) ids
.push(rows
[i
+1].id
.replace("RROW-", ""));
1474 if (i
< rows
.length
-2) ids
.push(rows
[i
+2].id
.replace("RROW-", ""));
1475 if (i
< rows
.length
-3) ids
.push(rows
[i
+3].id
.replace("RROW-", ""));
1485 function openArticleInNewWindow(id
) {
1487 debug("openArticleInNewWindow: " + id
);
1489 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1493 new Ajax
.Request(query
, {
1494 onComplete: function(transport
) {
1495 open_article_callback(transport
);
1500 exception_error("openArticleInNewWindow", e
);
1504 /* http://textsnippets.com/posts/show/835 */
1506 Position
.GetWindowSize = function(w
) {
1508 var width
= w
.innerWidth
|| (w
.document
.documentElement
.clientWidth
|| w
.document
.body
.clientWidth
);
1509 var height
= w
.innerHeight
|| (w
.document
.documentElement
.clientHeight
|| w
.document
.body
.clientHeight
);
1510 return [width
, height
]
1513 /* http://textsnippets.com/posts/show/836 */
1515 Position
.Center = function(element
, parent
) {
1517 var d
= Element
.getDimensions(element
);
1522 var ws
= Position
.GetWindowSize();
1526 pw
= parent
.offsetWidth
;
1527 ph
= parent
.offsetHeight
;
1529 element
.style
.top
= (ph
/2) - (h/2) - Position
.deltaY
+ "px";
1530 element
.style
.left
= (pw
/2) - (w/2) - Position
.deltaX
+ "px";
1534 function labeltest_callback(transport
) {
1536 var container
= document
.getElementById('label_test_result');
1538 container
.innerHTML
= transport
.responseText
;
1539 if (!Element
.visible(container
)) {
1540 Effect
.SlideDown(container
, { duration
: 0.5 });
1545 exception_error("labeltest_callback", e
);
1549 function labelTest() {
1552 var container
= document
.getElementById('label_test_result');
1554 var form
= document
.forms
['label_edit_form'];
1556 var sql_exp
= form
.sql_exp
.value
;
1557 var description
= form
.description
.value
;
1559 notify_progress("Loading, please wait...");
1561 var query
= "backend.php?op=pref-labels&subop=test&expr=" +
1562 param_escape(sql_exp
) + "&descr=" + param_escape(description
);
1564 new Ajax
.Request(query
, {
1565 onComplete: function (transport
) {
1566 labeltest_callback(transport
);
1572 exception_error("labelTest", e
);
1576 function isCdmMode() {
1577 return !document
.getElementById("headlinesList");
1580 function getSelectedArticleIds2() {
1581 var rows
= new Array();
1582 var cdm_mode
= isCdmMode();
1585 rows
= cdmGetSelectedArticles();
1587 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1590 var ids
= new Array();
1592 for (var i
= 0; i
< rows
.length
; i
++) {
1593 var chk
= document
.getElementById("RCHK-" + rows
[i
]);
1594 if (chk
&& chk
.checked
) {
1602 function displayHelpInfobox(topic_id
) {
1604 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
1606 var w
= window
.open(url
, "ttrss_help",
1607 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1612 var _border_color_normal
= "#88b0f0";
1613 var _border_color_highlight
= "#72eda8";
1614 var _border_color_flash
= "#f0fff0";
1616 function highlightHotkeyZone(zone
) {
1618 var feeds
= document
.getElementById("feeds-holder");
1619 var headlines
= document
.getElementById("headlines-frame");
1620 var content
= document
.getElementById("content-frame");
1622 feeds
.style
.borderColor
= _border_color_normal
;
1623 headlines
.style
.borderColor
= _border_color_normal
;
1624 content
.style
.borderColor
= _border_color_normal
;
1627 feeds
.style
.borderColor
= _border_color_highlight
;
1629 new Effect
.Highlight(feeds
, {duration
: 0.5, startcolor
:
1630 _border_color_flash
,
1631 queue
: { position
:'end', scope
: 'EFCHL-Q', limit
: 1 } } );
1635 headlines
.style
.borderColor
= _border_color_highlight
;
1637 new Effect
.Highlight(headlines
, {duration
: 0.5, startcolor
:
1638 _border_color_flash
,
1639 queue
: { position
:'end', scope
: 'EFCHL-Q', limit
: 1 } } );
1642 if (zone
== 3 && content
) {
1643 content
.style
.borderColor
= _border_color_highlight
;
1645 new Effect
.Highlight(content
, {duration
: 0.5, startcolor
:
1646 _border_color_flash
,
1647 queue
: { position
:'end', scope
: 'EFCHL-Q', limit
: 1 } } );
1651 exception_error("highlightHotkeyZone", e
);
1656 function setHotkeyZone(zone
) {
1660 highlightHotkeyZone(zone
);
1664 exception_error("setHotkeyZone", e
);