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