]>
git.wh0rd.org - tt-rss.git/blob - functions.js
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') {
133 localHotkeyHandler(keycode
);
138 function cleanSelectedList(element
) {
139 var content
= document
.getElementById(element
);
141 if (!document
.getElementById("feedCatHolder")) {
142 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
143 var child
= content
.childNodes
[i
];
144 child
.className
= child
.className
.replace("Selected", "");
147 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
148 var child
= content
.childNodes
[i
];
150 if (child
.id
== "feedCatHolder") {
151 var fcat
= child
.firstChild
;
152 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
153 var feed
= fcat
.childNodes
[j
];
154 feed
.className
= feed
.className
.replace("Selected", "");
163 function cleanSelected(element
) {
164 var content
= document
.getElementById(element
);
166 for (i
= 0; i
< content
.rows
.length
; i
++) {
167 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
172 function getVisibleUnreadHeadlines() {
173 var content
= document
.getElementById("headlinesList");
175 var rows
= new Array();
177 for (i
= 0; i
< content
.rows
.length
; i
++) {
178 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
179 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
186 function getVisibleHeadlineIds() {
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) {
201 function getFirstVisibleHeadlineId() {
202 var rows
= getVisibleHeadlineIds();
206 function getLastVisibleHeadlineId() {
207 var rows
= getVisibleHeadlineIds();
208 return rows
[rows
.length
-1];
211 function markHeadline(id
) {
212 var row
= document
.getElementById("RROW-" + id
);
214 var is_active
= false;
216 if (row
.className
.match("Active")) {
219 row
.className
= row
.className
.replace("Selected", "");
220 row
.className
= row
.className
.replace("Active", "");
221 row
.className
= row
.className
.replace("Insensitive", "");
224 row
.className
= row
.className
= "Active";
227 row
.className
= row
.className
+ "Selected";
232 function getFeedIds() {
233 var content
= document
.getElementById("feedsList");
235 var rows
= new Array();
237 for (i
= 0; i
< content
.rows
.length
; i
++) {
238 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
247 function setCookie(name
, value
, expires
, path
, domain
, secure
) {
248 document
.cookie
= name
+ "=" + escape(value
) +
249 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
250 ((path
) ? "; path=" + path
: "") +
251 ((domain
) ? "; domain=" + domain
: "") +
252 ((secure
) ? "; secure" : "");
255 function getCookie(name
) {
257 var dc
= document
.cookie
;
258 var prefix
= name
+ "=";
259 var begin
= dc
.indexOf("; " + prefix
);
261 begin
= dc
.indexOf(prefix
);
262 if (begin
!= 0) return null;
267 var end
= document
.cookie
.indexOf(";", begin
);
271 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
274 function disableContainerChildren(id
, disable
, doc
) {
276 if (!doc
) doc
= document
;
278 var container
= doc
.getElementById(id
);
280 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
281 var child
= container
.childNodes
[i
];
284 child
.disabled
= disable
;
290 if (child
.className
&& child
.className
.match("button")) {
291 child
.className
= "disabledButton";
294 if (child
.className
&& child
.className
.match("disabledButton")) {
295 child
.className
= "button";
302 function gotoPreferences() {
303 document
.location
.href
= "prefs.php";
306 function gotoMain() {
307 document
.location
.href
= "tt-rss.php";
310 function gotoExportOpml() {
311 document
.location
.href
= "opml.php?op=Export";
314 function getActiveFeedId() {
315 return getCookie("ttrss_vf_actfeed");
318 function setActiveFeedId(id
) {
319 return setCookie("ttrss_vf_actfeed", id
);
322 var xmlhttp_rpc
= false;
325 /*@if (@_jscript_version >= 5)
326 // JScript gives us Conditional compilation, we can cope with old IE versions.
327 // and security blocked creation of the objects.
329 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
332 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
339 if (!xmlhttp_rpc
&& typeof XMLHttpRequest
!='undefined') {
340 xmlhttp_rpc
= new XMLHttpRequest();
343 function all_counters_callback() {
344 if (xmlhttp_rpc
.readyState
== 4) {
346 if (!xmlhttp_rpc
.responseXML
) {
347 notify("[all_counters_callback] backend did not return valid XML");
351 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
353 var f_document
= parent
.frames
["feeds-frame"].document
;
355 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
356 var id
= reply
.childNodes
[l
].getAttribute("id");
357 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
359 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
360 var feedu
= f_document
.getElementById("FEEDU-" + id
);
361 var feedr
= f_document
.getElementById("FEEDR-" + id
);
363 if (feedctr
&& feedu
&& feedr
) {
365 feedu
.innerHTML
= ctr
;
368 feedctr
.className
= "odd";
369 if (!feedr
.className
.match("Unread")) {
370 var is_selected
= feedr
.className
.match("Selected");
372 feedr
.className
= feedr
.className
.replace("Selected", "");
373 feedr
.className
= feedr
.className
.replace("Unread", "");
375 feedr
.className
= feedr
.className
+ "Unread";
378 feedr
.className
= feedr
.className
+ "Selected";
383 feedctr
.className
= "invisible";
384 feedr
.className
= feedr
.className
.replace("Unread", "");
389 exception_error("all_counters_callback", e
);
394 function update_all_counters(feed
) {
395 if (xmlhttp_ready(xmlhttp_rpc
)) {
396 var query
= "backend.php?op=rpc&subop=getAllCounters";
399 query
= query
+ "&aid=" + feed
;
402 xmlhttp_rpc
.open("GET", query
, true);
403 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
404 xmlhttp_rpc
.send(null);
408 function popupHelp(tid
) {
409 var w
= window
.open("backend.php?op=help&tid=" + tid
,
411 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
414 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
415 * * @author Sundar Dorai-Raj
416 * * Email: sdoraira@vt.edu
417 * * This program is free software; you can redistribute it and/or
418 * * modify it under the terms of the GNU General Public License
419 * * as published by the Free Software Foundation; either version 2
420 * * of the License, or (at your option) any later version,
421 * * provided that any use properly credits the author.
422 * * This program is distributed in the hope that it will be useful,
423 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
424 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
425 * * GNU General Public License for more details at http://www.gnu.org * * */
427 var numbers
=".0123456789";
428 function isNumeric(x
) {
429 // is x a String or a character?
431 // remove negative sign
433 for(j
=0;j
<x
.length
;j
++) {
434 // call isNumeric recursively for each character
435 number
=isNumeric(x
.substring(j
,j
+1));
436 if(!number
) return number
;
441 // if x is number return true
442 if(numbers
.indexOf(x
)>=0) return true;
448 function hideOrShowFeeds(doc
, hide
) {
450 var css_rules
= doc
.styleSheets
[0].cssRules
;
452 for (i
= 0; i
< css_rules
.length
; i
++) {
453 var rule
= css_rules
[i
];
455 if (rule
.selectorText
== "ul.feedList li.feed") {
457 rule
.style
.display
= "block";
459 rule
.style
.display
= "none";
467 function fatalError(code
) {
468 window
.location
= "error.php?c=" + param_escape(code
);
471 function selectTableRow(r
, do_select
) {
472 r
.className
= r
.className
.replace("Selected", "");
475 r
.className
= r
.className
+ "Selected";
479 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
482 var content
= document
.getElementById(content_id
);
485 alert("[selectTableRows] Element " + content_id
+ " not found.");
489 for (i
= 0; i
< content
.rows
.length
; i
++) {
490 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
492 if (content
.rows
[i
].id
.match(prefix
)) {
493 selectTableRow(content
.rows
[i
], do_select
);
496 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
497 var check
= document
.getElementById(check_prefix
+ row_id
);
500 check
.checked
= do_select
;
506 function getSelectedTableRowIds(content_id
, prefix
) {
508 var content
= document
.getElementById(content_id
);
511 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
515 var sel_rows
= new Array();
517 for (i
= 0; i
< content
.rows
.length
; i
++) {
518 if (content
.rows
[i
].id
.match(prefix
) &&
519 content
.rows
[i
].className
.match("Selected")) {
521 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
522 sel_rows
.push(row_id
);
530 function toggleSelectRow(sender
) {
531 var parent_row
= sender
.parentNode
.parentNode
;
533 if (sender
.checked
) {
534 if (!parent_row
.className
.match("Selected")) {
535 parent_row
.className
= parent_row
.className
+ "Selected";
538 if (parent_row
.className
.match("Selected")) {
539 parent_row
.className
= parent_row
.className
.replace("Selected", "");