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