]>
git.wh0rd.org - tt-rss.git/blob - functions.js
b72c1157bfa3819c0d90b9f557715d734c787adb
1 var hotkeys_enabled
= true;
3 function exception_error(location
, e
) {
4 alert("Exception: " + e
.name
+ "\nMessage: " + e
.message
+
5 "\nLocation: " + location
);
8 function disableHotkeys() {
9 hotkeys_enabled
= false;
12 function enableHotkeys() {
13 hotkeys_enabled
= true;
16 function xmlhttp_ready(obj
) {
17 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
21 function notify_callback() {
22 var container
= document
.getElementById('notify');
23 if (xmlhttp
.readyState
== 4) {
24 container
.innerHTML
=xmlhttp
.responseText
;
28 function rpc_notify_callback() {
29 var container
= document
.getElementById('notify');
30 if (xmlhttp_rpc
.readyState
== 4) {
31 container
.innerHTML
=xmlhttp_rpc
.responseText
;
35 function rpc_pnotify_callback() {
36 var container
= parent
.document
.getElementById('notify');
37 if (xmlhttp_rpc
.readyState
== 4) {
38 container
.innerHTML
=xmlhttp_rpc
.responseText
;
42 function param_escape(arg
) {
43 if (typeof encodeURIComponent
!= 'undefined')
44 return encodeURIComponent(arg
);
49 function param_unescape(arg
) {
50 if (typeof decodeURIComponent
!= 'undefined')
51 return decodeURIComponent(arg
);
58 then
=new Date().getTime();
60 while((now
-then
)<gap
) {
61 now
=new Date().getTime();
65 function p_notify(msg
) {
67 var n
= parent
.document
.getElementById("notify");
68 var nb
= parent
.document
.getElementById("notify_body");
70 if (!n
|| !nb
) return;
73 nb
.innerHTML
= " ";
74 // n.style.background = "#ffffff";
77 // n.style.background = "#fffff0";
81 function notify(msg
) {
83 var n
= document
.getElementById("notify");
84 var nb
= document
.getElementById("notify_body");
86 if (!n
|| !nb
) return;
89 nb
.innerHTML
= " ";
90 // n.style.background = "#ffffff";
93 // n.style.background = "#fffff0";
98 function printLockingError() {
99 notify("Please wait until operation finishes");}
103 function hotkey_handler(e
) {
107 if (!hotkeys_enabled
) return;
110 keycode
= window
.event
.keyCode
;
115 if (keycode
== 13 || keycode
== 27) {
118 seq
= seq
+ "" + keycode
;
121 var piggie
= document
.getElementById("piggie");
125 if (seq
.match("807371717369")) {
126 localPiggieFunction(true);
128 localPiggieFunction(false);
132 if (typeof localHotkeyHandler
!= 'undefined') {
134 localHotkeyHandler(keycode
);
142 function cleanSelectedList(element
) {
143 var content
= document
.getElementById(element
);
145 if (!document
.getElementById("feedCatHolder")) {
146 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
147 var child
= content
.childNodes
[i
];
148 child
.className
= child
.className
.replace("Selected", "");
151 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
152 var child
= content
.childNodes
[i
];
154 if (child
.id
== "feedCatHolder") {
155 var fcat
= child
.firstChild
;
156 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
157 var feed
= fcat
.childNodes
[j
];
158 feed
.className
= feed
.className
.replace("Selected", "");
167 function cleanSelected(element
) {
168 var content
= document
.getElementById(element
);
170 for (i
= 0; i
< content
.rows
.length
; i
++) {
171 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
176 function getVisibleUnreadHeadlines() {
177 var content
= document
.getElementById("headlinesList");
179 var rows
= new Array();
181 for (i
= 0; i
< content
.rows
.length
; i
++) {
182 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
183 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
190 function getVisibleHeadlineIds() {
192 var content
= document
.getElementById("headlinesList");
194 var rows
= new Array();
196 for (i
= 0; i
< content
.rows
.length
; i
++) {
197 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
198 if (row_id
.length
> 0) {
205 function getFirstVisibleHeadlineId() {
206 var rows
= getVisibleHeadlineIds();
210 function getLastVisibleHeadlineId() {
211 var rows
= getVisibleHeadlineIds();
212 return rows
[rows
.length
-1];
215 function markHeadline(id
) {
216 var row
= document
.getElementById("RROW-" + id
);
218 var is_active
= false;
220 if (row
.className
.match("Active")) {
223 row
.className
= row
.className
.replace("Selected", "");
224 row
.className
= row
.className
.replace("Active", "");
225 row
.className
= row
.className
.replace("Insensitive", "");
228 row
.className
= row
.className
= "Active";
231 row
.className
= row
.className
+ "Selected";
236 function getFeedIds() {
237 var content
= document
.getElementById("feedsList");
239 var rows
= new Array();
241 for (i
= 0; i
< content
.rows
.length
; i
++) {
242 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
251 function setCookie(name
, value
, expires
, path
, domain
, secure
) {
252 document
.cookie
= name
+ "=" + escape(value
) +
253 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
254 ((path
) ? "; path=" + path
: "") +
255 ((domain
) ? "; domain=" + domain
: "") +
256 ((secure
) ? "; secure" : "");
259 function getCookie(name
) {
261 var dc
= document
.cookie
;
262 var prefix
= name
+ "=";
263 var begin
= dc
.indexOf("; " + prefix
);
265 begin
= dc
.indexOf(prefix
);
266 if (begin
!= 0) return null;
271 var end
= document
.cookie
.indexOf(";", begin
);
275 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
278 function disableContainerChildren(id
, disable
, doc
) {
280 if (!doc
) doc
= document
;
282 var container
= doc
.getElementById(id
);
284 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
285 var child
= container
.childNodes
[i
];
288 child
.disabled
= disable
;
294 if (child
.className
&& child
.className
.match("button")) {
295 child
.className
= "disabledButton";
298 if (child
.className
&& child
.className
.match("disabledButton")) {
299 child
.className
= "button";
306 function gotoPreferences() {
307 document
.location
.href
= "prefs.php";
310 function gotoMain() {
311 document
.location
.href
= "tt-rss.php";
314 function gotoExportOpml() {
315 document
.location
.href
= "opml.php?op=Export";
318 function getActiveFeedId() {
319 return getCookie("ttrss_vf_actfeed");
322 function setActiveFeedId(id
) {
323 return setCookie("ttrss_vf_actfeed", id
);
326 var xmlhttp_rpc
= false;
329 /*@if (@_jscript_version >= 5)
330 // JScript gives us Conditional compilation, we can cope with old IE versions.
331 // and security blocked creation of the objects.
333 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
336 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
343 if (!xmlhttp_rpc
&& typeof XMLHttpRequest
!='undefined') {
344 xmlhttp_rpc
= new XMLHttpRequest();
347 function all_counters_callback() {
348 if (xmlhttp_rpc
.readyState
== 4) {
350 if (!xmlhttp_rpc
.responseXML
|| !xmlhttp_rpc
.responseXML
.firstChild
) {
351 notify("[all_counters_callback] backend did not return valid XML");
355 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
357 var f_document
= parent
.frames
["feeds-frame"].document
;
359 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
360 var id
= reply
.childNodes
[l
].getAttribute("id");
361 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
363 if (id
== "global-unread") {
364 parent
.global_unread
= ctr
;
365 parent
.updateTitle();
369 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
370 var feedu
= f_document
.getElementById("FEEDU-" + id
);
371 var feedr
= f_document
.getElementById("FEEDR-" + id
);
373 if (feedctr
&& feedu
&& feedr
) {
375 feedu
.innerHTML
= ctr
;
378 feedctr
.className
= "odd";
379 if (!feedr
.className
.match("Unread")) {
380 var is_selected
= feedr
.className
.match("Selected");
382 feedr
.className
= feedr
.className
.replace("Selected", "");
383 feedr
.className
= feedr
.className
.replace("Unread", "");
385 feedr
.className
= feedr
.className
+ "Unread";
388 feedr
.className
= feedr
.className
+ "Selected";
393 feedctr
.className
= "invisible";
394 feedr
.className
= feedr
.className
.replace("Unread", "");
399 exception_error("all_counters_callback", e
);
404 function update_all_counters(feed
) {
405 if (xmlhttp_ready(xmlhttp_rpc
)) {
406 var query
= "backend.php?op=rpc&subop=getAllCounters";
409 query
= query
+ "&aid=" + feed
;
412 xmlhttp_rpc
.open("GET", query
, true);
413 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
414 xmlhttp_rpc
.send(null);
418 function popupHelp(tid
) {
419 var w
= window
.open("backend.php?op=help&tid=" + tid
,
421 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
424 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
425 * * @author Sundar Dorai-Raj
426 * * Email: sdoraira@vt.edu
427 * * This program is free software; you can redistribute it and/or
428 * * modify it under the terms of the GNU General Public License
429 * * as published by the Free Software Foundation; either version 2
430 * * of the License, or (at your option) any later version,
431 * * provided that any use properly credits the author.
432 * * This program is distributed in the hope that it will be useful,
433 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
434 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
435 * * GNU General Public License for more details at http://www.gnu.org * * */
437 var numbers
=".0123456789";
438 function isNumeric(x
) {
439 // is x a String or a character?
441 // remove negative sign
443 for(j
=0;j
<x
.length
;j
++) {
444 // call isNumeric recursively for each character
445 number
=isNumeric(x
.substring(j
,j
+1));
446 if(!number
) return number
;
451 // if x is number return true
452 if(numbers
.indexOf(x
)>=0) return true;
458 function hideOrShowFeeds(doc
, hide
) {
460 var css_rules
= doc
.styleSheets
[0].cssRules
;
462 for (i
= 0; i
< css_rules
.length
; i
++) {
463 var rule
= css_rules
[i
];
465 if (rule
.selectorText
== "ul.feedList li.feed") {
467 rule
.style
.display
= "block";
469 rule
.style
.display
= "none";
477 function fatalError(code
) {
478 window
.location
= "error.php?c=" + param_escape(code
);
481 function selectTableRow(r
, do_select
) {
482 r
.className
= r
.className
.replace("Selected", "");
485 r
.className
= r
.className
+ "Selected";
489 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
492 var content
= document
.getElementById(content_id
);
495 alert("[selectTableRows] Element " + content_id
+ " not found.");
499 for (i
= 0; i
< content
.rows
.length
; i
++) {
500 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
502 if (content
.rows
[i
].id
.match(prefix
)) {
503 selectTableRow(content
.rows
[i
], do_select
);
506 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
507 var check
= document
.getElementById(check_prefix
+ row_id
);
510 check
.checked
= do_select
;
516 function getSelectedTableRowIds(content_id
, prefix
) {
518 var content
= document
.getElementById(content_id
);
521 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
525 var sel_rows
= new Array();
527 for (i
= 0; i
< content
.rows
.length
; i
++) {
528 if (content
.rows
[i
].id
.match(prefix
) &&
529 content
.rows
[i
].className
.match("Selected")) {
531 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
532 sel_rows
.push(row_id
);
540 function toggleSelectRowById(sender
, id
) {
541 var row
= document
.getElementById(id
);
543 if (sender
.checked
) {
544 if (!row
.className
.match("Selected")) {
545 row
.className
= row
.className
+ "Selected";
548 if (row
.className
.match("Selected")) {
549 row
.className
= row
.className
.replace("Selected", "");
555 function toggleSelectRow(sender
) {
556 var parent_row
= sender
.parentNode
.parentNode
;
558 if (sender
.checked
) {
559 if (!parent_row
.className
.match("Selected")) {
560 parent_row
.className
= parent_row
.className
+ "Selected";
563 if (parent_row
.className
.match("Selected")) {
564 parent_row
.className
= parent_row
.className
.replace("Selected", "");
569 function openExternalUrl(url
) {
570 var w
= window
.open(url
);
574 function getRelativeFeedId(list
, id
, direction
) {
576 if (direction
== "next") {
577 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
578 var child
= list
.childNodes
[i
];
579 if (child
.id
== "feedCatHolder") {
580 if (child
.firstChild
) {
581 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
584 } else if (child
.id
.match("FEEDR-")) {
585 return child
.id
.replace('FEEDR-', '');
590 // FIXME select last feed doesn't work when only unread feeds are visible
592 if (direction
== "prev") {
593 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
594 var child
= list
.childNodes
[i
];
595 if (child
.id
== "feedCatHolder") {
596 if (child
.firstChild
) {
597 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
600 } else if (child
.id
.match("FEEDR-")) {
602 if (getCookie("ttrss_vf_hreadf") == 1) {
603 if (child
.className
!= "feed") {
604 alert(child
.className
);
605 return child
.id
.replace('FEEDR-', '');
608 return child
.id
.replace('FEEDR-', '');
615 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + getActiveFeedId());
617 if (direction
== "next") {
619 if (feed
.nextSibling
) {
621 var next_feed
= feed
.nextSibling
;
623 while (!next_feed
.id
&& next_feed
.nextSibling
) {
624 next_feed
= next_feed
.nextSibling
;
627 if (getCookie("ttrss_vf_hreadf") == 1) {
628 while (next_feed
&& next_feed
.className
== "feed") {
629 next_feed
= next_feed
.nextSibling
;
633 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
634 return next_feed
.id
.replace("FEEDR-", "");
638 var this_cat
= feed
.parentNode
.parentNode
;
640 if (this_cat
&& this_cat
.nextSibling
) {
641 while (this_cat
= this_cat
.nextSibling
) {
642 if (this_cat
.firstChild
&& this_cat
.firstChild
.firstChild
) {
643 var next_feed
= this_cat
.firstChild
.firstChild
;
644 if (getCookie("ttrss_vf_hreadf") == 1) {
645 while (next_feed
&& next_feed
.className
== "feed") {
646 next_feed
= next_feed
.nextSibling
;
649 if (next_feed
&& next_feed
.id
.match("FEEDR-")) {
650 return next_feed
.id
.replace("FEEDR-", "");
655 } else if (direction
== "prev") {
657 if (feed
.previousSibling
) {
659 var prev_feed
= feed
.previousSibling
;
661 if (getCookie("ttrss_vf_hreadf") == 1) {
662 while (prev_feed
&& prev_feed
.className
== "feed") {
663 prev_feed
= prev_feed
.previousSibling
;
667 while (!prev_feed
.id
&& prev_feed
.previousSibling
) {
668 prev_feed
= prev_feed
.previousSibling
;
671 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
672 return prev_feed
.id
.replace("FEEDR-", "");
676 var this_cat
= feed
.parentNode
.parentNode
;
678 if (this_cat
&& this_cat
.previousSibling
) {
679 while (this_cat
= this_cat
.previousSibling
) {
680 if (this_cat
.lastChild
&& this_cat
.firstChild
.lastChild
) {
681 var prev_feed
= this_cat
.firstChild
.lastChild
;
682 if (getCookie("ttrss_vf_hreadf") == 1) {
683 while (prev_feed
&& prev_feed
.className
== "feed") {
684 prev_feed
= prev_feed
.previousSibling
;
687 if (prev_feed
&& prev_feed
.id
.match("FEEDR-")) {
688 return prev_feed
.id
.replace("FEEDR-", "");
697 function showBlockElement(id
) {
698 var elem
= document
.getElementById(id
);
701 elem
.style
.display
= "block";
703 alert("[showBlockElement] can't find element with id " + id
);