]>
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
];
158 child
.className
= child
.className
.replace("Selected", "");
161 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
162 var child
= content
.childNodes
[i
];
164 if (child
.id
== "feedCatHolder") {
165 var fcat
= child
.lastChild
;
166 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
167 var feed
= fcat
.childNodes
[j
];
168 feed
.className
= feed
.className
.replace("Selected", "");
177 function cleanSelected(element
) {
178 var content
= document
.getElementById(element
);
180 for (i
= 0; i
< content
.rows
.length
; i
++) {
181 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
186 function getVisibleUnreadHeadlines() {
187 var content
= document
.getElementById("headlinesList");
189 var rows
= new Array();
191 for (i
= 0; i
< content
.rows
.length
; i
++) {
192 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
193 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
200 function getVisibleHeadlineIds() {
202 var content
= document
.getElementById("headlinesList");
204 var rows
= new Array();
206 for (i
= 0; i
< content
.rows
.length
; i
++) {
207 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
208 if (row_id
.length
> 0) {
215 function getFirstVisibleHeadlineId() {
216 var rows
= getVisibleHeadlineIds();
220 function getLastVisibleHeadlineId() {
221 var rows
= getVisibleHeadlineIds();
222 return rows
[rows
.length
-1];
225 function markHeadline(id
) {
226 var row
= document
.getElementById("RROW-" + id
);
228 var is_active
= false;
230 if (row
.className
.match("Active")) {
233 row
.className
= row
.className
.replace("Selected", "");
234 row
.className
= row
.className
.replace("Active", "");
235 row
.className
= row
.className
.replace("Insensitive", "");
238 row
.className
= row
.className
= "Active";
241 row
.className
= row
.className
+ "Selected";
246 function getFeedIds() {
247 var content
= document
.getElementById("feedsList");
249 var rows
= new Array();
251 for (i
= 0; i
< content
.rows
.length
; i
++) {
252 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
261 function setCookie(name
, value
, expires
, path
, domain
, secure
) {
262 document
.cookie
= name
+ "=" + escape(value
) +
263 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
264 ((path
) ? "; path=" + path
: "") +
265 ((domain
) ? "; domain=" + domain
: "") +
266 ((secure
) ? "; secure" : "");
269 function getCookie(name
) {
271 var dc
= document
.cookie
;
272 var prefix
= name
+ "=";
273 var begin
= dc
.indexOf("; " + prefix
);
275 begin
= dc
.indexOf(prefix
);
276 if (begin
!= 0) return null;
281 var end
= document
.cookie
.indexOf(";", begin
);
285 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
288 function disableContainerChildren(id
, disable
, doc
) {
290 if (!doc
) doc
= document
;
292 var container
= doc
.getElementById(id
);
294 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
295 var child
= container
.childNodes
[i
];
298 child
.disabled
= disable
;
304 if (child
.className
&& child
.className
.match("button")) {
305 child
.className
= "disabledButton";
308 if (child
.className
&& child
.className
.match("disabledButton")) {
309 child
.className
= "button";
316 function gotoPreferences() {
317 document
.location
.href
= "prefs.php";
320 function gotoMain() {
321 document
.location
.href
= "tt-rss.php";
324 function gotoExportOpml() {
325 document
.location
.href
= "opml.php?op=Export";
328 function getActiveFeedId() {
329 return getCookie("ttrss_vf_actfeed");
332 function setActiveFeedId(id
) {
333 return setCookie("ttrss_vf_actfeed", id
);
336 var xmlhttp_rpc
= false;
339 /*@if (@_jscript_version >= 5)
340 // JScript gives us Conditional compilation, we can cope with old IE versions.
341 // and security blocked creation of the objects.
343 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
346 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
353 if (!xmlhttp_rpc
&& typeof XMLHttpRequest
!='undefined') {
354 xmlhttp_rpc
= new XMLHttpRequest();
357 function parse_counters(reply
, f_document
, title_obj
) {
359 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
360 if (!reply
.childNodes
[l
] ||
361 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
362 // where did this come from?
366 var id
= reply
.childNodes
[l
].getAttribute("id");
367 var t
= reply
.childNodes
[l
].getAttribute("type");
368 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
369 var error
= reply
.childNodes
[l
].getAttribute("error");
370 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
372 if (id
== "global-unread") {
373 title_obj
.global_unread
= ctr
;
374 title_obj
.updateTitle();
378 if (t
== "category") {
379 var catctr
= f_document
.getElementById("FCATCTR-" + id
);
381 catctr
.innerHTML
= "(" + ctr
+ " unread)";
386 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
387 var feedu
= f_document
.getElementById("FEEDU-" + id
);
388 var feedr
= f_document
.getElementById("FEEDR-" + id
);
389 var feed_img
= f_document
.getElementById("FIMG-" + id
);
391 if (feedctr
&& feedu
&& feedr
) {
393 feedu
.innerHTML
= ctr
;
396 feedr
.className
= feedr
.className
.replace("feed", "error");
398 feedr
.className
= feedr
.className
.replace("error", "feed");
402 feedctr
.className
= "odd";
403 if (!feedr
.className
.match("Unread")) {
404 var is_selected
= feedr
.className
.match("Selected");
406 feedr
.className
= feedr
.className
.replace("Selected", "");
407 feedr
.className
= feedr
.className
.replace("Unread", "");
409 feedr
.className
= feedr
.className
+ "Unread";
412 feedr
.className
= feedr
.className
+ "Selected";
417 feedctr
.className
= "invisible";
418 feedr
.className
= feedr
.className
.replace("Unread", "");
423 exception_error("parse_counters", e
);
427 // this one is called from feedlist context
428 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
430 function all_counters_callback() {
431 if (xmlhttp_rpc
.readyState
== 4) {
433 if (!xmlhttp_rpc
.responseXML
|| !xmlhttp_rpc
.responseXML
.firstChild
) {
434 notify("[all_counters_callback] backend did not return valid XML");
438 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
439 var f_document
= parent
.frames
["feeds-frame"].document
;
441 parse_counters(reply
, f_document
, parent
);
444 exception_error("all_counters_callback", e
);
449 function update_all_counters(feed
) {
450 if (xmlhttp_ready(xmlhttp_rpc
)) {
451 var query
= "backend.php?op=rpc&subop=getAllCounters";
454 query
= query
+ "&aid=" + feed
;
457 xmlhttp_rpc
.open("GET", query
, true);
458 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
459 xmlhttp_rpc
.send(null);
463 function popupHelp(tid
) {
464 var w
= window
.open("backend.php?op=help&tid=" + tid
,
466 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
469 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
470 * * @author Sundar Dorai-Raj
471 * * Email: sdoraira@vt.edu
472 * * This program is free software; you can redistribute it and/or
473 * * modify it under the terms of the GNU General Public License
474 * * as published by the Free Software Foundation; either version 2
475 * * of the License, or (at your option) any later version,
476 * * provided that any use properly credits the author.
477 * * This program is distributed in the hope that it will be useful,
478 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
479 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
480 * * GNU General Public License for more details at http://www.gnu.org * * */
482 var numbers
=".0123456789";
483 function isNumeric(x
) {
484 // is x a String or a character?
486 // remove negative sign
488 for(j
=0;j
<x
.length
;j
++) {
489 // call isNumeric recursively for each character
490 number
=isNumeric(x
.substring(j
,j
+1));
491 if(!number
) return number
;
496 // if x is number return true
497 if(numbers
.indexOf(x
)>=0) return true;
503 function hideOrShowFeeds(doc
, hide
) {
505 if (!doc
.styleSheets
) return;
507 var css_rules
= doc
.styleSheets
[0].cssRules
;
509 if (!css_rules
|| !css_rules
.length
) return;
511 for (i
= 0; i
< css_rules
.length
; i
++) {
512 var rule
= css_rules
[i
];
514 if (rule
.selectorText
== "ul.feedList li.feed") {
516 rule
.style
.display
= "block";
518 rule
.style
.display
= "none";
526 function fatalError(code
, params
) {
528 window
.location
= "error.php?c=" + param_escape(code
);
530 window
.location
= "error.php?c=" + param_escape(code
) +
531 "&p=" + param_escape(params
);
535 function selectTableRow(r
, do_select
) {
536 r
.className
= r
.className
.replace("Selected", "");
539 r
.className
= r
.className
+ "Selected";
543 function selectTableRowById(elem_id
, check_id
, do_select
) {
547 var row
= document
.getElementById(elem_id
);
550 selectTableRow(row
, do_select
);
553 var check
= document
.getElementById(check_id
);
556 check
.checked
= do_select
;
559 exception_error("selectTableRowById", e
);
563 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
564 classcheck
, reset_others
) {
566 var content
= document
.getElementById(content_id
);
569 alert("[selectTableRows] Element " + content_id
+ " not found.");
573 for (i
= 0; i
< content
.rows
.length
; i
++) {
574 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
576 if (content
.rows
[i
].id
.match(prefix
)) {
577 selectTableRow(content
.rows
[i
], do_select
);
579 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
580 var check
= document
.getElementById(check_prefix
+ row_id
);
583 check
.checked
= do_select
;
585 } else if (reset_others
) {
586 selectTableRow(content
.rows
[i
], false);
588 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
589 var check
= document
.getElementById(check_prefix
+ row_id
);
592 check
.checked
= false;
596 } else if (reset_others
) {
597 selectTableRow(content
.rows
[i
], false);
599 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
600 var check
= document
.getElementById(check_prefix
+ row_id
);
603 check
.checked
= false;
610 function getSelectedTableRowIds(content_id
, prefix
) {
612 var content
= document
.getElementById(content_id
);
615 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
619 var sel_rows
= new Array();
621 for (i
= 0; i
< content
.rows
.length
; i
++) {
622 if (content
.rows
[i
].id
.match(prefix
) &&
623 content
.rows
[i
].className
.match("Selected")) {
625 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
626 sel_rows
.push(row_id
);
634 function toggleSelectRowById(sender
, id
) {
635 var row
= document
.getElementById(id
);
637 if (sender
.checked
) {
638 if (!row
.className
.match("Selected")) {
639 row
.className
= row
.className
+ "Selected";
642 if (row
.className
.match("Selected")) {
643 row
.className
= row
.className
.replace("Selected", "");
648 function toggleSelectListRow(sender
) {
649 var parent_row
= sender
.parentNode
;
651 if (sender
.checked
) {
652 if (!parent_row
.className
.match("Selected")) {
653 parent_row
.className
= parent_row
.className
+ "Selected";
656 if (parent_row
.className
.match("Selected")) {
657 parent_row
.className
= parent_row
.className
.replace("Selected", "");
663 function toggleSelectRow(sender
) {
664 var parent_row
= sender
.parentNode
.parentNode
;
666 if (sender
.checked
) {
667 if (!parent_row
.className
.match("Selected")) {
668 parent_row
.className
= parent_row
.className
+ "Selected";
671 if (parent_row
.className
.match("Selected")) {
672 parent_row
.className
= parent_row
.className
.replace("Selected", "");
677 function openExternalUrl(url
) {
678 var w
= window
.open(url
);
682 function getRelativeFeedId(list
, id
, direction
) {
684 if (direction
== "next") {
685 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
686 var child
= list
.childNodes
[i
];
687 if (child
.id
== "feedCatHolder") {
688 if (child
.lastChild
) {
689 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
692 } else if (child
.id
.match("FEEDR-")) {
693 return child
.id
.replace('FEEDR-', '');
698 // FIXME select last feed doesn't work when only unread feeds are visible
700 if (direction
== "prev") {
701 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
702 var child
= list
.childNodes
[i
];
703 if (child
.id
== "feedCatHolder") {
704 if (child
.firstChild
) {
705 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
708 } else if (child
.id
.match("FEEDR-")) {
710 if (getCookie("ttrss_vf_hreadf") == 1) {
711 if (child
.className
!= "feed") {
712 alert(child
.className
);
713 return child
.id
.replace('FEEDR-', '');
716 return child
.id
.replace('FEEDR-', '');
723 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + getActiveFeedId());
725 if (direction
== "next") {
727 if (feed
.nextSibling
) {
729 var next_feed
= feed
.nextSibling
;
731 while (!next_feed
.id
&& next_feed
.nextSibling
) {
732 next_feed
= next_feed
.nextSibling
;
735 if (getCookie("ttrss_vf_hreadf") == 1) {
736 while (next_feed
&& next_feed
.className
== "feed") {
737 next_feed
= next_feed
.nextSibling
;
741 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
742 return next_feed
.id
.replace("FEEDR-", "");
746 var this_cat
= feed
.parentNode
.parentNode
;
748 if (this_cat
&& this_cat
.nextSibling
) {
749 while (this_cat
= this_cat
.nextSibling
) {
750 if (this_cat
.firstChild
&& this_cat
.firstChild
.firstChild
) {
751 var next_feed
= this_cat
.firstChild
.firstChild
;
752 if (getCookie("ttrss_vf_hreadf") == 1) {
753 while (next_feed
&& next_feed
.className
== "feed") {
754 next_feed
= next_feed
.nextSibling
;
757 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
758 return next_feed
.id
.replace("FEEDR-", "");
763 } else if (direction
== "prev") {
765 if (feed
.previousSibling
) {
767 var prev_feed
= feed
.previousSibling
;
769 if (getCookie("ttrss_vf_hreadf") == 1) {
770 while (prev_feed
&& prev_feed
.className
== "feed") {
771 prev_feed
= prev_feed
.previousSibling
;
775 while (!prev_feed
.id
&& prev_feed
.previousSibling
) {
776 prev_feed
= prev_feed
.previousSibling
;
779 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
780 return prev_feed
.id
.replace("FEEDR-", "");
784 var this_cat
= feed
.parentNode
.parentNode
;
786 if (this_cat
&& this_cat
.previousSibling
) {
787 while (this_cat
= this_cat
.previousSibling
) {
788 if (this_cat
.lastChild
&& this_cat
.firstChild
.lastChild
) {
789 var prev_feed
= this_cat
.firstChild
.lastChild
;
790 if (getCookie("ttrss_vf_hreadf") == 1) {
791 while (prev_feed
&& prev_feed
.className
== "feed") {
792 prev_feed
= prev_feed
.previousSibling
;
795 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
796 return prev_feed
.id
.replace("FEEDR-", "");
805 function showBlockElement(id
) {
806 var elem
= document
.getElementById(id
);
809 elem
.style
.display
= "block";
811 alert("[showBlockElement] can't find element with id " + id
);
815 function hideParentElement(e
) {
816 e
.parentNode
.style
.display
= "none";
819 function dropboxSelect(e
, v
) {
820 for (i
= 0; i
< e
.length
; i
++) {
821 if (e
[i
].value
== v
) {
828 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
829 // bugfixed just a little bit :-)
830 function getURLParam(strParamName
){
832 var strHref
= window
.location
.href
;
834 if (strHref
.indexOf("#") == strHref
.length
-1) {
835 strHref
= strHref
.substring(0, strHref
.length
-1);
838 if ( strHref
.indexOf("?") > -1 ){
839 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
840 var aQueryString
= strQueryString
.split("&");
841 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
842 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
843 var aParam
= aQueryString
[iParam
].split("=");
844 strReturn
= aParam
[1];