]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var hotkeys_enabled
= true;
2 var xmlhttp_rpc
= Ajax
.getTransport();
3 var notify_silent
= false;
4 var last_progress_point
= 0;
5 var async_counters_work
= false;
7 /* add method to remove element from array */
9 Array
.prototype.remove = function(s
) {
10 for (var i
=0; i
< this.length
; i
++) {
11 if (s
== this[i
]) this.splice(i
, 1);
19 function exception_error(location
, e
, silent
) {
23 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
25 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
26 "\nFunction: " + location
+ "()" +
27 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
29 } else if (e
.description
) {
30 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
32 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
35 debug("<b>EXCEPTION: " + msg
+ "</b>");
42 function disableHotkeys() {
43 hotkeys_enabled
= false;
46 function enableHotkeys() {
47 hotkeys_enabled
= true;
50 function xmlhttp_ready(obj
) {
51 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
54 function open_article_callback(transport
) {
57 if (transport
.responseXML
) {
59 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
60 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
62 debug("open_article_callback, received link: " + link
);
66 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
68 debug("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
70 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
72 if (!w
) { notify_error("Failed to load article in new window"); }
75 id
= id
.firstChild
.nodeValue
;
76 if (!document
.getElementById("headlinesList")) {
77 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
81 notify_error("Can't open article: received invalid article link");
84 notify_error("Can't open article: received invalid XML");
88 exception_error("open_article_callback", e
);
92 function param_escape(arg
) {
93 if (typeof encodeURIComponent
!= 'undefined')
94 return encodeURIComponent(arg
);
99 function param_unescape(arg
) {
100 if (typeof decodeURIComponent
!= 'undefined')
101 return decodeURIComponent(arg
);
103 return unescape(arg
);
106 function delay(gap
) {
108 then
=new Date().getTime();
110 while((now
-then
)<gap
) {
111 now
=new Date().getTime();
115 var notify_hide_timerid
= false;
117 function hide_notify() {
118 var n
= document
.getElementById("notify");
120 n
.style
.display
= "none";
124 function notify_silent_next() {
125 notify_silent
= true;
128 function notify_real(msg
, no_hide
, n_type
) {
131 notify_silent
= false;
135 var n
= document
.getElementById("notify");
136 var nb
= document
.getElementById("notify_body");
138 if (!n
|| !nb
) return;
140 if (notify_hide_timerid
) {
141 window
.clearTimeout(notify_hide_timerid
);
145 if (n
.style
.display
== "block") {
146 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
150 n
.style
.display
= "block";
162 if (typeof __
!= 'undefined') {
167 n
.className
= "notify";
168 } else if (n_type
== 2) {
169 n
.className
= "notifyProgress";
170 msg
= "<img src='images/indicator_white.gif'> " + msg
;
171 } else if (n_type
== 3) {
172 n
.className
= "notifyError";
173 msg
= "<img src='images/sign_excl.gif'> " + msg
;
174 } else if (n_type
== 4) {
175 n
.className
= "notifyInfo";
176 msg
= "<img src='images/sign_info.gif'> " + msg
;
179 // msg = "<img src='images/live_com_loading.gif'> " + msg;
184 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
188 function notify(msg
, no_hide
) {
189 notify_real(msg
, no_hide
, 1);
192 function notify_progress(msg
, no_hide
) {
193 notify_real(msg
, no_hide
, 2);
196 function notify_error(msg
, no_hide
) {
197 notify_real(msg
, no_hide
, 3);
201 function notify_info(msg
, no_hide
) {
202 notify_real(msg
, no_hide
, 4);
205 function printLockingError() {
206 notify_info("Please wait until operation finishes.");
209 function cleanSelected(element
) {
210 var content
= document
.getElementById(element
);
212 for (i
= 0; i
< content
.rows
.length
; i
++) {
213 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
217 function getVisibleUnreadHeadlines() {
218 var content
= document
.getElementById("headlinesList");
220 var rows
= new Array();
222 if (!content
) return rows
;
224 for (i
= 0; i
< content
.rows
.length
; i
++) {
225 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
226 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
233 function getVisibleHeadlineIds() {
235 var content
= document
.getElementById("headlinesList");
237 var rows
= new Array();
239 if (!content
) return rows
;
241 for (i
= 0; i
< content
.rows
.length
; i
++) {
242 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
243 if (row_id
.length
> 0) {
250 function getFirstVisibleHeadlineId() {
252 var rows
= cdmGetVisibleArticles();
255 var rows
= getVisibleHeadlineIds();
260 function getLastVisibleHeadlineId() {
262 var rows
= cdmGetVisibleArticles();
263 return rows
[rows
.length
-1];
265 var rows
= getVisibleHeadlineIds();
266 return rows
[rows
.length
-1];
270 function markHeadline(id
) {
271 var row
= document
.getElementById("RROW-" + id
);
273 var is_active
= false;
275 if (row
.className
.match("Active")) {
278 row
.className
= row
.className
.replace("Selected", "");
279 row
.className
= row
.className
.replace("Active", "");
280 row
.className
= row
.className
.replace("Insensitive", "");
283 row
.className
= row
.className
= "Active";
286 var check
= document
.getElementById("RCHK-" + id
);
289 check
.checked
= true;
292 row
.className
= row
.className
+ "Selected";
297 function getFeedIds() {
298 var content
= document
.getElementById("feedsList");
300 var rows
= new Array();
302 for (i
= 0; i
< content
.rows
.length
; i
++) {
303 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
312 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
318 d
.setTime(d
.getTime() + (lifetime
* 1000));
321 debug("setCookie: " + name
+ " => " + value
+ ": " + d
);
323 int_setCookie(name
, value
, d
, path
, domain
, secure
);
327 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
328 document
.cookie
= name
+ "=" + escape(value
) +
329 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
330 ((path
) ? "; path=" + path
: "") +
331 ((domain
) ? "; domain=" + domain
: "") +
332 ((secure
) ? "; secure" : "");
335 function delCookie(name
, path
, domain
) {
336 if (getCookie(name
)) {
337 document
.cookie
= name
+ "=" +
338 ((path
) ? ";path=" + path
: "") +
339 ((domain
) ? ";domain=" + domain
: "" ) +
340 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
345 function getCookie(name
) {
347 var dc
= document
.cookie
;
348 var prefix
= name
+ "=";
349 var begin
= dc
.indexOf("; " + prefix
);
351 begin
= dc
.indexOf(prefix
);
352 if (begin
!= 0) return null;
357 var end
= document
.cookie
.indexOf(";", begin
);
361 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
364 function disableContainerChildren(id
, disable
, doc
) {
366 if (!doc
) doc
= document
;
368 var container
= doc
.getElementById(id
);
371 //alert("disableContainerChildren: element " + id + " not found");
375 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
376 var child
= container
.childNodes
[i
];
379 child
.disabled
= disable
;
385 if (child
.className
&& child
.className
.match("button")) {
386 child
.className
= "disabledButton";
389 if (child
.className
&& child
.className
.match("disabledButton")) {
390 child
.className
= "button";
397 function gotoPreferences() {
398 document
.location
.href
= "prefs.php";
401 function gotoMain() {
402 document
.location
.href
= "tt-rss.php";
405 function gotoExportOpml() {
406 document
.location
.href
= "opml.php?op=Export";
409 function getActiveFeedId() {
410 // return getCookie("ttrss_vf_actfeed");
412 debug("gAFID: " + active_feed_id
);
413 return active_feed_id
;
415 exception_error("getActiveFeedId", e
);
419 function activeFeedIsCat() {
420 return active_feed_is_cat
;
423 function setActiveFeedId(id
) {
424 // return setCookie("ttrss_vf_actfeed", id);
426 debug("sAFID(" + id
+ ")");
429 exception_error("setActiveFeedId", e
);
433 function parse_counters(reply
, scheduled_call
) {
438 var elems
= reply
.getElementsByTagName("counter");
440 for (var l
= 0; l
< elems
.length
; l
++) {
442 var id
= elems
[l
].getAttribute("id");
443 var t
= elems
[l
].getAttribute("type");
444 var ctr
= elems
[l
].getAttribute("counter");
445 var error
= elems
[l
].getAttribute("error");
446 var has_img
= elems
[l
].getAttribute("hi");
447 var updated
= elems
[l
].getAttribute("updated");
448 var title
= elems
[l
].getAttribute("title");
449 var xmsg
= elems
[l
].getAttribute("xmsg");
451 if (id
== "global-unread") {
457 if (id
== "subscribed-feeds") {
462 if (t
== "category") {
463 var catctr
= document
.getElementById("FCATCTR-" + id
);
465 catctr
.innerHTML
= "(" + ctr
+ ")";
467 catctr
.className
= "catCtrHasUnread";
469 catctr
.className
= "catCtrNoUnread";
475 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
476 var feedu
= document
.getElementById("FEEDU-" + id
);
477 var feedr
= document
.getElementById("FEEDR-" + id
);
478 var feed_img
= document
.getElementById("FIMG-" + id
);
479 var feedlink
= document
.getElementById("FEEDL-" + id
);
480 var feedupd
= document
.getElementById("FLUPD-" + id
);
482 if (updated
&& feedlink
) {
484 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
486 feedlink
.title
= "Updated: " + updated
;
491 if (!updated
) updated
= "";
495 feedupd
.innerHTML
= updated
+ " " + xmsg
+ " (Error)";
497 feedupd
.innerHTML
= updated
+ " (Error)";
501 feedupd
.innerHTML
= updated
+ " " + xmsg
;
503 feedupd
.innerHTML
= updated
;
508 if (has_img
&& feed_img
) {
509 if (!feed_img
.src
.match(id
+ ".ico")) {
510 feed_img
.src
= getInitParam("icons_location") + "/" + id
+ ".ico";
514 if (feedlink
&& title
) {
515 feedlink
.innerHTML
= title
;
518 if (feedctr
&& feedu
&& feedr
) {
520 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
524 var row_needs_hl
= (ctr
> 0 && ctr
> parseInt(feedu
.innerHTML
));
526 feedu
.innerHTML
= ctr
;
529 feedr
.className
= feedr
.className
.replace("feed", "error");
531 feedr
.className
= feedr
.className
.replace("error", "feed");
535 feedctr
.className
= "odd";
536 if (!feedr
.className
.match("Unread")) {
537 var is_selected
= feedr
.className
.match("Selected");
539 feedr
.className
= feedr
.className
.replace("Selected", "");
540 feedr
.className
= feedr
.className
.replace("Unread", "");
542 feedr
.className
= feedr
.className
+ "Unread";
545 feedr
.className
= feedr
.className
+ "Selected";
551 new Effect
.Highlight(feedr
, {duration
: 1, startcolor
: "#fff7d5",
552 queue
: { position
:'end', scope
: 'EFQ-' + id
, limit
: 1 } } );
555 feedctr
.className
= "invisible";
556 feedr
.className
= feedr
.className
.replace("Unread", "");
561 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
563 var feeds_stored
= number_of_feeds
;
565 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
567 if (feeds_stored
!= feeds_found
) {
568 number_of_feeds
= feeds_found
;
570 if (feeds_stored
!= 0 && feeds_found
!= 0) {
571 debug("Subscribed feed number changed, refreshing feedlist");
572 setTimeout('updateFeedList(false, false)', 50);
577 exception_error("parse_counters", e
);
581 function parse_counters_reply(transport
, scheduled_call
) {
583 if (!transport
.responseXML
) {
584 notify_error("Backend did not return valid XML", true);
588 var reply
= transport
.responseXML
.firstChild
;
591 notify_error("Backend did not return expected XML object", true);
596 var error_code
= false;
597 var error_msg
= false;
599 if (reply
.firstChild
) {
600 error_code
= reply
.firstChild
.getAttribute("error-code");
601 error_msg
= reply
.firstChild
.getAttribute("error-msg");
605 error_code
= reply
.getAttribute("error-code");
606 error_msg
= reply
.getAttribute("error-msg");
609 if (error_code
&& error_code
!= 0) {
610 debug("refetch_callback: got error code " + error_code
);
611 return fatalError(error_code
, error_msg
);
614 var counters
= reply
.getElementsByTagName("counters")[0];
616 parse_counters(counters
, scheduled_call
);
618 var runtime_info
= reply
.getElementsByTagName("runtime-info")[0];
620 parse_runtime_info(runtime_info
);
622 if (feedsSortByUnread()) {
626 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
630 function all_counters_callback2(transport
, async_call
) {
632 if (async_call
) async_counters_work
= true;
634 debug("<b>all_counters_callback2 IN: " + transport
+ "</b>");
635 parse_counters_reply(transport
);
636 debug("<b>all_counters_callback2 OUT: " + transport
+ "</b>");
639 exception_error("all_counters_callback2", e
);
643 function get_feed_unread(id
) {
645 return parseInt(document
.getElementById("FEEDU-" + id
).innerHTML
);
647 exception_error("get_feed_unread", e
, true);
652 function get_cat_unread(id
) {
654 var ctr
= document
.getElementById("FCATCTR-" + id
).innerHTML
;
655 ctr
= ctr
.replace("(", "");
656 ctr
= ctr
.replace(")", "");
657 return parseInt(ctr
);
659 exception_error("get_feed_unread", e
, true);
664 function get_feed_entry_unread(elem
) {
666 var id
= elem
.id
.replace("FEEDR-", "");
673 return parseInt(document
.getElementById("FEEDU-" + id
).innerHTML
);
679 function get_feed_entry_name(elem
) {
680 var id
= elem
.id
.replace("FEEDR-", "");
681 return getFeedName(id
);
685 function resort_category(node
) {
689 debug("resort_category: " + node
);
691 var by_unread
= feedsSortByUnread();
693 var list
= node
.getElementsByTagName("LI");
695 for (i
= 0; i
< list
.length
; i
++) {
697 for (j
= i
+1; j
< list
.length
; j
++) {
699 var tmp_val
= get_feed_entry_unread(list
[i
]);
700 var cur_val
= get_feed_entry_unread(list
[j
]);
702 var tmp_name
= get_feed_entry_name(list
[i
]);
703 var cur_name
= get_feed_entry_name(list
[j
]);
705 if ((by_unread
&& (cur_val
> tmp_val
)) || (!by_unread
&& (cur_name
< tmp_name
))) {
706 tempnode_i
= list
[i
].cloneNode(true);
707 tempnode_j
= list
[j
].cloneNode(true);
708 node
.replaceChild(tempnode_i
, list
[j
]);
709 node
.replaceChild(tempnode_j
, list
[i
]);
715 exception_error("resort_category", e
);
720 function resort_feedlist() {
721 debug("resort_feedlist");
723 if (document
.getElementById("FCATLIST--1")) {
725 var lists
= document
.getElementsByTagName("UL");
727 for (var i
= 0; i
< lists
.length
; i
++) {
728 if (lists
[i
].id
&& lists
[i
].id
.match("FCATLIST-")) {
729 resort_category(lists
[i
]);
734 resort_category(document
.getElementById("feedList"));
738 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
739 * * @author Sundar Dorai-Raj
740 * * Email: sdoraira@vt.edu
741 * * This program is free software; you can redistribute it and/or
742 * * modify it under the terms of the GNU General Public License
743 * * as published by the Free Software Foundation; either version 2
744 * * of the License, or (at your option) any later version,
745 * * provided that any use properly credits the author.
746 * * This program is distributed in the hope that it will be useful,
747 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
748 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
749 * * GNU General Public License for more details at http://www.gnu.org * * */
751 var numbers
=".0123456789";
752 function isNumeric(x
) {
753 // is x a String or a character?
755 // remove negative sign
757 for(j
=0;j
<x
.length
;j
++) {
758 // call isNumeric recursively for each character
759 number
=isNumeric(x
.substring(j
,j
+1));
760 if(!number
) return number
;
765 // if x is number return true
766 if(numbers
.indexOf(x
)>=0) return true;
772 function hideOrShowFeeds(hide
) {
776 debug("hideOrShowFeeds: " + hide
);
778 if (document
.getElementById("FCATLIST--1")) {
780 var lists
= document
.getElementsByTagName("UL");
782 for (var i
= 0; i
< lists
.length
; i
++) {
783 if (lists
[i
].id
&& lists
[i
].id
.match("FCATLIST-")) {
785 var id
= lists
[i
].id
.replace("FCATLIST-", "");
786 hideOrShowFeedsCategory(id
, hide
);
791 hideOrShowFeedsCategory(null, hide
);
795 exception_error("hideOrShowFeeds", e
);
799 function hideOrShowFeedsCategory(id
, hide
) {
807 node
= document
.getElementById("FCATLIST-" + id
);
808 cat_node
= document
.getElementById("FCAT-" + id
);
810 node
= document
.getElementById("feedList"); // no categories
813 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
818 debug("hideOrShowFeeds: passed node is null, aborting");
822 // debug("cat: " + node.id);
824 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
825 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
826 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
828 if (node
.childNodes
[i
].style
!= undefined) {
830 var has_unread
= (node
.childNodes
[i
].className
!= "feed" &&
831 node
.childNodes
[i
].className
!= "label" &&
832 !(!getInitParam("hide_read_shows_special") &&
833 node
.childNodes
[i
].className
== "virt") &&
834 node
.childNodes
[i
].className
!= "error" &&
835 node
.childNodes
[i
].className
!= "tag");
837 // debug(node.childNodes[i].id + " --> " + has_unread);
839 if (hide
&& !has_unread
) {
840 //node.childNodes[i].style.display = "none";
841 var id
= node
.childNodes
[i
].id
;
842 Effect
.Fade(node
.childNodes
[i
], {duration
: 0.3,
843 queue
: { position
: 'end', scope
: 'FFADE-' + id
, limit
: 1 }});
847 node
.childNodes
[i
].style
.display
= "list-item";
848 //Effect.Appear(node.childNodes[i], {duration : 0.3});
852 node
.childNodes
[i
].style
.display
= "list-item";
854 //Effect.Appear(node.childNodes[i], {duration : 0.3});
855 //Effect.Highlight(node.childNodes[i]);
861 // debug("end cat: " + node.id + " unread " + cat_unread);
863 if (cat_unread
== 0) {
864 if (cat_node
.style
== undefined) {
865 debug("ERROR: supplied cat_node " + cat_node
+
866 " has no styles. WTF?");
870 //cat_node.style.display = "none";
871 Effect
.Fade(cat_node
, {duration
: 0.3,
872 queue
: { position
: 'end', scope
: 'CFADE-' + node
.id
, limit
: 1 }});
874 cat_node
.style
.display
= "list-item";
878 cat_node
.style
.display
= "list-item";
884 // debug("unread for category: " + cat_unread);
887 exception_error("hideOrShowFeedsCategory", e
);
891 function selectTableRow(r
, do_select
) {
892 r
.className
= r
.className
.replace("Selected", "");
895 r
.className
= r
.className
+ "Selected";
899 function selectTableRowById(elem_id
, check_id
, do_select
) {
903 var row
= document
.getElementById(elem_id
);
906 selectTableRow(row
, do_select
);
909 var check
= document
.getElementById(check_id
);
912 check
.checked
= do_select
;
915 exception_error("selectTableRowById", e
);
919 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
920 classcheck
, reset_others
) {
922 var content
= document
.getElementById(content_id
);
925 alert("[selectTableRows] Element " + content_id
+ " not found.");
929 for (i
= 0; i
< content
.rows
.length
; i
++) {
930 if (Element
.visible(content
.rows
[i
])) {
931 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
933 if (content
.rows
[i
].id
.match(prefix
)) {
934 selectTableRow(content
.rows
[i
], do_select
);
936 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
937 var check
= document
.getElementById(check_prefix
+ row_id
);
940 check
.checked
= do_select
;
942 } else if (reset_others
) {
943 selectTableRow(content
.rows
[i
], false);
945 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
946 var check
= document
.getElementById(check_prefix
+ row_id
);
949 check
.checked
= false;
953 } else if (reset_others
) {
954 selectTableRow(content
.rows
[i
], false);
956 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
957 var check
= document
.getElementById(check_prefix
+ row_id
);
960 check
.checked
= false;
968 function getSelectedTableRowIds(content_id
, prefix
) {
970 var content
= document
.getElementById(content_id
);
973 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
977 var sel_rows
= new Array();
979 for (i
= 0; i
< content
.rows
.length
; i
++) {
980 if (content
.rows
[i
].id
.match(prefix
) &&
981 content
.rows
[i
].className
.match("Selected")) {
983 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
984 sel_rows
.push(row_id
);
992 function toggleSelectRowById(sender
, id
) {
993 var row
= document
.getElementById(id
);
995 if (sender
.checked
) {
996 if (!row
.className
.match("Selected")) {
997 row
.className
= row
.className
+ "Selected";
1000 if (row
.className
.match("Selected")) {
1001 row
.className
= row
.className
.replace("Selected", "");
1006 function toggleSelectListRow(sender
) {
1007 var parent_row
= sender
.parentNode
;
1009 if (sender
.checked
) {
1010 if (!parent_row
.className
.match("Selected")) {
1011 parent_row
.className
= parent_row
.className
+ "Selected";
1014 if (parent_row
.className
.match("Selected")) {
1015 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1020 function tSR(sender
) {
1021 return toggleSelectRow(sender
);
1024 function toggleSelectRow(sender
) {
1025 var parent_row
= sender
.parentNode
.parentNode
;
1027 if (sender
.checked
) {
1028 if (!parent_row
.className
.match("Selected")) {
1029 parent_row
.className
= parent_row
.className
+ "Selected";
1032 if (parent_row
.className
.match("Selected")) {
1033 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1039 function getRelativeFeedId2(id
, is_cat
, direction
, unread_only
) {
1042 // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
1044 var rows
= document
.getElementById("feedList").getElementsByTagName("LI");
1045 var feeds
= new Array();
1047 for (var i
= 0; i
< rows
.length
; i
++) {
1048 if (rows
[i
].id
.match("FEEDR-")) {
1050 if (rows
[i
].id
== "FEEDR-" + id
&& !is_cat
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1053 (rows
[i
].className
.match("Unread") || rows
[i
].id
== "FEEDR-" + id
)) {
1054 feeds
.push(rows
[i
].id
.replace("FEEDR-", ""));
1059 if (rows
[i
].id
.match("FCAT-")) {
1060 if (rows
[i
].id
== "FCAT-" + id
&& is_cat
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1062 var cat_id
= parseInt(rows
[i
].id
.replace("FCAT-", ""));
1065 if (!unread_only
|| get_cat_unread(cat_id
) > 0) {
1066 feeds
.push("CAT:"+cat_id
);
1073 // alert(feeds.toString());
1076 if (direction
== "next") {
1077 return feeds
.shift();
1082 if (direction
== "next") {
1083 if (is_cat
) id
= "CAT:" + id
;
1084 var idx
= feeds
.indexOf(id
);
1085 if (idx
!= -1 && idx
< feeds
.length
) {
1086 return feeds
[idx
+1];
1088 return getRelativeFeedId2(false, is_cat
, direction
, unread_only
);
1091 if (is_cat
) id
= "CAT:" + id
;
1092 var idx
= feeds
.indexOf(id
);
1094 return feeds
[idx
-1];
1096 return getRelativeFeedId2(false, is_cat
, direction
, unread_only
);
1103 exception_error("getRelativeFeedId2", e
);
1108 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1109 var rows
= list
.getElementsByTagName("LI");
1110 var feeds
= new Array();
1112 for (var i
= 0; i
< rows
.length
; i
++) {
1113 if (rows
[i
].id
.match("FEEDR-")) {
1115 if (rows
[i
].id
== "FEEDR-" + id
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1118 (rows
[i
].className
.match("Unread") || rows
[i
].id
== "FEEDR-" + id
)) {
1119 feeds
.push(rows
[i
].id
.replace("FEEDR-", ""));
1126 if (direction
== "next") {
1127 return feeds
.shift();
1132 if (direction
== "next") {
1133 var idx
= feeds
.indexOf(id
);
1134 if (idx
!= -1 && idx
< feeds
.length
) {
1135 return feeds
[idx
+1];
1137 return getRelativeFeedId(list
, false, direction
, unread_only
);
1140 var idx
= feeds
.indexOf(id
);
1142 return feeds
[idx
-1];
1144 return getRelativeFeedId(list
, false, direction
, unread_only
);
1151 function showBlockElement(id
, h_id
) {
1152 var elem
= document
.getElementById(id
);
1155 elem
.style
.display
= "block";
1158 elem
= document
.getElementById(h_id
);
1160 elem
.style
.display
= "none";
1164 alert("[showBlockElement] can't find element with id " + id
);
1168 function appearBlockElement_afh(effect
) {
1172 function checkboxToggleElement(elem
, id
) {
1174 Effect
.Appear(id
, {duration
: 0.5});
1176 Effect
.Fade(id
, {duration
: 0.5});
1180 function appearBlockElement(id
, h_id
) {
1186 Effect
.SlideDown(id
, {duration
: 1.0, afterFinish
: appearBlockElement_afh
});
1188 exception_error("appearBlockElement", e
);
1193 function hideParentElement(e
) {
1194 e
.parentNode
.style
.display
= "none";
1197 function dropboxSelect(e
, v
) {
1198 for (i
= 0; i
< e
.length
; i
++) {
1199 if (e
[i
].value
== v
) {
1200 e
.selectedIndex
= i
;
1206 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1207 // bugfixed just a little bit :-)
1208 function getURLParam(strParamName
){
1210 var strHref
= window
.location
.href
;
1212 if (strHref
.indexOf("#") == strHref
.length
-1) {
1213 strHref
= strHref
.substring(0, strHref
.length
-1);
1216 if ( strHref
.indexOf("?") > -1 ){
1217 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1218 var aQueryString
= strQueryString
.split("&");
1219 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1220 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1221 var aParam
= aQueryString
[iParam
].split("=");
1222 strReturn
= aParam
[1];
1230 function leading_zero(p
) {
1232 if (s
.length
== 1) s
= "0" + s
;
1236 function closeInfoBox(cleanup
) {
1238 Element
.hide("dialog_overlay");
1240 var box
= document
.getElementById('infoBox');
1241 var shadow
= document
.getElementById('infoBoxShadow');
1244 shadow
.style
.display
= "none";
1246 box
.style
.display
= "none";
1249 if (cleanup
) box
.innerHTML
= " ";
1257 function displayDlg(id
, param
) {
1259 notify_progress("Loading, please wait...", true);
1263 var query
= "backend.php?op=dlg&id=" +
1264 param_escape(id
) + "¶m=" + param_escape(param
);
1266 new Ajax
.Request(query
, {
1267 onComplete: function (transport
) {
1268 infobox_callback2(transport
);
1274 function infobox_submit_callback2(transport
) {
1278 // called from prefs, reload tab
1279 if (typeof active_tab
!= 'undefined' && active_tab
) {
1280 selectTab(active_tab
, false);
1284 if (transport
.responseText
) {
1285 notify_info(transport
.responseText
);
1289 function infobox_callback2(transport
) {
1292 debug("infobox_callback2");
1294 if (!getInitParam("infobox_disable_overlay")) {
1295 Element
.show("dialog_overlay");
1298 var box
= document
.getElementById('infoBox');
1299 var shadow
= document
.getElementById('infoBoxShadow');
1302 box
.innerHTML
=transport
.responseText
;
1304 shadow
.style
.display
= "block";
1306 box
.style
.display
= "block";
1310 /* FIXME this needs to be moved out somewhere */
1312 if (document
.getElementById("tags_choices")) {
1313 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1314 "backend.php?op=rpc&subop=completeTags",
1315 { tokens
: ',', paramName
: "search" });
1322 exception_error("infobox_callback2", e
);
1326 function createFilter() {
1330 var form
= document
.forms
['filter_add_form'];
1331 var reg_exp
= form
.reg_exp
.value
;
1333 if (reg_exp
== "") {
1334 alert(__("Can't add filter: nothing to match on."));
1338 var query
= Form
.serialize("filter_add_form");
1340 // we can be called from some other tab in Prefs
1341 if (typeof active_tab
!= 'undefined' && active_tab
) {
1342 active_tab
= "filterConfig";
1345 new Ajax
.Request("backend.php?" + query
, {
1346 onComplete: function (transport
) {
1347 infobox_submit_callback2(transport
);
1353 exception_error("createFilter", e
);
1357 function toggleSubmitNotEmpty(e
, submit_id
) {
1359 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1361 exception_error("toggleSubmitNotEmpty", e
);
1365 function isValidURL(s
) {
1366 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1369 function subscribeToFeed() {
1371 var form
= document
.forms
['feed_add_form'];
1372 var feed_url
= form
.feed_url
.value
;
1374 if (feed_url
== "") {
1375 alert(__("Can't subscribe: no feed URL given."));
1379 notify_progress(__("Subscribing to feed..."), true);
1383 var feeds_doc
= document
;
1385 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1387 var query
= Form
.serialize("feed_add_form");
1389 debug("subscribe q: " + query
);
1391 new Ajax
.Request("backend.php", {
1393 onComplete: function(transport
) {
1394 dlg_frefresh_callback(transport
);
1400 function filterCR(e
, f
)
1405 key
= window
.event
.keyCode
; //IE
1407 key
= e
.which
; //firefox
1410 if (typeof f
!= 'undefined') {
1421 var debug_last_class
= "even";
1423 function debug(msg
) {
1425 if (debug_last_class
== "even") {
1426 debug_last_class
= "odd";
1428 debug_last_class
= "even";
1431 var c
= document
.getElementById('debug_output');
1432 if (c
&& Element
.visible(c
)) {
1433 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1434 c
.removeChild(c
.lastChild
);
1438 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1439 ":" + leading_zero(d
.getSeconds());
1440 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1441 msg
+ "</li>" + c
.innerHTML
;
1445 function getInitParam(key
) {
1446 return init_params
[key
];
1449 function storeInitParam(key
, value
) {
1450 debug("<b>storeInitParam is OBSOLETE: " + key
+ " => " + value
+ "</b>");
1451 init_params
[key
] = value
;
1454 function fatalError(code
, message
) {
1458 window
.location
.href
= "tt-rss.php";
1459 } else if (code
== 5) {
1460 window
.location
.href
= "update.php";
1462 var fe
= document
.getElementById("fatal_error");
1463 var fc
= document
.getElementById("fatal_error_msg");
1465 if (message
== "") message
= "Unknown error";
1467 fc
.innerHTML
= "<img src='images/sign_excl.gif'> " + message
+ " (Code " + code
+ ")";
1469 fe
.style
.display
= "block";
1473 exception_error("fatalError", e
);
1477 function getFeedName(id
, is_cat
) {
1481 e
= document
.getElementById("FCATN-" + id
);
1483 e
= document
.getElementById("FEEDN-" + id
);
1486 return e
.innerHTML
.stripTags();
1492 function filterDlgCheckAction(sender
) {
1496 var action
= sender
[sender
.selectedIndex
].value
;
1498 var form
= document
.forms
["filter_add_form"];
1501 form
= document
.forms
["filter_edit_form"];
1505 debug("filterDlgCheckAction: can't find form!");
1509 var action_param
= document
.getElementById("filter_dlg_param_box");
1511 if (!action_param
) {
1512 debug("filterDlgCheckAction: can't find action param box!");
1516 // if selected action supports parameters, enable params field
1517 if (action
== 4 || action
== 6) {
1518 Element
.show(action_param
);
1520 Element
.hide(action_param
);
1524 exception_error("filterDlgCheckAction", e
);
1529 function explainError(code
) {
1530 return displayDlg("explainError", code
);
1533 // this only searches loaded headlines list, not in CDM
1534 function getRelativePostIds(id
, limit
) {
1536 if (!limit
) limit
= 3;
1538 debug("getRelativePostIds: " + id
+ " limit=" + limit
);
1540 var ids
= new Array();
1541 var container
= document
.getElementById("headlinesList");
1544 var rows
= container
.rows
;
1546 for (var i
= 0; i
< rows
.length
; i
++) {
1547 var r_id
= rows
[i
].id
.replace("RROW-", "");
1550 for (var k
= 1; k
<= limit
; k
++) {
1553 if (i
> k
-1) var nid
= rows
[i
-k
].id
.replace("RROW-", "");
1554 if (nid
) ids
.push(nid
);
1556 if (i
< rows
.length
-k
) nid
= rows
[i
+k
].id
.replace("RROW-", "");
1557 if (nid
) ids
.push(nid
);
1568 function openArticleInNewWindow(id
) {
1570 debug("openArticleInNewWindow: " + id
);
1572 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1573 var wname
= "ttrss_article_" + id
;
1575 debug(query
+ " " + wname
);
1577 var w
= window
.open("", wname
);
1579 if (!w
) notify_error("Failed to open window for the article");
1581 new Ajax
.Request(query
, {
1582 onComplete: function(transport
) {
1583 open_article_callback(transport
);
1588 exception_error("openArticleInNewWindow", e
);
1592 /* http://textsnippets.com/posts/show/835 */
1594 Position
.GetWindowSize = function(w
) {
1596 var width
= w
.innerWidth
|| (w
.document
.documentElement
.clientWidth
|| w
.document
.body
.clientWidth
);
1597 var height
= w
.innerHeight
|| (w
.document
.documentElement
.clientHeight
|| w
.document
.body
.clientHeight
);
1598 return [width
, height
]
1601 /* http://textsnippets.com/posts/show/836 */
1603 Position
.Center = function(element
, parent
) {
1605 var d
= Element
.getDimensions(element
);
1610 var ws
= Position
.GetWindowSize();
1614 pw
= parent
.offsetWidth
;
1615 ph
= parent
.offsetHeight
;
1617 element
.style
.top
= (ph
/2) - (h/2) - Position
.deltaY
+ "px";
1618 element
.style
.left
= (pw
/2) - (w/2) - Position
.deltaX
+ "px";
1622 function labeltest_callback(transport
) {
1624 var container
= document
.getElementById('label_test_result');
1626 container
.innerHTML
= transport
.responseText
;
1627 if (!Element
.visible(container
)) {
1628 Effect
.SlideDown(container
, { duration
: 0.5 });
1633 exception_error("labeltest_callback", e
);
1637 function labelTest() {
1640 var container
= document
.getElementById('label_test_result');
1642 var form
= document
.forms
['label_edit_form'];
1644 var sql_exp
= form
.sql_exp
.value
;
1645 var description
= form
.description
.value
;
1647 notify_progress("Loading, please wait...");
1649 var query
= "backend.php?op=pref-labels&subop=test&expr=" +
1650 param_escape(sql_exp
) + "&descr=" + param_escape(description
);
1652 new Ajax
.Request(query
, {
1653 onComplete: function (transport
) {
1654 labeltest_callback(transport
);
1660 exception_error("labelTest", e
);
1664 function isCdmMode() {
1665 return !document
.getElementById("headlinesList");
1668 function getSelectedArticleIds2() {
1669 var rows
= new Array();
1670 var cdm_mode
= isCdmMode();
1673 rows
= cdmGetSelectedArticles();
1675 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1678 var ids
= new Array();
1680 for (var i
= 0; i
< rows
.length
; i
++) {
1681 var chk
= document
.getElementById("RCHK-" + rows
[i
]);
1682 if (chk
&& chk
.checked
) {
1690 function displayHelpInfobox(topic_id
) {
1692 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
1694 var w
= window
.open(url
, "ttrss_help",
1695 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1700 function focus_element(id
) {
1702 var e
= document
.getElementById(id
);
1705 exception_error("focus_element", e
);
1710 function loading_set_progress(p
) {
1712 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
1714 debug("<b>loading_set_progress : " + p
+ " (" + last_progress_point
+ ")</b>");
1716 var o
= document
.getElementById("l_progress_i");
1718 // o.style.width = (p * 2) + "px";
1720 new Effect
.Scale(o
, p
, {
1722 scaleFrom
: last_progress_point
,
1723 scaleMode
: { originalWidth
: 200 },
1724 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
1726 last_progress_point
= p
;
1729 exception_error("loading_set_progress", e
);
1733 function remove_splash() {
1734 if (Element
.visible("overlay")) {
1735 debug("about to remove splash, OMG!");
1736 Element
.hide("overlay");
1737 debug("removed splash!");
1741 function addLabelExample() {
1743 var form
= document
.forms
["label_edit_form"];
1745 var text
= form
.sql_exp
;
1746 var op
= form
.label_fields
[form
.label_fields
.selectedIndex
];
1747 var p
= form
.label_fields_param
;
1754 if (text
.value
!= "") {
1755 if (text
.value
.substring(text
.value
.length
-3, 3).toUpperCase() != "AND") {
1762 if (op
== "unread") {
1763 tmp
= tmp
+ "unread = true";
1766 if (op
== "updated") {
1767 tmp
= tmp
+ "last_read is null and unread = false";
1770 if (op
== "kw_title") {
1771 tmp
= tmp
+ "ttrss_entries.title like '%"+p
.value
+"%'";
1773 if (op
== "kw_content") {
1774 tmp
= tmp
+ "ttrss_entries.content like '%"+p
.value
+"%'";
1777 if (op
== "scoreE") {
1778 tmp
= tmp
+ "score = " + p
.value
;
1781 if (op
== "scoreG") {
1782 tmp
= tmp
+ "score > " + p
.value
;
1785 if (op
== "scoreL") {
1786 tmp
= tmp
+ "score < " + p
.value
;
1789 if (op
== "newerD") {
1790 if (isNaN(parseInt(p
.value
))) {
1791 alert("This action expects numeric parameter.");
1794 tmp
= tmp
+ "updated > NOW() - INTERVAL '"+parseInt(p
.value
)+" days'";
1797 if (op
== "newerH") {
1798 if (isNaN(parseInt(p
.value
))) {
1799 alert("This action expects numeric parameter.");
1803 tmp
= tmp
+ "updated > NOW() - INTERVAL '"+parseInt(p
.value
)+" hours'";
1806 text
.value
= text
.value
+ tmp
;
1813 exception_error("addLabelExample", e
);
1819 function labelFieldsCheck(elem
) {
1821 var op
= elem
[elem
.selectedIndex
].value
;
1823 var p
= document
.forms
["label_edit_form"].label_fields_param
;
1825 if (op
== "kw_title" || op
== "kw_content" || op
== "scoreL" ||
1826 op
== "scoreG" || op
== "scoreE" || op
== "newerD" ||
1834 exception_error("labelFieldsCheck", e
);