]> git.wh0rd.org - tt-rss.git/blame - functions.js
toolbar placement fix in graycube
[tt-rss.git] / functions.js
CommitLineData
760966c1
AD
1var hotkeys_enabled = true;
2
a7565293
AD
3var xmlhttp_rpc = Ajax.getTransport();
4
292a8a12 5function browser_has_opacity() {
605f7d46
AD
6 return navigator.userAgent.match("Gecko") != null ||
7 navigator.userAgent.match("Opera") != null;
292a8a12
AD
8}
9
7c620da8
AD
10function is_opera() {
11 return navigator.userAgent.match("Opera");
12}
13
55160955 14function exception_error(location, e, silent) {
83f043bb
AD
15 var msg;
16
17 if (e.fileName) {
18 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
19
20 msg = "Exception: " + e.name + ", " + e.message +
21 "\nFunction: " + location + "()" +
22 "\nLocation: " + base_fname + ":" + e.lineNumber;
ee1f45f4 23
83f043bb
AD
24 } else {
25 msg = "Exception: " + e + "\nFunction: " + location + "()";
26 }
27
ee1f45f4
AD
28 debug("<b>EXCEPTION: " + msg + "</b>");
29
55160955
AD
30 if (!silent) {
31 alert(msg);
32 }
7719618b
AD
33}
34
760966c1
AD
35function disableHotkeys() {
36 hotkeys_enabled = false;
37}
38
39function enableHotkeys() {
40 hotkeys_enabled = true;
41}
42
c0e5a40e
AD
43function xmlhttp_ready(obj) {
44 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
45}
46
9cfc649a
AD
47function notify_callback() {
48 var container = document.getElementById('notify');
49 if (xmlhttp.readyState == 4) {
50 container.innerHTML=xmlhttp.responseText;
51 }
52}
53
54function rpc_notify_callback() {
55 var container = document.getElementById('notify');
56 if (xmlhttp_rpc.readyState == 4) {
57 container.innerHTML=xmlhttp_rpc.responseText;
58 }
59}
60
7726fa02
AD
61function param_escape(arg) {
62 if (typeof encodeURIComponent != 'undefined')
63 return encodeURIComponent(arg);
64 else
65 return escape(arg);
66}
67
68function param_unescape(arg) {
69 if (typeof decodeURIComponent != 'undefined')
70 return decodeURIComponent(arg);
71 else
72 return unescape(arg);
73}
74
508a81e1
AD
75function delay(gap) {
76 var then,now;
77 then=new Date().getTime();
78 now=then;
79 while((now-then)<gap) {
80 now=new Date().getTime();
81 }
82}
7726fa02 83
ce3bf408
AD
84var notify_hide_timerid = false;
85var notify_last_doc = false;
86
d05514a4 87var notify_effect = false;
59a543f0 88
ce3bf408
AD
89function hide_notify() {
90 if (notify_last_doc) {
91 var n = notify_last_doc.getElementById("notify");
d05514a4
AD
92 n.style.display = "none";
93
94/* if (browser_has_opacity()) {
ce3bf408 95 if (notify_opacity >= 0) {
0655a1d5 96 notify_opacity = notify_opacity - 0.1;
ce3bf408 97 n.style.opacity = notify_opacity;
292a8a12 98 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
ce3bf408
AD
99 } else {
100 n.style.display = "none";
292a8a12 101 n.style.opacity = 1;
ce3bf408
AD
102 }
103 } else {
104 n.style.display = "none";
d05514a4 105 } */
8dcfffd0 106 }
d05514a4 107}
c05608c2 108
0530ddd8 109function notify_real(msg, doc, no_hide, is_err) {
7726fa02 110
ce3bf408
AD
111 var n = doc.getElementById("notify");
112 var nb = doc.getElementById("notify_body");
7726fa02 113
c05608c2 114 if (!n || !nb) return;
f0601b87 115
0655a1d5
AD
116 if (notify_hide_timerid) {
117 window.clearTimeout(notify_hide_timerid);
118 }
119
120 notify_last_doc = doc;
121 notify_opacity = 1;
122
8dcfffd0 123 if (msg == "") {
0655a1d5
AD
124 if (n.style.display == "block") {
125 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
126 }
127 return;
7726fa02 128 } else {
0ceded7a 129 n.style.display = "block";
8dcfffd0 130 }
7726fa02 131
0530ddd8 132 if (is_err) {
caa53a7c
AD
133 n.style.backgroundColor = "#ffcccc";
134 n.style.color = "black";
0530ddd8
AD
135 n.style.borderColor = "#ff0000";
136 } else {
137 n.style.backgroundColor = "#fff7d5";
138 n.style.borderColor = "#d7c47a";
139 n.style.color = "black";
140 }
141
106689b0
AD
142// msg = "<img src='images/live_com_loading.gif'> " + msg;
143
0ceded7a
AD
144 nb.innerHTML = msg;
145
4d4200a8 146 if (!no_hide) {
292a8a12 147 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 148 }
ce3bf408
AD
149}
150
0530ddd8 151function p_notify(msg, no_hide, is_err) {
9cb99906 152 notify_real(msg, document, no_hide, is_err);
ce3bf408
AD
153}
154
0530ddd8
AD
155function notify(msg, no_hide, is_err) {
156 notify_real(msg, document, no_hide, is_err);
7726fa02
AD
157}
158
508a81e1 159function printLockingError() {
f0601b87 160 notify("Please wait until operation finishes");}
508a81e1 161
13ad9102 162function hotkey_handler(e) {
760966c1 163
ee1f45f4 164 try {
2e02b896 165
ee1f45f4
AD
166 var keycode;
167
168 if (!hotkeys_enabled) return;
169
170 if (window.event) {
171 keycode = window.event.keyCode;
172 } else if (e) {
173 keycode = e.which;
174 }
d437c8cf 175
ee1f45f4 176 if (keycode == 82) { // r
0feab655 177 return scheduleFeedUpdate(true);
ee1f45f4 178 }
0a383013
AD
179
180 if (keycode == 83) { // r
0feab655 181 return displayDlg("search", getActiveFeedId());
0a383013
AD
182 }
183
ee1f45f4
AD
184 if (keycode == 85) { // u
185 if (getActiveFeedId()) {
0feab655 186 return viewfeed(getActiveFeedId(), "ForceUpdate");
ee1f45f4
AD
187 }
188 }
189
190 if (keycode == 65) { // a
0feab655 191 return toggleDispRead();
ee1f45f4
AD
192 }
193
0feab655 194 var feedlist = document.getElementById('feedList');
ee1f45f4
AD
195
196 if (keycode == 74) { // j
197 var feed = getActiveFeedId();
198 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
767e2486 199 if (new_feed) viewfeed(new_feed, '');
ee1f45f4
AD
200 }
201
202 if (keycode == 75) { // k
203 var feed = getActiveFeedId();
204 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
767e2486 205 if (new_feed) viewfeed(new_feed, '');
7b433d8c 206 }
9cfc649a 207
ee1f45f4 208 if (keycode == 78 || keycode == 40) { // n, down
0feab655
AD
209 if (typeof moveToPost != 'undefined') {
210 return moveToPost('next');
e59a2f12 211 }
ee1f45f4
AD
212 }
213
214 if (keycode == 80 || keycode == 38) { // p, up
0feab655
AD
215 if (typeof moveToPost != 'undefined') {
216 return moveToPost('prev');
e59a2f12 217 }
ee1f45f4
AD
218 }
219
220 if (typeof localHotkeyHandler != 'undefined') {
221 try {
222 localHotkeyHandler(keycode);
223 } catch (e) {
224 exception_error("hotkey_handler, local:", e);
225 }
226 }
227 } catch (e) {
228 exception_error("hotkey_handler", e);
229 }
13ad9102
AD
230}
231
e828e31e 232function cleanSelectedList(element) {
f0601b87
AD
233 var content = document.getElementById(element);
234
703b632e
AD
235 if (!document.getElementById("feedCatHolder")) {
236 for (i = 0; i < content.childNodes.length; i++) {
237 var child = content.childNodes[i];
d0bb308e
AD
238 try {
239 child.className = child.className.replace("Selected", "");
240 } catch (e) {
241 //
242 }
703b632e
AD
243 }
244 } else {
245 for (i = 0; i < content.childNodes.length; i++) {
246 var child = content.childNodes[i];
703b632e 247 if (child.id == "feedCatHolder") {
9cb99906 248 debug(child.id);
c3f348c2 249 var fcat = child.lastChild;
703b632e 250 for (j = 0; j < fcat.childNodes.length; j++) {
befc807f 251 var feed = fcat.childNodes[j];
703b632e
AD
252 feed.className = feed.className.replace("Selected", "");
253 }
254 }
befc807f 255 }
703b632e 256 }
e828e31e
AD
257}
258
259
260function cleanSelected(element) {
261 var content = document.getElementById(element);
f0601b87
AD
262
263 for (i = 0; i < content.rows.length; i++) {
264 content.rows[i].className = content.rows[i].className.replace("Selected", "");
265 }
f0601b87
AD
266}
267
268function getVisibleUnreadHeadlines() {
269 var content = document.getElementById("headlinesList");
270
271 var rows = new Array();
272
273 for (i = 0; i < content.rows.length; i++) {
274 var row_id = content.rows[i].id.replace("RROW-", "");
275 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
276 rows.push(row_id);
277 }
278 }
279 return rows;
280}
281
282function getVisibleHeadlineIds() {
283
284 var content = document.getElementById("headlinesList");
285
286 var rows = new Array();
287
288 for (i = 0; i < content.rows.length; i++) {
289 var row_id = content.rows[i].id.replace("RROW-", "");
290 if (row_id.length > 0) {
291 rows.push(row_id);
292 }
293 }
294 return rows;
295}
296
297function getFirstVisibleHeadlineId() {
298 var rows = getVisibleHeadlineIds();
299 return rows[0];
300}
301
302function getLastVisibleHeadlineId() {
303 var rows = getVisibleHeadlineIds();
304 return rows[rows.length-1];
305}
306
307function markHeadline(id) {
308 var row = document.getElementById("RROW-" + id);
309 if (row) {
35f3c923
AD
310 var is_active = false;
311
312 if (row.className.match("Active")) {
313 is_active = true;
314 }
315 row.className = row.className.replace("Selected", "");
316 row.className = row.className.replace("Active", "");
317 row.className = row.className.replace("Insensitive", "");
318
319 if (is_active) {
320 row.className = row.className = "Active";
321 }
322
72020095
AD
323 var check = document.getElementById("RCHK-" + id);
324
325 if (check) {
326 check.checked = true;
327 }
328
35f3c923
AD
329 row.className = row.className + "Selected";
330
f0601b87
AD
331 }
332}
333
334function getFeedIds() {
335 var content = document.getElementById("feedsList");
336
337 var rows = new Array();
338
339 for (i = 0; i < content.rows.length; i++) {
340 var id = content.rows[i].id.replace("FEEDR-", "");
341 if (id.length > 0) {
342 rows.push(id);
343 }
344 }
345
346 return rows;
347}
13ad9102 348
76b4eae1
AD
349function setCookie(name, value, lifetime, path, domain, secure) {
350
351 var d = false;
352
353 if (lifetime) {
354 d = new Date();
355 d.setTime(lifetime * 1000);
356 }
357
358 int_setCookie(name, value, d, path, domain, secure);
359
360}
361
362function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
363 document.cookie= name + "=" + escape(value) +
364 ((expires) ? "; expires=" + expires.toGMTString() : "") +
365 ((path) ? "; path=" + path : "") +
366 ((domain) ? "; domain=" + domain : "") +
367 ((secure) ? "; secure" : "");
368}
369
76b4eae1
AD
370function delCookie(name, path, domain) {
371 if (getCookie(name)) {
372 document.cookie = name + "=" +
373 ((path) ? ";path=" + path : "") +
374 ((domain) ? ";domain=" + domain : "" ) +
375 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
376 }
377}
378
379
ac43eba1
AD
380function getCookie(name) {
381
382 var dc = document.cookie;
383 var prefix = name + "=";
384 var begin = dc.indexOf("; " + prefix);
385 if (begin == -1) {
386 begin = dc.indexOf(prefix);
387 if (begin != 0) return null;
388 }
389 else {
390 begin += 2;
391 }
392 var end = document.cookie.indexOf(";", begin);
393 if (end == -1) {
394 end = dc.length;
395 }
396 return unescape(dc.substring(begin + prefix.length, end));
397}
398
1a66d16e
AD
399function disableContainerChildren(id, disable, doc) {
400
401 if (!doc) doc = document;
402
403 var container = doc.getElementById(id);
ac43eba1 404
4220b0bd
AD
405 if (!container) {
406 //alert("disableContainerChildren: element " + id + " not found");
407 return;
408 }
409
ac43eba1
AD
410 for (var i = 0; i < container.childNodes.length; i++) {
411 var child = container.childNodes[i];
412
d5224f0d
AD
413 try {
414 child.disabled = disable;
415 } catch (E) {
416
417 }
ac43eba1
AD
418
419 if (disable) {
420 if (child.className && child.className.match("button")) {
421 child.className = "disabledButton";
422 }
423 } else {
424 if (child.className && child.className.match("disabledButton")) {
425 child.className = "button";
426 }
d5224f0d 427 }
ac43eba1
AD
428 }
429
430}
7726fa02 431
e828e31e
AD
432function gotoPreferences() {
433 document.location.href = "prefs.php";
434}
435
436function gotoMain() {
437 document.location.href = "tt-rss.php";
438}
439
8158c57a
AD
440function gotoExportOpml() {
441 document.location.href = "opml.php?op=Export";
442}
86741347
AD
443
444function getActiveFeedId() {
33d13e72
AD
445// return getCookie("ttrss_vf_actfeed");
446 try {
0feab655
AD
447 debug("gAFID: " + active_feed_id);
448 return active_feed_id;
33d13e72
AD
449 } catch (e) {
450 exception_error("getActiveFeedId", e);
451 }
86741347
AD
452}
453
0a6c4846 454function activeFeedIsCat() {
0feab655 455 return active_feed_is_cat;
0a6c4846
AD
456}
457
86741347 458function setActiveFeedId(id) {
33d13e72
AD
459// return setCookie("ttrss_vf_actfeed", id);
460 try {
5c365f60 461 debug("sAFID(" + id + ")");
0feab655 462 active_feed_id = id;
33d13e72
AD
463 } catch (e) {
464 exception_error("setActiveFeedId", e);
465 }
86741347 466}
090e250b 467
ac378ad4 468function parse_counters(reply, scheduled_call) {
1a6a9555 469 try {
ac378ad4 470
9e397d0f
AD
471 var feeds_found = 0;
472
f54f515f
AD
473 if (reply.firstChild && reply.firstChild.firstChild) {
474 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
475 reply = reply.firstChild;
476 }
477
1a6a9555 478 for (var l = 0; l < reply.childNodes.length; l++) {
9cbca41f
AD
479 if (!reply.childNodes[l] ||
480 typeof(reply.childNodes[l].getAttribute) == "undefined") {
6043fb7e
AD
481 // where did this come from?
482 continue;
483 }
484
1a6a9555
AD
485 var id = reply.childNodes[l].getAttribute("id");
486 var t = reply.childNodes[l].getAttribute("type");
487 var ctr = reply.childNodes[l].getAttribute("counter");
023fe037
AD
488 var error = reply.childNodes[l].getAttribute("error");
489 var has_img = reply.childNodes[l].getAttribute("hi");
fb1fb4ab 490 var updated = reply.childNodes[l].getAttribute("updated");
1a6a9555
AD
491
492 if (id == "global-unread") {
0feab655
AD
493 global_unread = ctr;
494 updateTitle();
1a6a9555
AD
495 continue;
496 }
7bf7e4d3
AD
497
498 if (id == "subscribed-feeds") {
499 feeds_found = ctr;
500 continue;
501 }
1a6a9555
AD
502
503 if (t == "category") {
0feab655 504 var catctr = document.getElementById("FCATCTR-" + id);
1a6a9555
AD
505 if (catctr) {
506 catctr.innerHTML = "(" + ctr + " unread)";
507 }
508 continue;
509 }
510
0feab655
AD
511 var feedctr = document.getElementById("FEEDCTR-" + id);
512 var feedu = document.getElementById("FEEDU-" + id);
513 var feedr = document.getElementById("FEEDR-" + id);
514 var feed_img = document.getElementById("FIMG-" + id);
515 var feedlink = document.getElementById("FEEDL-" + id);
516 var feedupd = document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
517
518 if (updated && feedlink) {
519 if (error) {
520 feedlink.title = "Error: " + error + " (" + updated + ")";
521 } else {
522 feedlink.title = "Updated: " + updated;
523 }
524 }
023fe037 525
78d5212c
AD
526 if (updated && feedupd) {
527 if (error) {
528 feedupd.innerHTML = updated + " (Error)";
529 } else {
530 feedupd.innerHTML = updated;
531 }
532 }
533
1a6a9555 534 if (feedctr && feedu && feedr) {
e8ef3b97
AD
535
536 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
5b064721 537 viewCurrentFeed();
e8ef3b97 538 }
1a6a9555
AD
539
540 feedu.innerHTML = ctr;
023fe037 541
426d3c57
AD
542 if (error) {
543 feedr.className = feedr.className.replace("feed", "error");
544 } else if (id > 0) {
545 feedr.className = feedr.className.replace("error", "feed");
023fe037 546 }
1a6a9555
AD
547
548 if (ctr > 0) {
549 feedctr.className = "odd";
550 if (!feedr.className.match("Unread")) {
551 var is_selected = feedr.className.match("Selected");
552
553 feedr.className = feedr.className.replace("Selected", "");
554 feedr.className = feedr.className.replace("Unread", "");
555
556 feedr.className = feedr.className + "Unread";
557
558 if (is_selected) {
559 feedr.className = feedr.className + "Selected";
560 }
561
562 }
563 } else {
564 feedctr.className = "invisible";
565 feedr.className = feedr.className.replace("Unread", "");
566 }
567 }
568 }
9e397d0f 569
0feab655 570 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
7553dd8b 571
0feab655 572 var feeds_stored = number_of_feeds;
9e397d0f
AD
573
574 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
575
576 if (feeds_stored != feeds_found) {
0feab655 577 number_of_feeds = feeds_found;
7bf7e4d3
AD
578
579 if (feeds_stored != 0) {
9e397d0f 580 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 581 setTimeout('updateFeedList(false, false)', 50);
9e397d0f
AD
582 }
583 }
584
1a6a9555 585 } catch (e) {
83f043bb 586 exception_error("parse_counters", e);
1a6a9555
AD
587 }
588}
589
4f3a84f4 590function all_counters_callback() {
090e250b 591 if (xmlhttp_rpc.readyState == 4) {
7719618b 592 try {
3866b046 593 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
b00ed196 594 debug("[all_counters_callback] backend did not return valid XML");
7719618b
AD
595 return;
596 }
894ebcf5 597
6b4163cb 598 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
1cb7492d 599
7719618b 600 var reply = xmlhttp_rpc.responseXML.firstChild;
280ee9a3 601
f54f515f
AD
602 var counters = reply.firstChild;
603
604 parse_counters(counters);
1cb7492d
AD
605
606 var runtime = counters.nextSibling;
607
608 if (runtime) {
0feab655 609 parse_runtime_info(runtime);
1cb7492d 610 }
c9268ed5 611
cea51014 612 if (getInitParam("feeds_sort_by_unread") == 1) {
c9268ed5
AD
613 resort_feedlist();
614 }
293fa942
AD
615
616 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
617
7719618b
AD
618 } catch (e) {
619 exception_error("all_counters_callback", e);
090e250b
AD
620 }
621 }
622}
623
c9268ed5
AD
624function get_feed_entry_unread(doc, elem) {
625
626 var id = elem.id.replace("FEEDR-", "");
627
628 if (id <= 0) {
629 return -1;
630 }
631
632 try {
633 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
634 } catch (e) {
635 return -1;
636 }
637}
638
639function resort_category(doc, node) {
640 debug("resort_category: " + node);
641
642 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
643 for (i = 0; i < node.childNodes.length; i++) {
644 if (node.childNodes[i].nodeName != "LI") { continue; }
645
646 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
647 continue;
648 }
649
650 for (j = i+1; j < node.childNodes.length; j++) {
651 if (node.childNodes[j].nodeName != "LI") { continue; }
652
653 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
654 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
655
656 if (cur_val > tmp_val) {
657 tempnode_i = node.childNodes[i].cloneNode(true);
658 tempnode_j = node.childNodes[j].cloneNode(true);
659 node.replaceChild(tempnode_i, node.childNodes[j]);
660 node.replaceChild(tempnode_j, node.childNodes[i]);
661 }
662 }
663
664 }
665 }
666
667}
668
669function resort_feedlist() {
670 debug("resort_feedlist");
671
0feab655 672 var fd = document;
c9268ed5
AD
673
674 if (fd.getElementById("feedCatHolder")) {
675
676 var feeds = fd.getElementById("feedList");
677 var child = feeds.firstChild;
678
679 while (child) {
680
681 if (child.id == "feedCatHolder") {
682 resort_category(fd, child.firstChild);
683 }
684
685 child = child.nextSibling;
686 }
687
688 } else {
689 resort_category(fd, fd.getElementById("feedList"));
690 }
691}
692
4f3a84f4 693function update_all_counters(feed) {
090e250b 694 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 695 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
696
697 if (feed > 0) {
698 query = query + "&aid=" + feed;
699 }
700
090e250b 701 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 702 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
703 xmlhttp_rpc.send(null);
704 }
705}
7dc66a61
AD
706
707function popupHelp(tid) {
708 var w = window.open("backend.php?op=help&tid=" + tid,
709 "Popup Help",
710 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
711}
b6644d29
AD
712
713/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
714 * * @author Sundar Dorai-Raj
715 * * Email: sdoraira@vt.edu
716 * * This program is free software; you can redistribute it and/or
717 * * modify it under the terms of the GNU General Public License
718 * * as published by the Free Software Foundation; either version 2
719 * * of the License, or (at your option) any later version,
720 * * provided that any use properly credits the author.
721 * * This program is distributed in the hope that it will be useful,
722 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
723 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
724 * * GNU General Public License for more details at http://www.gnu.org * * */
725
726 var numbers=".0123456789";
727 function isNumeric(x) {
728 // is x a String or a character?
729 if(x.length>1) {
730 // remove negative sign
731 x=Math.abs(x)+"";
732 for(j=0;j<x.length;j++) {
733 // call isNumeric recursively for each character
734 number=isNumeric(x.substring(j,j+1));
735 if(!number) return number;
736 }
737 return number;
738 }
739 else {
740 // if x is number return true
741 if(numbers.indexOf(x)>=0) return true;
742 return false;
743 }
744 }
745
3745788e
AD
746
747function hideOrShowFeeds(doc, hide) {
748
7553dd8b
AD
749 debug("hideOrShowFeeds: " + doc + ", " + hide);
750
0feab655 751 var fd = document;
293fa942
AD
752
753 var list = fd.getElementById("feedList");
754
755 if (fd.getElementById("feedCatHolder")) {
756
757 var feeds = fd.getElementById("feedList");
758 var child = feeds.firstChild;
759
760 while (child) {
761
762 if (child.id == "feedCatHolder") {
763 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
764 }
765
766 child = child.nextSibling;
767 }
768
769 } else {
770 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
771 }
772}
773
774function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
775
776// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 777
293fa942 778 var cat_unread = 0;
3745788e 779
293fa942
AD
780 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
781 for (i = 0; i < node.childNodes.length; i++) {
782 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 783
b31c2311 784 if (node.childNodes[i].style != undefined) {
293fa942 785
b31c2311
AD
786 var has_unread = (node.childNodes[i].className != "feed");
787
788 // debug(node.childNodes[i].id + " --> " + has_unread);
789
790 if (hide && !has_unread) {
791 node.childNodes[i].style.display = "none";
792 }
793
794 if (!hide) {
795 node.childNodes[i].style.display = "list-item";
796 }
797
798 if (has_unread) {
7553dd8b 799 node.childNodes[i].style.display = "list-item";
b31c2311
AD
800 cat_unread++;
801 }
293fa942 802 }
3745788e 803 }
b31c2311 804 }
3745788e 805
293fa942 806 if (cat_unread == 0) {
b31c2311
AD
807 if (cat_node.style == undefined) {
808 debug("ERROR: supplied cat_node " + cat_node +
809 " has no styles. WTF?");
810 return;
811 }
293fa942
AD
812 if (hide) {
813 cat_node.style.display = "none";
814 } else {
815 cat_node.style.display = "list-item";
816 }
7553dd8b 817 } else {
0ac2faea
AD
818 try {
819 cat_node.style.display = "list-item";
820 } catch (e) {
821 debug(e);
822 }
293fa942 823 }
3745788e 824
293fa942 825// debug("unread for category: " + cat_unread);
3745788e
AD
826}
827
35f3c923
AD
828function selectTableRow(r, do_select) {
829 r.className = r.className.replace("Selected", "");
830
831 if (do_select) {
832 r.className = r.className + "Selected";
833 }
834}
835
6c12c809
AD
836function selectTableRowById(elem_id, check_id, do_select) {
837
838 try {
839
840 var row = document.getElementById(elem_id);
841
842 if (row) {
843 selectTableRow(row, do_select);
844 }
845
846 var check = document.getElementById(check_id);
847
848 if (check) {
849 check.checked = do_select;
850 }
851 } catch (e) {
852 exception_error("selectTableRowById", e);
853 }
854}
855
1572afe5 856function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 857 classcheck, reset_others) {
3745788e 858
35f3c923
AD
859 var content = document.getElementById(content_id);
860
861 if (!content) {
862 alert("[selectTableRows] Element " + content_id + " not found.");
863 return;
864 }
865
866 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
867 if (!classcheck || content.rows[i].className.match(classcheck)) {
868
869 if (content.rows[i].id.match(prefix)) {
870 selectTableRow(content.rows[i], do_select);
649e0af9
AD
871
872 var row_id = content.rows[i].id.replace(prefix, "");
873 var check = document.getElementById(check_prefix + row_id);
3055bc41 874
649e0af9
AD
875 if (check) {
876 check.checked = do_select;
877 }
878 } else if (reset_others) {
879 selectTableRow(content.rows[i], false);
7d8d10c6
AD
880
881 var row_id = content.rows[i].id.replace(prefix, "");
882 var check = document.getElementById(check_prefix + row_id);
883
884 if (check) {
885 check.checked = false;
886 }
887
1572afe5 888 }
649e0af9
AD
889 } else if (reset_others) {
890 selectTableRow(content.rows[i], false);
7d8d10c6
AD
891
892 var row_id = content.rows[i].id.replace(prefix, "");
893 var check = document.getElementById(check_prefix + row_id);
894
895 if (check) {
896 check.checked = false;
897 }
898
3055bc41 899 }
35f3c923 900 }
295f9b42 901}
91ff844a
AD
902
903function getSelectedTableRowIds(content_id, prefix) {
904
905 var content = document.getElementById(content_id);
906
907 if (!content) {
908 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
909 return;
910 }
911
912 var sel_rows = new Array();
913
914 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
915 if (content.rows[i].id.match(prefix) &&
916 content.rows[i].className.match("Selected")) {
917
91ff844a
AD
918 var row_id = content.rows[i].id.replace(prefix + "-", "");
919 sel_rows.push(row_id);
920 }
921 }
922
923 return sel_rows;
924
925}
926
386cbf27
AD
927function toggleSelectRowById(sender, id) {
928 var row = document.getElementById(id);
929
930 if (sender.checked) {
931 if (!row.className.match("Selected")) {
932 row.className = row.className + "Selected";
933 }
934 } else {
935 if (row.className.match("Selected")) {
936 row.className = row.className.replace("Selected", "");
937 }
938 }
939}
940
b92e6209
AD
941function toggleSelectListRow(sender) {
942 var parent_row = sender.parentNode;
943
944 if (sender.checked) {
945 if (!parent_row.className.match("Selected")) {
946 parent_row.className = parent_row.className + "Selected";
947 }
948 } else {
949 if (parent_row.className.match("Selected")) {
950 parent_row.className = parent_row.className.replace("Selected", "");
951 }
952 }
953}
954
386cbf27 955
1572afe5
AD
956function toggleSelectRow(sender) {
957 var parent_row = sender.parentNode.parentNode;
958
959 if (sender.checked) {
960 if (!parent_row.className.match("Selected")) {
961 parent_row.className = parent_row.className + "Selected";
962 }
963 } else {
964 if (parent_row.className.match("Selected")) {
965 parent_row.className = parent_row.className.replace("Selected", "");
966 }
967 }
968}
969
3866b046
AD
970function openExternalUrl(url) {
971 var w = window.open(url);
972}
1572afe5 973
1da76274 974function getRelativeFeedId(list, id, direction, unread_only) {
7b433d8c
AD
975 if (!id) {
976 if (direction == "next") {
977 for (i = 0; i < list.childNodes.length; i++) {
978 var child = list.childNodes[i];
1da76274 979 if (child.id && child.id == "feedCatHolder") {
c3f348c2 980 if (child.lastChild) {
d05514a4 981 var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only);
7b433d8c
AD
982 if (cr) return cr;
983 }
1da76274 984 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
985 return child.id.replace('FEEDR-', '');
986 }
987 }
988 }
989
990 // FIXME select last feed doesn't work when only unread feeds are visible
991
992 if (direction == "prev") {
993 for (i = list.childNodes.length-1; i >= 0; i--) {
994 var child = list.childNodes[i];
995 if (child.id == "feedCatHolder") {
996 if (child.firstChild) {
997 var cr = getRelativeFeedId(child.firstChild, id, direction);
998 if (cr) return cr;
999 }
1000 } else if (child.id.match("FEEDR-")) {
1001
e8bd0da9 1002 if (getInitParam("hide_read_feeds") == 1) {
7b433d8c
AD
1003 if (child.className != "feed") {
1004 alert(child.className);
1005 return child.id.replace('FEEDR-', '');
1006 }
1007 } else {
1008 return child.id.replace('FEEDR-', '');
1009 }
1010 }
1011 }
1012 }
1013 } else {
1014
d05514a4 1015 var feed = list.ownerDocument.getElementById("FEEDR-" + id);
7b433d8c 1016
e8bd0da9 1017 if (getInitParam("hide_read_feeds") == 1) {
1da76274
AD
1018 unread_only = true;
1019 }
1020
7b433d8c
AD
1021 if (direction == "next") {
1022
1da76274 1023 var e = feed;
7b433d8c 1024
1da76274 1025 while (e) {
7b433d8c 1026
1da76274
AD
1027 if (e.nextSibling) {
1028
1029 e = e.nextSibling;
1030
1031 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 1032
1da76274 1033 var this_cat = e.parentNode.parentNode;
7b433d8c 1034
1da76274 1035 e = false;
7b433d8c 1036
1da76274
AD
1037 if (this_cat && this_cat.nextSibling) {
1038 while (!e && this_cat.nextSibling) {
1039 this_cat = this_cat.nextSibling;
1040 if (this_cat.id == "feedCatHolder") {
1041 e = this_cat.firstChild.firstChild;
7b433d8c
AD
1042 }
1043 }
7b433d8c 1044 }
1da76274
AD
1045
1046 } else {
1047 e = false;
1048 }
1049
1050 if (e) {
d05514a4 1051 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1052 e.className.match("feed"))) {
1da76274
AD
1053 return e.id.replace("FEEDR-", "");
1054 }
1055 }
7b433d8c 1056 }
1da76274 1057
7b433d8c
AD
1058 } else if (direction == "prev") {
1059
1da76274 1060 var e = feed;
7b433d8c 1061
1da76274 1062 while (e) {
7b433d8c 1063
1da76274
AD
1064 if (e.previousSibling) {
1065
1066 e = e.previousSibling;
1067
1068 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 1069
1da76274 1070 var this_cat = e.parentNode.parentNode;
7b433d8c 1071
1da76274
AD
1072 e = false;
1073
1074 if (this_cat && this_cat.previousSibling) {
1075 while (!e && this_cat.previousSibling) {
1076 this_cat = this_cat.previousSibling;
1077 if (this_cat.id == "feedCatHolder") {
1078 e = this_cat.firstChild.lastChild;
7b433d8c
AD
1079 }
1080 }
7b433d8c 1081 }
1da76274
AD
1082
1083 } else {
1084 e = false;
1085 }
1086
1087 if (e) {
e686782e 1088 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1089 e.className.match("feed"))) {
1da76274
AD
1090 return e.id.replace("FEEDR-", "");
1091 }
1092 }
1093 }
7b433d8c
AD
1094 }
1095 }
1096}
36aab70f
AD
1097
1098function showBlockElement(id) {
1099 var elem = document.getElementById(id);
1100
1101 if (elem) {
1102 elem.style.display = "block";
1103 } else {
1104 alert("[showBlockElement] can't find element with id " + id);
1105 }
1106}
1107
a9b0bfd5
AD
1108function hideParentElement(e) {
1109 e.parentNode.style.display = "none";
1110}
1b0809ae
AD
1111
1112function dropboxSelect(e, v) {
1113 for (i = 0; i < e.length; i++) {
1114 if (e[i].value == v) {
1115 e.selectedIndex = i;
1116 break;
1117 }
1118 }
1119}
0ee1d1a0
AD
1120
1121// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1122// bugfixed just a little bit :-)
1123function getURLParam(strParamName){
1124 var strReturn = "";
1125 var strHref = window.location.href;
1126
1127 if (strHref.indexOf("#") == strHref.length-1) {
1128 strHref = strHref.substring(0, strHref.length-1);
1129 }
1130
1131 if ( strHref.indexOf("?") > -1 ){
1132 var strQueryString = strHref.substr(strHref.indexOf("?"));
1133 var aQueryString = strQueryString.split("&");
1134 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1135 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1136 var aParam = aQueryString[iParam].split("=");
1137 strReturn = aParam[1];
1138 break;
1139 }
1140 }
1141 }
1142 return strReturn;
1143}
1144
cf1bc085
AD
1145function leading_zero(p) {
1146 var s = String(p);
1147 if (s.length == 1) s = "0" + s;
1148 return s;
1149}
c38c2b69 1150
86b682ce 1151function closeInfoBox(cleanup) {
e5d758e3
AD
1152 var box = document.getElementById('infoBox');
1153 var shadow = document.getElementById('infoBoxShadow');
1154
1155 if (shadow) {
1156 shadow.style.display = "none";
1157 } else if (box) {
1158 box.style.display = "none";
1159 }
1160
86b682ce
AD
1161 if (cleanup) box.innerHTML = "&nbsp;";
1162
e5d758e3 1163 enableHotkeys();
c14b5566 1164
90ac84df 1165 return false;
e5d758e3
AD
1166}
1167
1168
7b5c6012
AD
1169function displayDlg(id, param) {
1170
1171 if (!xmlhttp_ready(xmlhttp)) {
1172 printLockingError();
1173 return
1174 }
1175
1176 notify("");
1177
1178 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1179 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 1180 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
1181 xmlhttp.send(null);
1182
1183 disableHotkeys();
2371c520 1184
90ac84df 1185 return false;
7b5c6012
AD
1186}
1187
e5d758e3 1188function infobox_submit_callback() {
7b5c6012 1189 if (xmlhttp.readyState == 4) {
e5d758e3 1190 closeInfoBox();
7b5c6012 1191
6e6504bc
AD
1192 try {
1193 // called from prefs, reload tab
1194 if (active_tab) {
1195 selectTab(active_tab, false);
1196 }
1197 } catch (e) { }
79f3553b
AD
1198
1199 notify(xmlhttp.responseText);
1200
7b5c6012
AD
1201 }
1202}
1203
e5d758e3 1204function infobox_callback() {
7b5c6012 1205 if (xmlhttp.readyState == 4) {
e5d758e3
AD
1206 var box = document.getElementById('infoBox');
1207 var shadow = document.getElementById('infoBoxShadow');
1208 if (box) {
1209 box.innerHTML=xmlhttp.responseText;
1210 if (shadow) {
1211 shadow.style.display = "block";
1212 } else {
1213 box.style.display = "block";
1214 }
1215 }
1216 }
7b5c6012
AD
1217}
1218
1219function qaddFilter() {
1220
1221 if (!xmlhttp_ready(xmlhttp)) {
1222 printLockingError();
1223 return
1224 }
1225
c91c2249
AD
1226 var form = document.forms['filter_add_form'];
1227 var reg_exp = form.reg_exp.value;
1228
1229 if (reg_exp == "") {
1230 alert("Can't add filter: nothing to match on.");
1231 return false;
1232 }
1233
79f3553b 1234 var query = Form.serialize("filter_add_form");
7b5c6012 1235
79f3553b
AD
1236 xmlhttp.open("GET", "backend.php?" + query, true);
1237 xmlhttp.onreadystatechange=infobox_submit_callback;
1238 xmlhttp.send(null);
7b5c6012 1239
c14b5566 1240 return true;
7b5c6012
AD
1241}
1242
2371c520
AD
1243function toggleSubmitNotEmpty(e, submit_id) {
1244 try {
1245 document.getElementById(submit_id).disabled = (e.value == "")
1246 } catch (e) {
1247 exception_error("toggleSubmitNotEmpty", e);
1248 }
1249}
1d7bf5a0 1250
605f7d46
AD
1251function isValidURL(s) {
1252 return s.match("http://") != null || s.match("https://") != null;
1253}
07eb9178
AD
1254
1255function qafAdd() {
1256
1257 if (!xmlhttp_ready(xmlhttp)) {
1258 printLockingError();
1259 return
1260 }
1261
c91c2249
AD
1262 var form = document.forms['feed_add_form'];
1263 var feed_url = form.feed_url.value;
1264
1265 if (feed_url == "") {
1266 alert("Can't subscribe: no feed URL given.");
1267 return false;
1268 }
1269
a58d997c 1270 notify("Adding feed...", true);
07eb9178
AD
1271
1272 closeInfoBox();
1273
0feab655 1274 var feeds_doc = document;
07eb9178 1275
80e4dc34 1276// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1277
1278 var query = Form.serialize("feed_add_form");
1279
1280 xmlhttp.open("GET", "backend.php?" + query, true);
1281 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1282 xmlhttp.send(null);
7bc4f251
AD
1283
1284 return false;
07eb9178
AD
1285}
1286
6e6504bc 1287function filterCR(e, f)
86b682ce
AD
1288{
1289 var key;
1290
1291 if(window.event)
1292 key = window.event.keyCode; //IE
1293 else
1294 key = e.which; //firefox
1295
6e6504bc
AD
1296 if (key == 13) {
1297 if (typeof f != 'undefined') {
1298 f();
1299 return false;
1300 } else {
1301 return false;
1302 }
1303 } else {
1304 return true;
1305 }
86b682ce
AD
1306}
1307
ac378ad4 1308function getMainContext() {
6b4163cb 1309 return this.window;
ac378ad4
AD
1310}
1311
33d13e72 1312function getFeedsContext() {
6b4163cb 1313 return this.window;
33d13e72
AD
1314}
1315
0bd411db 1316function getContentContext() {
6b4163cb 1317 return this.window;
0bd411db
AD
1318}
1319
ee1f45f4 1320function getHeadlinesContext() {
6b4163cb 1321 return this.window;
ee1f45f4
AD
1322}
1323
e8614131
AD
1324var debug_last_class = "even";
1325
ac378ad4 1326function debug(msg) {
ac378ad4 1327
0feab655
AD
1328 if (debug_last_class == "even") {
1329 debug_last_class = "odd";
e8614131 1330 } else {
0feab655 1331 debug_last_class = "even";
e8614131
AD
1332 }
1333
0feab655 1334 var c = document.getElementById('debug_output');
ac378ad4 1335 if (c && c.style.display == "block") {
c9268ed5 1336 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1337 c.removeChild(c.lastChild);
1338 }
1339
1340 var d = new Date();
1341 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1342 ":" + leading_zero(d.getSeconds());
0feab655 1343 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1344 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1345 }
1346}
1347
33d13e72
AD
1348function getInitParam(key) {
1349 return getMainContext().init_params[key];
1350}
3ac2b520 1351
e8bd0da9 1352function storeInitParam(key, value, is_client) {
33d13e72 1353 try {
e8bd0da9 1354 if (!is_client) {
1035fcec
AD
1355 if (getMainContext().init_params[key] != value) {
1356 debug("storeInitParam: " + key + " => " + value);
0b7cb301
AD
1357 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1358 // param_escape(key) + "&value=" + param_escape(value));
1359 var f = getMainContext().document.getElementById("backReqBox");
1360 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1361 param_escape(key) + "&value=" + param_escape(value);
1035fcec 1362 }
e8bd0da9 1363 }
1035fcec 1364 getMainContext().init_params[key] = value;
33d13e72
AD
1365 } catch (e) {
1366 exception_error("storeInitParam", e);
1367 }
1368}
a7565293 1369
1035fcec
AD
1370/*
1371function storeInitParams(params, is_client) {
1372 try {
1373 var s = "";
1374
1375 for (k in params) {
1376 if (getMainContext().init_params[k] != params[k]) {
1377 s += k + "=" + params[k] + ";";
1378 getMainContext().init_params[k] = params[k];
1379 }
1380 }
1381
1382 debug("storeInitParams: " + s);
1383
1384 if (!is_client) {
1385 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1386 }
1387 } catch (e) {
1388 exception_error("storeInitParams", e);
1389 }
1390}*/
1391
a7565293
AD
1392function fatalError(code, message) {
1393 try {
1394 var fe = document.getElementById("fatal_error");
1395 var fc = document.getElementById("fatal_error_msg");
1396
1397 fc.innerHTML = "Code " + code + ": " + message;
1398
1399 fe.style.display = "block";
1400
1401 } catch (e) {
1402 exception_error("fatalError", e);
1403 }
1404}
1405
234e467c 1406function getFeedName(id, is_cat) {
64a2875d 1407 var d = getFeedsContext().document;
234e467c
AD
1408
1409 var e;
1410
1411 if (is_cat) {
1412 e = d.getElementById("FCATN-" + id);
1413 } else {
1414 e = d.getElementById("FEEDN-" + id);
1415 }
64a2875d
AD
1416 if (e) {
1417 return e.innerHTML.stripTags();
1418 } else {
1419 return null;
1420 }
1421}
0bd411db
AD
1422
1423function viewContentUrl(url) {
1424 getContentContext().location = url;
1425}