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