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