]> git.wh0rd.org - tt-rss.git/blob - functions.js
fix layout of login form
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2 var debug_mode_enabled = false;
3 var xmlhttp_rpc = Ajax.getTransport();
4
5 /* add method to remove element from array */
6
7 Array.prototype.remove = function(s) {
8 for (var i=0; i < this.length; i++) {
9 if (s == this[i]) this.splice(i, 1);
10 }
11 }
12
13 function browser_has_opacity() {
14 return navigator.userAgent.match("Gecko") != null ||
15 navigator.userAgent.match("Opera") != null;
16 }
17
18 function is_msie() {
19 return navigator.userAgent.match("MSIE");
20 }
21
22 function is_opera() {
23 return navigator.userAgent.match("Opera");
24 }
25
26 function is_khtml() {
27 return navigator.userAgent.match("KHTML");
28 }
29
30 function is_safari() {
31 return navigator.userAgent.match("Safari");
32 }
33
34 function exception_error(location, e, silent) {
35 var msg;
36
37 if (e.fileName) {
38 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
39
40 msg = "Exception: " + e.name + ", " + e.message +
41 "\nFunction: " + location + "()" +
42 "\nLocation: " + base_fname + ":" + e.lineNumber;
43
44 } else {
45 msg = "Exception: " + e + "\nFunction: " + location + "()";
46 }
47
48 debug("<b>EXCEPTION: " + msg + "</b>");
49
50 if (!silent) {
51 alert(msg);
52 }
53 }
54
55 function disableHotkeys() {
56 hotkeys_enabled = false;
57 }
58
59 function enableHotkeys() {
60 hotkeys_enabled = true;
61 }
62
63 function xmlhttp_ready(obj) {
64 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
65 }
66
67 function open_article_callback(transport) {
68 try {
69
70 if (transport.responseXML) {
71 var link = transport.responseXML.getElementsByTagName("link")[0];
72 var id = transport.responseXML.getElementsByTagName("id")[0];
73
74 if (link) {
75 window.open(link.firstChild.nodeValue, "_blank");
76
77 if (id) {
78 id = id.firstChild.nodeValue;
79 if (!document.getElementById("headlinesList")) {
80 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
81 }
82 }
83 }
84 }
85
86 } catch (e) {
87 exception_error("open_article_callback", e);
88 }
89 }
90
91 function param_escape(arg) {
92 if (typeof encodeURIComponent != 'undefined')
93 return encodeURIComponent(arg);
94 else
95 return escape(arg);
96 }
97
98 function param_unescape(arg) {
99 if (typeof decodeURIComponent != 'undefined')
100 return decodeURIComponent(arg);
101 else
102 return unescape(arg);
103 }
104
105 function delay(gap) {
106 var then,now;
107 then=new Date().getTime();
108 now=then;
109 while((now-then)<gap) {
110 now=new Date().getTime();
111 }
112 }
113
114 var notify_hide_timerid = false;
115
116 function hide_notify() {
117 var n = document.getElementById("notify");
118 if (n) {
119 n.style.display = "none";
120 }
121 }
122
123 function notify_real(msg, no_hide, n_type) {
124
125 var n = document.getElementById("notify");
126 var nb = document.getElementById("notify_body");
127
128 if (!n || !nb) return;
129
130 if (notify_hide_timerid) {
131 window.clearTimeout(notify_hide_timerid);
132 }
133
134 if (msg == "") {
135 if (n.style.display == "block") {
136 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
137 }
138 return;
139 } else {
140 n.style.display = "block";
141 }
142
143 /* types:
144
145 1 - generic
146 2 - progress
147 3 - error
148 4 - info
149
150 */
151
152 if (typeof __ != 'undefined') {
153 msg = __(msg);
154 }
155
156 if (n_type == 1) {
157 n.className = "notify";
158 } else if (n_type == 2) {
159 n.className = "notifyProgress";
160 msg = "<img src='images/indicator_white.gif'> " + msg;
161 } else if (n_type == 3) {
162 n.className = "notifyError";
163 msg = "<img src='images/sign_excl.gif'> " + msg;
164 } else if (n_type == 4) {
165 n.className = "notifyInfo";
166 msg = "<img src='images/sign_info.gif'> " + msg;
167 }
168
169 // msg = "<img src='images/live_com_loading.gif'> " + msg;
170
171 nb.innerHTML = msg;
172
173 if (!no_hide) {
174 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
175 }
176 }
177
178 function notify(msg, no_hide) {
179 notify_real(msg, no_hide, 1);
180 }
181
182 function notify_progress(msg, no_hide) {
183 notify_real(msg, no_hide, 2);
184 }
185
186 function notify_error(msg, no_hide) {
187 notify_real(msg, no_hide, 3);
188
189 }
190
191 function notify_info(msg, no_hide) {
192 notify_real(msg, no_hide, 4);
193 }
194
195 function printLockingError() {
196 notify_info("Please wait until operation finishes.");
197 }
198
199 function hotkey_handler(e) {
200
201 try {
202
203 var keycode;
204 var shift_key = false;
205
206 try {
207 shift_key = e.shiftKey;
208 } catch (e) {
209
210 }
211
212 if (!hotkeys_enabled) return;
213
214 if (window.event) {
215 keycode = window.event.keyCode;
216 } else if (e) {
217 keycode = e.which;
218 }
219
220 if (keycode == 82) { // r
221 return scheduleFeedUpdate(true);
222 }
223
224 if (keycode == 83) { // s
225 return displayDlg("search", getActiveFeedId());
226 }
227
228 if (keycode == 85) { // u
229 if (getActiveFeedId()) {
230 return viewfeed(getActiveFeedId(), "ForceUpdate");
231 }
232 }
233
234 if (keycode == 65) { // a
235 return toggleDispRead();
236 }
237
238 var feedlist = document.getElementById('feedList');
239
240 if (keycode == 74) { // j
241 var feed = getActiveFeedId();
242 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
243 if (new_feed) viewfeed(new_feed, '');
244 }
245
246 if (keycode == 75) { // k
247 var feed = getActiveFeedId();
248 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
249 if (new_feed) viewfeed(new_feed, '');
250 }
251
252 if (keycode == 78 || keycode == 40) { // n, down
253 if (typeof moveToPost != 'undefined') {
254 return moveToPost('next');
255 }
256 }
257
258 if (keycode == 80 || keycode == 38) { // p, up
259 if (typeof moveToPost != 'undefined') {
260 return moveToPost('prev');
261 }
262 }
263
264 if (keycode == 68 && shift_key) { // d
265 if (!debug_mode_enabled) {
266 document.getElementById('debug_output').style.display = 'block';
267 debug('debug mode activated');
268 } else {
269 document.getElementById('debug_output').style.display = 'none';
270 }
271
272 debug_mode_enabled = !debug_mode_enabled;
273 }
274
275 if (keycode == 190 && shift_key) { // >
276 viewFeedGoPage(1);
277 }
278
279 if (keycode == 188 && shift_key) { // <
280 viewFeedGoPage(-1);
281 }
282
283 if (keycode == 191 && shift_key) { // ?
284 viewFeedGoPage(0);
285 }
286
287 if (keycode == 69 && shift_key) { // e
288 return editFeedDlg(getActiveFeedId());
289 }
290
291 if (keycode == 70 && shift_key) { // f
292 if (getActiveFeedId()) {
293 return catchupCurrentFeed();
294 }
295 }
296
297 if (keycode == 80 && shift_key) { // p
298 if (getActiveFeedId()) {
299 return catchupPage();
300 }
301 }
302
303 if (keycode == 86) { // v
304 if (getActiveArticleId()) {
305 openArticleInNewWindow(getActiveArticleId());
306 }
307 }
308
309 if (keycode == 84) { // t
310
311 var id = getActiveArticleId();
312
313 if (id) {
314
315 var cb = document.getElementById("RCHK-" + id);
316
317 if (cb) {
318 cb.checked = !cb.checked;
319 toggleSelectRowById(cb, "RROW-" + id);
320 }
321 }
322 }
323
324 if (keycode == 67) { // c
325 var id = getActiveArticleId();
326
327 if (id) {
328 toggleUnread(id, 0);
329 }
330 }
331
332 if (typeof localHotkeyHandler != 'undefined') {
333 try {
334 return localHotkeyHandler(e);
335 } catch (e) {
336 exception_error("hotkey_handler, local:", e);
337 }
338 }
339
340 debug("KP=" + keycode);
341 } catch (e) {
342 exception_error("hotkey_handler", e);
343 }
344 }
345
346 function cleanSelectedList(element) {
347 var content = document.getElementById(element);
348
349 if (!document.getElementById("feedCatHolder")) {
350 for (i = 0; i < content.childNodes.length; i++) {
351 var child = content.childNodes[i];
352 try {
353 child.className = child.className.replace("Selected", "");
354 } catch (e) {
355 //
356 }
357 }
358 } else {
359 for (i = 0; i < content.childNodes.length; i++) {
360 var child = content.childNodes[i];
361 if (child.id == "feedCatHolder") {
362 debug(child.id);
363 var fcat = child.lastChild;
364 for (j = 0; j < fcat.childNodes.length; j++) {
365 var feed = fcat.childNodes[j];
366 feed.className = feed.className.replace("Selected", "");
367 }
368 }
369 }
370 }
371 }
372
373
374 function cleanSelected(element) {
375 var content = document.getElementById(element);
376
377 for (i = 0; i < content.rows.length; i++) {
378 content.rows[i].className = content.rows[i].className.replace("Selected", "");
379 }
380 }
381
382 function getVisibleUnreadHeadlines() {
383 var content = document.getElementById("headlinesList");
384
385 var rows = new Array();
386
387 for (i = 0; i < content.rows.length; i++) {
388 var row_id = content.rows[i].id.replace("RROW-", "");
389 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
390 rows.push(row_id);
391 }
392 }
393 return rows;
394 }
395
396 function getVisibleHeadlineIds() {
397
398 var content = document.getElementById("headlinesList");
399
400 var rows = new Array();
401
402 for (i = 0; i < content.rows.length; i++) {
403 var row_id = content.rows[i].id.replace("RROW-", "");
404 if (row_id.length > 0) {
405 rows.push(row_id);
406 }
407 }
408 return rows;
409 }
410
411 function getFirstVisibleHeadlineId() {
412 var rows = getVisibleHeadlineIds();
413 return rows[0];
414 }
415
416 function getLastVisibleHeadlineId() {
417 var rows = getVisibleHeadlineIds();
418 return rows[rows.length-1];
419 }
420
421 function markHeadline(id) {
422 var row = document.getElementById("RROW-" + id);
423 if (row) {
424 var is_active = false;
425
426 if (row.className.match("Active")) {
427 is_active = true;
428 }
429 row.className = row.className.replace("Selected", "");
430 row.className = row.className.replace("Active", "");
431 row.className = row.className.replace("Insensitive", "");
432
433 if (is_active) {
434 row.className = row.className = "Active";
435 }
436
437 var check = document.getElementById("RCHK-" + id);
438
439 if (check) {
440 check.checked = true;
441 }
442
443 row.className = row.className + "Selected";
444
445 }
446 }
447
448 function getFeedIds() {
449 var content = document.getElementById("feedsList");
450
451 var rows = new Array();
452
453 for (i = 0; i < content.rows.length; i++) {
454 var id = content.rows[i].id.replace("FEEDR-", "");
455 if (id.length > 0) {
456 rows.push(id);
457 }
458 }
459
460 return rows;
461 }
462
463 function setCookie(name, value, lifetime, path, domain, secure) {
464
465 var d = false;
466
467 if (lifetime) {
468 d = new Date();
469 d.setTime(d.getTime() + (lifetime * 1000));
470 }
471
472 debug("setCookie: " + name + " => " + value + ": " + d);
473
474 int_setCookie(name, value, d, path, domain, secure);
475
476 }
477
478 function int_setCookie(name, value, expires, path, domain, secure) {
479 document.cookie= name + "=" + escape(value) +
480 ((expires) ? "; expires=" + expires.toGMTString() : "") +
481 ((path) ? "; path=" + path : "") +
482 ((domain) ? "; domain=" + domain : "") +
483 ((secure) ? "; secure" : "");
484 }
485
486 function delCookie(name, path, domain) {
487 if (getCookie(name)) {
488 document.cookie = name + "=" +
489 ((path) ? ";path=" + path : "") +
490 ((domain) ? ";domain=" + domain : "" ) +
491 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
492 }
493 }
494
495
496 function getCookie(name) {
497
498 var dc = document.cookie;
499 var prefix = name + "=";
500 var begin = dc.indexOf("; " + prefix);
501 if (begin == -1) {
502 begin = dc.indexOf(prefix);
503 if (begin != 0) return null;
504 }
505 else {
506 begin += 2;
507 }
508 var end = document.cookie.indexOf(";", begin);
509 if (end == -1) {
510 end = dc.length;
511 }
512 return unescape(dc.substring(begin + prefix.length, end));
513 }
514
515 function disableContainerChildren(id, disable, doc) {
516
517 if (!doc) doc = document;
518
519 var container = doc.getElementById(id);
520
521 if (!container) {
522 //alert("disableContainerChildren: element " + id + " not found");
523 return;
524 }
525
526 for (var i = 0; i < container.childNodes.length; i++) {
527 var child = container.childNodes[i];
528
529 try {
530 child.disabled = disable;
531 } catch (E) {
532
533 }
534
535 if (disable) {
536 if (child.className && child.className.match("button")) {
537 child.className = "disabledButton";
538 }
539 } else {
540 if (child.className && child.className.match("disabledButton")) {
541 child.className = "button";
542 }
543 }
544 }
545
546 }
547
548 function gotoPreferences() {
549 document.location.href = "prefs.php";
550 }
551
552 function gotoMain() {
553 document.location.href = "tt-rss.php";
554 }
555
556 function gotoExportOpml() {
557 document.location.href = "opml.php?op=Export";
558 }
559
560 function getActiveFeedId() {
561 // return getCookie("ttrss_vf_actfeed");
562 try {
563 debug("gAFID: " + active_feed_id);
564 return active_feed_id;
565 } catch (e) {
566 exception_error("getActiveFeedId", e);
567 }
568 }
569
570 function activeFeedIsCat() {
571 return active_feed_is_cat;
572 }
573
574 function setActiveFeedId(id) {
575 // return setCookie("ttrss_vf_actfeed", id);
576 try {
577 debug("sAFID(" + id + ")");
578 active_feed_id = id;
579 } catch (e) {
580 exception_error("setActiveFeedId", e);
581 }
582 }
583
584 function parse_counters(reply, scheduled_call) {
585 try {
586
587 var feeds_found = 0;
588
589 var elems = reply.getElementsByTagName("counter");
590
591 for (var l = 0; l < elems.length; l++) {
592
593 var id = elems[l].getAttribute("id");
594 var t = elems[l].getAttribute("type");
595 var ctr = elems[l].getAttribute("counter");
596 var error = elems[l].getAttribute("error");
597 var has_img = elems[l].getAttribute("hi");
598 var updated = elems[l].getAttribute("updated");
599 var title = elems[l].getAttribute("title");
600
601 if (id == "global-unread") {
602 global_unread = ctr;
603 updateTitle();
604 continue;
605 }
606
607 if (id == "subscribed-feeds") {
608 feeds_found = ctr;
609 continue;
610 }
611
612 if (t == "category") {
613 var catctr = document.getElementById("FCATCTR-" + id);
614 if (catctr) {
615 catctr.innerHTML = "(" + ctr + ")";
616 if (ctr > 0) {
617 catctr.className = "catCtrHasUnread";
618 } else {
619 catctr.className = "catCtrNoUnread";
620 }
621 }
622 continue;
623 }
624
625 var feedctr = document.getElementById("FEEDCTR-" + id);
626 var feedu = document.getElementById("FEEDU-" + id);
627 var feedr = document.getElementById("FEEDR-" + id);
628 var feed_img = document.getElementById("FIMG-" + id);
629 var feedlink = document.getElementById("FEEDL-" + id);
630 var feedupd = document.getElementById("FLUPD-" + id);
631
632 if (updated && feedlink) {
633 if (error) {
634 feedlink.title = "Error: " + error + " (" + updated + ")";
635 } else {
636 feedlink.title = "Updated: " + updated;
637 }
638 }
639
640 if (updated && feedupd) {
641 if (error) {
642 feedupd.innerHTML = updated + " (Error)";
643 } else {
644 feedupd.innerHTML = updated;
645 }
646 }
647
648 if (has_img && feed_img && !is_msie()) {
649 if (!feed_img.src.match(id + ".ico")) {
650 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
651 }
652 }
653
654 if (feedlink && title) {
655 feedlink.innerHTML = title;
656 }
657
658 if (feedctr && feedu && feedr) {
659
660 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
661 viewCurrentFeed();
662 }
663
664 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
665
666 feedu.innerHTML = ctr;
667
668 if (error) {
669 feedr.className = feedr.className.replace("feed", "error");
670 } else if (id > 0) {
671 feedr.className = feedr.className.replace("error", "feed");
672 }
673
674 if (ctr > 0) {
675 feedctr.className = "odd";
676 if (!feedr.className.match("Unread")) {
677 var is_selected = feedr.className.match("Selected");
678
679 feedr.className = feedr.className.replace("Selected", "");
680 feedr.className = feedr.className.replace("Unread", "");
681
682 feedr.className = feedr.className + "Unread";
683
684 if (is_selected) {
685 feedr.className = feedr.className + "Selected";
686 }
687
688 }
689
690 if (row_needs_hl) {
691 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
692 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
693 }
694 } else {
695 feedctr.className = "invisible";
696 feedr.className = feedr.className.replace("Unread", "");
697 }
698 }
699 }
700
701 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
702
703 var feeds_stored = number_of_feeds;
704
705 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
706
707 if (feeds_stored != feeds_found) {
708 number_of_feeds = feeds_found;
709
710 if (feeds_stored != 0 && feeds_found != 0) {
711 debug("Subscribed feed number changed, refreshing feedlist");
712 setTimeout('updateFeedList(false, false)', 50);
713 }
714 }
715
716 } catch (e) {
717 exception_error("parse_counters", e);
718 }
719 }
720
721 function parse_counters_reply(transport, scheduled_call) {
722
723 if (!transport.responseXML) {
724 notify_error("Backend did not return valid XML", true);
725 return;
726 }
727
728 var reply = transport.responseXML.firstChild;
729
730 if (!reply) {
731 notify_error("Backend did not return expected XML object", true);
732 updateTitle("");
733 return;
734 }
735
736 var error_code = false;
737 var error_msg = false;
738
739 if (reply.firstChild) {
740 error_code = reply.firstChild.getAttribute("error-code");
741 error_msg = reply.firstChild.getAttribute("error-msg");
742 }
743
744 if (!error_code) {
745 error_code = reply.getAttribute("error-code");
746 error_msg = reply.getAttribute("error-msg");
747 }
748
749 if (error_code && error_code != 0) {
750 debug("refetch_callback: got error code " + error_code);
751 return fatalError(error_code, error_msg);
752 }
753
754 var counters = reply.getElementsByTagName("counters")[0];
755
756 parse_counters(counters, scheduled_call);
757
758 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
759
760 parse_runtime_info(runtime_info);
761
762 if (getInitParam("feeds_sort_by_unread") == 1) {
763 resort_feedlist();
764 }
765
766 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
767
768 }
769
770 function all_counters_callback2(transport) {
771 try {
772 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
773 parse_counters_reply(transport);
774 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
775
776 } catch (e) {
777 exception_error("all_counters_callback2", e);
778 }
779 }
780
781 function get_feed_entry_unread(doc, elem) {
782
783 var id = elem.id.replace("FEEDR-", "");
784
785 if (id <= 0) {
786 return -1;
787 }
788
789 try {
790 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
791 } catch (e) {
792 return -1;
793 }
794 }
795
796 function resort_category(doc, node) {
797 debug("resort_category: " + node);
798
799 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
800 for (i = 0; i < node.childNodes.length; i++) {
801 if (node.childNodes[i].nodeName != "LI") { continue; }
802
803 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
804 continue;
805 }
806
807 for (j = i+1; j < node.childNodes.length; j++) {
808 if (node.childNodes[j].nodeName != "LI") { continue; }
809
810 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
811 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
812
813 if (cur_val > tmp_val) {
814 tempnode_i = node.childNodes[i].cloneNode(true);
815 tempnode_j = node.childNodes[j].cloneNode(true);
816 node.replaceChild(tempnode_i, node.childNodes[j]);
817 node.replaceChild(tempnode_j, node.childNodes[i]);
818 }
819 }
820
821 }
822 }
823
824 }
825
826 function resort_feedlist() {
827 debug("resort_feedlist");
828
829 var fd = document;
830
831 if (fd.getElementById("feedCatHolder")) {
832
833 var feeds = fd.getElementById("feedList");
834 var child = feeds.firstChild;
835
836 while (child) {
837
838 if (child.id == "feedCatHolder") {
839 resort_category(fd, child.firstChild);
840 }
841
842 child = child.nextSibling;
843 }
844
845 } else {
846 resort_category(fd, fd.getElementById("feedList"));
847 }
848 }
849
850 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
851 * * @author Sundar Dorai-Raj
852 * * Email: sdoraira@vt.edu
853 * * This program is free software; you can redistribute it and/or
854 * * modify it under the terms of the GNU General Public License
855 * * as published by the Free Software Foundation; either version 2
856 * * of the License, or (at your option) any later version,
857 * * provided that any use properly credits the author.
858 * * This program is distributed in the hope that it will be useful,
859 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
860 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
861 * * GNU General Public License for more details at http://www.gnu.org * * */
862
863 var numbers=".0123456789";
864 function isNumeric(x) {
865 // is x a String or a character?
866 if(x.length>1) {
867 // remove negative sign
868 x=Math.abs(x)+"";
869 for(j=0;j<x.length;j++) {
870 // call isNumeric recursively for each character
871 number=isNumeric(x.substring(j,j+1));
872 if(!number) return number;
873 }
874 return number;
875 }
876 else {
877 // if x is number return true
878 if(numbers.indexOf(x)>=0) return true;
879 return false;
880 }
881 }
882
883
884 function hideOrShowFeeds(doc, hide) {
885
886 debug("hideOrShowFeeds: " + doc + ", " + hide);
887
888 var fd = document;
889
890 var list = fd.getElementById("feedList");
891
892 if (fd.getElementById("feedCatHolder")) {
893
894 var feeds = fd.getElementById("feedList");
895 var child = feeds.firstChild;
896
897 while (child) {
898
899 if (child.id == "feedCatHolder") {
900 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
901 }
902
903 child = child.nextSibling;
904 }
905
906 } else {
907 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
908 }
909 }
910
911 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
912
913 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
914
915 var cat_unread = 0;
916
917 if (!node) {
918 debug("hideOrShowFeeds: passed node is null, aborting");
919 return;
920 }
921
922 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
923 for (i = 0; i < node.childNodes.length; i++) {
924 if (node.childNodes[i].nodeName != "LI") { continue; }
925
926 if (node.childNodes[i].style != undefined) {
927
928 var has_unread = (node.childNodes[i].className != "feed" &&
929 node.childNodes[i].className != "label" &&
930 node.childNodes[i].className != "virt" &&
931 node.childNodes[i].className != "tag");
932
933 // debug(node.childNodes[i].id + " --> " + has_unread);
934
935 if (hide && !has_unread) {
936 //node.childNodes[i].style.display = "none";
937 var id = node.childNodes[i].id;
938 Effect.Fade(node.childNodes[i], {duration : 0.3,
939 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
940 }
941
942 if (!hide) {
943 node.childNodes[i].style.display = "list-item";
944 //Effect.Appear(node.childNodes[i], {duration : 0.3});
945 }
946
947 if (has_unread) {
948 node.childNodes[i].style.display = "list-item";
949 cat_unread++;
950 //Effect.Appear(node.childNodes[i], {duration : 0.3});
951 //Effect.Highlight(node.childNodes[i]);
952 }
953 }
954 }
955 }
956
957 if (cat_unread == 0) {
958 if (cat_node.style == undefined) {
959 debug("ERROR: supplied cat_node " + cat_node +
960 " has no styles. WTF?");
961 return;
962 }
963 if (hide) {
964 //cat_node.style.display = "none";
965 Effect.Fade(cat_node, {duration : 0.3,
966 queue: { position: 'end', scope: 'CFADE-' + i, limit: 1 }});
967 } else {
968 cat_node.style.display = "list-item";
969 }
970 } else {
971 try {
972 cat_node.style.display = "list-item";
973 } catch (e) {
974 debug(e);
975 }
976 }
977
978 // debug("unread for category: " + cat_unread);
979 }
980
981 function selectTableRow(r, do_select) {
982 r.className = r.className.replace("Selected", "");
983
984 if (do_select) {
985 r.className = r.className + "Selected";
986 }
987 }
988
989 function selectTableRowById(elem_id, check_id, do_select) {
990
991 try {
992
993 var row = document.getElementById(elem_id);
994
995 if (row) {
996 selectTableRow(row, do_select);
997 }
998
999 var check = document.getElementById(check_id);
1000
1001 if (check) {
1002 check.checked = do_select;
1003 }
1004 } catch (e) {
1005 exception_error("selectTableRowById", e);
1006 }
1007 }
1008
1009 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
1010 classcheck, reset_others) {
1011
1012 var content = document.getElementById(content_id);
1013
1014 if (!content) {
1015 alert("[selectTableRows] Element " + content_id + " not found.");
1016 return;
1017 }
1018
1019 for (i = 0; i < content.rows.length; i++) {
1020 if (!classcheck || content.rows[i].className.match(classcheck)) {
1021
1022 if (content.rows[i].id.match(prefix)) {
1023 selectTableRow(content.rows[i], do_select);
1024
1025 var row_id = content.rows[i].id.replace(prefix, "");
1026 var check = document.getElementById(check_prefix + row_id);
1027
1028 if (check) {
1029 check.checked = do_select;
1030 }
1031 } else if (reset_others) {
1032 selectTableRow(content.rows[i], false);
1033
1034 var row_id = content.rows[i].id.replace(prefix, "");
1035 var check = document.getElementById(check_prefix + row_id);
1036
1037 if (check) {
1038 check.checked = false;
1039 }
1040
1041 }
1042 } else if (reset_others) {
1043 selectTableRow(content.rows[i], false);
1044
1045 var row_id = content.rows[i].id.replace(prefix, "");
1046 var check = document.getElementById(check_prefix + row_id);
1047
1048 if (check) {
1049 check.checked = false;
1050 }
1051
1052 }
1053 }
1054 }
1055
1056 function getSelectedTableRowIds(content_id, prefix) {
1057
1058 var content = document.getElementById(content_id);
1059
1060 if (!content) {
1061 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
1062 return;
1063 }
1064
1065 var sel_rows = new Array();
1066
1067 for (i = 0; i < content.rows.length; i++) {
1068 if (content.rows[i].id.match(prefix) &&
1069 content.rows[i].className.match("Selected")) {
1070
1071 var row_id = content.rows[i].id.replace(prefix + "-", "");
1072 sel_rows.push(row_id);
1073 }
1074 }
1075
1076 return sel_rows;
1077
1078 }
1079
1080 function toggleSelectRowById(sender, id) {
1081 var row = document.getElementById(id);
1082
1083 if (sender.checked) {
1084 if (!row.className.match("Selected")) {
1085 row.className = row.className + "Selected";
1086 }
1087 } else {
1088 if (row.className.match("Selected")) {
1089 row.className = row.className.replace("Selected", "");
1090 }
1091 }
1092 }
1093
1094 function toggleSelectListRow(sender) {
1095 var parent_row = sender.parentNode;
1096
1097 if (sender.checked) {
1098 if (!parent_row.className.match("Selected")) {
1099 parent_row.className = parent_row.className + "Selected";
1100 }
1101 } else {
1102 if (parent_row.className.match("Selected")) {
1103 parent_row.className = parent_row.className.replace("Selected", "");
1104 }
1105 }
1106 }
1107
1108 function tSR(sender) {
1109 return toggleSelectRow(sender);
1110 }
1111
1112 function toggleSelectRow(sender) {
1113 var parent_row = sender.parentNode.parentNode;
1114
1115 if (sender.checked) {
1116 if (!parent_row.className.match("Selected")) {
1117 parent_row.className = parent_row.className + "Selected";
1118 }
1119 } else {
1120 if (parent_row.className.match("Selected")) {
1121 parent_row.className = parent_row.className.replace("Selected", "");
1122 }
1123 }
1124 }
1125
1126 function getRelativeFeedId(list, id, direction, unread_only) {
1127 var rows = list.getElementsByTagName("LI");
1128 var feeds = new Array();
1129
1130 for (var i = 0; i < rows.length; i++) {
1131 if (rows[i].id.match("FEEDR-")) {
1132
1133 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1134
1135 if (!unread_only ||
1136 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1137 feeds.push(rows[i].id.replace("FEEDR-", ""));
1138 }
1139 }
1140 }
1141 }
1142
1143 if (!id) {
1144 if (direction == "next") {
1145 return feeds.shift();
1146 } else {
1147 return feeds.pop();
1148 }
1149 } else {
1150 if (direction == "next") {
1151 var idx = feeds.indexOf(id);
1152 if (idx != -1 && idx < feeds.length) {
1153 return feeds[idx+1];
1154 } else {
1155 return getRelativeFeedId(list, false, direction, unread_only);
1156 }
1157 } else {
1158 var idx = feeds.indexOf(id);
1159 if (idx > 0) {
1160 return feeds[idx-1];
1161 } else {
1162 return getRelativeFeedId(list, false, direction, unread_only);
1163 }
1164 }
1165
1166 }
1167 }
1168
1169 function showBlockElement(id, h_id) {
1170 var elem = document.getElementById(id);
1171
1172 if (elem) {
1173 elem.style.display = "block";
1174
1175 if (h_id) {
1176 elem = document.getElementById(h_id);
1177 if (elem) {
1178 elem.style.display = "none";
1179 }
1180 }
1181 } else {
1182 alert("[showBlockElement] can't find element with id " + id);
1183 }
1184 }
1185
1186 function appearBlockElement_afh(effect) {
1187
1188 }
1189
1190 function checkboxToggleElement(elem, id) {
1191 if (elem.checked) {
1192 Effect.SlideDown(id, {duration : 0.5});
1193 } else {
1194 Effect.SlideUp(id, {duration : 0.5});
1195 }
1196 }
1197
1198 function appearBlockElement(id, h_id) {
1199
1200 try {
1201 if (h_id) {
1202 Effect.Fade(h_id);
1203 }
1204 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1205 } catch (e) {
1206 exception_error("appearBlockElement", e);
1207 }
1208
1209 }
1210
1211 function hideParentElement(e) {
1212 e.parentNode.style.display = "none";
1213 }
1214
1215 function dropboxSelect(e, v) {
1216 for (i = 0; i < e.length; i++) {
1217 if (e[i].value == v) {
1218 e.selectedIndex = i;
1219 break;
1220 }
1221 }
1222 }
1223
1224 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1225 // bugfixed just a little bit :-)
1226 function getURLParam(strParamName){
1227 var strReturn = "";
1228 var strHref = window.location.href;
1229
1230 if (strHref.indexOf("#") == strHref.length-1) {
1231 strHref = strHref.substring(0, strHref.length-1);
1232 }
1233
1234 if ( strHref.indexOf("?") > -1 ){
1235 var strQueryString = strHref.substr(strHref.indexOf("?"));
1236 var aQueryString = strQueryString.split("&");
1237 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1238 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1239 var aParam = aQueryString[iParam].split("=");
1240 strReturn = aParam[1];
1241 break;
1242 }
1243 }
1244 }
1245 return strReturn;
1246 }
1247
1248 function leading_zero(p) {
1249 var s = String(p);
1250 if (s.length == 1) s = "0" + s;
1251 return s;
1252 }
1253
1254 function closeInfoBox(cleanup) {
1255
1256 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1257 var overlay = document.getElementById("dialog_overlay");
1258 if (overlay) {
1259 overlay.style.display = "none";
1260 }
1261 }
1262
1263 var box = document.getElementById('infoBox');
1264 var shadow = document.getElementById('infoBoxShadow');
1265
1266 if (shadow) {
1267 shadow.style.display = "none";
1268 } else if (box) {
1269 box.style.display = "none";
1270 }
1271
1272 if (cleanup) box.innerHTML = "&nbsp;";
1273
1274 enableHotkeys();
1275
1276 return false;
1277 }
1278
1279
1280 function displayDlg(id, param) {
1281
1282 notify_progress("Loading, please wait...", true);
1283
1284 disableHotkeys();
1285
1286 var query = "backend.php?op=dlg&id=" +
1287 param_escape(id) + "&param=" + param_escape(param);
1288
1289 new Ajax.Request(query, {
1290 onComplete: function (transport) {
1291 infobox_callback2(transport);
1292 } });
1293
1294 return false;
1295 }
1296
1297 function infobox_submit_callback2(transport) {
1298 closeInfoBox();
1299
1300 try {
1301 // called from prefs, reload tab
1302 if (active_tab) {
1303 selectTab(active_tab, false);
1304 }
1305 } catch (e) { }
1306
1307 if (transport.responseText) {
1308 notify_info(transport.responseText);
1309 }
1310 }
1311
1312 function infobox_callback2(transport) {
1313 try {
1314
1315 debug("infobox_callback2");
1316
1317 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1318 var overlay = document.getElementById("dialog_overlay");
1319 if (overlay) {
1320 overlay.style.display = "block";
1321 }
1322 }
1323
1324 var box = document.getElementById('infoBox');
1325 var shadow = document.getElementById('infoBoxShadow');
1326 if (box) {
1327
1328 /* if (!is_safari()) {
1329 new Draggable(shadow);
1330 } */
1331
1332 box.innerHTML=transport.responseText;
1333 if (shadow) {
1334 shadow.style.display = "block";
1335 } else {
1336 box.style.display = "block";
1337 }
1338 }
1339
1340 /* FIXME this needs to be moved out somewhere */
1341
1342 if (document.getElementById("tags_choices")) {
1343 new Ajax.Autocompleter('tags_str', 'tags_choices',
1344 "backend.php?op=rpc&subop=completeTags",
1345 { tokens: ',', paramName: "search" });
1346 }
1347
1348 notify("");
1349 } catch (e) {
1350 exception_error("infobox_callback2", e);
1351 }
1352 }
1353
1354 function createFilter() {
1355
1356 var form = document.forms['filter_add_form'];
1357 var reg_exp = form.reg_exp.value;
1358
1359 if (reg_exp == "") {
1360 alert(__("Can't add filter: nothing to match on."));
1361 return false;
1362 }
1363
1364 var query = Form.serialize("filter_add_form");
1365
1366 new Ajax.Request("backend.php?" + query, {
1367 onComplete: function (transport) {
1368 infobox_submit_callback2(transport);
1369 } });
1370
1371 return true;
1372 }
1373
1374 function toggleSubmitNotEmpty(e, submit_id) {
1375 try {
1376 document.getElementById(submit_id).disabled = (e.value == "")
1377 } catch (e) {
1378 exception_error("toggleSubmitNotEmpty", e);
1379 }
1380 }
1381
1382 function isValidURL(s) {
1383 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1384 }
1385
1386 function subscribeToFeed() {
1387
1388 var form = document.forms['feed_add_form'];
1389 var feed_url = form.feed_url.value;
1390
1391 if (feed_url == "") {
1392 alert(__("Can't subscribe: no feed URL given."));
1393 return false;
1394 }
1395
1396 notify_progress(__("Subscribing to feed..."), true);
1397
1398 closeInfoBox();
1399
1400 var feeds_doc = document;
1401
1402 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1403
1404 var query = Form.serialize("feed_add_form");
1405
1406 debug("subscribe q: " + query);
1407
1408 new Ajax.Request("backend.php", {
1409 parameters: query,
1410 onComplete: function(transport) {
1411 dlg_frefresh_callback(transport);
1412 } });
1413
1414 return false;
1415 }
1416
1417 function filterCR(e, f)
1418 {
1419 var key;
1420
1421 if(window.event)
1422 key = window.event.keyCode; //IE
1423 else
1424 key = e.which; //firefox
1425
1426 if (key == 13) {
1427 if (typeof f != 'undefined') {
1428 f();
1429 return false;
1430 } else {
1431 return false;
1432 }
1433 } else {
1434 return true;
1435 }
1436 }
1437
1438 function getMainContext() {
1439 return this.window;
1440 }
1441
1442 function getFeedsContext() {
1443 return this.window;
1444 }
1445
1446 function getContentContext() {
1447 return this.window;
1448 }
1449
1450 function getHeadlinesContext() {
1451 return this.window;
1452 }
1453
1454 var debug_last_class = "even";
1455
1456 function debug(msg) {
1457
1458 if (debug_last_class == "even") {
1459 debug_last_class = "odd";
1460 } else {
1461 debug_last_class = "even";
1462 }
1463
1464 var c = document.getElementById('debug_output');
1465 if (c && c.style.display == "block") {
1466 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1467 c.removeChild(c.lastChild);
1468 }
1469
1470 var d = new Date();
1471 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1472 ":" + leading_zero(d.getSeconds());
1473 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1474 msg + "</li>" + c.innerHTML;
1475 }
1476 }
1477
1478 function getInitParam(key) {
1479 return init_params[key];
1480 }
1481
1482 function storeInitParam(key, value) {
1483 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1484 init_params[key] = value;
1485 }
1486
1487 function fatalError(code, message) {
1488 try {
1489
1490 if (code == 6) {
1491 window.location.href = "tt-rss.php";
1492 } else if (code == 5) {
1493 window.location.href = "update.php";
1494 } else {
1495 var fe = document.getElementById("fatal_error");
1496 var fc = document.getElementById("fatal_error_msg");
1497
1498 if (message == "") message = "Unknown error";
1499
1500 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
1501
1502 fe.style.display = "block";
1503 }
1504
1505 } catch (e) {
1506 exception_error("fatalError", e);
1507 }
1508 }
1509
1510 function getFeedName(id, is_cat) {
1511 var d = getFeedsContext().document;
1512
1513 var e;
1514
1515 if (is_cat) {
1516 e = d.getElementById("FCATN-" + id);
1517 } else {
1518 e = d.getElementById("FEEDN-" + id);
1519 }
1520 if (e) {
1521 return e.innerHTML.stripTags();
1522 } else {
1523 return null;
1524 }
1525 }
1526
1527 function viewContentUrl(url) {
1528 getContentContext().location = url;
1529 }
1530
1531 function filterDlgCheckAction(sender) {
1532
1533 try {
1534
1535 var action = sender[sender.selectedIndex].value;
1536
1537 var form = document.forms["filter_add_form"];
1538
1539 if (!form) {
1540 form = document.forms["filter_edit_form"];
1541 }
1542
1543 if (!form) {
1544 debug("filterDlgCheckAction: can't find form!");
1545 return;
1546 }
1547
1548 var action_param = form.action_param;
1549
1550 if (!action_param) {
1551 debug("filterDlgCheckAction: can't find action param!");
1552 return;
1553 }
1554
1555 // if selected action supports parameters, enable params field
1556 if (action == 4) {
1557 action_param.disabled = false;
1558 } else {
1559 action_param.disabled = true;
1560 }
1561
1562 } catch (e) {
1563 exception_error(e, "filterDlgCheckAction");
1564 }
1565
1566 }
1567
1568 function explainError(code) {
1569 return displayDlg("explainError", code);
1570 }
1571
1572 // this only searches loaded headlines list, not in CDM
1573 function getRelativePostIds(id) {
1574
1575 debug("getRelativePostIds: " + id);
1576
1577 var ids = new Array();
1578 var container = document.getElementById("headlinesList");
1579
1580 if (container) {
1581 var rows = container.rows;
1582
1583 for (var i = 0; i < rows.length; i++) {
1584 var r_id = rows[i].id.replace("RROW-", "");
1585
1586 if (r_id == id) {
1587 if (i > 0) ids.push(rows[i-1].id.replace("RROW-", ""));
1588 if (i > 1) ids.push(rows[i-2].id.replace("RROW-", ""));
1589 if (i > 2) ids.push(rows[i-3].id.replace("RROW-", ""));
1590
1591 if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", ""));
1592 if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", ""));
1593 if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", ""));
1594
1595 return ids;
1596 }
1597 }
1598 }
1599
1600 return false;
1601 }
1602
1603 function openArticleInNewWindow(id) {
1604 try {
1605 debug("openArticleInNewWindow: " + id);
1606
1607 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1608
1609 debug(query);
1610
1611 new Ajax.Request(query, {
1612 onComplete: function(transport) {
1613 open_article_callback(transport);
1614 } });
1615
1616
1617 } catch (e) {
1618 exception_error("openArticleInNewWindow", e);
1619 }
1620 }
1621
1622 /* http://textsnippets.com/posts/show/835 */
1623
1624 Position.GetWindowSize = function(w) {
1625 w = w ? w : window;
1626 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1627 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1628 return [width, height]
1629 }
1630
1631 /* http://textsnippets.com/posts/show/836 */
1632
1633 Position.Center = function(element, parent) {
1634 var w, h, pw, ph;
1635 var d = Element.getDimensions(element);
1636 w = d.width;
1637 h = d.height;
1638 Position.prepare();
1639 if (!parent) {
1640 var ws = Position.GetWindowSize();
1641 pw = ws[0];
1642 ph = ws[1];
1643 } else {
1644 pw = parent.offsetWidth;
1645 ph = parent.offsetHeight;
1646 }
1647 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1648 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1649 }
1650
1651
1652 function labeltest_callback(transport) {
1653 try {
1654 var container = document.getElementById('label_test_result');
1655
1656 container.innerHTML = transport.responseText;
1657 if (!Element.visible(container)) {
1658 Effect.SlideDown(container, { duration : 0.5 });
1659 }
1660
1661 notify("");
1662 } catch (e) {
1663 exception_error("labeltest_callback", e);
1664 }
1665 }
1666
1667 function labelTest() {
1668
1669 try {
1670 var container = document.getElementById('label_test_result');
1671
1672 var form = document.forms['label_edit_form'];
1673
1674 var sql_exp = form.sql_exp.value;
1675 var description = form.description.value;
1676
1677 notify_progress("Loading, please wait...");
1678
1679 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1680 param_escape(sql_exp) + "&descr=" + param_escape(description);
1681
1682 new Ajax.Request(query, {
1683 onComplete: function (transport) {
1684 labeltest_callback(transport);
1685 } });
1686
1687 return false;
1688
1689 } catch (e) {
1690 exception_error("labelTest", e);
1691 }
1692 }
1693
1694 function isCdmMode() {
1695 return !document.getElementById("headlinesList");
1696 }
1697
1698 function getSelectedArticleIds2() {
1699 var rows = new Array();
1700 var cdm_mode = isCdmMode();
1701
1702 if (cdm_mode) {
1703 rows = cdmGetSelectedArticles();
1704 } else {
1705 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1706 }
1707
1708 var ids = new Array();
1709
1710 for (var i = 0; i < rows.length; i++) {
1711 var chk = document.getElementById("RCHK-" + rows[i]);
1712 if (chk && chk.checked) {
1713 ids.push(rows[i]);
1714 }
1715 }
1716
1717 return ids;
1718 }
1719
1720