]>
git.wh0rd.org - tt-rss.git/blob - functions.js
60fd9da640ef14b4b3e800abcedcf2896d8378de
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 var piggie
= document
.getElementById("piggie");
136 if (seq
.match("807371717369")) {
137 localPiggieFunction(true);
139 localPiggieFunction(false);
143 if (typeof localHotkeyHandler
!= 'undefined') {
145 localHotkeyHandler(keycode
);
147 exception_error("hotkey_handler", e
);
153 function cleanSelectedList(element
) {
154 var content
= document
.getElementById(element
);
156 if (!document
.getElementById("feedCatHolder")) {
157 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
158 var child
= content
.childNodes
[i
];
159 child
.className
= child
.className
.replace("Selected", "");
162 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
163 var child
= content
.childNodes
[i
];
165 if (child
.id
== "feedCatHolder") {
166 var fcat
= child
.lastChild
;
167 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
168 var feed
= fcat
.childNodes
[j
];
169 feed
.className
= feed
.className
.replace("Selected", "");
178 function cleanSelected(element
) {
179 var content
= document
.getElementById(element
);
181 for (i
= 0; i
< content
.rows
.length
; i
++) {
182 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
187 function getVisibleUnreadHeadlines() {
188 var content
= document
.getElementById("headlinesList");
190 var rows
= new Array();
192 for (i
= 0; i
< content
.rows
.length
; i
++) {
193 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
194 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
201 function getVisibleHeadlineIds() {
203 var content
= document
.getElementById("headlinesList");
205 var rows
= new Array();
207 for (i
= 0; i
< content
.rows
.length
; i
++) {
208 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
209 if (row_id
.length
> 0) {
216 function getFirstVisibleHeadlineId() {
217 var rows
= getVisibleHeadlineIds();
221 function getLastVisibleHeadlineId() {
222 var rows
= getVisibleHeadlineIds();
223 return rows
[rows
.length
-1];
226 function markHeadline(id
) {
227 var row
= document
.getElementById("RROW-" + id
);
229 var is_active
= false;
231 if (row
.className
.match("Active")) {
234 row
.className
= row
.className
.replace("Selected", "");
235 row
.className
= row
.className
.replace("Active", "");
236 row
.className
= row
.className
.replace("Insensitive", "");
239 row
.className
= row
.className
= "Active";
242 row
.className
= row
.className
+ "Selected";
247 function getFeedIds() {
248 var content
= document
.getElementById("feedsList");
250 var rows
= new Array();
252 for (i
= 0; i
< content
.rows
.length
; i
++) {
253 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
262 function setCookie(name
, value
, expires
, path
, domain
, secure
) {
263 document
.cookie
= name
+ "=" + escape(value
) +
264 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
265 ((path
) ? "; path=" + path
: "") +
266 ((domain
) ? "; domain=" + domain
: "") +
267 ((secure
) ? "; secure" : "");
270 function getCookie(name
) {
272 var dc
= document
.cookie
;
273 var prefix
= name
+ "=";
274 var begin
= dc
.indexOf("; " + prefix
);
276 begin
= dc
.indexOf(prefix
);
277 if (begin
!= 0) return null;
282 var end
= document
.cookie
.indexOf(";", begin
);
286 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
289 function disableContainerChildren(id
, disable
, doc
) {
291 if (!doc
) doc
= document
;
293 var container
= doc
.getElementById(id
);
295 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
296 var child
= container
.childNodes
[i
];
299 child
.disabled
= disable
;
305 if (child
.className
&& child
.className
.match("button")) {
306 child
.className
= "disabledButton";
309 if (child
.className
&& child
.className
.match("disabledButton")) {
310 child
.className
= "button";
317 function gotoPreferences() {
318 document
.location
.href
= "prefs.php";
321 function gotoMain() {
322 document
.location
.href
= "tt-rss.php";
325 function gotoExportOpml() {
326 document
.location
.href
= "opml.php?op=Export";
329 function getActiveFeedId() {
330 return getCookie("ttrss_vf_actfeed");
333 function setActiveFeedId(id
) {
334 return setCookie("ttrss_vf_actfeed", id
);
337 var xmlhttp_rpc
= false;
340 /*@if (@_jscript_version >= 5)
341 // JScript gives us Conditional compilation, we can cope with old IE versions.
342 // and security blocked creation of the objects.
344 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
347 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
354 if (!xmlhttp_rpc
&& typeof XMLHttpRequest
!='undefined') {
355 xmlhttp_rpc
= new XMLHttpRequest();
358 function parse_counters(reply
, f_document
, title_obj
) {
360 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
361 if (!reply
.childNodes
[l
] ||
362 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
363 // where did this come from?
367 var id
= reply
.childNodes
[l
].getAttribute("id");
368 var t
= reply
.childNodes
[l
].getAttribute("type");
369 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
370 var error
= reply
.childNodes
[l
].getAttribute("error");
371 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
373 if (id
== "global-unread") {
374 title_obj
.global_unread
= ctr
;
375 title_obj
.updateTitle();
379 if (t
== "category") {
380 var catctr
= f_document
.getElementById("FCATCTR-" + id
);
382 catctr
.innerHTML
= "(" + ctr
+ " unread)";
387 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
388 var feedu
= f_document
.getElementById("FEEDU-" + id
);
389 var feedr
= f_document
.getElementById("FEEDR-" + id
);
390 var feed_img
= f_document
.getElementById("FIMG-" + id
);
392 if (feedctr
&& feedu
&& feedr
) {
394 feedu
.innerHTML
= ctr
;
397 feedr
.className
= feedr
.className
.replace("feed", "error");
399 feedr
.className
= feedr
.className
.replace("error", "feed");
403 feedctr
.className
= "odd";
404 if (!feedr
.className
.match("Unread")) {
405 var is_selected
= feedr
.className
.match("Selected");
407 feedr
.className
= feedr
.className
.replace("Selected", "");
408 feedr
.className
= feedr
.className
.replace("Unread", "");
410 feedr
.className
= feedr
.className
+ "Unread";
413 feedr
.className
= feedr
.className
+ "Selected";
418 feedctr
.className
= "invisible";
419 feedr
.className
= feedr
.className
.replace("Unread", "");
424 exception_error("parse_counters", e
);
428 // this one is called from feedlist context
429 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
431 function all_counters_callback() {
432 if (xmlhttp_rpc
.readyState
== 4) {
434 if (!xmlhttp_rpc
.responseXML
|| !xmlhttp_rpc
.responseXML
.firstChild
) {
435 notify("[all_counters_callback] backend did not return valid XML");
439 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
440 var f_document
= parent
.frames
["feeds-frame"].document
;
442 parse_counters(reply
, f_document
, parent
);
445 exception_error("all_counters_callback", e
);
450 function update_all_counters(feed
) {
451 if (xmlhttp_ready(xmlhttp_rpc
)) {
452 var query
= "backend.php?op=rpc&subop=getAllCounters";
455 query
= query
+ "&aid=" + feed
;
458 xmlhttp_rpc
.open("GET", query
, true);
459 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
460 xmlhttp_rpc
.send(null);
464 function popupHelp(tid
) {
465 var w
= window
.open("backend.php?op=help&tid=" + tid
,
467 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
470 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
471 * * @author Sundar Dorai-Raj
472 * * Email: sdoraira@vt.edu
473 * * This program is free software; you can redistribute it and/or
474 * * modify it under the terms of the GNU General Public License
475 * * as published by the Free Software Foundation; either version 2
476 * * of the License, or (at your option) any later version,
477 * * provided that any use properly credits the author.
478 * * This program is distributed in the hope that it will be useful,
479 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
480 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
481 * * GNU General Public License for more details at http://www.gnu.org * * */
483 var numbers
=".0123456789";
484 function isNumeric(x
) {
485 // is x a String or a character?
487 // remove negative sign
489 for(j
=0;j
<x
.length
;j
++) {
490 // call isNumeric recursively for each character
491 number
=isNumeric(x
.substring(j
,j
+1));
492 if(!number
) return number
;
497 // if x is number return true
498 if(numbers
.indexOf(x
)>=0) return true;
504 function hideOrShowFeeds(doc
, hide
) {
506 if (!doc
.styleSheets
) return;
508 var css_rules
= doc
.styleSheets
[0].cssRules
;
510 if (!css_rules
|| !css_rules
.length
) return;
512 for (i
= 0; i
< css_rules
.length
; i
++) {
513 var rule
= css_rules
[i
];
515 if (rule
.selectorText
== "ul.feedList li.feed") {
517 rule
.style
.display
= "block";
519 rule
.style
.display
= "none";
527 function fatalError(code
) {
528 window
.location
= "error.php?c=" + param_escape(code
);
531 function selectTableRow(r
, do_select
) {
532 r
.className
= r
.className
.replace("Selected", "");
535 r
.className
= r
.className
+ "Selected";
539 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
542 var content
= document
.getElementById(content_id
);
545 alert("[selectTableRows] Element " + content_id
+ " not found.");
549 for (i
= 0; i
< content
.rows
.length
; i
++) {
550 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
552 if (content
.rows
[i
].id
.match(prefix
)) {
553 selectTableRow(content
.rows
[i
], do_select
);
556 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
557 var check
= document
.getElementById(check_prefix
+ row_id
);
560 check
.checked
= do_select
;
566 function getSelectedTableRowIds(content_id
, prefix
) {
568 var content
= document
.getElementById(content_id
);
571 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
575 var sel_rows
= new Array();
577 for (i
= 0; i
< content
.rows
.length
; i
++) {
578 if (content
.rows
[i
].id
.match(prefix
) &&
579 content
.rows
[i
].className
.match("Selected")) {
581 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
582 sel_rows
.push(row_id
);
590 function toggleSelectRowById(sender
, id
) {
591 var row
= document
.getElementById(id
);
593 if (sender
.checked
) {
594 if (!row
.className
.match("Selected")) {
595 row
.className
= row
.className
+ "Selected";
598 if (row
.className
.match("Selected")) {
599 row
.className
= row
.className
.replace("Selected", "");
605 function toggleSelectRow(sender
) {
606 var parent_row
= sender
.parentNode
.parentNode
;
608 if (sender
.checked
) {
609 if (!parent_row
.className
.match("Selected")) {
610 parent_row
.className
= parent_row
.className
+ "Selected";
613 if (parent_row
.className
.match("Selected")) {
614 parent_row
.className
= parent_row
.className
.replace("Selected", "");
619 function openExternalUrl(url
) {
620 var w
= window
.open(url
);
624 function getRelativeFeedId(list
, id
, direction
) {
626 if (direction
== "next") {
627 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
628 var child
= list
.childNodes
[i
];
629 if (child
.id
== "feedCatHolder") {
630 if (child
.lastChild
) {
631 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
634 } else if (child
.id
.match("FEEDR-")) {
635 return child
.id
.replace('FEEDR-', '');
640 // FIXME select last feed doesn't work when only unread feeds are visible
642 if (direction
== "prev") {
643 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
644 var child
= list
.childNodes
[i
];
645 if (child
.id
== "feedCatHolder") {
646 if (child
.firstChild
) {
647 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
650 } else if (child
.id
.match("FEEDR-")) {
652 if (getCookie("ttrss_vf_hreadf") == 1) {
653 if (child
.className
!= "feed") {
654 alert(child
.className
);
655 return child
.id
.replace('FEEDR-', '');
658 return child
.id
.replace('FEEDR-', '');
665 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + getActiveFeedId());
667 if (direction
== "next") {
669 if (feed
.nextSibling
) {
671 var next_feed
= feed
.nextSibling
;
673 while (!next_feed
.id
&& next_feed
.nextSibling
) {
674 next_feed
= next_feed
.nextSibling
;
677 if (getCookie("ttrss_vf_hreadf") == 1) {
678 while (next_feed
&& next_feed
.className
== "feed") {
679 next_feed
= next_feed
.nextSibling
;
683 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
684 return next_feed
.id
.replace("FEEDR-", "");
688 var this_cat
= feed
.parentNode
.parentNode
;
690 if (this_cat
&& this_cat
.nextSibling
) {
691 while (this_cat
= this_cat
.nextSibling
) {
692 if (this_cat
.firstChild
&& this_cat
.firstChild
.firstChild
) {
693 var next_feed
= this_cat
.firstChild
.firstChild
;
694 if (getCookie("ttrss_vf_hreadf") == 1) {
695 while (next_feed
&& next_feed
.className
== "feed") {
696 next_feed
= next_feed
.nextSibling
;
699 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
700 return next_feed
.id
.replace("FEEDR-", "");
705 } else if (direction
== "prev") {
707 if (feed
.previousSibling
) {
709 var prev_feed
= feed
.previousSibling
;
711 if (getCookie("ttrss_vf_hreadf") == 1) {
712 while (prev_feed
&& prev_feed
.className
== "feed") {
713 prev_feed
= prev_feed
.previousSibling
;
717 while (!prev_feed
.id
&& prev_feed
.previousSibling
) {
718 prev_feed
= prev_feed
.previousSibling
;
721 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
722 return prev_feed
.id
.replace("FEEDR-", "");
726 var this_cat
= feed
.parentNode
.parentNode
;
728 if (this_cat
&& this_cat
.previousSibling
) {
729 while (this_cat
= this_cat
.previousSibling
) {
730 if (this_cat
.lastChild
&& this_cat
.firstChild
.lastChild
) {
731 var prev_feed
= this_cat
.firstChild
.lastChild
;
732 if (getCookie("ttrss_vf_hreadf") == 1) {
733 while (prev_feed
&& prev_feed
.className
== "feed") {
734 prev_feed
= prev_feed
.previousSibling
;
737 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
738 return prev_feed
.id
.replace("FEEDR-", "");
747 function showBlockElement(id
) {
748 var elem
= document
.getElementById(id
);
751 elem
.style
.display
= "block";
753 alert("[showBlockElement] can't find element with id " + id
);
757 function hideParentElement(e
) {
758 e
.parentNode
.style
.display
= "none";
761 function dropboxSelect(e
, v
) {
762 for (i
= 0; i
< e
.length
; i
++) {
763 if (e
[i
].value
== v
) {