]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var hotkeys_enabled
= true;
3 function browser_has_opacity() {
4 return navigator
.userAgent
.match("Gecko") != null ||
5 navigator
.userAgent
.match("Opera") != null;
8 function exception_error(location
, e
) {
12 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
14 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
15 "\nFunction: " + location
+ "()" +
16 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
18 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
24 function disableHotkeys() {
25 hotkeys_enabled
= false;
28 function enableHotkeys() {
29 hotkeys_enabled
= true;
32 function xmlhttp_ready(obj
) {
33 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
36 function notify_callback() {
37 var container
= document
.getElementById('notify');
38 if (xmlhttp
.readyState
== 4) {
39 container
.innerHTML
=xmlhttp
.responseText
;
43 function rpc_notify_callback() {
44 var container
= document
.getElementById('notify');
45 if (xmlhttp_rpc
.readyState
== 4) {
46 container
.innerHTML
=xmlhttp_rpc
.responseText
;
50 function rpc_pnotify_callback() {
51 var container
= parent
.document
.getElementById('notify');
52 if (xmlhttp_rpc
.readyState
== 4) {
53 container
.innerHTML
=xmlhttp_rpc
.responseText
;
57 function param_escape(arg
) {
58 if (typeof encodeURIComponent
!= 'undefined')
59 return encodeURIComponent(arg
);
64 function param_unescape(arg
) {
65 if (typeof decodeURIComponent
!= 'undefined')
66 return decodeURIComponent(arg
);
73 then
=new Date().getTime();
75 while((now
-then
)<gap
) {
76 now
=new Date().getTime();
80 var notify_hide_timerid
= false;
81 var notify_last_doc
= false;
83 function hide_notify() {
84 if (notify_last_doc
) {
85 var n
= notify_last_doc
.getElementById("notify");
86 if (browser_has_opacity()) {
87 if (notify_opacity
>= 0) {
88 notify_opacity
= notify_opacity
- 0.1;
89 n
.style
.opacity
= notify_opacity
;
90 notify_hide_timerid
= window
.setTimeout("hide_notify()", 20);
92 n
.style
.display
= "none";
96 n
.style
.display
= "none";
101 function notify_real(msg
, doc
, no_hide
, is_err
) {
103 var n
= doc
.getElementById("notify");
104 var nb
= doc
.getElementById("notify_body");
106 if (!n
|| !nb
) return;
108 if (notify_hide_timerid
) {
109 window
.clearTimeout(notify_hide_timerid
);
112 notify_last_doc
= doc
;
116 if (n
.style
.display
== "block") {
117 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
121 n
.style
.display
= "block";
125 n
.style
.backgroundColor
= "#ffcccc";
126 n
.style
.color
= "black";
127 n
.style
.borderColor
= "#ff0000";
129 n
.style
.backgroundColor
= "#fff7d5";
130 n
.style
.borderColor
= "#d7c47a";
131 n
.style
.color
= "black";
137 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
141 function p_notify(msg
, no_hide
, is_err
) {
142 notify_real(msg
, parent
.document
, no_hide
, is_err
);
145 function notify(msg
, no_hide
, is_err
) {
146 notify_real(msg
, document
, no_hide
, is_err
);
149 function printLockingError() {
150 notify("Please wait until operation finishes");}
154 function hotkey_handler(e
) {
158 if (!hotkeys_enabled
) return;
161 keycode
= window
.event
.keyCode
;
166 if (keycode
== 13 || keycode
== 27) {
169 seq
= seq
+ "" + keycode
;
172 if (document
.getElementById("piggie")) {
174 if (seq
.match("807371717369")) {
176 localPiggieFunction(true);
178 localPiggieFunction(false);
182 if (typeof localHotkeyHandler
!= 'undefined') {
184 localHotkeyHandler(keycode
);
186 exception_error("hotkey_handler", e
);
192 function cleanSelectedList(element
) {
193 var content
= document
.getElementById(element
);
195 if (!document
.getElementById("feedCatHolder")) {
196 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
197 var child
= content
.childNodes
[i
];
199 child
.className
= child
.className
.replace("Selected", "");
205 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
206 var child
= content
.childNodes
[i
];
207 if (child
.id
== "feedCatHolder") {
208 parent
.debug(child
.id
);
209 var fcat
= child
.lastChild
;
210 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
211 var feed
= fcat
.childNodes
[j
];
212 feed
.className
= feed
.className
.replace("Selected", "");
220 function cleanSelected(element
) {
221 var content
= document
.getElementById(element
);
223 for (i
= 0; i
< content
.rows
.length
; i
++) {
224 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
228 function getVisibleUnreadHeadlines() {
229 var content
= document
.getElementById("headlinesList");
231 var rows
= new Array();
233 for (i
= 0; i
< content
.rows
.length
; i
++) {
234 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
235 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
242 function getVisibleHeadlineIds() {
244 var content
= document
.getElementById("headlinesList");
246 var rows
= new Array();
248 for (i
= 0; i
< content
.rows
.length
; i
++) {
249 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
250 if (row_id
.length
> 0) {
257 function getFirstVisibleHeadlineId() {
258 var rows
= getVisibleHeadlineIds();
262 function getLastVisibleHeadlineId() {
263 var rows
= getVisibleHeadlineIds();
264 return rows
[rows
.length
-1];
267 function markHeadline(id
) {
268 var row
= document
.getElementById("RROW-" + id
);
270 var is_active
= false;
272 if (row
.className
.match("Active")) {
275 row
.className
= row
.className
.replace("Selected", "");
276 row
.className
= row
.className
.replace("Active", "");
277 row
.className
= row
.className
.replace("Insensitive", "");
280 row
.className
= row
.className
= "Active";
283 var check
= document
.getElementById("RCHK-" + id
);
286 check
.checked
= true;
289 row
.className
= row
.className
+ "Selected";
294 function getFeedIds() {
295 var content
= document
.getElementById("feedsList");
297 var rows
= new Array();
299 for (i
= 0; i
< content
.rows
.length
; i
++) {
300 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
309 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
315 d
.setTime(lifetime
* 1000);
318 int_setCookie(name
, value
, d
, path
, domain
, secure
);
322 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
323 document
.cookie
= name
+ "=" + escape(value
) +
324 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
325 ((path
) ? "; path=" + path
: "") +
326 ((domain
) ? "; domain=" + domain
: "") +
327 ((secure
) ? "; secure" : "");
330 function delCookie(name
, path
, domain
) {
331 if (getCookie(name
)) {
332 document
.cookie
= name
+ "=" +
333 ((path
) ? ";path=" + path
: "") +
334 ((domain
) ? ";domain=" + domain
: "" ) +
335 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
340 function getCookie(name
) {
342 var dc
= document
.cookie
;
343 var prefix
= name
+ "=";
344 var begin
= dc
.indexOf("; " + prefix
);
346 begin
= dc
.indexOf(prefix
);
347 if (begin
!= 0) return null;
352 var end
= document
.cookie
.indexOf(";", begin
);
356 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
359 function disableContainerChildren(id
, disable
, doc
) {
361 if (!doc
) doc
= document
;
363 var container
= doc
.getElementById(id
);
365 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
366 var child
= container
.childNodes
[i
];
369 child
.disabled
= disable
;
375 if (child
.className
&& child
.className
.match("button")) {
376 child
.className
= "disabledButton";
379 if (child
.className
&& child
.className
.match("disabledButton")) {
380 child
.className
= "button";
387 function gotoPreferences() {
388 document
.location
.href
= "prefs.php";
391 function gotoMain() {
392 document
.location
.href
= "tt-rss.php";
395 function gotoExportOpml() {
396 document
.location
.href
= "opml.php?op=Export";
399 function getActiveFeedId() {
400 return getCookie("ttrss_vf_actfeed");
403 function setActiveFeedId(id
) {
404 return setCookie("ttrss_vf_actfeed", id
);
407 var xmlhttp_rpc
= Ajax
.getTransport();
409 function parse_counters(reply
, f_document
, title_obj
, scheduled_call
) {
411 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
412 if (!reply
.childNodes
[l
] ||
413 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
414 // where did this come from?
418 var id
= reply
.childNodes
[l
].getAttribute("id");
419 var t
= reply
.childNodes
[l
].getAttribute("type");
420 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
421 var error
= reply
.childNodes
[l
].getAttribute("error");
422 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
423 var updated
= reply
.childNodes
[l
].getAttribute("updated");
425 if (id
== "global-unread") {
426 title_obj
.global_unread
= ctr
;
427 title_obj
.updateTitle();
431 if (t
== "category") {
432 var catctr
= f_document
.getElementById("FCATCTR-" + id
);
434 catctr
.innerHTML
= "(" + ctr
+ " unread)";
439 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
440 var feedu
= f_document
.getElementById("FEEDU-" + id
);
441 var feedr
= f_document
.getElementById("FEEDR-" + id
);
442 var feed_img
= f_document
.getElementById("FIMG-" + id
);
443 var feedlink
= f_document
.getElementById("FEEDL-" + id
);
445 if (updated
&& feedlink
) {
447 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
449 feedlink
.title
= "Updated: " + updated
;
453 if (feedctr
&& feedu
&& feedr
) {
455 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
456 var hf
= title_obj
.parent
.frames
["headlines-frame"];
457 hf
.location
.reload(true);
460 feedu
.innerHTML
= ctr
;
463 feedr
.className
= feedr
.className
.replace("feed", "error");
465 feedr
.className
= feedr
.className
.replace("error", "feed");
469 feedctr
.className
= "odd";
470 if (!feedr
.className
.match("Unread")) {
471 var is_selected
= feedr
.className
.match("Selected");
473 feedr
.className
= feedr
.className
.replace("Selected", "");
474 feedr
.className
= feedr
.className
.replace("Unread", "");
476 feedr
.className
= feedr
.className
+ "Unread";
479 feedr
.className
= feedr
.className
+ "Selected";
484 feedctr
.className
= "invisible";
485 feedr
.className
= feedr
.className
.replace("Unread", "");
490 exception_error("parse_counters", e
);
494 // this one is called from feedlist context
495 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
497 function all_counters_callback() {
498 if (xmlhttp_rpc
.readyState
== 4) {
500 if (!xmlhttp_rpc
.responseXML
|| !xmlhttp_rpc
.responseXML
.firstChild
) {
501 notify("[all_counters_callback] backend did not return valid XML");
505 if (!parent
.frames
["feeds-frame"]) {
506 notify("[all_counters_callback] no parent feeds-frame");
510 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
511 var f_document
= parent
.frames
["feeds-frame"].document
;
513 parse_counters(reply
, f_document
, parent
);
516 exception_error("all_counters_callback", e
);
521 function update_all_counters(feed
) {
522 if (xmlhttp_ready(xmlhttp_rpc
)) {
523 var query
= "backend.php?op=rpc&subop=getAllCounters";
526 query
= query
+ "&aid=" + feed
;
529 xmlhttp_rpc
.open("GET", query
, true);
530 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
531 xmlhttp_rpc
.send(null);
535 function popupHelp(tid
) {
536 var w
= window
.open("backend.php?op=help&tid=" + tid
,
538 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
541 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
542 * * @author Sundar Dorai-Raj
543 * * Email: sdoraira@vt.edu
544 * * This program is free software; you can redistribute it and/or
545 * * modify it under the terms of the GNU General Public License
546 * * as published by the Free Software Foundation; either version 2
547 * * of the License, or (at your option) any later version,
548 * * provided that any use properly credits the author.
549 * * This program is distributed in the hope that it will be useful,
550 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
551 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
552 * * GNU General Public License for more details at http://www.gnu.org * * */
554 var numbers
=".0123456789";
555 function isNumeric(x
) {
556 // is x a String or a character?
558 // remove negative sign
560 for(j
=0;j
<x
.length
;j
++) {
561 // call isNumeric recursively for each character
562 number
=isNumeric(x
.substring(j
,j
+1));
563 if(!number
) return number
;
568 // if x is number return true
569 if(numbers
.indexOf(x
)>=0) return true;
575 function hideOrShowFeeds(doc
, hide
) {
577 if (!doc
.styleSheets
) return;
579 var css_rules
= doc
.styleSheets
[0].cssRules
;
581 if (!css_rules
|| !css_rules
.length
) return;
583 for (i
= 0; i
< css_rules
.length
; i
++) {
584 var rule
= css_rules
[i
];
586 if (rule
.selectorText
== "ul.feedList li.feed") {
588 rule
.style
.display
= "block";
590 rule
.style
.display
= "none";
598 function selectTableRow(r
, do_select
) {
599 r
.className
= r
.className
.replace("Selected", "");
602 r
.className
= r
.className
+ "Selected";
606 function selectTableRowById(elem_id
, check_id
, do_select
) {
610 var row
= document
.getElementById(elem_id
);
613 selectTableRow(row
, do_select
);
616 var check
= document
.getElementById(check_id
);
619 check
.checked
= do_select
;
622 exception_error("selectTableRowById", e
);
626 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
627 classcheck
, reset_others
) {
629 var content
= document
.getElementById(content_id
);
632 alert("[selectTableRows] Element " + content_id
+ " not found.");
636 for (i
= 0; i
< content
.rows
.length
; i
++) {
637 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
639 if (content
.rows
[i
].id
.match(prefix
)) {
640 selectTableRow(content
.rows
[i
], do_select
);
642 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
643 var check
= document
.getElementById(check_prefix
+ row_id
);
646 check
.checked
= do_select
;
648 } else if (reset_others
) {
649 selectTableRow(content
.rows
[i
], false);
651 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
652 var check
= document
.getElementById(check_prefix
+ row_id
);
655 check
.checked
= false;
659 } else if (reset_others
) {
660 selectTableRow(content
.rows
[i
], false);
662 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
663 var check
= document
.getElementById(check_prefix
+ row_id
);
666 check
.checked
= false;
673 function getSelectedTableRowIds(content_id
, prefix
) {
675 var content
= document
.getElementById(content_id
);
678 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
682 var sel_rows
= new Array();
684 for (i
= 0; i
< content
.rows
.length
; i
++) {
685 if (content
.rows
[i
].id
.match(prefix
) &&
686 content
.rows
[i
].className
.match("Selected")) {
688 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
689 sel_rows
.push(row_id
);
697 function toggleSelectRowById(sender
, id
) {
698 var row
= document
.getElementById(id
);
700 if (sender
.checked
) {
701 if (!row
.className
.match("Selected")) {
702 row
.className
= row
.className
+ "Selected";
705 if (row
.className
.match("Selected")) {
706 row
.className
= row
.className
.replace("Selected", "");
711 function toggleSelectListRow(sender
) {
712 var parent_row
= sender
.parentNode
;
714 if (sender
.checked
) {
715 if (!parent_row
.className
.match("Selected")) {
716 parent_row
.className
= parent_row
.className
+ "Selected";
719 if (parent_row
.className
.match("Selected")) {
720 parent_row
.className
= parent_row
.className
.replace("Selected", "");
726 function toggleSelectRow(sender
) {
727 var parent_row
= sender
.parentNode
.parentNode
;
729 if (sender
.checked
) {
730 if (!parent_row
.className
.match("Selected")) {
731 parent_row
.className
= parent_row
.className
+ "Selected";
734 if (parent_row
.className
.match("Selected")) {
735 parent_row
.className
= parent_row
.className
.replace("Selected", "");
740 function openExternalUrl(url
) {
741 var w
= window
.open(url
);
744 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
746 if (direction
== "next") {
747 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
748 var child
= list
.childNodes
[i
];
749 if (child
.id
&& child
.id
== "feedCatHolder") {
750 if (child
.lastChild
) {
751 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
754 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
755 return child
.id
.replace('FEEDR-', '');
760 // FIXME select last feed doesn't work when only unread feeds are visible
762 if (direction
== "prev") {
763 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
764 var child
= list
.childNodes
[i
];
765 if (child
.id
== "feedCatHolder") {
766 if (child
.firstChild
) {
767 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
770 } else if (child
.id
.match("FEEDR-")) {
772 if (getCookie("ttrss_vf_hreadf") == 1) {
773 if (child
.className
!= "feed") {
774 alert(child
.className
);
775 return child
.id
.replace('FEEDR-', '');
778 return child
.id
.replace('FEEDR-', '');
785 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + getActiveFeedId());
787 if (getCookie("ttrss_vf_hreadf") == 1) {
791 if (direction
== "next") {
801 } else if (e
.parentNode
.parentNode
.nextSibling
) {
803 var this_cat
= e
.parentNode
.parentNode
;
807 if (this_cat
&& this_cat
.nextSibling
) {
808 while (!e
&& this_cat
.nextSibling
) {
809 this_cat
= this_cat
.nextSibling
;
810 if (this_cat
.id
== "feedCatHolder") {
811 e
= this_cat
.firstChild
.firstChild
;
821 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
822 e
.className
!= "error")) {
823 return e
.id
.replace("FEEDR-", "");
828 } else if (direction
== "prev") {
834 if (e
.previousSibling
) {
836 e
= e
.previousSibling
;
838 } else if (e
.parentNode
.parentNode
.previousSibling
) {
840 var this_cat
= e
.parentNode
.parentNode
;
844 if (this_cat
&& this_cat
.previousSibling
) {
845 while (!e
&& this_cat
.previousSibling
) {
846 this_cat
= this_cat
.previousSibling
;
847 if (this_cat
.id
== "feedCatHolder") {
848 e
= this_cat
.firstChild
.lastChild
;
858 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
859 e
.className
!= "error")) {
860 return e
.id
.replace("FEEDR-", "");
868 function showBlockElement(id
) {
869 var elem
= document
.getElementById(id
);
872 elem
.style
.display
= "block";
874 alert("[showBlockElement] can't find element with id " + id
);
878 function hideParentElement(e
) {
879 e
.parentNode
.style
.display
= "none";
882 function dropboxSelect(e
, v
) {
883 for (i
= 0; i
< e
.length
; i
++) {
884 if (e
[i
].value
== v
) {
891 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
892 // bugfixed just a little bit :-)
893 function getURLParam(strParamName
){
895 var strHref
= window
.location
.href
;
897 if (strHref
.indexOf("#") == strHref
.length
-1) {
898 strHref
= strHref
.substring(0, strHref
.length
-1);
901 if ( strHref
.indexOf("?") > -1 ){
902 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
903 var aQueryString
= strQueryString
.split("&");
904 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
905 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
906 var aParam
= aQueryString
[iParam
].split("=");
907 strReturn
= aParam
[1];
915 function leading_zero(p
) {
917 if (s
.length
== 1) s
= "0" + s
;
921 function closeInfoBox() {
922 var box
= document
.getElementById('infoBox');
923 var shadow
= document
.getElementById('infoBoxShadow');
926 shadow
.style
.display
= "none";
928 box
.style
.display
= "none";
936 function displayDlg(id
, param
) {
938 if (!xmlhttp_ready(xmlhttp
)) {
945 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
946 param_escape(id
) + "¶m=" + param_escape(param
), true);
947 xmlhttp
.onreadystatechange
=infobox_callback
;
954 function infobox_submit_callback() {
955 if (xmlhttp
.readyState
== 4) {
958 // called from prefs, reload tab
960 selectTab(active_tab
, false);
963 notify(xmlhttp
.responseText
);
968 function infobox_callback() {
969 if (xmlhttp
.readyState
== 4) {
970 var box
= document
.getElementById('infoBox');
971 var shadow
= document
.getElementById('infoBoxShadow');
973 box
.innerHTML
=xmlhttp
.responseText
;
975 shadow
.style
.display
= "block";
977 box
.style
.display
= "block";
983 function qaddFilter() {
985 if (!xmlhttp_ready(xmlhttp
)) {
990 var query
= Form
.serialize("filter_add_form");
992 xmlhttp
.open("GET", "backend.php?" + query
, true);
993 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
999 function toggleSubmitNotEmpty(e
, submit_id
) {
1001 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1003 exception_error("toggleSubmitNotEmpty", e
);
1007 function isValidURL(s
) {
1008 return s
.match("http://") != null || s
.match("https://") != null;
1013 if (!xmlhttp_ready(xmlhttp
)) {
1014 printLockingError();
1018 notify("Adding feed...");
1022 var feeds_doc
= window
.frames
["feeds-frame"].document
;
1024 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
1026 var query
= Form
.serialize("feed_add_form");
1028 xmlhttp
.open("GET", "backend.php?" + query
, true);
1029 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;