]> git.wh0rd.org - tt-rss.git/blame - functions.js
fail sanity if RSS_BACKEND_TYPE is not defined
[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()) {
767e2486 190 return f_ctx.viewfeed(getActiveFeedId(), "ForceUpdate");
ee1f45f4
AD
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');
767e2486 204 if (new_feed) viewfeed(new_feed, '');
ee1f45f4
AD
205 }
206
207 if (keycode == 75) { // k
208 var feed = getActiveFeedId();
209 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
767e2486 210 if (new_feed) viewfeed(new_feed, '');
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
0a6c4846
AD
465function activeFeedIsCat() {
466 return getMainContext().active_feed_is_cat;
467}
468
86741347 469function setActiveFeedId(id) {
33d13e72
AD
470// return setCookie("ttrss_vf_actfeed", id);
471 try {
5c365f60 472 debug("sAFID(" + id + ")");
33d13e72
AD
473 getMainContext().active_feed_id = id;
474 } catch (e) {
475 exception_error("setActiveFeedId", e);
476 }
86741347 477}
090e250b 478
ac378ad4 479function parse_counters(reply, scheduled_call) {
1a6a9555 480 try {
33d13e72 481 var f_document = getFeedsContext().document;
ac378ad4
AD
482 var title_obj = getMainContext();
483
f54f515f
AD
484 if (reply.firstChild && reply.firstChild.firstChild) {
485 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
486 reply = reply.firstChild;
487 }
488
ac378ad4
AD
489 debug("F_DOC: " + f_document + ", T_OBJ: " + title_obj);
490
1a6a9555 491 for (var l = 0; l < reply.childNodes.length; l++) {
9cbca41f
AD
492 if (!reply.childNodes[l] ||
493 typeof(reply.childNodes[l].getAttribute) == "undefined") {
6043fb7e
AD
494 // where did this come from?
495 continue;
496 }
497
1a6a9555
AD
498 var id = reply.childNodes[l].getAttribute("id");
499 var t = reply.childNodes[l].getAttribute("type");
500 var ctr = reply.childNodes[l].getAttribute("counter");
023fe037
AD
501 var error = reply.childNodes[l].getAttribute("error");
502 var has_img = reply.childNodes[l].getAttribute("hi");
fb1fb4ab 503 var updated = reply.childNodes[l].getAttribute("updated");
1a6a9555
AD
504
505 if (id == "global-unread") {
3bdb368b
AD
506 title_obj.global_unread = ctr;
507 title_obj.updateTitle();
1a6a9555
AD
508 continue;
509 }
510
511 if (t == "category") {
512 var catctr = f_document.getElementById("FCATCTR-" + id);
513 if (catctr) {
514 catctr.innerHTML = "(" + ctr + " unread)";
515 }
516 continue;
517 }
518
519 var feedctr = f_document.getElementById("FEEDCTR-" + id);
520 var feedu = f_document.getElementById("FEEDU-" + id);
521 var feedr = f_document.getElementById("FEEDR-" + id);
023fe037 522 var feed_img = f_document.getElementById("FIMG-" + id);
fb1fb4ab 523 var feedlink = f_document.getElementById("FEEDL-" + id);
78d5212c 524 var feedupd = f_document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
525
526 if (updated && feedlink) {
527 if (error) {
528 feedlink.title = "Error: " + error + " (" + updated + ")";
529 } else {
530 feedlink.title = "Updated: " + updated;
531 }
532 }
023fe037 533
78d5212c
AD
534 if (updated && feedupd) {
535 if (error) {
536 feedupd.innerHTML = updated + " (Error)";
537 } else {
538 feedupd.innerHTML = updated;
539 }
540 }
541
1a6a9555 542 if (feedctr && feedu && feedr) {
e8ef3b97
AD
543
544 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
545 var hf = title_obj.parent.frames["headlines-frame"];
546 hf.location.reload(true);
547 }
1a6a9555
AD
548
549 feedu.innerHTML = ctr;
023fe037 550
426d3c57
AD
551 if (error) {
552 feedr.className = feedr.className.replace("feed", "error");
553 } else if (id > 0) {
554 feedr.className = feedr.className.replace("error", "feed");
023fe037 555 }
1a6a9555
AD
556
557 if (ctr > 0) {
558 feedctr.className = "odd";
559 if (!feedr.className.match("Unread")) {
560 var is_selected = feedr.className.match("Selected");
561
562 feedr.className = feedr.className.replace("Selected", "");
563 feedr.className = feedr.className.replace("Unread", "");
564
565 feedr.className = feedr.className + "Unread";
566
567 if (is_selected) {
568 feedr.className = feedr.className + "Selected";
569 }
570
571 }
572 } else {
573 feedctr.className = "invisible";
574 feedr.className = feedr.className.replace("Unread", "");
575 }
576 }
577 }
578 } catch (e) {
83f043bb 579 exception_error("parse_counters", e);
1a6a9555
AD
580 }
581}
582
4f3a84f4 583function all_counters_callback() {
090e250b 584 if (xmlhttp_rpc.readyState == 4) {
7719618b 585 try {
3866b046 586 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
b00ed196 587 debug("[all_counters_callback] backend did not return valid XML");
7719618b
AD
588 return;
589 }
894ebcf5 590
1cb7492d
AD
591 debug("in all_counters_callback");
592
7719618b 593 var reply = xmlhttp_rpc.responseXML.firstChild;
280ee9a3 594
f54f515f
AD
595 var counters = reply.firstChild;
596
597 parse_counters(counters);
1cb7492d
AD
598
599 var runtime = counters.nextSibling;
600
601 if (runtime) {
602 getMainContext().parse_runtime_info(runtime);
603 }
c9268ed5 604
cea51014 605 if (getInitParam("feeds_sort_by_unread") == 1) {
c9268ed5
AD
606 resort_feedlist();
607 }
293fa942
AD
608
609 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
610
7719618b
AD
611 } catch (e) {
612 exception_error("all_counters_callback", e);
090e250b
AD
613 }
614 }
615}
616
c9268ed5
AD
617function get_feed_entry_unread(doc, elem) {
618
619 var id = elem.id.replace("FEEDR-", "");
620
621 if (id <= 0) {
622 return -1;
623 }
624
625 try {
626 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
627 } catch (e) {
628 return -1;
629 }
630}
631
632function resort_category(doc, node) {
633 debug("resort_category: " + node);
634
635 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
636 for (i = 0; i < node.childNodes.length; i++) {
637 if (node.childNodes[i].nodeName != "LI") { continue; }
638
639 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
640 continue;
641 }
642
643 for (j = i+1; j < node.childNodes.length; j++) {
644 if (node.childNodes[j].nodeName != "LI") { continue; }
645
646 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
647 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
648
649 if (cur_val > tmp_val) {
650 tempnode_i = node.childNodes[i].cloneNode(true);
651 tempnode_j = node.childNodes[j].cloneNode(true);
652 node.replaceChild(tempnode_i, node.childNodes[j]);
653 node.replaceChild(tempnode_j, node.childNodes[i]);
654 }
655 }
656
657 }
658 }
659
660}
661
662function resort_feedlist() {
663 debug("resort_feedlist");
664
665 var fd = getFeedsContext().document;
666
667 if (fd.getElementById("feedCatHolder")) {
668
669 var feeds = fd.getElementById("feedList");
670 var child = feeds.firstChild;
671
672 while (child) {
673
674 if (child.id == "feedCatHolder") {
675 resort_category(fd, child.firstChild);
676 }
677
678 child = child.nextSibling;
679 }
680
681 } else {
682 resort_category(fd, fd.getElementById("feedList"));
683 }
684}
685
4f3a84f4 686function update_all_counters(feed) {
090e250b 687 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 688 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
689
690 if (feed > 0) {
691 query = query + "&aid=" + feed;
692 }
693
090e250b 694 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 695 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
696 xmlhttp_rpc.send(null);
697 }
698}
7dc66a61
AD
699
700function popupHelp(tid) {
701 var w = window.open("backend.php?op=help&tid=" + tid,
702 "Popup Help",
703 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
704}
b6644d29
AD
705
706/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
707 * * @author Sundar Dorai-Raj
708 * * Email: sdoraira@vt.edu
709 * * This program is free software; you can redistribute it and/or
710 * * modify it under the terms of the GNU General Public License
711 * * as published by the Free Software Foundation; either version 2
712 * * of the License, or (at your option) any later version,
713 * * provided that any use properly credits the author.
714 * * This program is distributed in the hope that it will be useful,
715 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
716 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
717 * * GNU General Public License for more details at http://www.gnu.org * * */
718
719 var numbers=".0123456789";
720 function isNumeric(x) {
721 // is x a String or a character?
722 if(x.length>1) {
723 // remove negative sign
724 x=Math.abs(x)+"";
725 for(j=0;j<x.length;j++) {
726 // call isNumeric recursively for each character
727 number=isNumeric(x.substring(j,j+1));
728 if(!number) return number;
729 }
730 return number;
731 }
732 else {
733 // if x is number return true
734 if(numbers.indexOf(x)>=0) return true;
735 return false;
736 }
737 }
738
3745788e
AD
739
740function hideOrShowFeeds(doc, hide) {
741
293fa942
AD
742 var fd = getFeedsContext().document;
743
744 var list = fd.getElementById("feedList");
745
746 if (fd.getElementById("feedCatHolder")) {
747
748 var feeds = fd.getElementById("feedList");
749 var child = feeds.firstChild;
750
751 while (child) {
752
753 if (child.id == "feedCatHolder") {
754 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
755 }
756
757 child = child.nextSibling;
758 }
759
760 } else {
761 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
762 }
763}
764
765function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
766
767// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 768
293fa942 769 var cat_unread = 0;
3745788e 770
293fa942
AD
771 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
772 for (i = 0; i < node.childNodes.length; i++) {
773 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 774
293fa942
AD
775 var has_unread = (node.childNodes[i].className != "feed");
776
777// debug(node.childNodes[i].id + " --> " + has_unread);
778
779 if (hide && !has_unread) {
780 node.childNodes[i].style.display = "none";
781 }
3745788e 782
3745788e 783 if (!hide) {
293fa942 784 node.childNodes[i].style.display = "list-item";
3745788e 785 }
293fa942
AD
786
787 if (has_unread) {
788 cat_unread++;
789 }
790
3745788e 791 }
293fa942 792 }
3745788e 793
293fa942
AD
794 if (cat_unread == 0) {
795 if (hide) {
796 cat_node.style.display = "none";
797 } else {
798 cat_node.style.display = "list-item";
799 }
800 }
3745788e 801
293fa942 802// debug("unread for category: " + cat_unread);
3745788e
AD
803}
804
35f3c923
AD
805function selectTableRow(r, do_select) {
806 r.className = r.className.replace("Selected", "");
807
808 if (do_select) {
809 r.className = r.className + "Selected";
810 }
811}
812
6c12c809
AD
813function selectTableRowById(elem_id, check_id, do_select) {
814
815 try {
816
817 var row = document.getElementById(elem_id);
818
819 if (row) {
820 selectTableRow(row, do_select);
821 }
822
823 var check = document.getElementById(check_id);
824
825 if (check) {
826 check.checked = do_select;
827 }
828 } catch (e) {
829 exception_error("selectTableRowById", e);
830 }
831}
832
1572afe5 833function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 834 classcheck, reset_others) {
3745788e 835
35f3c923
AD
836 var content = document.getElementById(content_id);
837
838 if (!content) {
839 alert("[selectTableRows] Element " + content_id + " not found.");
840 return;
841 }
842
843 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
844 if (!classcheck || content.rows[i].className.match(classcheck)) {
845
846 if (content.rows[i].id.match(prefix)) {
847 selectTableRow(content.rows[i], do_select);
649e0af9
AD
848
849 var row_id = content.rows[i].id.replace(prefix, "");
850 var check = document.getElementById(check_prefix + row_id);
3055bc41 851
649e0af9
AD
852 if (check) {
853 check.checked = do_select;
854 }
855 } else if (reset_others) {
856 selectTableRow(content.rows[i], false);
7d8d10c6
AD
857
858 var row_id = content.rows[i].id.replace(prefix, "");
859 var check = document.getElementById(check_prefix + row_id);
860
861 if (check) {
862 check.checked = false;
863 }
864
1572afe5 865 }
649e0af9
AD
866 } else if (reset_others) {
867 selectTableRow(content.rows[i], false);
7d8d10c6
AD
868
869 var row_id = content.rows[i].id.replace(prefix, "");
870 var check = document.getElementById(check_prefix + row_id);
871
872 if (check) {
873 check.checked = false;
874 }
875
3055bc41 876 }
35f3c923 877 }
295f9b42 878}
91ff844a
AD
879
880function getSelectedTableRowIds(content_id, prefix) {
881
882 var content = document.getElementById(content_id);
883
884 if (!content) {
885 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
886 return;
887 }
888
889 var sel_rows = new Array();
890
891 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
892 if (content.rows[i].id.match(prefix) &&
893 content.rows[i].className.match("Selected")) {
894
91ff844a
AD
895 var row_id = content.rows[i].id.replace(prefix + "-", "");
896 sel_rows.push(row_id);
897 }
898 }
899
900 return sel_rows;
901
902}
903
386cbf27
AD
904function toggleSelectRowById(sender, id) {
905 var row = document.getElementById(id);
906
907 if (sender.checked) {
908 if (!row.className.match("Selected")) {
909 row.className = row.className + "Selected";
910 }
911 } else {
912 if (row.className.match("Selected")) {
913 row.className = row.className.replace("Selected", "");
914 }
915 }
916}
917
b92e6209
AD
918function toggleSelectListRow(sender) {
919 var parent_row = sender.parentNode;
920
921 if (sender.checked) {
922 if (!parent_row.className.match("Selected")) {
923 parent_row.className = parent_row.className + "Selected";
924 }
925 } else {
926 if (parent_row.className.match("Selected")) {
927 parent_row.className = parent_row.className.replace("Selected", "");
928 }
929 }
930}
931
386cbf27 932
1572afe5
AD
933function toggleSelectRow(sender) {
934 var parent_row = sender.parentNode.parentNode;
935
936 if (sender.checked) {
937 if (!parent_row.className.match("Selected")) {
938 parent_row.className = parent_row.className + "Selected";
939 }
940 } else {
941 if (parent_row.className.match("Selected")) {
942 parent_row.className = parent_row.className.replace("Selected", "");
943 }
944 }
945}
946
3866b046
AD
947function openExternalUrl(url) {
948 var w = window.open(url);
949}
1572afe5 950
1da76274 951function getRelativeFeedId(list, id, direction, unread_only) {
7b433d8c
AD
952 if (!id) {
953 if (direction == "next") {
954 for (i = 0; i < list.childNodes.length; i++) {
955 var child = list.childNodes[i];
1da76274 956 if (child.id && child.id == "feedCatHolder") {
c3f348c2 957 if (child.lastChild) {
7b433d8c
AD
958 var cr = getRelativeFeedId(child.firstChild, id, direction);
959 if (cr) return cr;
960 }
1da76274 961 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
962 return child.id.replace('FEEDR-', '');
963 }
964 }
965 }
966
967 // FIXME select last feed doesn't work when only unread feeds are visible
968
969 if (direction == "prev") {
970 for (i = list.childNodes.length-1; i >= 0; i--) {
971 var child = list.childNodes[i];
972 if (child.id == "feedCatHolder") {
973 if (child.firstChild) {
974 var cr = getRelativeFeedId(child.firstChild, id, direction);
975 if (cr) return cr;
976 }
977 } else if (child.id.match("FEEDR-")) {
978
e8bd0da9 979 if (getInitParam("hide_read_feeds") == 1) {
7b433d8c
AD
980 if (child.className != "feed") {
981 alert(child.className);
982 return child.id.replace('FEEDR-', '');
983 }
984 } else {
985 return child.id.replace('FEEDR-', '');
986 }
987 }
988 }
989 }
990 } else {
991
992 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
993
e8bd0da9 994 if (getInitParam("hide_read_feeds") == 1) {
1da76274
AD
995 unread_only = true;
996 }
997
7b433d8c
AD
998 if (direction == "next") {
999
1da76274 1000 var e = feed;
7b433d8c 1001
1da76274 1002 while (e) {
7b433d8c 1003
1da76274
AD
1004 if (e.nextSibling) {
1005
1006 e = e.nextSibling;
1007
1008 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 1009
1da76274 1010 var this_cat = e.parentNode.parentNode;
7b433d8c 1011
1da76274 1012 e = false;
7b433d8c 1013
1da76274
AD
1014 if (this_cat && this_cat.nextSibling) {
1015 while (!e && this_cat.nextSibling) {
1016 this_cat = this_cat.nextSibling;
1017 if (this_cat.id == "feedCatHolder") {
1018 e = this_cat.firstChild.firstChild;
7b433d8c
AD
1019 }
1020 }
7b433d8c 1021 }
1da76274
AD
1022
1023 } else {
1024 e = false;
1025 }
1026
1027 if (e) {
e686782e
AD
1028 if (!unread_only || (unread_only && e.className != "feed" &&
1029 e.className != "error")) {
1da76274
AD
1030 return e.id.replace("FEEDR-", "");
1031 }
1032 }
7b433d8c 1033 }
1da76274 1034
7b433d8c
AD
1035 } else if (direction == "prev") {
1036
1da76274 1037 var e = feed;
7b433d8c 1038
1da76274 1039 while (e) {
7b433d8c 1040
1da76274
AD
1041 if (e.previousSibling) {
1042
1043 e = e.previousSibling;
1044
1045 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 1046
1da76274 1047 var this_cat = e.parentNode.parentNode;
7b433d8c 1048
1da76274
AD
1049 e = false;
1050
1051 if (this_cat && this_cat.previousSibling) {
1052 while (!e && this_cat.previousSibling) {
1053 this_cat = this_cat.previousSibling;
1054 if (this_cat.id == "feedCatHolder") {
1055 e = this_cat.firstChild.lastChild;
7b433d8c
AD
1056 }
1057 }
7b433d8c 1058 }
1da76274
AD
1059
1060 } else {
1061 e = false;
1062 }
1063
1064 if (e) {
e686782e
AD
1065 if (!unread_only || (unread_only && e.className != "feed" &&
1066 e.className != "error")) {
1da76274
AD
1067 return e.id.replace("FEEDR-", "");
1068 }
1069 }
1070 }
7b433d8c
AD
1071 }
1072 }
1073}
36aab70f
AD
1074
1075function showBlockElement(id) {
1076 var elem = document.getElementById(id);
1077
1078 if (elem) {
1079 elem.style.display = "block";
1080 } else {
1081 alert("[showBlockElement] can't find element with id " + id);
1082 }
1083}
1084
a9b0bfd5
AD
1085function hideParentElement(e) {
1086 e.parentNode.style.display = "none";
1087}
1b0809ae
AD
1088
1089function dropboxSelect(e, v) {
1090 for (i = 0; i < e.length; i++) {
1091 if (e[i].value == v) {
1092 e.selectedIndex = i;
1093 break;
1094 }
1095 }
1096}
0ee1d1a0
AD
1097
1098// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1099// bugfixed just a little bit :-)
1100function getURLParam(strParamName){
1101 var strReturn = "";
1102 var strHref = window.location.href;
1103
1104 if (strHref.indexOf("#") == strHref.length-1) {
1105 strHref = strHref.substring(0, strHref.length-1);
1106 }
1107
1108 if ( strHref.indexOf("?") > -1 ){
1109 var strQueryString = strHref.substr(strHref.indexOf("?"));
1110 var aQueryString = strQueryString.split("&");
1111 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1112 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1113 var aParam = aQueryString[iParam].split("=");
1114 strReturn = aParam[1];
1115 break;
1116 }
1117 }
1118 }
1119 return strReturn;
1120}
1121
cf1bc085
AD
1122function leading_zero(p) {
1123 var s = String(p);
1124 if (s.length == 1) s = "0" + s;
1125 return s;
1126}
c38c2b69 1127
86b682ce 1128function closeInfoBox(cleanup) {
e5d758e3
AD
1129 var box = document.getElementById('infoBox');
1130 var shadow = document.getElementById('infoBoxShadow');
1131
1132 if (shadow) {
1133 shadow.style.display = "none";
1134 } else if (box) {
1135 box.style.display = "none";
1136 }
1137
86b682ce
AD
1138 if (cleanup) box.innerHTML = "&nbsp;";
1139
e5d758e3 1140 enableHotkeys();
c14b5566 1141
90ac84df 1142 return false;
e5d758e3
AD
1143}
1144
1145
7b5c6012
AD
1146function displayDlg(id, param) {
1147
1148 if (!xmlhttp_ready(xmlhttp)) {
1149 printLockingError();
1150 return
1151 }
1152
1153 notify("");
1154
1155 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1156 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 1157 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
1158 xmlhttp.send(null);
1159
1160 disableHotkeys();
2371c520 1161
90ac84df 1162 return false;
7b5c6012
AD
1163}
1164
e5d758e3 1165function infobox_submit_callback() {
7b5c6012 1166 if (xmlhttp.readyState == 4) {
e5d758e3 1167 closeInfoBox();
7b5c6012
AD
1168
1169 // called from prefs, reload tab
1170 if (active_tab) {
1171 selectTab(active_tab, false);
1172 }
79f3553b
AD
1173
1174 notify(xmlhttp.responseText);
1175
7b5c6012
AD
1176 }
1177}
1178
e5d758e3 1179function infobox_callback() {
7b5c6012 1180 if (xmlhttp.readyState == 4) {
e5d758e3
AD
1181 var box = document.getElementById('infoBox');
1182 var shadow = document.getElementById('infoBoxShadow');
1183 if (box) {
1184 box.innerHTML=xmlhttp.responseText;
1185 if (shadow) {
1186 shadow.style.display = "block";
1187 } else {
1188 box.style.display = "block";
1189 }
1190 }
1191 }
7b5c6012
AD
1192}
1193
1194function qaddFilter() {
1195
1196 if (!xmlhttp_ready(xmlhttp)) {
1197 printLockingError();
1198 return
1199 }
1200
79f3553b 1201 var query = Form.serialize("filter_add_form");
7b5c6012 1202
79f3553b
AD
1203 xmlhttp.open("GET", "backend.php?" + query, true);
1204 xmlhttp.onreadystatechange=infobox_submit_callback;
1205 xmlhttp.send(null);
7b5c6012 1206
c14b5566 1207 return true;
7b5c6012
AD
1208}
1209
2371c520
AD
1210function toggleSubmitNotEmpty(e, submit_id) {
1211 try {
1212 document.getElementById(submit_id).disabled = (e.value == "")
1213 } catch (e) {
1214 exception_error("toggleSubmitNotEmpty", e);
1215 }
1216}
1d7bf5a0 1217
605f7d46
AD
1218function isValidURL(s) {
1219 return s.match("http://") != null || s.match("https://") != null;
1220}
07eb9178
AD
1221
1222function qafAdd() {
1223
1224 if (!xmlhttp_ready(xmlhttp)) {
1225 printLockingError();
1226 return
1227 }
1228
1229 notify("Adding feed...");
1230
1231 closeInfoBox();
1232
33d13e72 1233 var feeds_doc = getFeedsContext().document;
07eb9178
AD
1234
1235 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1236
1237 var query = Form.serialize("feed_add_form");
1238
1239 xmlhttp.open("GET", "backend.php?" + query, true);
1240 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1241 xmlhttp.send(null);
07eb9178
AD
1242}
1243
86b682ce
AD
1244function filterCR(e)
1245{
1246 var key;
1247
1248 if(window.event)
1249 key = window.event.keyCode; //IE
1250 else
1251 key = e.which; //firefox
1252
1253 if(key == 13)
1254 return false;
1255 else
1256 return true;
1257}
1258
ac378ad4
AD
1259function getMainContext() {
1260 if (parent.window != window) {
1261 return parent.window;
1262 } else {
1263 return this.window;
1264 }
1265}
1266
33d13e72
AD
1267function getFeedsContext() {
1268 try {
1269 return getMainContext().frames["feeds-frame"];
1270 } catch (e) {
1271 exception_error("getFeedsContext", e);
1272 }
1273}
1274
ee1f45f4
AD
1275
1276function getHeadlinesContext() {
1277 try {
1278 return getMainContext().frames["headlines-frame"];
1279 } catch (e) {
1280 exception_error("getHeadlinesContext", e);
1281 }
1282}
1283
e8614131
AD
1284var debug_last_class = "even";
1285
ac378ad4
AD
1286function debug(msg) {
1287 var ctx = getMainContext();
1288
e8614131
AD
1289 if (ctx.debug_last_class == "even") {
1290 ctx.debug_last_class = "odd";
1291 } else {
1292 ctx.debug_last_class = "even";
1293 }
1294
ac378ad4
AD
1295 var c = ctx.document.getElementById('debug_output');
1296 if (c && c.style.display == "block") {
c9268ed5 1297 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1298 c.removeChild(c.lastChild);
1299 }
1300
1301 var d = new Date();
1302 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1303 ":" + leading_zero(d.getSeconds());
e8614131
AD
1304 c.innerHTML = "<li class=\"" + ctx.debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1305 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1306 }
1307}
1308
33d13e72
AD
1309function getInitParam(key) {
1310 return getMainContext().init_params[key];
1311}
3ac2b520 1312
e8bd0da9 1313function storeInitParam(key, value, is_client) {
33d13e72 1314 try {
e8bd0da9 1315 if (!is_client) {
1035fcec
AD
1316 if (getMainContext().init_params[key] != value) {
1317 debug("storeInitParam: " + key + " => " + value);
0b7cb301
AD
1318 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1319 // param_escape(key) + "&value=" + param_escape(value));
1320 var f = getMainContext().document.getElementById("backReqBox");
1321 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1322 param_escape(key) + "&value=" + param_escape(value);
1035fcec 1323 }
e8bd0da9 1324 }
1035fcec 1325 getMainContext().init_params[key] = value;
33d13e72
AD
1326 } catch (e) {
1327 exception_error("storeInitParam", e);
1328 }
1329}
a7565293 1330
1035fcec
AD
1331/*
1332function storeInitParams(params, is_client) {
1333 try {
1334 var s = "";
1335
1336 for (k in params) {
1337 if (getMainContext().init_params[k] != params[k]) {
1338 s += k + "=" + params[k] + ";";
1339 getMainContext().init_params[k] = params[k];
1340 }
1341 }
1342
1343 debug("storeInitParams: " + s);
1344
1345 if (!is_client) {
1346 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1347 }
1348 } catch (e) {
1349 exception_error("storeInitParams", e);
1350 }
1351}*/
1352
a7565293
AD
1353function fatalError(code, message) {
1354 try {
1355 var fe = document.getElementById("fatal_error");
1356 var fc = document.getElementById("fatal_error_msg");
1357
1358 fc.innerHTML = "Code " + code + ": " + message;
1359
1360 fe.style.display = "block";
1361
1362 } catch (e) {
1363 exception_error("fatalError", e);
1364 }
1365}
1366
234e467c 1367function getFeedName(id, is_cat) {
64a2875d 1368 var d = getFeedsContext().document;
234e467c
AD
1369
1370 var e;
1371
1372 if (is_cat) {
1373 e = d.getElementById("FCATN-" + id);
1374 } else {
1375 e = d.getElementById("FEEDN-" + id);
1376 }
64a2875d
AD
1377 if (e) {
1378 return e.innerHTML.stripTags();
1379 } else {
1380 return null;
1381 }
1382}