]>
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 param_escape(arg
) {
36 if (typeof encodeURIComponent
!= 'undefined')
37 return encodeURIComponent(arg
);
42 function param_unescape(arg
) {
43 if (typeof decodeURIComponent
!= 'undefined')
44 return decodeURIComponent(arg
);
51 then
=new Date().getTime();
53 while((now
-then
)<gap
) {
54 now
=new Date().getTime();
58 function p_notify(msg
) {
60 var n
= parent
.document
.getElementById("notify");
61 var nb
= parent
.document
.getElementById("notify_body");
63 if (!n
|| !nb
) return;
66 nb
.innerHTML
= " ";
67 // n.style.background = "#ffffff";
70 // n.style.background = "#fffff0";
74 function notify(msg
) {
76 var n
= document
.getElementById("notify");
77 var nb
= document
.getElementById("notify_body");
79 if (!n
|| !nb
) return;
82 nb
.innerHTML
= " ";
83 // n.style.background = "#ffffff";
86 // n.style.background = "#fffff0";
91 function printLockingError() {
92 notify("Please wait until operation finishes");}
96 function hotkey_handler(e
) {
100 if (!hotkeys_enabled
) return;
103 keycode
= window
.event
.keyCode
;
108 if (keycode
== 13 || keycode
== 27) {
111 seq
= seq
+ "" + keycode
;
114 var piggie
= document
.getElementById("piggie");
118 if (seq
.match("807371717369")) {
119 localPiggieFunction(true);
121 localPiggieFunction(false);
125 if (typeof localHotkeyHandler
!= 'undefined') {
126 localHotkeyHandler(keycode
);
131 function cleanSelectedList(element
) {
132 var content
= document
.getElementById(element
);
134 if (!document
.getElementById("feedCatHolder")) {
135 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
136 var child
= content
.childNodes
[i
];
137 child
.className
= child
.className
.replace("Selected", "");
140 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
141 var child
= content
.childNodes
[i
];
143 if (child
.id
== "feedCatHolder") {
144 var fcat
= child
.firstChild
;
145 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
146 var feed
= fcat
.childNodes
[j
];
147 feed
.className
= feed
.className
.replace("Selected", "");
156 function cleanSelected(element
) {
157 var content
= document
.getElementById(element
);
159 for (i
= 0; i
< content
.rows
.length
; i
++) {
160 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
165 function getVisibleUnreadHeadlines() {
166 var content
= document
.getElementById("headlinesList");
168 var rows
= new Array();
170 for (i
= 0; i
< content
.rows
.length
; i
++) {
171 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
172 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
179 function getVisibleHeadlineIds() {
181 var content
= document
.getElementById("headlinesList");
183 var rows
= new Array();
185 for (i
= 0; i
< content
.rows
.length
; i
++) {
186 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
187 if (row_id
.length
> 0) {
194 function getFirstVisibleHeadlineId() {
195 var rows
= getVisibleHeadlineIds();
199 function getLastVisibleHeadlineId() {
200 var rows
= getVisibleHeadlineIds();
201 return rows
[rows
.length
-1];
204 function markHeadline(id
) {
205 var row
= document
.getElementById("RROW-" + id
);
207 var is_active
= false;
209 if (row
.className
.match("Active")) {
212 row
.className
= row
.className
.replace("Selected", "");
213 row
.className
= row
.className
.replace("Active", "");
214 row
.className
= row
.className
.replace("Insensitive", "");
217 row
.className
= row
.className
= "Active";
220 row
.className
= row
.className
+ "Selected";
225 function getFeedIds() {
226 var content
= document
.getElementById("feedsList");
228 var rows
= new Array();
230 for (i
= 0; i
< content
.rows
.length
; i
++) {
231 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
240 function setCookie(name
, value
, expires
, path
, domain
, secure
) {
241 document
.cookie
= name
+ "=" + escape(value
) +
242 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
243 ((path
) ? "; path=" + path
: "") +
244 ((domain
) ? "; domain=" + domain
: "") +
245 ((secure
) ? "; secure" : "");
248 function getCookie(name
) {
250 var dc
= document
.cookie
;
251 var prefix
= name
+ "=";
252 var begin
= dc
.indexOf("; " + prefix
);
254 begin
= dc
.indexOf(prefix
);
255 if (begin
!= 0) return null;
260 var end
= document
.cookie
.indexOf(";", begin
);
264 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
267 function disableContainerChildren(id
, disable
, doc
) {
269 if (!doc
) doc
= document
;
271 var container
= doc
.getElementById(id
);
273 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
274 var child
= container
.childNodes
[i
];
277 child
.disabled
= disable
;
283 if (child
.className
&& child
.className
.match("button")) {
284 child
.className
= "disabledButton";
287 if (child
.className
&& child
.className
.match("disabledButton")) {
288 child
.className
= "button";
295 function gotoPreferences() {
296 document
.location
.href
= "prefs.php";
299 function gotoMain() {
300 document
.location
.href
= "tt-rss.php";
303 function gotoExportOpml() {
304 document
.location
.href
= "opml.php?op=Export";
307 function getActiveFeedId() {
308 return getCookie("ttrss_vf_actfeed");
311 function setActiveFeedId(id
) {
312 return setCookie("ttrss_vf_actfeed", id
);
315 var xmlhttp_rpc
= false;
318 /*@if (@_jscript_version >= 5)
319 // JScript gives us Conditional compilation, we can cope with old IE versions.
320 // and security blocked creation of the objects.
322 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
325 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
332 if (!xmlhttp_rpc
&& typeof XMLHttpRequest
!='undefined') {
333 xmlhttp_rpc
= new XMLHttpRequest();
336 function all_counters_callback() {
337 if (xmlhttp_rpc
.readyState
== 4) {
339 if (!xmlhttp_rpc
.responseXML
) {
340 notify("[all_counters_callback] backend did not return valid XML");
344 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
346 var f_document
= parent
.frames
["feeds-frame"].document
;
348 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
349 var id
= reply
.childNodes
[l
].getAttribute("id");
350 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
352 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
353 var feedu
= f_document
.getElementById("FEEDU-" + id
);
354 var feedr
= f_document
.getElementById("FEEDR-" + id
);
356 if (feedctr
&& feedu
&& feedr
) {
358 feedu
.innerHTML
= ctr
;
361 feedctr
.className
= "odd";
362 if (!feedr
.className
.match("Unread")) {
363 var is_selected
= feedr
.className
.match("Selected");
365 feedr
.className
= feedr
.className
.replace("Selected", "");
366 feedr
.className
= feedr
.className
.replace("Unread", "");
368 feedr
.className
= feedr
.className
+ "Unread";
371 feedr
.className
= feedr
.className
+ "Selected";
376 feedctr
.className
= "invisible";
377 feedr
.className
= feedr
.className
.replace("Unread", "");
382 exception_error("all_counters_callback", e
);
387 function update_all_counters(feed
) {
388 if (xmlhttp_ready(xmlhttp_rpc
)) {
389 var query
= "backend.php?op=rpc&subop=getAllCounters";
392 query
= query
+ "&aid=" + feed
;
395 xmlhttp_rpc
.open("GET", query
, true);
396 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
397 xmlhttp_rpc
.send(null);
401 function popupHelp(tid
) {
402 var w
= window
.open("backend.php?op=help&tid=" + tid
,
404 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
407 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
408 * * @author Sundar Dorai-Raj
409 * * Email: sdoraira@vt.edu
410 * * This program is free software; you can redistribute it and/or
411 * * modify it under the terms of the GNU General Public License
412 * * as published by the Free Software Foundation; either version 2
413 * * of the License, or (at your option) any later version,
414 * * provided that any use properly credits the author.
415 * * This program is distributed in the hope that it will be useful,
416 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
417 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
418 * * GNU General Public License for more details at http://www.gnu.org * * */
420 var numbers
=".0123456789";
421 function isNumeric(x
) {
422 // is x a String or a character?
424 // remove negative sign
426 for(j
=0;j
<x
.length
;j
++) {
427 // call isNumeric recursively for each character
428 number
=isNumeric(x
.substring(j
,j
+1));
429 if(!number
) return number
;
434 // if x is number return true
435 if(numbers
.indexOf(x
)>=0) return true;
441 function hideOrShowFeeds(doc
, hide
) {
443 var css_rules
= doc
.styleSheets
[0].cssRules
;
445 for (i
= 0; i
< css_rules
.length
; i
++) {
446 var rule
= css_rules
[i
];
448 if (rule
.selectorText
== "ul.feedList li.feed") {
450 rule
.style
.display
= "block";
452 rule
.style
.display
= "none";
460 function fatalError(code
) {
461 window
.location
= "error.php?c=" + param_escape(code
);
464 function selectTableRow(r
, do_select
) {
465 r
.className
= r
.className
.replace("Selected", "");
468 r
.className
= r
.className
+ "Selected";
472 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
) {
474 var content
= document
.getElementById(content_id
);
477 alert("[selectTableRows] Element " + content_id
+ " not found.");
481 for (i
= 0; i
< content
.rows
.length
; i
++) {
482 if (content
.rows
[i
].id
.match(prefix
)) {
483 selectTableRow(content
.rows
[i
], do_select
);
486 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
487 var check
= document
.getElementById(check_prefix
+ row_id
);
490 check
.checked
= do_select
;
495 function getSelectedTableRowIds(content_id
, prefix
) {
497 var content
= document
.getElementById(content_id
);
500 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
504 var sel_rows
= new Array();
506 for (i
= 0; i
< content
.rows
.length
; i
++) {
507 if (content
.rows
[i
].className
.match("Selected")) {
508 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
509 sel_rows
.push(row_id
);