]>
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", "");
189 function getVisibleUnreadHeadlines() {
190 var content
= document
.getElementById("headlinesList");
192 var rows
= new Array();
194 for (i
= 0; i
< content
.rows
.length
; i
++) {
195 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
196 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
203 function getVisibleHeadlineIds() {
205 var content
= document
.getElementById("headlinesList");
207 var rows
= new Array();
209 for (i
= 0; i
< content
.rows
.length
; i
++) {
210 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
211 if (row_id
.length
> 0) {
218 function getFirstVisibleHeadlineId() {
219 var rows
= getVisibleHeadlineIds();
223 function getLastVisibleHeadlineId() {
224 var rows
= getVisibleHeadlineIds();
225 return rows
[rows
.length
-1];
228 function markHeadline(id
) {
229 var row
= document
.getElementById("RROW-" + id
);
231 var is_active
= false;
233 if (row
.className
.match("Active")) {
236 row
.className
= row
.className
.replace("Selected", "");
237 row
.className
= row
.className
.replace("Active", "");
238 row
.className
= row
.className
.replace("Insensitive", "");
241 row
.className
= row
.className
= "Active";
244 var check
= document
.getElementById("RCHK-" + id
);
247 check
.checked
= true;
250 row
.className
= row
.className
+ "Selected";
255 function getFeedIds() {
256 var content
= document
.getElementById("feedsList");
258 var rows
= new Array();
260 for (i
= 0; i
< content
.rows
.length
; i
++) {
261 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
270 function setCookie(name
, value
, expires
, path
, domain
, secure
) {
271 document
.cookie
= name
+ "=" + escape(value
) +
272 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
273 ((path
) ? "; path=" + path
: "") +
274 ((domain
) ? "; domain=" + domain
: "") +
275 ((secure
) ? "; secure" : "");
278 function getCookie(name
) {
280 var dc
= document
.cookie
;
281 var prefix
= name
+ "=";
282 var begin
= dc
.indexOf("; " + prefix
);
284 begin
= dc
.indexOf(prefix
);
285 if (begin
!= 0) return null;
290 var end
= document
.cookie
.indexOf(";", begin
);
294 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
297 function disableContainerChildren(id
, disable
, doc
) {
299 if (!doc
) doc
= document
;
301 var container
= doc
.getElementById(id
);
303 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
304 var child
= container
.childNodes
[i
];
307 child
.disabled
= disable
;
313 if (child
.className
&& child
.className
.match("button")) {
314 child
.className
= "disabledButton";
317 if (child
.className
&& child
.className
.match("disabledButton")) {
318 child
.className
= "button";
325 function gotoPreferences() {
326 document
.location
.href
= "prefs.php";
329 function gotoMain() {
330 document
.location
.href
= "tt-rss.php";
333 function gotoExportOpml() {
334 document
.location
.href
= "opml.php?op=Export";
337 function getActiveFeedId() {
338 return getCookie("ttrss_vf_actfeed");
341 function setActiveFeedId(id
) {
342 return setCookie("ttrss_vf_actfeed", id
);
345 var xmlhttp_rpc
= false;
348 /*@if (@_jscript_version >= 5)
349 // JScript gives us Conditional compilation, we can cope with old IE versions.
350 // and security blocked creation of the objects.
352 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
355 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
362 if (!xmlhttp_rpc
&& typeof XMLHttpRequest
!='undefined') {
363 xmlhttp_rpc
= new XMLHttpRequest();
366 function parse_counters(reply
, f_document
, title_obj
, scheduled_call
) {
368 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
369 if (!reply
.childNodes
[l
] ||
370 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
371 // where did this come from?
375 var id
= reply
.childNodes
[l
].getAttribute("id");
376 var t
= reply
.childNodes
[l
].getAttribute("type");
377 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
378 var error
= reply
.childNodes
[l
].getAttribute("error");
379 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
381 if (id
== "global-unread") {
382 title_obj
.global_unread
= ctr
;
383 title_obj
.updateTitle();
387 if (t
== "category") {
388 var catctr
= f_document
.getElementById("FCATCTR-" + id
);
390 catctr
.innerHTML
= "(" + ctr
+ " unread)";
395 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
396 var feedu
= f_document
.getElementById("FEEDU-" + id
);
397 var feedr
= f_document
.getElementById("FEEDR-" + id
);
398 var feed_img
= f_document
.getElementById("FIMG-" + id
);
400 if (feedctr
&& feedu
&& feedr
) {
402 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
403 var hf
= title_obj
.parent
.frames
["headlines-frame"];
404 hf
.location
.reload(true);
407 feedu
.innerHTML
= ctr
;
410 feedr
.className
= feedr
.className
.replace("feed", "error");
412 feedr
.className
= feedr
.className
.replace("error", "feed");
416 feedctr
.className
= "odd";
417 if (!feedr
.className
.match("Unread")) {
418 var is_selected
= feedr
.className
.match("Selected");
420 feedr
.className
= feedr
.className
.replace("Selected", "");
421 feedr
.className
= feedr
.className
.replace("Unread", "");
423 feedr
.className
= feedr
.className
+ "Unread";
426 feedr
.className
= feedr
.className
+ "Selected";
431 feedctr
.className
= "invisible";
432 feedr
.className
= feedr
.className
.replace("Unread", "");
437 exception_error("parse_counters", e
);
441 // this one is called from feedlist context
442 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
444 function all_counters_callback() {
445 if (xmlhttp_rpc
.readyState
== 4) {
447 if (!xmlhttp_rpc
.responseXML
|| !xmlhttp_rpc
.responseXML
.firstChild
) {
448 notify("[all_counters_callback] backend did not return valid XML");
452 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
453 var f_document
= parent
.frames
["feeds-frame"].document
;
455 parse_counters(reply
, f_document
, parent
);
458 exception_error("all_counters_callback", e
);
463 function update_all_counters(feed
) {
464 if (xmlhttp_ready(xmlhttp_rpc
)) {
465 var query
= "backend.php?op=rpc&subop=getAllCounters";
468 query
= query
+ "&aid=" + feed
;
471 xmlhttp_rpc
.open("GET", query
, true);
472 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
473 xmlhttp_rpc
.send(null);
477 function popupHelp(tid
) {
478 var w
= window
.open("backend.php?op=help&tid=" + tid
,
480 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
483 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
484 * * @author Sundar Dorai-Raj
485 * * Email: sdoraira@vt.edu
486 * * This program is free software; you can redistribute it and/or
487 * * modify it under the terms of the GNU General Public License
488 * * as published by the Free Software Foundation; either version 2
489 * * of the License, or (at your option) any later version,
490 * * provided that any use properly credits the author.
491 * * This program is distributed in the hope that it will be useful,
492 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
493 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
494 * * GNU General Public License for more details at http://www.gnu.org * * */
496 var numbers
=".0123456789";
497 function isNumeric(x
) {
498 // is x a String or a character?
500 // remove negative sign
502 for(j
=0;j
<x
.length
;j
++) {
503 // call isNumeric recursively for each character
504 number
=isNumeric(x
.substring(j
,j
+1));
505 if(!number
) return number
;
510 // if x is number return true
511 if(numbers
.indexOf(x
)>=0) return true;
517 function hideOrShowFeeds(doc
, hide
) {
519 if (!doc
.styleSheets
) return;
521 var css_rules
= doc
.styleSheets
[0].cssRules
;
523 if (!css_rules
|| !css_rules
.length
) return;
525 for (i
= 0; i
< css_rules
.length
; i
++) {
526 var rule
= css_rules
[i
];
528 if (rule
.selectorText
== "ul.feedList li.feed") {
530 rule
.style
.display
= "block";
532 rule
.style
.display
= "none";
540 function fatalError(code
, params
) {
542 window
.location
= "error.php?c=" + param_escape(code
);
544 window
.location
= "error.php?c=" + param_escape(code
) +
545 "&p=" + param_escape(params
);
549 function selectTableRow(r
, do_select
) {
550 r
.className
= r
.className
.replace("Selected", "");
553 r
.className
= r
.className
+ "Selected";
557 function selectTableRowById(elem_id
, check_id
, do_select
) {
561 var row
= document
.getElementById(elem_id
);
564 selectTableRow(row
, do_select
);
567 var check
= document
.getElementById(check_id
);
570 check
.checked
= do_select
;
573 exception_error("selectTableRowById", e
);
577 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
578 classcheck
, reset_others
) {
580 var content
= document
.getElementById(content_id
);
583 alert("[selectTableRows] Element " + content_id
+ " not found.");
587 for (i
= 0; i
< content
.rows
.length
; i
++) {
588 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
590 if (content
.rows
[i
].id
.match(prefix
)) {
591 selectTableRow(content
.rows
[i
], do_select
);
593 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
594 var check
= document
.getElementById(check_prefix
+ row_id
);
597 check
.checked
= do_select
;
599 } else if (reset_others
) {
600 selectTableRow(content
.rows
[i
], false);
602 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
603 var check
= document
.getElementById(check_prefix
+ row_id
);
606 check
.checked
= false;
610 } else if (reset_others
) {
611 selectTableRow(content
.rows
[i
], false);
613 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
614 var check
= document
.getElementById(check_prefix
+ row_id
);
617 check
.checked
= false;
624 function getSelectedTableRowIds(content_id
, prefix
) {
626 var content
= document
.getElementById(content_id
);
629 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
633 var sel_rows
= new Array();
635 for (i
= 0; i
< content
.rows
.length
; i
++) {
636 if (content
.rows
[i
].id
.match(prefix
) &&
637 content
.rows
[i
].className
.match("Selected")) {
639 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
640 sel_rows
.push(row_id
);
648 function toggleSelectRowById(sender
, id
) {
649 var row
= document
.getElementById(id
);
651 if (sender
.checked
) {
652 if (!row
.className
.match("Selected")) {
653 row
.className
= row
.className
+ "Selected";
656 if (row
.className
.match("Selected")) {
657 row
.className
= row
.className
.replace("Selected", "");
662 function toggleSelectListRow(sender
) {
663 var parent_row
= sender
.parentNode
;
665 if (sender
.checked
) {
666 if (!parent_row
.className
.match("Selected")) {
667 parent_row
.className
= parent_row
.className
+ "Selected";
670 if (parent_row
.className
.match("Selected")) {
671 parent_row
.className
= parent_row
.className
.replace("Selected", "");
677 function toggleSelectRow(sender
) {
678 var parent_row
= sender
.parentNode
.parentNode
;
680 if (sender
.checked
) {
681 if (!parent_row
.className
.match("Selected")) {
682 parent_row
.className
= parent_row
.className
+ "Selected";
685 if (parent_row
.className
.match("Selected")) {
686 parent_row
.className
= parent_row
.className
.replace("Selected", "");
691 function openExternalUrl(url
) {
692 var w
= window
.open(url
);
696 function getRelativeFeedId(list
, id
, direction
) {
698 if (direction
== "next") {
699 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
700 var child
= list
.childNodes
[i
];
701 if (child
.id
== "feedCatHolder") {
702 if (child
.lastChild
) {
703 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
706 } else if (child
.id
.match("FEEDR-")) {
707 return child
.id
.replace('FEEDR-', '');
712 // FIXME select last feed doesn't work when only unread feeds are visible
714 if (direction
== "prev") {
715 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
716 var child
= list
.childNodes
[i
];
717 if (child
.id
== "feedCatHolder") {
718 if (child
.firstChild
) {
719 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
722 } else if (child
.id
.match("FEEDR-")) {
724 if (getCookie("ttrss_vf_hreadf") == 1) {
725 if (child
.className
!= "feed") {
726 alert(child
.className
);
727 return child
.id
.replace('FEEDR-', '');
730 return child
.id
.replace('FEEDR-', '');
737 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + getActiveFeedId());
739 if (direction
== "next") {
741 if (feed
.nextSibling
) {
743 var next_feed
= feed
.nextSibling
;
745 while (!next_feed
.id
&& next_feed
.nextSibling
) {
746 next_feed
= next_feed
.nextSibling
;
749 if (getCookie("ttrss_vf_hreadf") == 1) {
750 while (next_feed
&& next_feed
.className
== "feed") {
751 next_feed
= next_feed
.nextSibling
;
755 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
756 return next_feed
.id
.replace("FEEDR-", "");
760 var this_cat
= feed
.parentNode
.parentNode
;
762 if (this_cat
&& this_cat
.nextSibling
) {
763 while (this_cat
= this_cat
.nextSibling
) {
764 if (this_cat
.firstChild
&& this_cat
.firstChild
.firstChild
) {
765 var next_feed
= this_cat
.firstChild
.firstChild
;
766 if (getCookie("ttrss_vf_hreadf") == 1) {
767 while (next_feed
&& next_feed
.className
== "feed") {
768 next_feed
= next_feed
.nextSibling
;
771 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
772 return next_feed
.id
.replace("FEEDR-", "");
777 } else if (direction
== "prev") {
779 if (feed
.previousSibling
) {
781 var prev_feed
= feed
.previousSibling
;
783 if (getCookie("ttrss_vf_hreadf") == 1) {
784 while (prev_feed
&& prev_feed
.className
== "feed") {
785 prev_feed
= prev_feed
.previousSibling
;
789 while (!prev_feed
.id
&& prev_feed
.previousSibling
) {
790 prev_feed
= prev_feed
.previousSibling
;
793 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
794 return prev_feed
.id
.replace("FEEDR-", "");
798 var this_cat
= feed
.parentNode
.parentNode
;
800 if (this_cat
&& this_cat
.previousSibling
) {
801 while (this_cat
= this_cat
.previousSibling
) {
802 if (this_cat
.lastChild
&& this_cat
.firstChild
.lastChild
) {
803 var prev_feed
= this_cat
.firstChild
.lastChild
;
804 if (getCookie("ttrss_vf_hreadf") == 1) {
805 while (prev_feed
&& prev_feed
.className
== "feed") {
806 prev_feed
= prev_feed
.previousSibling
;
809 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
810 return prev_feed
.id
.replace("FEEDR-", "");
819 function showBlockElement(id
) {
820 var elem
= document
.getElementById(id
);
823 elem
.style
.display
= "block";
825 alert("[showBlockElement] can't find element with id " + id
);
829 function hideParentElement(e
) {
830 e
.parentNode
.style
.display
= "none";
833 function dropboxSelect(e
, v
) {
834 for (i
= 0; i
< e
.length
; i
++) {
835 if (e
[i
].value
== v
) {
842 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
843 // bugfixed just a little bit :-)
844 function getURLParam(strParamName
){
846 var strHref
= window
.location
.href
;
848 if (strHref
.indexOf("#") == strHref
.length
-1) {
849 strHref
= strHref
.substring(0, strHref
.length
-1);
852 if ( strHref
.indexOf("?") > -1 ){
853 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
854 var aQueryString
= strQueryString
.split("&");
855 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
856 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
857 var aParam
= aQueryString
[iParam
].split("=");
858 strReturn
= aParam
[1];
866 function leading_zero(p
) {
868 if (s
.length
== 1) s
= "0" + s
;
872 function center_element(e
) {
875 var c_width
= document
.body
.clientWidth
;
876 var c_height
= document
.body
.clientHeight
;
878 var c_scroll
= document
.body
.scrollTop
;
880 var e_width
= e
.clientWidth
;
881 var e_height
= e
.clientHeight
;
883 var set_y
= (c_height
/ 2) + c_scroll
- (e_height
/ 2);
884 var set_x
= (c_width
/ 2) - (e_width
/ 2);
886 e
.style
.top
= set_y
+ "px";
887 e
.style
.left
= set_x
+ "px";
889 exception_error("center_element", e
);