]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var hotkeys_enabled
= true;
3 function exception_error(location
, e
) {
7 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
9 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
10 "\nFunction: " + location
+ "()" +
11 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
13 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
19 function disableHotkeys() {
20 hotkeys_enabled
= false;
23 function enableHotkeys() {
24 hotkeys_enabled
= true;
27 function xmlhttp_ready(obj
) {
28 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
32 function notify_callback() {
33 var container
= document
.getElementById('notify');
34 if (xmlhttp
.readyState
== 4) {
35 container
.innerHTML
=xmlhttp
.responseText
;
39 function rpc_notify_callback() {
40 var container
= document
.getElementById('notify');
41 if (xmlhttp_rpc
.readyState
== 4) {
42 container
.innerHTML
=xmlhttp_rpc
.responseText
;
46 function rpc_pnotify_callback() {
47 var container
= parent
.document
.getElementById('notify');
48 if (xmlhttp_rpc
.readyState
== 4) {
49 container
.innerHTML
=xmlhttp_rpc
.responseText
;
53 function param_escape(arg
) {
54 if (typeof encodeURIComponent
!= 'undefined')
55 return encodeURIComponent(arg
);
60 function param_unescape(arg
) {
61 if (typeof decodeURIComponent
!= 'undefined')
62 return decodeURIComponent(arg
);
69 then
=new Date().getTime();
71 while((now
-then
)<gap
) {
72 now
=new Date().getTime();
76 function p_notify(msg
) {
78 var n
= parent
.document
.getElementById("notify");
79 var nb
= parent
.document
.getElementById("notify_body");
81 if (!n
|| !nb
) return;
84 nb
.innerHTML
= " ";
85 // n.style.background = "#ffffff";
88 // n.style.background = "#fffff0";
92 function notify(msg
) {
94 var n
= document
.getElementById("notify");
95 var nb
= document
.getElementById("notify_body");
97 if (!n
|| !nb
) return;
100 nb
.innerHTML
= " ";
101 // n.style.background = "#ffffff";
104 // n.style.background = "#fffff0";
109 function printLockingError() {
110 notify("Please wait until operation finishes");}
114 function hotkey_handler(e
) {
118 if (!hotkeys_enabled
) return;
121 keycode
= window
.event
.keyCode
;
126 if (keycode
== 13 || keycode
== 27) {
129 seq
= seq
+ "" + keycode
;
132 if (document
.getElementById("piggie")) {
134 if (seq
.match("807371717369")) {
136 localPiggieFunction(true);
138 localPiggieFunction(false);
142 if (typeof localHotkeyHandler
!= 'undefined') {
144 localHotkeyHandler(keycode
);
146 exception_error("hotkey_handler", e
);
152 function cleanSelectedList(element
) {
153 var content
= document
.getElementById(element
);
155 if (!document
.getElementById("feedCatHolder")) {
156 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
157 var child
= content
.childNodes
[i
];
159 child
.className
= child
.className
.replace("Selected", "");
165 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
166 var child
= content
.childNodes
[i
];
168 if (child
.id
== "feedCatHolder") {
169 var fcat
= child
.lastChild
;
170 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
171 var feed
= fcat
.childNodes
[j
];
172 feed
.className
= feed
.className
.replace("Selected", "");
181 function cleanSelected(element
) {
182 var content
= document
.getElementById(element
);
184 for (i
= 0; i
< content
.rows
.length
; i
++) {
185 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
190 function getVisibleUnreadHeadlines() {
191 var content
= document
.getElementById("headlinesList");
193 var rows
= new Array();
195 for (i
= 0; i
< content
.rows
.length
; i
++) {
196 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
197 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
204 function getVisibleHeadlineIds() {
206 var content
= document
.getElementById("headlinesList");
208 var rows
= new Array();
210 for (i
= 0; i
< content
.rows
.length
; i
++) {
211 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
212 if (row_id
.length
> 0) {
219 function getFirstVisibleHeadlineId() {
220 var rows
= getVisibleHeadlineIds();
224 function getLastVisibleHeadlineId() {
225 var rows
= getVisibleHeadlineIds();
226 return rows
[rows
.length
-1];
229 function markHeadline(id
) {
230 var row
= document
.getElementById("RROW-" + id
);
232 var is_active
= false;
234 if (row
.className
.match("Active")) {
237 row
.className
= row
.className
.replace("Selected", "");
238 row
.className
= row
.className
.replace("Active", "");
239 row
.className
= row
.className
.replace("Insensitive", "");
242 row
.className
= row
.className
= "Active";
245 row
.className
= row
.className
+ "Selected";
250 function getFeedIds() {
251 var content
= document
.getElementById("feedsList");
253 var rows
= new Array();
255 for (i
= 0; i
< content
.rows
.length
; i
++) {
256 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
265 function setCookie(name
, value
, expires
, path
, domain
, secure
) {
266 document
.cookie
= name
+ "=" + escape(value
) +
267 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
268 ((path
) ? "; path=" + path
: "") +
269 ((domain
) ? "; domain=" + domain
: "") +
270 ((secure
) ? "; secure" : "");
273 function getCookie(name
) {
275 var dc
= document
.cookie
;
276 var prefix
= name
+ "=";
277 var begin
= dc
.indexOf("; " + prefix
);
279 begin
= dc
.indexOf(prefix
);
280 if (begin
!= 0) return null;
285 var end
= document
.cookie
.indexOf(";", begin
);
289 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
292 function disableContainerChildren(id
, disable
, doc
) {
294 if (!doc
) doc
= document
;
296 var container
= doc
.getElementById(id
);
298 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
299 var child
= container
.childNodes
[i
];
302 child
.disabled
= disable
;
308 if (child
.className
&& child
.className
.match("button")) {
309 child
.className
= "disabledButton";
312 if (child
.className
&& child
.className
.match("disabledButton")) {
313 child
.className
= "button";
320 function gotoPreferences() {
321 document
.location
.href
= "prefs.php";
324 function gotoMain() {
325 document
.location
.href
= "tt-rss.php";
328 function gotoExportOpml() {
329 document
.location
.href
= "opml.php?op=Export";
332 function getActiveFeedId() {
333 return getCookie("ttrss_vf_actfeed");
336 function setActiveFeedId(id
) {
337 return setCookie("ttrss_vf_actfeed", id
);
340 var xmlhttp_rpc
= false;
343 /*@if (@_jscript_version >= 5)
344 // JScript gives us Conditional compilation, we can cope with old IE versions.
345 // and security blocked creation of the objects.
347 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
350 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
357 if (!xmlhttp_rpc
&& typeof XMLHttpRequest
!='undefined') {
358 xmlhttp_rpc
= new XMLHttpRequest();
361 function parse_counters(reply
, f_document
, title_obj
) {
363 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
364 if (!reply
.childNodes
[l
] ||
365 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
366 // where did this come from?
370 var id
= reply
.childNodes
[l
].getAttribute("id");
371 var t
= reply
.childNodes
[l
].getAttribute("type");
372 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
373 var error
= reply
.childNodes
[l
].getAttribute("error");
374 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
376 if (id
== "global-unread") {
377 title_obj
.global_unread
= ctr
;
378 title_obj
.updateTitle();
382 if (t
== "category") {
383 var catctr
= f_document
.getElementById("FCATCTR-" + id
);
385 catctr
.innerHTML
= "(" + ctr
+ " unread)";
390 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
391 var feedu
= f_document
.getElementById("FEEDU-" + id
);
392 var feedr
= f_document
.getElementById("FEEDR-" + id
);
393 var feed_img
= f_document
.getElementById("FIMG-" + id
);
395 if (feedctr
&& feedu
&& feedr
) {
397 feedu
.innerHTML
= ctr
;
400 feedr
.className
= feedr
.className
.replace("feed", "error");
402 feedr
.className
= feedr
.className
.replace("error", "feed");
406 feedctr
.className
= "odd";
407 if (!feedr
.className
.match("Unread")) {
408 var is_selected
= feedr
.className
.match("Selected");
410 feedr
.className
= feedr
.className
.replace("Selected", "");
411 feedr
.className
= feedr
.className
.replace("Unread", "");
413 feedr
.className
= feedr
.className
+ "Unread";
416 feedr
.className
= feedr
.className
+ "Selected";
421 feedctr
.className
= "invisible";
422 feedr
.className
= feedr
.className
.replace("Unread", "");
427 exception_error("parse_counters", e
);
431 // this one is called from feedlist context
432 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
434 function all_counters_callback() {
435 if (xmlhttp_rpc
.readyState
== 4) {
437 if (!xmlhttp_rpc
.responseXML
|| !xmlhttp_rpc
.responseXML
.firstChild
) {
438 notify("[all_counters_callback] backend did not return valid XML");
442 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
443 var f_document
= parent
.frames
["feeds-frame"].document
;
445 parse_counters(reply
, f_document
, parent
);
448 exception_error("all_counters_callback", e
);
453 function update_all_counters(feed
) {
454 if (xmlhttp_ready(xmlhttp_rpc
)) {
455 var query
= "backend.php?op=rpc&subop=getAllCounters";
458 query
= query
+ "&aid=" + feed
;
461 xmlhttp_rpc
.open("GET", query
, true);
462 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
463 xmlhttp_rpc
.send(null);
467 function popupHelp(tid
) {
468 var w
= window
.open("backend.php?op=help&tid=" + tid
,
470 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
473 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
474 * * @author Sundar Dorai-Raj
475 * * Email: sdoraira@vt.edu
476 * * This program is free software; you can redistribute it and/or
477 * * modify it under the terms of the GNU General Public License
478 * * as published by the Free Software Foundation; either version 2
479 * * of the License, or (at your option) any later version,
480 * * provided that any use properly credits the author.
481 * * This program is distributed in the hope that it will be useful,
482 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
483 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
484 * * GNU General Public License for more details at http://www.gnu.org * * */
486 var numbers
=".0123456789";
487 function isNumeric(x
) {
488 // is x a String or a character?
490 // remove negative sign
492 for(j
=0;j
<x
.length
;j
++) {
493 // call isNumeric recursively for each character
494 number
=isNumeric(x
.substring(j
,j
+1));
495 if(!number
) return number
;
500 // if x is number return true
501 if(numbers
.indexOf(x
)>=0) return true;
507 function hideOrShowFeeds(doc
, hide
) {
509 if (!doc
.styleSheets
) return;
511 var css_rules
= doc
.styleSheets
[0].cssRules
;
513 if (!css_rules
|| !css_rules
.length
) return;
515 for (i
= 0; i
< css_rules
.length
; i
++) {
516 var rule
= css_rules
[i
];
518 if (rule
.selectorText
== "ul.feedList li.feed") {
520 rule
.style
.display
= "block";
522 rule
.style
.display
= "none";
530 function fatalError(code
, params
) {
532 window
.location
= "error.php?c=" + param_escape(code
);
534 window
.location
= "error.php?c=" + param_escape(code
) +
535 "&p=" + param_escape(params
);
539 function selectTableRow(r
, do_select
) {
540 r
.className
= r
.className
.replace("Selected", "");
543 r
.className
= r
.className
+ "Selected";
547 function selectTableRowById(elem_id
, check_id
, do_select
) {
551 var row
= document
.getElementById(elem_id
);
554 selectTableRow(row
, do_select
);
557 var check
= document
.getElementById(check_id
);
560 check
.checked
= do_select
;
563 exception_error("selectTableRowById", e
);
567 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
568 classcheck
, reset_others
) {
570 var content
= document
.getElementById(content_id
);
573 alert("[selectTableRows] Element " + content_id
+ " not found.");
577 for (i
= 0; i
< content
.rows
.length
; i
++) {
578 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
580 if (content
.rows
[i
].id
.match(prefix
)) {
581 selectTableRow(content
.rows
[i
], do_select
);
583 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
584 var check
= document
.getElementById(check_prefix
+ row_id
);
587 check
.checked
= do_select
;
589 } else if (reset_others
) {
590 selectTableRow(content
.rows
[i
], false);
592 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
593 var check
= document
.getElementById(check_prefix
+ row_id
);
596 check
.checked
= false;
600 } else if (reset_others
) {
601 selectTableRow(content
.rows
[i
], false);
603 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
604 var check
= document
.getElementById(check_prefix
+ row_id
);
607 check
.checked
= false;
614 function getSelectedTableRowIds(content_id
, prefix
) {
616 var content
= document
.getElementById(content_id
);
619 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
623 var sel_rows
= new Array();
625 for (i
= 0; i
< content
.rows
.length
; i
++) {
626 if (content
.rows
[i
].id
.match(prefix
) &&
627 content
.rows
[i
].className
.match("Selected")) {
629 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
630 sel_rows
.push(row_id
);
638 function toggleSelectRowById(sender
, id
) {
639 var row
= document
.getElementById(id
);
641 if (sender
.checked
) {
642 if (!row
.className
.match("Selected")) {
643 row
.className
= row
.className
+ "Selected";
646 if (row
.className
.match("Selected")) {
647 row
.className
= row
.className
.replace("Selected", "");
652 function toggleSelectListRow(sender
) {
653 var parent_row
= sender
.parentNode
;
655 if (sender
.checked
) {
656 if (!parent_row
.className
.match("Selected")) {
657 parent_row
.className
= parent_row
.className
+ "Selected";
660 if (parent_row
.className
.match("Selected")) {
661 parent_row
.className
= parent_row
.className
.replace("Selected", "");
667 function toggleSelectRow(sender
) {
668 var parent_row
= sender
.parentNode
.parentNode
;
670 if (sender
.checked
) {
671 if (!parent_row
.className
.match("Selected")) {
672 parent_row
.className
= parent_row
.className
+ "Selected";
675 if (parent_row
.className
.match("Selected")) {
676 parent_row
.className
= parent_row
.className
.replace("Selected", "");
681 function openExternalUrl(url
) {
682 var w
= window
.open(url
);
686 function getRelativeFeedId(list
, id
, direction
) {
688 if (direction
== "next") {
689 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
690 var child
= list
.childNodes
[i
];
691 if (child
.id
== "feedCatHolder") {
692 if (child
.lastChild
) {
693 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
696 } else if (child
.id
.match("FEEDR-")) {
697 return child
.id
.replace('FEEDR-', '');
702 // FIXME select last feed doesn't work when only unread feeds are visible
704 if (direction
== "prev") {
705 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
706 var child
= list
.childNodes
[i
];
707 if (child
.id
== "feedCatHolder") {
708 if (child
.firstChild
) {
709 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
712 } else if (child
.id
.match("FEEDR-")) {
714 if (getCookie("ttrss_vf_hreadf") == 1) {
715 if (child
.className
!= "feed") {
716 alert(child
.className
);
717 return child
.id
.replace('FEEDR-', '');
720 return child
.id
.replace('FEEDR-', '');
727 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + getActiveFeedId());
729 if (direction
== "next") {
731 if (feed
.nextSibling
) {
733 var next_feed
= feed
.nextSibling
;
735 while (!next_feed
.id
&& next_feed
.nextSibling
) {
736 next_feed
= next_feed
.nextSibling
;
739 if (getCookie("ttrss_vf_hreadf") == 1) {
740 while (next_feed
&& next_feed
.className
== "feed") {
741 next_feed
= next_feed
.nextSibling
;
745 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
746 return next_feed
.id
.replace("FEEDR-", "");
750 var this_cat
= feed
.parentNode
.parentNode
;
752 if (this_cat
&& this_cat
.nextSibling
) {
753 while (this_cat
= this_cat
.nextSibling
) {
754 if (this_cat
.firstChild
&& this_cat
.firstChild
.firstChild
) {
755 var next_feed
= this_cat
.firstChild
.firstChild
;
756 if (getCookie("ttrss_vf_hreadf") == 1) {
757 while (next_feed
&& next_feed
.className
== "feed") {
758 next_feed
= next_feed
.nextSibling
;
761 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
762 return next_feed
.id
.replace("FEEDR-", "");
767 } else if (direction
== "prev") {
769 if (feed
.previousSibling
) {
771 var prev_feed
= feed
.previousSibling
;
773 if (getCookie("ttrss_vf_hreadf") == 1) {
774 while (prev_feed
&& prev_feed
.className
== "feed") {
775 prev_feed
= prev_feed
.previousSibling
;
779 while (!prev_feed
.id
&& prev_feed
.previousSibling
) {
780 prev_feed
= prev_feed
.previousSibling
;
783 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
784 return prev_feed
.id
.replace("FEEDR-", "");
788 var this_cat
= feed
.parentNode
.parentNode
;
790 if (this_cat
&& this_cat
.previousSibling
) {
791 while (this_cat
= this_cat
.previousSibling
) {
792 if (this_cat
.lastChild
&& this_cat
.firstChild
.lastChild
) {
793 var prev_feed
= this_cat
.firstChild
.lastChild
;
794 if (getCookie("ttrss_vf_hreadf") == 1) {
795 while (prev_feed
&& prev_feed
.className
== "feed") {
796 prev_feed
= prev_feed
.previousSibling
;
799 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
800 return prev_feed
.id
.replace("FEEDR-", "");
809 function showBlockElement(id
) {
810 var elem
= document
.getElementById(id
);
813 elem
.style
.display
= "block";
815 alert("[showBlockElement] can't find element with id " + id
);
819 function hideParentElement(e
) {
820 e
.parentNode
.style
.display
= "none";
823 function dropboxSelect(e
, v
) {
824 for (i
= 0; i
< e
.length
; i
++) {
825 if (e
[i
].value
== v
) {
832 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
833 // bugfixed just a little bit :-)
834 function getURLParam(strParamName
){
836 var strHref
= window
.location
.href
;
838 if (strHref
.indexOf("#") == strHref
.length
-1) {
839 strHref
= strHref
.substring(0, strHref
.length
-1);
842 if ( strHref
.indexOf("?") > -1 ){
843 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
844 var aQueryString
= strQueryString
.split("&");
845 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
846 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
847 var aParam
= aQueryString
[iParam
].split("=");
848 strReturn
= aParam
[1];
856 function leading_zero(p
) {
858 if (s
.length
== 1) s
= "0" + s
;