]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var hotkeys_enabled
= true;
3 function disableHotkeys() {
4 hotkeys_enabled
= false;
7 function enableHotkeys() {
8 hotkeys_enabled
= true;
11 function xmlhttp_ready(obj
) {
12 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
16 function notify_callback() {
17 var container
= document
.getElementById('notify');
18 if (xmlhttp
.readyState
== 4) {
19 container
.innerHTML
=xmlhttp
.responseText
;
23 function rpc_notify_callback() {
24 var container
= document
.getElementById('notify');
25 if (xmlhttp_rpc
.readyState
== 4) {
26 container
.innerHTML
=xmlhttp_rpc
.responseText
;
30 function param_escape(arg
) {
31 if (typeof encodeURIComponent
!= 'undefined')
32 return encodeURIComponent(arg
);
37 function param_unescape(arg
) {
38 if (typeof decodeURIComponent
!= 'undefined')
39 return decodeURIComponent(arg
);
46 then
=new Date().getTime();
48 while((now
-then
)<gap
) {
49 now
=new Date().getTime();
53 function p_notify(msg
) {
55 var n
= parent
.document
.getElementById("notify");
56 var nb
= parent
.document
.getElementById("notify_body");
58 if (!n
|| !nb
) return;
61 nb
.innerHTML
= " ";
62 // n.style.background = "#ffffff";
65 // n.style.background = "#fffff0";
69 function notify(msg
) {
71 var n
= document
.getElementById("notify");
72 var nb
= document
.getElementById("notify_body");
74 if (!n
|| !nb
) return;
77 nb
.innerHTML
= " ";
78 // n.style.background = "#ffffff";
81 // n.style.background = "#fffff0";
86 function printLockingError() {
87 notify("Please wait until operation finishes");}
91 function hotkey_handler(e
) {
95 if (!hotkeys_enabled
) return;
98 keycode
= window
.event
.keyCode
;
103 if (keycode
== 13 || keycode
== 27) {
106 seq
= seq
+ "" + keycode
;
109 var piggie
= document
.getElementById("piggie");
113 if (seq
.match("807371717369")) {
114 localPiggieFunction(true);
116 localPiggieFunction(false);
120 if (typeof localHotkeyHandler
!= 'undefined') {
121 localHotkeyHandler(keycode
);
126 function cleanSelectedList(element
) {
127 var content
= document
.getElementById(element
);
129 if (!document
.getElementById("feedCatHolder")) {
130 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
131 var child
= content
.childNodes
[i
];
132 child
.className
= child
.className
.replace("Selected", "");
135 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
136 var child
= content
.childNodes
[i
];
138 if (child
.id
== "feedCatHolder") {
139 var fcat
= child
.firstChild
;
140 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
141 var feed
= fcat
.childNodes
[j
];
142 feed
.className
= feed
.className
.replace("Selected", "");
151 function cleanSelected(element
) {
152 var content
= document
.getElementById(element
);
154 for (i
= 0; i
< content
.rows
.length
; i
++) {
155 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
160 function getVisibleUnreadHeadlines() {
161 var content
= document
.getElementById("headlinesList");
163 var rows
= new Array();
165 for (i
= 0; i
< content
.rows
.length
; i
++) {
166 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
167 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
174 function getVisibleHeadlineIds() {
176 var content
= document
.getElementById("headlinesList");
178 var rows
= new Array();
180 for (i
= 0; i
< content
.rows
.length
; i
++) {
181 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
182 if (row_id
.length
> 0) {
189 function getFirstVisibleHeadlineId() {
190 var rows
= getVisibleHeadlineIds();
194 function getLastVisibleHeadlineId() {
195 var rows
= getVisibleHeadlineIds();
196 return rows
[rows
.length
-1];
199 function markHeadline(id
) {
200 var row
= document
.getElementById("RROW-" + id
);
202 var is_active
= false;
204 if (row
.className
.match("Active")) {
207 row
.className
= row
.className
.replace("Selected", "");
208 row
.className
= row
.className
.replace("Active", "");
209 row
.className
= row
.className
.replace("Insensitive", "");
212 row
.className
= row
.className
= "Active";
215 row
.className
= row
.className
+ "Selected";
220 function getFeedIds() {
221 var content
= document
.getElementById("feedsList");
223 var rows
= new Array();
225 for (i
= 0; i
< content
.rows
.length
; i
++) {
226 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
235 function setCookie(name
, value
, expires
, path
, domain
, secure
) {
236 document
.cookie
= name
+ "=" + escape(value
) +
237 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
238 ((path
) ? "; path=" + path
: "") +
239 ((domain
) ? "; domain=" + domain
: "") +
240 ((secure
) ? "; secure" : "");
243 function getCookie(name
) {
245 var dc
= document
.cookie
;
246 var prefix
= name
+ "=";
247 var begin
= dc
.indexOf("; " + prefix
);
249 begin
= dc
.indexOf(prefix
);
250 if (begin
!= 0) return null;
255 var end
= document
.cookie
.indexOf(";", begin
);
259 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
262 function disableContainerChildren(id
, disable
, doc
) {
264 if (!doc
) doc
= document
;
266 var container
= doc
.getElementById(id
);
268 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
269 var child
= container
.childNodes
[i
];
272 child
.disabled
= disable
;
278 if (child
.className
&& child
.className
.match("button")) {
279 child
.className
= "disabledButton";
282 if (child
.className
&& child
.className
.match("disabledButton")) {
283 child
.className
= "button";
290 function gotoPreferences() {
291 document
.location
.href
= "prefs.php";
294 function gotoMain() {
295 document
.location
.href
= "tt-rss.php";
298 function gotoExportOpml() {
299 document
.location
.href
= "opml.php?op=Export";
302 function getActiveFeedId() {
303 return getCookie("ttrss_vf_actfeed");
306 function setActiveFeedId(id
) {
307 return setCookie("ttrss_vf_actfeed", id
);
310 var xmlhttp_rpc
= false;
313 /*@if (@_jscript_version >= 5)
314 // JScript gives us Conditional compilation, we can cope with old IE versions.
315 // and security blocked creation of the objects.
317 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
320 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
327 if (!xmlhttp_rpc
&& typeof XMLHttpRequest
!='undefined') {
328 xmlhttp_rpc
= new XMLHttpRequest();
331 function all_counters_callback() {
332 if (xmlhttp_rpc
.readyState
== 4) {
334 if (!xmlhttp_rpc
.responseXML
) {
335 notify("[all_counters_callback] backend did not return valid XML");
339 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
341 var f_document
= parent
.frames
["feeds-frame"].document
;
343 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
344 var id
= reply
.childNodes
[l
].getAttribute("id");
345 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
347 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
348 var feedu
= f_document
.getElementById("FEEDU-" + id
);
349 var feedr
= f_document
.getElementById("FEEDR-" + id
);
351 if (feedctr
&& feedu
&& feedr
) {
353 feedu
.innerHTML
= ctr
;
356 feedctr
.className
= "odd";
357 if (!feedr
.className
.match("Unread")) {
358 var is_selected
= feedr
.className
.match("Selected");
360 feedr
.className
= feedr
.className
.replace("Selected", "");
361 feedr
.className
= feedr
.className
.replace("Unread", "");
363 feedr
.className
= feedr
.className
+ "Unread";
366 feedr
.className
= feedr
.className
+ "Selected";
371 feedctr
.className
= "invisible";
372 feedr
.className
= feedr
.className
.replace("Unread", "");
379 function update_all_counters(feed
) {
380 if (xmlhttp_ready(xmlhttp_rpc
)) {
381 var query
= "backend.php?op=rpc&subop=getAllCounters";
384 query
= query
+ "&aid=" + feed
;
387 xmlhttp_rpc
.open("GET", query
, true);
388 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
389 xmlhttp_rpc
.send(null);
393 function popupHelp(tid
) {
394 var w
= window
.open("backend.php?op=help&tid=" + tid
,
396 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
399 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
400 * * @author Sundar Dorai-Raj
401 * * Email: sdoraira@vt.edu
402 * * This program is free software; you can redistribute it and/or
403 * * modify it under the terms of the GNU General Public License
404 * * as published by the Free Software Foundation; either version 2
405 * * of the License, or (at your option) any later version,
406 * * provided that any use properly credits the author.
407 * * This program is distributed in the hope that it will be useful,
408 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
409 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
410 * * GNU General Public License for more details at http://www.gnu.org * * */
412 var numbers
=".0123456789";
413 function isNumeric(x
) {
414 // is x a String or a character?
416 // remove negative sign
418 for(j
=0;j
<x
.length
;j
++) {
419 // call isNumeric recursively for each character
420 number
=isNumeric(x
.substring(j
,j
+1));
421 if(!number
) return number
;
426 // if x is number return true
427 if(numbers
.indexOf(x
)>=0) return true;
433 function hideOrShowFeeds(doc
, hide
) {
435 var css_rules
= doc
.styleSheets
[0].cssRules
;
437 for (i
= 0; i
< css_rules
.length
; i
++) {
438 var rule
= css_rules
[i
];
440 if (rule
.selectorText
== "ul.feedList li.feed") {
442 rule
.style
.display
= "block";
444 rule
.style
.display
= "none";
452 function fatalError(code
) {
453 window
.location
= "error.php?c=" + param_escape(code
);
456 function selectTableRow(r
, do_select
) {
457 r
.className
= r
.className
.replace("Selected", "");
460 r
.className
= r
.className
+ "Selected";
464 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
) {
466 var content
= document
.getElementById(content_id
);
469 alert("[selectTableRows] Element " + content_id
+ " not found.");
473 for (i
= 0; i
< content
.rows
.length
; i
++) {
474 if (content
.rows
[i
].id
.match(prefix
)) {
475 selectTableRow(content
.rows
[i
], do_select
);
478 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
479 var check
= document
.getElementById(check_prefix
+ row_id
);
482 check
.checked
= do_select
;
487 function getSelectedTableRowIds(content_id
, prefix
) {
489 var content
= document
.getElementById(content_id
);
492 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
496 var sel_rows
= new Array();
498 for (i
= 0; i
< content
.rows
.length
; i
++) {
499 if (content
.rows
[i
].className
.match("Selected")) {
500 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
501 sel_rows
.push(row_id
);