]> git.wh0rd.org - tt-rss.git/blame - functions.js
removed view.js
[tt-rss.git] / functions.js
CommitLineData
760966c1
AD
1var hotkeys_enabled = true;
2
3function disableHotkeys() {
4 hotkeys_enabled = false;
5}
6
7function enableHotkeys() {
8 hotkeys_enabled = true;
9}
10
c0e5a40e
AD
11function xmlhttp_ready(obj) {
12 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
13}
14
15
9cfc649a
AD
16function notify_callback() {
17 var container = document.getElementById('notify');
18 if (xmlhttp.readyState == 4) {
19 container.innerHTML=xmlhttp.responseText;
20 }
21}
22
23function rpc_notify_callback() {
24 var container = document.getElementById('notify');
25 if (xmlhttp_rpc.readyState == 4) {
26 container.innerHTML=xmlhttp_rpc.responseText;
27 }
28}
29
7726fa02
AD
30function param_escape(arg) {
31 if (typeof encodeURIComponent != 'undefined')
32 return encodeURIComponent(arg);
33 else
34 return escape(arg);
35}
36
37function param_unescape(arg) {
38 if (typeof decodeURIComponent != 'undefined')
39 return decodeURIComponent(arg);
40 else
41 return unescape(arg);
42}
43
508a81e1
AD
44function delay(gap) {
45 var then,now;
46 then=new Date().getTime();
47 now=then;
48 while((now-then)<gap) {
49 now=new Date().getTime();
50 }
51}
7726fa02 52
c05608c2
AD
53function p_notify(msg) {
54
55 var n = parent.document.getElementById("notify");
56 var nb = parent.document.getElementById("notify_body");
57
58 if (!n || !nb) return;
59
8dcfffd0
AD
60 if (msg == "") {
61 nb.innerHTML = "&nbsp;";
e93919dd 62// n.style.background = "#ffffff";
c05608c2 63 } else {
8dcfffd0 64 nb.innerHTML = msg;
e93919dd 65// n.style.background = "#fffff0";
8dcfffd0 66 }
c05608c2
AD
67}
68
7726fa02
AD
69function notify(msg) {
70
71 var n = document.getElementById("notify");
c05608c2 72 var nb = document.getElementById("notify_body");
7726fa02 73
c05608c2 74 if (!n || !nb) return;
f0601b87 75
8dcfffd0
AD
76 if (msg == "") {
77 nb.innerHTML = "&nbsp;";
e93919dd 78// n.style.background = "#ffffff";
7726fa02 79 } else {
8dcfffd0 80 nb.innerHTML = msg;
e93919dd 81// n.style.background = "#fffff0";
8dcfffd0 82 }
7726fa02
AD
83
84}
85
508a81e1 86function printLockingError() {
f0601b87 87 notify("Please wait until operation finishes");}
508a81e1 88
13ad9102
AD
89var seq = "";
90
91function hotkey_handler(e) {
760966c1 92
13ad9102
AD
93 var keycode;
94
760966c1
AD
95 if (!hotkeys_enabled) return;
96
13ad9102
AD
97 if (window.event) {
98 keycode = window.event.keyCode;
99 } else if (e) {
100 keycode = e.which;
101 }
102
103 if (keycode == 13 || keycode == 27) {
104 seq = "";
105 } else {
106 seq = seq + "" + keycode;
107 }
108
109 var piggie = document.getElementById("piggie");
110
bb7cface 111 if (piggie) {
13ad9102 112
bb7cface
AD
113 if (seq.match("807371717369")) {
114 localPiggieFunction(true);
115 } else {
116 localPiggieFunction(false);
117 }
118 }
119
9cfc649a
AD
120 if (typeof localHotkeyHandler != 'undefined') {
121 localHotkeyHandler(keycode);
122 }
123
13ad9102
AD
124}
125
e828e31e 126function cleanSelectedList(element) {
f0601b87
AD
127 var content = document.getElementById(element);
128
703b632e
AD
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", "");
133 }
134 } else {
135 for (i = 0; i < content.childNodes.length; i++) {
136 var child = content.childNodes[i];
137
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", "");
143 }
144 }
145 }
e828e31e 146
703b632e 147 }
e828e31e
AD
148}
149
150
151function cleanSelected(element) {
152 var content = document.getElementById(element);
f0601b87
AD
153
154 for (i = 0; i < content.rows.length; i++) {
155 content.rows[i].className = content.rows[i].className.replace("Selected", "");
156 }
157
158}
159
160function getVisibleUnreadHeadlines() {
161 var content = document.getElementById("headlinesList");
162
163 var rows = new Array();
164
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")) {
168 rows.push(row_id);
169 }
170 }
171 return rows;
172}
173
174function getVisibleHeadlineIds() {
175
176 var content = document.getElementById("headlinesList");
177
178 var rows = new Array();
179
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) {
183 rows.push(row_id);
184 }
185 }
186 return rows;
187}
188
189function getFirstVisibleHeadlineId() {
190 var rows = getVisibleHeadlineIds();
191 return rows[0];
192}
193
194function getLastVisibleHeadlineId() {
195 var rows = getVisibleHeadlineIds();
196 return rows[rows.length-1];
197}
198
199function markHeadline(id) {
200 var row = document.getElementById("RROW-" + id);
201 if (row) {
35f3c923
AD
202 var is_active = false;
203
204 if (row.className.match("Active")) {
205 is_active = true;
206 }
207 row.className = row.className.replace("Selected", "");
208 row.className = row.className.replace("Active", "");
209 row.className = row.className.replace("Insensitive", "");
210
211 if (is_active) {
212 row.className = row.className = "Active";
213 }
214
215 row.className = row.className + "Selected";
216
f0601b87
AD
217 }
218}
219
220function getFeedIds() {
221 var content = document.getElementById("feedsList");
222
223 var rows = new Array();
224
225 for (i = 0; i < content.rows.length; i++) {
226 var id = content.rows[i].id.replace("FEEDR-", "");
227 if (id.length > 0) {
228 rows.push(id);
229 }
230 }
231
232 return rows;
233}
13ad9102 234
ac43eba1
AD
235function 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" : "");
241}
242
243function getCookie(name) {
244
245 var dc = document.cookie;
246 var prefix = name + "=";
247 var begin = dc.indexOf("; " + prefix);
248 if (begin == -1) {
249 begin = dc.indexOf(prefix);
250 if (begin != 0) return null;
251 }
252 else {
253 begin += 2;
254 }
255 var end = document.cookie.indexOf(";", begin);
256 if (end == -1) {
257 end = dc.length;
258 }
259 return unescape(dc.substring(begin + prefix.length, end));
260}
261
1a66d16e
AD
262function disableContainerChildren(id, disable, doc) {
263
264 if (!doc) doc = document;
265
266 var container = doc.getElementById(id);
ac43eba1
AD
267
268 for (var i = 0; i < container.childNodes.length; i++) {
269 var child = container.childNodes[i];
270
d5224f0d
AD
271 try {
272 child.disabled = disable;
273 } catch (E) {
274
275 }
ac43eba1
AD
276
277 if (disable) {
278 if (child.className && child.className.match("button")) {
279 child.className = "disabledButton";
280 }
281 } else {
282 if (child.className && child.className.match("disabledButton")) {
283 child.className = "button";
284 }
d5224f0d 285 }
ac43eba1
AD
286 }
287
288}
7726fa02 289
e828e31e
AD
290function gotoPreferences() {
291 document.location.href = "prefs.php";
292}
293
294function gotoMain() {
295 document.location.href = "tt-rss.php";
296}
297
8158c57a
AD
298function gotoExportOpml() {
299 document.location.href = "opml.php?op=Export";
300}
86741347
AD
301
302function getActiveFeedId() {
303 return getCookie("ttrss_vf_actfeed");
304}
305
306function setActiveFeedId(id) {
307 return setCookie("ttrss_vf_actfeed", id);
308}
090e250b
AD
309
310var xmlhttp_rpc = false;
311
312/*@cc_on @*/
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.
316try {
317 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
318} catch (e) {
319 try {
320 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
321 } catch (E) {
322 xmlhttp_rpc = false;
323 }
324}
325@end @*/
326
327if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
328 xmlhttp_rpc = new XMLHttpRequest();
329}
330
4f3a84f4 331function all_counters_callback() {
090e250b 332 if (xmlhttp_rpc.readyState == 4) {
bc18bcdd 333
9cab3250 334 if (!xmlhttp_rpc.responseXML) {
4f3a84f4 335 notify("[all_counters_callback] backend did not return valid XML");
bc18bcdd
AD
336 return;
337 }
338
090e250b
AD
339 var reply = xmlhttp_rpc.responseXML.firstChild;
340
341 var f_document = parent.frames["feeds-frame"].document;
342
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");
346
347 var feedctr = f_document.getElementById("FEEDCTR-" + id);
348 var feedu = f_document.getElementById("FEEDU-" + id);
392d4563 349 var feedr = f_document.getElementById("FEEDR-" + id);
090e250b 350
8143ae1f
AD
351 if (feedctr && feedu && feedr) {
352
353 feedu.innerHTML = ctr;
354
355 if (ctr > 0) {
356 feedctr.className = "odd";
357 if (!feedr.className.match("Unread")) {
4f3a84f4
AD
358 var is_selected = feedr.className.match("Selected");
359
360 feedr.className = feedr.className.replace("Selected", "");
361 feedr.className = feedr.className.replace("Unread", "");
362
8143ae1f 363 feedr.className = feedr.className + "Unread";
4f3a84f4
AD
364
365 if (is_selected) {
366 feedr.className = feedr.className + "Selected";
367 }
368
8143ae1f
AD
369 }
370 } else {
371 feedctr.className = "invisible";
372 feedr.className = feedr.className.replace("Unread", "");
373 }
374 }
090e250b
AD
375 }
376 }
377}
378
4f3a84f4 379function update_all_counters(feed) {
090e250b 380 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 381 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
382
383 if (feed > 0) {
384 query = query + "&aid=" + feed;
385 }
386
090e250b 387 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 388 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
389 xmlhttp_rpc.send(null);
390 }
391}
7dc66a61
AD
392
393function popupHelp(tid) {
394 var w = window.open("backend.php?op=help&tid=" + tid,
395 "Popup Help",
396 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
397}
b6644d29
AD
398
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 * * */
411
412 var numbers=".0123456789";
413 function isNumeric(x) {
414 // is x a String or a character?
415 if(x.length>1) {
416 // remove negative sign
417 x=Math.abs(x)+"";
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;
422 }
423 return number;
424 }
425 else {
426 // if x is number return true
427 if(numbers.indexOf(x)>=0) return true;
428 return false;
429 }
430 }
431
3745788e
AD
432
433function hideOrShowFeeds(doc, hide) {
434
435 var css_rules = doc.styleSheets[0].cssRules;
436
437 for (i = 0; i < css_rules.length; i++) {
438 var rule = css_rules[i];
439
440 if (rule.selectorText == "ul.feedList li.feed") {
441 if (!hide) {
442 rule.style.display = "block";
443 } else {
444 rule.style.display = "none";
445 }
446 }
447
448 }
449
450}
451
295f9b42
AD
452function fatalError(code) {
453 window.location = "error.php?c=" + param_escape(code);
35f3c923
AD
454}
455
456function selectTableRow(r, do_select) {
457 r.className = r.className.replace("Selected", "");
458
459 if (do_select) {
460 r.className = r.className + "Selected";
461 }
462}
463
3055bc41 464function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select) {
3745788e 465
35f3c923
AD
466 var content = document.getElementById(content_id);
467
468 if (!content) {
469 alert("[selectTableRows] Element " + content_id + " not found.");
470 return;
471 }
472
473 for (i = 0; i < content.rows.length; i++) {
474 if (content.rows[i].id.match(prefix)) {
475 selectTableRow(content.rows[i], do_select);
476 }
3055bc41
AD
477
478 var row_id = content.rows[i].id.replace(prefix, "");
479 var check = document.getElementById(check_prefix + row_id);
480
481 if (check) {
482 check.checked = do_select;
483 }
35f3c923 484 }
295f9b42 485}
91ff844a
AD
486
487function getSelectedTableRowIds(content_id, prefix) {
488
489 var content = document.getElementById(content_id);
490
491 if (!content) {
492 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
493 return;
494 }
495
496 var sel_rows = new Array();
497
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);
502 }
503 }
504
505 return sel_rows;
506
507}
508
509