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