]> git.wh0rd.org - tt-rss.git/blob - functions.js
Merge branch 'master' of /home/fox/public_html/testbox/tt-rss
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2 var notify_silent = false;
3 var last_progress_point = 0;
4 var async_counters_work = false;
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 is_opera() {
15 return window.opera;
16 }
17
18 function exception_error(location, e, ext_info) {
19 var msg = format_exception_error(location, e);
20
21 if (!ext_info) ext_info = "N/A";
22
23 disableHotkeys();
24
25 try {
26
27 var ebc = $("xebContent");
28
29 if (ebc) {
30
31 Element.show("dialog_overlay");
32 Element.show("errorBoxShadow");
33
34 if (ext_info) {
35 if (ext_info.responseText) {
36 ext_info = ext_info.responseText;
37 }
38 }
39
40 ebc.innerHTML =
41 "<div><b>Error message:</b></div>" +
42 "<pre>" + msg + "</pre>" +
43 "<div><b>Additional information:</b></div>" +
44 "<textarea readonly=\"1\">" + ext_info + "</textarea>";
45
46 } else {
47 alert(msg);
48 }
49
50 } catch (e) {
51 alert(msg);
52
53 }
54
55 }
56
57 function format_exception_error(location, e) {
58 var msg;
59
60 if (e.fileName) {
61 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
62
63 msg = "Exception: " + e.name + ", " + e.message +
64 "\nFunction: " + location + "()" +
65 "\nLocation: " + base_fname + ":" + e.lineNumber;
66
67 } else if (e.description) {
68 msg = "Exception: " + e.description + "\nFunction: " + location + "()";
69 } else {
70 msg = "Exception: " + e + "\nFunction: " + location + "()";
71 }
72
73 debug("<b>EXCEPTION: " + msg + "</b>");
74
75 return msg;
76 }
77
78
79 function disableHotkeys() {
80 hotkeys_enabled = false;
81 }
82
83 function enableHotkeys() {
84 hotkeys_enabled = true;
85 }
86
87 function open_article_callback(transport) {
88 try {
89
90 if (transport.responseXML) {
91
92 var link = transport.responseXML.getElementsByTagName("link")[0];
93 var id = transport.responseXML.getElementsByTagName("id")[0];
94
95 debug("open_article_callback, received link: " + link);
96
97 if (link && id) {
98
99 var wname = "ttrss_article_" + id.firstChild.nodeValue;
100
101 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
102
103 var w = window.open(link.firstChild.nodeValue, wname);
104
105 if (!w) { notify_error("Failed to load article in new window"); }
106
107 if (id) {
108 id = id.firstChild.nodeValue;
109 if (!$("headlinesList")) {
110 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
111 }
112 }
113 } else {
114 notify_error("Can't open article: received invalid article link");
115 }
116 } else {
117 notify_error("Can't open article: received invalid XML");
118 }
119
120 } catch (e) {
121 exception_error("open_article_callback", e);
122 }
123 }
124
125 function param_escape(arg) {
126 if (typeof encodeURIComponent != 'undefined')
127 return encodeURIComponent(arg);
128 else
129 return escape(arg);
130 }
131
132 function param_unescape(arg) {
133 if (typeof decodeURIComponent != 'undefined')
134 return decodeURIComponent(arg);
135 else
136 return unescape(arg);
137 }
138
139 function delay(gap) {
140 var then,now;
141 then=new Date().getTime();
142 now=then;
143 while((now-then)<gap) {
144 now=new Date().getTime();
145 }
146 }
147
148 var notify_hide_timerid = false;
149
150 function hide_notify() {
151 var n = $("notify");
152 if (n) {
153 n.style.display = "none";
154 }
155 }
156
157 function notify_silent_next() {
158 notify_silent = true;
159 }
160
161 function notify_real(msg, no_hide, n_type) {
162
163 if (notify_silent) {
164 notify_silent = false;
165 return;
166 }
167
168 var n = $("notify");
169 var nb = $("notify_body");
170
171 if (!n || !nb) return;
172
173 if (notify_hide_timerid) {
174 window.clearTimeout(notify_hide_timerid);
175 }
176
177 if (msg == "") {
178 if (n.style.display == "block") {
179 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
180 }
181 return;
182 } else {
183 n.style.display = "block";
184 }
185
186 /* types:
187
188 1 - generic
189 2 - progress
190 3 - error
191 4 - info
192
193 */
194
195 if (typeof __ != 'undefined') {
196 msg = __(msg);
197 }
198
199 if (n_type == 1) {
200 n.className = "notify";
201 } else if (n_type == 2) {
202 n.className = "notifyProgress";
203 msg = "<img src='images/indicator_white.gif'> " + msg;
204 } else if (n_type == 3) {
205 n.className = "notifyError";
206 msg = "<img src='images/sign_excl.gif'> " + msg;
207 } else if (n_type == 4) {
208 n.className = "notifyInfo";
209 msg = "<img src='images/sign_info.gif'> " + msg;
210 }
211
212 // msg = "<img src='images/live_com_loading.gif'> " + msg;
213
214 nb.innerHTML = msg;
215
216 if (!no_hide) {
217 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
218 }
219 }
220
221 function notify(msg, no_hide) {
222 notify_real(msg, no_hide, 1);
223 }
224
225 function notify_progress(msg, no_hide) {
226 notify_real(msg, no_hide, 2);
227 }
228
229 function notify_error(msg, no_hide) {
230 notify_real(msg, no_hide, 3);
231
232 }
233
234 function notify_info(msg, no_hide) {
235 notify_real(msg, no_hide, 4);
236 }
237
238 function printLockingError() {
239 notify_info("Please wait until operation finishes.");
240 }
241
242 function cleanSelected(element) {
243 var content = $(element);
244
245 for (i = 0; i < content.rows.length; i++) {
246 content.rows[i].className = content.rows[i].className.replace("Selected", "");
247 }
248 }
249
250 function getVisibleUnreadHeadlines() {
251 var content = $("headlinesList");
252
253 var rows = new Array();
254
255 if (!content) return rows;
256
257 for (i = 0; i < content.rows.length; i++) {
258 var row_id = content.rows[i].id.replace("RROW-", "");
259 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
260 rows.push(row_id);
261 }
262 }
263 return rows;
264 }
265
266 function getVisibleHeadlineIds() {
267
268 var content = $("headlinesList");
269
270 var rows = new Array();
271
272 if (!content) return rows;
273
274 for (i = 0; i < content.rows.length; i++) {
275 var row_id = content.rows[i].id.replace("RROW-", "");
276 if (row_id.length > 0) {
277 rows.push(row_id);
278 }
279 }
280 return rows;
281 }
282
283 function getFirstVisibleHeadlineId() {
284 if (isCdmMode()) {
285 var rows = cdmGetVisibleArticles();
286 return rows[0];
287 } else {
288 var rows = getVisibleHeadlineIds();
289 return rows[0];
290 }
291 }
292
293 function getLastVisibleHeadlineId() {
294 if (isCdmMode()) {
295 var rows = cdmGetVisibleArticles();
296 return rows[rows.length-1];
297 } else {
298 var rows = getVisibleHeadlineIds();
299 return rows[rows.length-1];
300 }
301 }
302
303 function markHeadline(id) {
304 var row = $("RROW-" + id);
305 if (row) {
306 var is_active = false;
307
308 if (row.className.match("Active")) {
309 is_active = true;
310 }
311 row.className = row.className.replace("Selected", "");
312 row.className = row.className.replace("Active", "");
313 row.className = row.className.replace("Insensitive", "");
314
315 if (is_active) {
316 row.className = row.className = "Active";
317 }
318
319 var check = $("RCHK-" + id);
320
321 if (check) {
322 check.checked = true;
323 }
324
325 row.className = row.className + "Selected";
326
327 }
328 }
329
330 function getFeedIds() {
331 var content = $("feedsList");
332
333 var rows = new Array();
334
335 for (i = 0; i < content.rows.length; i++) {
336 var id = content.rows[i].id.replace("FEEDR-", "");
337 if (id.length > 0) {
338 rows.push(id);
339 }
340 }
341
342 return rows;
343 }
344
345 function setCookie(name, value, lifetime, path, domain, secure) {
346
347 var d = false;
348
349 if (lifetime) {
350 d = new Date();
351 d.setTime(d.getTime() + (lifetime * 1000));
352 }
353
354 debug("setCookie: " + name + " => " + value + ": " + d);
355
356 int_setCookie(name, value, d, path, domain, secure);
357
358 }
359
360 function int_setCookie(name, value, expires, path, domain, secure) {
361 document.cookie= name + "=" + escape(value) +
362 ((expires) ? "; expires=" + expires.toGMTString() : "") +
363 ((path) ? "; path=" + path : "") +
364 ((domain) ? "; domain=" + domain : "") +
365 ((secure) ? "; secure" : "");
366 }
367
368 function delCookie(name, path, domain) {
369 if (getCookie(name)) {
370 document.cookie = name + "=" +
371 ((path) ? ";path=" + path : "") +
372 ((domain) ? ";domain=" + domain : "" ) +
373 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
374 }
375 }
376
377
378 function getCookie(name) {
379
380 var dc = document.cookie;
381 var prefix = name + "=";
382 var begin = dc.indexOf("; " + prefix);
383 if (begin == -1) {
384 begin = dc.indexOf(prefix);
385 if (begin != 0) return null;
386 }
387 else {
388 begin += 2;
389 }
390 var end = document.cookie.indexOf(";", begin);
391 if (end == -1) {
392 end = dc.length;
393 }
394 return unescape(dc.substring(begin + prefix.length, end));
395 }
396
397 function disableContainerChildren(id, disable, doc) {
398
399 if (!doc) doc = document;
400
401 var container = $(id);
402
403 if (!container) {
404 //alert("disableContainerChildren: element " + id + " not found");
405 return;
406 }
407
408 for (var i = 0; i < container.childNodes.length; i++) {
409 var child = container.childNodes[i];
410
411 try {
412 child.disabled = disable;
413 } catch (E) {
414
415 }
416
417 if (disable) {
418 if (child.className && child.className.match("button")) {
419 child.className = "disabledButton";
420 }
421 } else {
422 if (child.className && child.className.match("disabledButton")) {
423 child.className = "button";
424 }
425 }
426 }
427
428 }
429
430 function gotoPreferences() {
431 document.location.href = "prefs.php";
432 }
433
434 function gotoMain() {
435 document.location.href = "tt-rss.php";
436 }
437
438 function gotoExportOpml() {
439 document.location.href = "opml.php?op=Export";
440 }
441
442 function parse_counters(reply, scheduled_call) {
443 try {
444
445 var feeds_found = 0;
446
447 var elems = reply.getElementsByTagName("counter");
448
449 for (var l = 0; l < elems.length; l++) {
450
451 var id = elems[l].getAttribute("id");
452 var t = elems[l].getAttribute("type");
453 var ctr = elems[l].getAttribute("counter");
454 var error = elems[l].getAttribute("error");
455 var has_img = elems[l].getAttribute("hi");
456 var updated = elems[l].getAttribute("updated");
457 var title = elems[l].getAttribute("title");
458 var xmsg = elems[l].getAttribute("xmsg");
459
460 if (id == "global-unread") {
461
462 if (ctr > global_unread) {
463 offlineDownloadStart(1);
464 }
465
466 global_unread = ctr;
467 updateTitle();
468 continue;
469 }
470
471 if (id == "subscribed-feeds") {
472 feeds_found = ctr;
473 continue;
474 }
475
476 if (t == "category") {
477 var catctr = $("FCATCTR-" + id);
478 if (catctr) {
479 catctr.innerHTML = "(" + ctr + ")";
480 if (ctr > 0) {
481 catctr.className = "catCtrHasUnread";
482 } else {
483 catctr.className = "catCtrNoUnread";
484 }
485 }
486 continue;
487 }
488
489 var feedctr = $("FEEDCTR-" + id);
490 var feedu = $("FEEDU-" + id);
491 var feedr = $("FEEDR-" + id);
492 var feed_img = $("FIMG-" + id);
493 var feedlink = $("FEEDL-" + id);
494 var feedupd = $("FLUPD-" + id);
495
496 if (updated && feedlink) {
497 if (error) {
498 feedlink.title = "Error: " + error + " (" + updated + ")";
499 } else {
500 feedlink.title = "Updated: " + updated;
501 }
502 }
503
504 if (feedupd) {
505 if (!updated) updated = "";
506
507 if (error) {
508 if (xmsg) {
509 feedupd.innerHTML = updated + " " + xmsg + " (Error)";
510 } else {
511 feedupd.innerHTML = updated + " (Error)";
512 }
513 } else {
514 if (xmsg) {
515 feedupd.innerHTML = updated + " " + xmsg;
516 } else {
517 feedupd.innerHTML = updated;
518 }
519 }
520 }
521
522 if (has_img && feed_img) {
523 if (!feed_img.src.match(id + ".ico")) {
524 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
525 }
526 }
527
528 if (feedlink && title) {
529 feedlink.innerHTML = title;
530 }
531
532 if (feedctr && feedu && feedr) {
533
534 if (parseInt(ctr) > 0 &&
535 parseInt(feedu.innerHTML) < parseInt(ctr) &&
536 id == getActiveFeedId() && scheduled_call) {
537
538 displayNewContentPrompt(id);
539 }
540
541 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
542
543 feedu.innerHTML = ctr;
544
545 if (error) {
546 feedr.className = feedr.className.replace("feed", "error");
547 } else if (id > 0) {
548 feedr.className = feedr.className.replace("error", "feed");
549 }
550
551 if (ctr > 0) {
552 feedctr.className = "feedCtrHasUnread";
553 if (!feedr.className.match("Unread")) {
554 var is_selected = feedr.className.match("Selected");
555
556 feedr.className = feedr.className.replace("Selected", "");
557 feedr.className = feedr.className.replace("Unread", "");
558
559 feedr.className = feedr.className + "Unread";
560
561 if (is_selected) {
562 feedr.className = feedr.className + "Selected";
563 }
564
565 }
566
567 if (row_needs_hl) {
568 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
569 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
570 }
571 } else {
572 feedctr.className = "feedCtrNoUnread";
573 feedr.className = feedr.className.replace("Unread", "");
574 }
575 }
576 }
577
578 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
579
580 var feeds_stored = number_of_feeds;
581
582 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
583
584 if (feeds_stored != feeds_found) {
585 number_of_feeds = feeds_found;
586
587 if (feeds_stored != 0 && feeds_found != 0) {
588 debug("Subscribed feed number changed, refreshing feedlist");
589 setTimeout('updateFeedList(false, false)', 50);
590 }
591 } else {
592 /* var fl = $("feeds-frame").innerHTML;
593 if (fl) {
594 cache_invalidate("FEEDLIST");
595 cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
596 } */
597 }
598
599 } catch (e) {
600 exception_error("parse_counters", e);
601 }
602 }
603
604 function parse_counters_reply(transport, scheduled_call) {
605
606 if (!transport.responseXML) {
607 notify_error("Backend did not return valid XML", true);
608 return;
609 }
610
611 var reply = transport.responseXML.firstChild;
612
613 if (!reply) {
614 notify_error("Backend did not return expected XML object", true);
615 updateTitle("");
616 return;
617 }
618
619 if (!transport_error_check(transport)) return;
620
621 var counters = reply.getElementsByTagName("counters")[0];
622
623 parse_counters(counters, scheduled_call);
624
625 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
626
627 parse_runtime_info(runtime_info);
628
629 if (feedsSortByUnread()) {
630 resort_feedlist();
631 }
632
633 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
634
635 }
636
637 function all_counters_callback2(transport, async_call) {
638 try {
639 if (async_call) async_counters_work = true;
640
641 if (offline_mode) return;
642
643 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
644 parse_counters_reply(transport);
645 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
646
647 } catch (e) {
648 exception_error("all_counters_callback2", e, transport);
649 }
650 }
651
652 function get_feed_unread(id) {
653 try {
654 return parseInt($("FEEDU-" + id).innerHTML);
655 } catch (e) {
656 return -1;
657 }
658 }
659
660 function get_cat_unread(id) {
661 try {
662 var ctr = $("FCATCTR-" + id).innerHTML;
663 ctr = ctr.replace("(", "");
664 ctr = ctr.replace(")", "");
665 return parseInt(ctr);
666 } catch (e) {
667 return -1;
668 }
669 }
670
671 function get_feed_entry_unread(elem) {
672
673 var id = elem.id.replace("FEEDR-", "");
674
675 if (id <= 0) {
676 return -1;
677 }
678
679 try {
680 return parseInt($("FEEDU-" + id).innerHTML);
681 } catch (e) {
682 return -1;
683 }
684 }
685
686 function get_feed_entry_name(elem) {
687 var id = elem.id.replace("FEEDR-", "");
688 return getFeedName(id);
689 }
690
691
692 function resort_category(node) {
693
694 try {
695
696 debug("resort_category: " + node);
697
698 var by_unread = feedsSortByUnread();
699
700 var list = node.getElementsByTagName("LI");
701
702 for (i = 0; i < list.length; i++) {
703
704 for (j = i+1; j < list.length; j++) {
705
706 var tmp_val = get_feed_entry_unread(list[i]);
707 var cur_val = get_feed_entry_unread(list[j]);
708
709 var tmp_name = get_feed_entry_name(list[i]);
710 var cur_name = get_feed_entry_name(list[j]);
711
712 if ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name))) {
713 tempnode_i = list[i].cloneNode(true);
714 tempnode_j = list[j].cloneNode(true);
715 node.replaceChild(tempnode_i, list[j]);
716 node.replaceChild(tempnode_j, list[i]);
717 }
718 }
719 }
720
721 } catch (e) {
722 exception_error("resort_category", e);
723 }
724
725 }
726
727 function resort_feedlist() {
728 debug("resort_feedlist");
729
730 if ($("FCATLIST--1")) {
731
732 var lists = document.getElementsByTagName("UL");
733
734 for (var i = 0; i < lists.length; i++) {
735 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
736 resort_category(lists[i]);
737 }
738 }
739
740 } else {
741 resort_category($("feedList"));
742 }
743 }
744
745 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
746 * * @author Sundar Dorai-Raj
747 * * Email: sdoraira@vt.edu
748 * * This program is free software; you can redistribute it and/or
749 * * modify it under the terms of the GNU General Public License
750 * * as published by the Free Software Foundation; either version 2
751 * * of the License, or (at your option) any later version,
752 * * provided that any use properly credits the author.
753 * * This program is distributed in the hope that it will be useful,
754 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
755 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
756 * * GNU General Public License for more details at http://www.gnu.org * * */
757
758 var numbers=".0123456789";
759 function isNumeric(x) {
760 // is x a String or a character?
761 if(x.length>1) {
762 // remove negative sign
763 x=Math.abs(x)+"";
764 for(j=0;j<x.length;j++) {
765 // call isNumeric recursively for each character
766 number=isNumeric(x.substring(j,j+1));
767 if(!number) return number;
768 }
769 return number;
770 }
771 else {
772 // if x is number return true
773 if(numbers.indexOf(x)>=0) return true;
774 return false;
775 }
776 }
777
778
779 function hideOrShowFeeds(hide) {
780
781 try {
782
783 debug("hideOrShowFeeds: " + hide);
784
785 if ($("FCATLIST--1")) {
786
787 var lists = document.getElementsByTagName("UL");
788
789 for (var i = 0; i < lists.length; i++) {
790 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
791
792 var id = lists[i].id.replace("FCATLIST-", "");
793 hideOrShowFeedsCategory(id, hide);
794 }
795 }
796
797 } else {
798 hideOrShowFeedsCategory(null, hide);
799 }
800
801 } catch (e) {
802 exception_error("hideOrShowFeeds", e);
803 }
804 }
805
806 function hideOrShowFeedsCategory(id, hide) {
807
808 try {
809
810 var node = null;
811 var cat_node = null;
812
813 if (id) {
814 node = $("FCATLIST-" + id);
815 cat_node = $("FCAT-" + id);
816 } else {
817 node = $("feedList"); // no categories
818 }
819
820 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
821
822 var cat_unread = 0;
823
824 if (!node) {
825 debug("hideOrShowFeeds: passed node is null, aborting");
826 return;
827 }
828
829 // debug("cat: " + node.id);
830
831 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
832 for (i = 0; i < node.childNodes.length; i++) {
833 if (node.childNodes[i].nodeName != "LI") { continue; }
834
835 if (node.childNodes[i].style != undefined) {
836
837 var has_unread = (node.childNodes[i].className != "feed" &&
838 node.childNodes[i].className != "label" &&
839 !(!getInitParam("hide_read_shows_special") &&
840 node.childNodes[i].className == "virt") &&
841 node.childNodes[i].className != "error" &&
842 node.childNodes[i].className != "tag");
843
844 // debug(node.childNodes[i].id + " --> " + has_unread);
845
846 if (hide && !has_unread) {
847 //node.childNodes[i].style.display = "none";
848 var id = node.childNodes[i].id;
849 Effect.Fade(node.childNodes[i], {duration : 0.3,
850 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
851 }
852
853 if (!hide) {
854 node.childNodes[i].style.display = "list-item";
855 //Effect.Appear(node.childNodes[i], {duration : 0.3});
856 }
857
858 if (has_unread) {
859 node.childNodes[i].style.display = "list-item";
860 cat_unread++;
861 //Effect.Appear(node.childNodes[i], {duration : 0.3});
862 //Effect.Highlight(node.childNodes[i]);
863 }
864 }
865 }
866 }
867
868 // debug("end cat: " + node.id + " unread " + cat_unread);
869
870 if (cat_node) {
871
872 if (cat_unread == 0) {
873 if (cat_node.style == undefined) {
874 debug("ERROR: supplied cat_node " + cat_node +
875 " has no styles. WTF?");
876 return;
877 }
878 if (hide) {
879 //cat_node.style.display = "none";
880 Effect.Fade(cat_node, {duration : 0.3,
881 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
882 } else {
883 cat_node.style.display = "list-item";
884 }
885 } else {
886 try {
887 cat_node.style.display = "list-item";
888 } catch (e) {
889 debug(e);
890 }
891 }
892 }
893
894 // debug("unread for category: " + cat_unread);
895
896 } catch (e) {
897 exception_error("hideOrShowFeedsCategory", e);
898 }
899 }
900
901 function selectTableRow(r, do_select) {
902 r.className = r.className.replace("Selected", "");
903
904 if (do_select) {
905 r.className = r.className + "Selected";
906 }
907 }
908
909 function selectTableRowById(elem_id, check_id, do_select) {
910
911 try {
912
913 var row = $(elem_id);
914
915 if (row) {
916 selectTableRow(row, do_select);
917 }
918
919 var check = $(check_id);
920
921 if (check) {
922 check.checked = do_select;
923 }
924 } catch (e) {
925 exception_error("selectTableRowById", e);
926 }
927 }
928
929 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
930 classcheck, reset_others) {
931
932 var content = $(content_id);
933
934 if (!content) {
935 alert("[selectTableRows] Element " + content_id + " not found.");
936 return;
937 }
938
939 for (i = 0; i < content.rows.length; i++) {
940 if (Element.visible(content.rows[i])) {
941 if (!classcheck || content.rows[i].className.match(classcheck)) {
942
943 if (content.rows[i].id.match(prefix)) {
944 selectTableRow(content.rows[i], do_select);
945
946 var row_id = content.rows[i].id.replace(prefix, "");
947 var check = $(check_prefix + row_id);
948
949 if (check) {
950 check.checked = do_select;
951 }
952 } else if (reset_others) {
953 selectTableRow(content.rows[i], false);
954
955 var row_id = content.rows[i].id.replace(prefix, "");
956 var check = $(check_prefix + row_id);
957
958 if (check) {
959 check.checked = false;
960 }
961
962 }
963 } else if (reset_others) {
964 selectTableRow(content.rows[i], false);
965
966 var row_id = content.rows[i].id.replace(prefix, "");
967 var check = $(check_prefix + row_id);
968
969 if (check) {
970 check.checked = false;
971 }
972
973 }
974 }
975 }
976 }
977
978 function getSelectedTableRowIds(content_id, prefix) {
979
980 var content = $(content_id);
981
982 if (!content) {
983 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
984 return;
985 }
986
987 var sel_rows = new Array();
988
989 for (i = 0; i < content.rows.length; i++) {
990 if (content.rows[i].id.match(prefix) &&
991 content.rows[i].className.match("Selected")) {
992
993 var row_id = content.rows[i].id.replace(prefix + "-", "");
994 sel_rows.push(row_id);
995 }
996 }
997
998 return sel_rows;
999
1000 }
1001
1002 function toggleSelectRowById(sender, id) {
1003 var row = $(id);
1004
1005 if (sender.checked) {
1006 if (!row.className.match("Selected")) {
1007 row.className = row.className + "Selected";
1008 }
1009 } else {
1010 if (row.className.match("Selected")) {
1011 row.className = row.className.replace("Selected", "");
1012 }
1013 }
1014 }
1015
1016 function toggleSelectListRow(sender) {
1017 var parent_row = sender.parentNode;
1018
1019 if (sender.checked) {
1020 if (!parent_row.className.match("Selected")) {
1021 parent_row.className = parent_row.className + "Selected";
1022 }
1023 } else {
1024 if (parent_row.className.match("Selected")) {
1025 parent_row.className = parent_row.className.replace("Selected", "");
1026 }
1027 }
1028 }
1029
1030 function tSR(sender) {
1031 return toggleSelectRow(sender);
1032 }
1033
1034 function toggleSelectRow(sender) {
1035 var parent_row = sender.parentNode.parentNode;
1036
1037 if (sender.checked) {
1038 if (!parent_row.className.match("Selected")) {
1039 parent_row.className = parent_row.className + "Selected";
1040 }
1041 } else {
1042 if (parent_row.className.match("Selected")) {
1043 parent_row.className = parent_row.className.replace("Selected", "");
1044 }
1045 }
1046 }
1047
1048 function getNextUnreadCat(id) {
1049 try {
1050 var rows = $("feedList").getElementsByTagName("LI");
1051 var feeds = new Array();
1052
1053 var unread_only = true;
1054 var is_cat = true;
1055
1056 for (var i = 0; i < rows.length; i++) {
1057 if (rows[i].id.match("FCAT-")) {
1058 if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1059
1060 var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
1061
1062 if (cat_id >= 0) {
1063 if (!unread_only || get_cat_unread(cat_id) > 0) {
1064 feeds.push(cat_id);
1065 }
1066 }
1067 }
1068 }
1069 }
1070
1071 var idx = feeds.indexOf(id);
1072 if (idx != -1 && idx < feeds.length) {
1073 return feeds[idx+1];
1074 } else {
1075 return feeds.shift();
1076 }
1077
1078 } catch (e) {
1079 exception_error("getNextUnreadCat", e);
1080 }
1081 }
1082
1083 function getRelativeFeedId2(id, is_cat, direction, unread_only) {
1084 try {
1085
1086 // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
1087
1088 var rows = $("feedList").getElementsByTagName("LI");
1089 var feeds = new Array();
1090
1091 for (var i = 0; i < rows.length; i++) {
1092 if (rows[i].id.match("FEEDR-")) {
1093
1094 if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1095
1096 if (!unread_only ||
1097 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1098 feeds.push(rows[i].id.replace("FEEDR-", ""));
1099 }
1100 }
1101 }
1102
1103 if (rows[i].id.match("FCAT-")) {
1104 if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1105
1106 var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
1107
1108 if (cat_id >= 0) {
1109 if (!unread_only || get_cat_unread(cat_id) > 0) {
1110 feeds.push("CAT:"+cat_id);
1111 }
1112 }
1113 }
1114 }
1115 }
1116
1117 // alert(feeds.toString());
1118
1119 if (!id) {
1120 if (direction == "next") {
1121 return feeds.shift();
1122 } else {
1123 return feeds.pop();
1124 }
1125 } else {
1126 if (direction == "next") {
1127 if (is_cat) id = "CAT:" + id;
1128 var idx = feeds.indexOf(id);
1129 if (idx != -1 && idx < feeds.length) {
1130 return feeds[idx+1];
1131 } else {
1132 return getRelativeFeedId2(false, is_cat, direction, unread_only);
1133 }
1134 } else {
1135 if (is_cat) id = "CAT:" + id;
1136 var idx = feeds.indexOf(id);
1137 if (idx > 0) {
1138 return feeds[idx-1];
1139 } else {
1140 return getRelativeFeedId2(false, is_cat, direction, unread_only);
1141 }
1142 }
1143
1144 }
1145
1146 } catch (e) {
1147 exception_error("getRelativeFeedId2", e);
1148 }
1149 }
1150
1151
1152 function getRelativeFeedId(list, id, direction, unread_only) {
1153 var rows = list.getElementsByTagName("LI");
1154 var feeds = new Array();
1155
1156 for (var i = 0; i < rows.length; i++) {
1157 if (rows[i].id.match("FEEDR-")) {
1158
1159 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1160
1161 if (!unread_only ||
1162 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1163 feeds.push(rows[i].id.replace("FEEDR-", ""));
1164 }
1165 }
1166 }
1167 }
1168
1169 if (!id) {
1170 if (direction == "next") {
1171 return feeds.shift();
1172 } else {
1173 return feeds.pop();
1174 }
1175 } else {
1176 if (direction == "next") {
1177 var idx = feeds.indexOf(id);
1178 if (idx != -1 && idx < feeds.length) {
1179 return feeds[idx+1];
1180 } else {
1181 return getRelativeFeedId(list, false, direction, unread_only);
1182 }
1183 } else {
1184 var idx = feeds.indexOf(id);
1185 if (idx > 0) {
1186 return feeds[idx-1];
1187 } else {
1188 return getRelativeFeedId(list, false, direction, unread_only);
1189 }
1190 }
1191
1192 }
1193 }
1194
1195 function showBlockElement(id, h_id) {
1196 var elem = $(id);
1197
1198 if (elem) {
1199 elem.style.display = "block";
1200
1201 if (h_id) {
1202 elem = $(h_id);
1203 if (elem) {
1204 elem.style.display = "none";
1205 }
1206 }
1207 } else {
1208 alert("[showBlockElement] can't find element with id " + id);
1209 }
1210 }
1211
1212 function appearBlockElement_afh(effect) {
1213
1214 }
1215
1216 function checkboxToggleElement(elem, id) {
1217 if (elem.checked) {
1218 Effect.Appear(id, {duration : 0.5});
1219 } else {
1220 Effect.Fade(id, {duration : 0.5});
1221 }
1222 }
1223
1224 function appearBlockElement(id, h_id) {
1225
1226 try {
1227 if (h_id) {
1228 Effect.Fade(h_id);
1229 }
1230 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1231 } catch (e) {
1232 exception_error("appearBlockElement", e);
1233 }
1234
1235 }
1236
1237 function hideParentElement(e) {
1238 e.parentNode.style.display = "none";
1239 }
1240
1241 function dropboxSelect(e, v) {
1242 for (i = 0; i < e.length; i++) {
1243 if (e[i].value == v) {
1244 e.selectedIndex = i;
1245 break;
1246 }
1247 }
1248 }
1249
1250 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1251 // bugfixed just a little bit :-)
1252 function getURLParam(strParamName){
1253 var strReturn = "";
1254 var strHref = window.location.href;
1255
1256 if (strHref.indexOf("#") == strHref.length-1) {
1257 strHref = strHref.substring(0, strHref.length-1);
1258 }
1259
1260 if ( strHref.indexOf("?") > -1 ){
1261 var strQueryString = strHref.substr(strHref.indexOf("?"));
1262 var aQueryString = strQueryString.split("&");
1263 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1264 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1265 var aParam = aQueryString[iParam].split("=");
1266 strReturn = aParam[1];
1267 break;
1268 }
1269 }
1270 }
1271 return strReturn;
1272 }
1273
1274 function leading_zero(p) {
1275 var s = String(p);
1276 if (s.length == 1) s = "0" + s;
1277 return s;
1278 }
1279
1280 function closeErrorBox() {
1281
1282 if (Element.visible("errorBoxShadow")) {
1283 Element.hide("dialog_overlay");
1284 Element.hide("errorBoxShadow");
1285
1286 enableHotkeys();
1287 }
1288
1289 return false;
1290 }
1291
1292 function closeInfoBox(cleanup) {
1293
1294 try {
1295 enableHotkeys();
1296
1297 if (Element.visible("infoBoxShadow")) {
1298 Element.hide("dialog_overlay");
1299 Element.hide("infoBoxShadow");
1300
1301 if (cleanup) $("infoBoxShadow").innerHTML = "&nbsp;";
1302 }
1303 } catch (e) {
1304 exception_error("closeInfoBox", e);
1305 }
1306
1307 return false;
1308 }
1309
1310
1311 function displayDlg(id, param) {
1312
1313 notify_progress("Loading, please wait...", true);
1314
1315 disableHotkeys();
1316
1317 var query = "backend.php?op=dlg&id=" +
1318 param_escape(id) + "&param=" + param_escape(param);
1319
1320 new Ajax.Request(query, {
1321 onComplete: function (transport) {
1322 infobox_callback2(transport);
1323 } });
1324
1325 return false;
1326 }
1327
1328 function infobox_submit_callback2(transport) {
1329 closeInfoBox();
1330
1331 try {
1332 // called from prefs, reload tab
1333 if (typeof active_tab != 'undefined' && active_tab) {
1334 selectTab(active_tab, false);
1335 }
1336 } catch (e) { }
1337
1338 if (transport.responseText) {
1339 notify_info(transport.responseText);
1340 }
1341 }
1342
1343 function infobox_callback2(transport) {
1344 try {
1345
1346 debug("infobox_callback2");
1347
1348 var box = $('infoBox');
1349
1350 if (box) {
1351
1352 if (!getInitParam("infobox_disable_overlay")) {
1353 Element.show("dialog_overlay");
1354 }
1355
1356 box.innerHTML=transport.responseText;
1357 Element.show("infoBoxShadow");
1358 //Effect.SlideDown("infoBoxShadow", {duration : 1.0});
1359
1360
1361 }
1362
1363 /* FIXME this needs to be moved out somewhere */
1364
1365 if ($("tags_choices")) {
1366 new Ajax.Autocompleter('tags_str', 'tags_choices',
1367 "backend.php?op=rpc&subop=completeTags",
1368 { tokens: ',', paramName: "search" });
1369 }
1370
1371 disableHotkeys();
1372
1373 notify("");
1374 } catch (e) {
1375 exception_error("infobox_callback2", e);
1376 }
1377 }
1378
1379 function createFilter() {
1380
1381 try {
1382
1383 var form = document.forms['filter_add_form'];
1384 var reg_exp = form.reg_exp.value;
1385
1386 if (reg_exp == "") {
1387 alert(__("Can't add filter: nothing to match on."));
1388 return false;
1389 }
1390
1391 var query = Form.serialize("filter_add_form");
1392
1393 // we can be called from some other tab in Prefs
1394 if (typeof active_tab != 'undefined' && active_tab) {
1395 active_tab = "filterConfig";
1396 }
1397
1398 new Ajax.Request("backend.php?" + query, {
1399 onComplete: function (transport) {
1400 infobox_submit_callback2(transport);
1401 } });
1402
1403 return true;
1404
1405 } catch (e) {
1406 exception_error("createFilter", e);
1407 }
1408 }
1409
1410 function toggleSubmitNotEmpty(e, submit_id) {
1411 try {
1412 $(submit_id).disabled = (e.value == "")
1413 } catch (e) {
1414 exception_error("toggleSubmitNotEmpty", e);
1415 }
1416 }
1417
1418 function isValidURL(s) {
1419 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1420 }
1421
1422 function subscribeToFeed() {
1423
1424 var form = document.forms['feed_add_form'];
1425 var feed_url = form.feed_url.value;
1426
1427 if (feed_url == "") {
1428 alert(__("Can't subscribe: no feed URL given."));
1429 return false;
1430 }
1431
1432 notify_progress(__("Subscribing to feed..."), true);
1433
1434 closeInfoBox();
1435
1436 var feeds_doc = document;
1437
1438 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1439
1440 var query = Form.serialize("feed_add_form");
1441
1442 debug("subscribe q: " + query);
1443
1444 new Ajax.Request("backend.php", {
1445 parameters: query,
1446 onComplete: function(transport) {
1447 dlg_frefresh_callback(transport);
1448 } });
1449
1450 return false;
1451 }
1452
1453 function filterCR(e, f)
1454 {
1455 var key;
1456
1457 if(window.event)
1458 key = window.event.keyCode; //IE
1459 else
1460 key = e.which; //firefox
1461
1462 if (key == 13) {
1463 if (typeof f != 'undefined') {
1464 f();
1465 return false;
1466 } else {
1467 return false;
1468 }
1469 } else {
1470 return true;
1471 }
1472 }
1473
1474 var debug_last_class = "even";
1475
1476 function debug(msg) {
1477
1478 if (debug_last_class == "even") {
1479 debug_last_class = "odd";
1480 } else {
1481 debug_last_class = "even";
1482 }
1483
1484 var c = $('debug_output');
1485 if (c && Element.visible(c)) {
1486 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1487 c.removeChild(c.lastChild);
1488 }
1489
1490 var d = new Date();
1491 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1492 ":" + leading_zero(d.getSeconds());
1493 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1494 msg + "</li>" + c.innerHTML;
1495 }
1496 }
1497
1498 function getInitParam(key) {
1499 return init_params[key];
1500 }
1501
1502 function storeInitParam(key, value) {
1503 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1504 init_params[key] = value;
1505 }
1506
1507 function fatalError(code, msg, ext_info) {
1508 try {
1509
1510 if (!ext_info) ext_info = "N/A";
1511
1512 if (code == 6) {
1513 window.location.href = "tt-rss.php";
1514 } else if (code == 5) {
1515 window.location.href = "update.php";
1516 } else {
1517
1518 if (msg == "") msg = "Unknown error";
1519
1520 var ebc = $("xebContent");
1521
1522 if (ebc) {
1523
1524 Element.show("dialog_overlay");
1525 Element.show("errorBoxShadow");
1526 Element.hide("xebBtn");
1527
1528 if (ext_info) {
1529 if (ext_info.responseText) {
1530 ext_info = ext_info.responseText;
1531 }
1532 }
1533
1534 ebc.innerHTML =
1535 "<div><b>Error message:</b></div>" +
1536 "<pre>" + msg + "</pre>" +
1537 "<div><b>Additional information:</b></div>" +
1538 "<textarea readonly=\"1\">" + ext_info + "</textarea>";
1539 }
1540 }
1541
1542 } catch (e) {
1543 exception_error("fatalError", e);
1544 }
1545 }
1546
1547 function getFeedName(id, is_cat) {
1548 var e;
1549
1550 if (is_cat) {
1551 e = $("FCATN-" + id);
1552 } else {
1553 e = $("FEEDN-" + id);
1554 }
1555 if (e) {
1556 return e.innerHTML.stripTags();
1557 } else {
1558 return null;
1559 }
1560 }
1561
1562 function filterDlgCheckType(sender) {
1563
1564 try {
1565
1566 var ftype = sender[sender.selectedIndex].value;
1567
1568 var form = document.forms["filter_add_form"];
1569
1570 if (!form) {
1571 form = document.forms["filter_edit_form"];
1572 }
1573
1574 if (!form) {
1575 debug("filterDlgCheckType: can't find form!");
1576 return;
1577 }
1578
1579 // if selected filter type is 5 (Date) enable the modifier dropbox
1580 if (ftype == 5) {
1581 Element.show("filter_dlg_date_mod_box");
1582 Element.show("filter_dlg_date_chk_box");
1583 } else {
1584 Element.hide("filter_dlg_date_mod_box");
1585 Element.hide("filter_dlg_date_chk_box");
1586
1587 }
1588
1589 } catch (e) {
1590 exception_error("filterDlgCheckType", e);
1591 }
1592
1593 }
1594
1595 function filterDlgCheckAction(sender) {
1596
1597 try {
1598
1599 var action = sender[sender.selectedIndex].value;
1600
1601 var form = document.forms["filter_add_form"];
1602
1603 if (!form) {
1604 form = document.forms["filter_edit_form"];
1605 }
1606
1607 if (!form) {
1608 debug("filterDlgCheckAction: can't find form!");
1609 return;
1610 }
1611
1612 var action_param = $("filter_dlg_param_box");
1613
1614 if (!action_param) {
1615 debug("filterDlgCheckAction: can't find action param box!");
1616 return;
1617 }
1618
1619 // if selected action supports parameters, enable params field
1620 if (action == 4 || action == 6 || action == 7) {
1621 Element.show(action_param);
1622 if (action != 7) {
1623 Element.show(form.action_param);
1624 Element.hide(form.action_param_label);
1625 } else {
1626 Element.show(form.action_param_label);
1627 Element.hide(form.action_param);
1628 }
1629 } else {
1630 Element.hide(action_param);
1631 }
1632
1633 } catch (e) {
1634 exception_error("filterDlgCheckAction", e);
1635 }
1636
1637 }
1638
1639 function filterDlgCheckDate() {
1640 try {
1641 var form = document.forms["filter_add_form"];
1642
1643 if (!form) {
1644 form = document.forms["filter_edit_form"];
1645 }
1646
1647 if (!form) {
1648 debug("filterDlgCheckAction: can't find form!");
1649 return;
1650 }
1651
1652 var reg_exp = form.reg_exp.value;
1653
1654 var query = "backend.php?op=rpc&subop=checkDate&date=" + reg_exp;
1655
1656 new Ajax.Request(query, {
1657 onComplete: function(transport) {
1658
1659 var form = document.forms["filter_add_form"];
1660
1661 if (!form) {
1662 form = document.forms["filter_edit_form"];
1663 }
1664
1665 if (transport.responseXML) {
1666 var result = transport.responseXML.getElementsByTagName("result")[0];
1667
1668 if (result && result.firstChild) {
1669 if (result.firstChild.nodeValue == "1") {
1670
1671 new Effect.Highlight(form.reg_exp, {startcolor : '#00ff00'});
1672
1673 return;
1674 }
1675 }
1676 }
1677
1678 new Effect.Highlight(form.reg_exp, {startcolor : '#ff0000'});
1679
1680 } });
1681
1682
1683 } catch (e) {
1684 exception_error("filterDlgCheckDate", e);
1685 }
1686 }
1687
1688 function explainError(code) {
1689 return displayDlg("explainError", code);
1690 }
1691
1692 // this only searches loaded headlines list, not in CDM
1693 function getRelativePostIds(id, limit) {
1694
1695 if (!limit) limit = 3;
1696
1697 debug("getRelativePostIds: " + id + " limit=" + limit);
1698
1699 var ids = new Array();
1700 var container = $("headlinesList");
1701
1702 if (container) {
1703 var rows = container.rows;
1704
1705 for (var i = 0; i < rows.length; i++) {
1706 var r_id = rows[i].id.replace("RROW-", "");
1707
1708 if (r_id == id) {
1709 for (var k = 1; k <= limit; k++) {
1710 var nid = false;
1711
1712 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1713 if (nid) ids.push(nid);
1714
1715 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1716 if (nid) ids.push(nid);
1717 }
1718
1719 return ids;
1720 }
1721 }
1722 }
1723
1724 return false;
1725 }
1726
1727 function openArticleInNewWindow(id) {
1728 try {
1729 debug("openArticleInNewWindow: " + id);
1730
1731 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1732 var wname = "ttrss_article_" + id;
1733
1734 debug(query + " " + wname);
1735
1736 var w = window.open("", wname);
1737
1738 if (!w) notify_error("Failed to open window for the article");
1739
1740 new Ajax.Request(query, {
1741 onComplete: function(transport) {
1742 open_article_callback(transport);
1743 } });
1744
1745
1746 } catch (e) {
1747 exception_error("openArticleInNewWindow", e);
1748 }
1749 }
1750
1751 /* http://textsnippets.com/posts/show/835 */
1752
1753 Position.GetWindowSize = function(w) {
1754 w = w ? w : window;
1755 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1756 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1757 return [width, height]
1758 }
1759
1760 /* http://textsnippets.com/posts/show/836 */
1761
1762 Position.Center = function(element, parent) {
1763 var w, h, pw, ph;
1764 var d = Element.getDimensions(element);
1765 w = d.width;
1766 h = d.height;
1767 Position.prepare();
1768 if (!parent) {
1769 var ws = Position.GetWindowSize();
1770 pw = ws[0];
1771 ph = ws[1];
1772 } else {
1773 pw = parent.offsetWidth;
1774 ph = parent.offsetHeight;
1775 }
1776 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1777 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1778 }
1779
1780
1781 function labeltest_callback(transport) {
1782 try {
1783 var container = $('label_test_result');
1784
1785 container.innerHTML = transport.responseText;
1786 if (!Element.visible(container)) {
1787 Effect.SlideDown(container, { duration : 0.5 });
1788 }
1789
1790 notify("");
1791 } catch (e) {
1792 exception_error("labeltest_callback", e);
1793 }
1794 }
1795
1796 function labelTest() {
1797
1798 try {
1799 var container = $('label_test_result');
1800
1801 var form = document.forms['label_edit_form'];
1802
1803 var sql_exp = form.sql_exp.value;
1804 var description = form.description.value;
1805
1806 notify_progress("Loading, please wait...");
1807
1808 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1809 param_escape(sql_exp) + "&descr=" + param_escape(description);
1810
1811 new Ajax.Request(query, {
1812 onComplete: function (transport) {
1813 labeltest_callback(transport);
1814 } });
1815
1816 return false;
1817
1818 } catch (e) {
1819 exception_error("labelTest", e);
1820 }
1821 }
1822
1823 function isCdmMode() {
1824 return !$("headlinesList");
1825 }
1826
1827 function getSelectedArticleIds2() {
1828 var rows = new Array();
1829 var cdm_mode = isCdmMode();
1830
1831 if (cdm_mode) {
1832 rows = cdmGetSelectedArticles();
1833 } else {
1834 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1835 }
1836
1837 var ids = new Array();
1838
1839 for (var i = 0; i < rows.length; i++) {
1840 var chk = $("RCHK-" + rows[i]);
1841 if (chk && chk.checked) {
1842 ids.push(rows[i]);
1843 }
1844 }
1845
1846 return ids;
1847 }
1848
1849 function displayHelpInfobox(topic_id) {
1850
1851 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1852
1853 var w = window.open(url, "ttrss_help",
1854 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1855
1856 }
1857
1858 function focus_element(id) {
1859 try {
1860 var e = $(id);
1861 if (e) e.focus();
1862 } catch (e) {
1863 exception_error("focus_element", e);
1864 }
1865 return false;
1866 }
1867
1868 function loading_set_progress(p) {
1869 try {
1870 if (p < last_progress_point || !Element.visible("overlay")) return;
1871
1872 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
1873
1874 var o = $("l_progress_i");
1875
1876 // o.style.width = (p * 2) + "px";
1877
1878 new Effect.Scale(o, p, {
1879 scaleY : false,
1880 scaleFrom : last_progress_point,
1881 scaleMode: { originalWidth : 200 },
1882 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
1883
1884 last_progress_point = p;
1885
1886 } catch (e) {
1887 exception_error("loading_set_progress", e);
1888 }
1889 }
1890
1891 function remove_splash() {
1892 if (Element.visible("overlay")) {
1893 debug("about to remove splash, OMG!");
1894 Element.hide("overlay");
1895 debug("removed splash!");
1896 }
1897 }
1898
1899 function addLabelExample() {
1900 try {
1901 var form = document.forms["label_edit_form"];
1902
1903 var text = form.sql_exp;
1904 var op = form.label_fields[form.label_fields.selectedIndex];
1905 var p = form.label_fields_param;
1906
1907 if (op) {
1908 op = op.value;
1909
1910 var tmp = "";
1911
1912 if (text.value != "") {
1913 if (text.value.substring(text.value.length-3, 3).toUpperCase() != "AND") {
1914 tmp = " AND ";
1915 } else {
1916 tmp = " ";
1917 }
1918 }
1919
1920 if (op == "unread") {
1921 tmp = tmp + "unread = true";
1922 }
1923
1924 if (op == "updated") {
1925 tmp = tmp + "last_read is null and unread = false";
1926 }
1927
1928 if (op == "kw_title") {
1929 if (p.value == "") {
1930 alert("This action requires a parameter.");
1931 return false;
1932 }
1933 tmp = tmp + "ttrss_entries.title like '%"+p.value+"%'";
1934 }
1935
1936 if (op == "kw_content") {
1937 if (p.value == "") {
1938 alert("This action requires a parameter.");
1939 return false;
1940 }
1941
1942 tmp = tmp + "ttrss_entries.content like '%"+p.value+"%'";
1943 }
1944
1945 if (op == "scoreE") {
1946 if (isNaN(parseInt(p.value))) {
1947 alert("This action expects numeric parameter.");
1948 return false;
1949 }
1950 tmp = tmp + "score = " + p.value;
1951 }
1952
1953 if (op == "scoreG") {
1954 if (isNaN(parseInt(p.value))) {
1955 alert("This action expects numeric parameter.");
1956 return false;
1957 }
1958 tmp = tmp + "score > " + p.value;
1959 }
1960
1961 if (op == "scoreL") {
1962 if (isNaN(parseInt(p.value))) {
1963 alert("This action expects numeric parameter.");
1964 return false;
1965 }
1966 tmp = tmp + "score < " + p.value;
1967 }
1968
1969 if (op == "newerD") {
1970 if (isNaN(parseInt(p.value))) {
1971 alert("This action expects numeric parameter.");
1972 return false;
1973 }
1974 tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" days'";
1975 }
1976
1977 if (op == "newerH") {
1978 if (isNaN(parseInt(p.value))) {
1979 alert("This action expects numeric parameter.");
1980 return false;
1981 }
1982
1983 tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" hours'";
1984 }
1985
1986 text.value = text.value + tmp;
1987
1988 p.value = "";
1989
1990 }
1991
1992 } catch (e) {
1993 exception_error("addLabelExample", e);
1994 }
1995
1996 return false;
1997 }
1998
1999 function labelFieldsCheck(elem) {
2000 try {
2001 var op = elem[elem.selectedIndex].value;
2002
2003 var p = document.forms["label_edit_form"].label_fields_param;
2004
2005 if (op == "kw_title" || op == "kw_content" || op == "scoreL" ||
2006 op == "scoreG" || op == "scoreE" || op == "newerD" ||
2007 op == "newerH" ) {
2008 Element.show(p);
2009 } else {
2010 Element.hide(p);
2011 }
2012
2013 } catch (e) {
2014 exception_error("labelFieldsCheck", e);
2015
2016 }
2017 }
2018
2019 function getSelectedFeedsFromBrowser() {
2020
2021 var list = $("browseFeedList");
2022 if (!list) list = $("browseBigFeedList");
2023
2024 var selected = new Array();
2025
2026 for (i = 0; i < list.childNodes.length; i++) {
2027 var child = list.childNodes[i];
2028 if (child.id && child.id.match("FBROW-")) {
2029 var id = child.id.replace("FBROW-", "");
2030
2031 var cb = $("FBCHK-" + id);
2032
2033 if (cb.checked) {
2034 selected.push(id);
2035 }
2036 }
2037 }
2038
2039 return selected;
2040 }
2041
2042 function updateFeedBrowser() {
2043 try {
2044
2045 var query = "backend.php?op=rpc&subop=feedBrowser";
2046
2047 var search = $("feed_browser_search");
2048 var limit = $("feed_browser_limit");
2049
2050 if (limit) {
2051 query = query + "&limit=" + limit[limit.selectedIndex].value;
2052 }
2053
2054 if (search) {
2055 query = query + "&search=" + param_escape(search.value);
2056 }
2057
2058 //notify_progress("Loading, please wait...", true);
2059
2060 Element.show('feed_browser_spinner');
2061
2062 new Ajax.Request(query, {
2063 onComplete: function(transport) {
2064 notify('');
2065
2066 Element.hide('feed_browser_spinner');
2067
2068 var c = $("browseFeedList");
2069 var r = transport.responseXML.getElementsByTagName("content")[0];
2070 var nr = transport.responseXML.getElementsByTagName("num-results")[0];
2071 var sb = $("feed_browser_subscribe");
2072
2073 if (c && r) {
2074 c.innerHTML = r.firstChild.nodeValue;
2075 }
2076
2077 if (nr && sb) {
2078 if (nr.getAttribute("value") > 0) {
2079 sb.disabled = false;
2080 } else {
2081 sb.disabled = true;
2082 }
2083 }
2084
2085 } });
2086
2087
2088 } catch (e) {
2089 exception_error("updateFeedBrowser", e);
2090 }
2091 }
2092
2093 function browseFeeds(limit) {
2094
2095 try {
2096
2097 var query = "backend.php?op=pref-feeds&subop=browse";
2098
2099 notify_progress("Loading, please wait...", true);
2100
2101 new Ajax.Request(query, {
2102 onComplete: function(transport) {
2103 infobox_callback2(transport);
2104 } });
2105
2106 return false;
2107 } catch (e) {
2108 exception_error("browseFeeds", e);
2109 }
2110 }
2111
2112 function transport_error_check(transport) {
2113 try {
2114 if (transport.responseXML) {
2115 var error = transport.responseXML.getElementsByTagName("error")[0];
2116
2117 if (error) {
2118 var code = error.getAttribute("error-code");
2119 var msg = error.getAttribute("error-msg");
2120 if (code != 0) {
2121 fatalError(code, msg);
2122 return false;
2123 }
2124 }
2125 }
2126 } catch (e) {
2127 exception_error("check_for_error_xml", e);
2128 }
2129 return true;
2130 }
2131
2132 function strip_tags(s) {
2133 return s.replace(/<\/?[^>]+(>|$)/g, "");
2134 }
2135
2136 function truncate_string(s, length) {
2137 if (!length) length = 30;
2138 var tmp = s.substring(0, length);
2139 if (s.length > length) tmp += "&hellip;";
2140 return tmp;
2141 }
2142
2143 /*
2144 function switchToFlash(e) {
2145 try {
2146 var targ = e;
2147 if (!e) var e = window.event;
2148 if (e.target) targ = e.target;
2149 else if (e.srcElement) targ = e.srcElement;
2150 if (targ.nodeType == 3) // defeat Safari bug
2151 targ = targ.parentNode;
2152
2153 //targ is the link that was clicked
2154 var audioTag=targ;
2155 do {
2156 audioTag=audioTag.previousSibling;
2157 } while(audioTag && audioTag.nodeType != 1)
2158
2159 var flashPlayer = audioTag.getElementsByTagName('span')[0];
2160 targ.parentNode.insertBefore(flashPlayer,targ);
2161 targ.parentNode.removeChild(targ);
2162 audioTag.parentNode.removeChild(audioTag);
2163
2164 return false;
2165 } catch (e) {
2166 exception_error("switchToFlash", e);
2167 }
2168 }
2169
2170 function html5AudioOrFlash(type) {
2171 var audioTag = document.createElement('audio');
2172 if(! audioTag.canPlayType || audioTag.canPlayType(type) == "no" ||
2173 audioTag.canPlayType(type) == ""){
2174 if($('switchToFlashLink')){
2175 switchToFlash($('switchToFlashLink'));
2176 }
2177 }
2178 } */
2179
2180 function hotkey_prefix_timeout() {
2181 try {
2182
2183 var date = new Date();
2184 var ts = Math.round(date.getTime() / 1000);
2185
2186 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
2187 debug("hotkey_prefix seems to be stuck, aborting");
2188 hotkey_prefix_pressed = false;
2189 hotkey_prefix = false;
2190 Element.hide('cmdline');
2191 }
2192
2193 setTimeout("hotkey_prefix_timeout()", 1000);
2194
2195 } catch (e) {
2196 exception_error("hotkey_prefix_timeout", e);
2197 }
2198 }
2199
2200 function hideAuxDlg() {
2201 try {
2202 Element.hide('auxDlg');
2203 } catch (e) {
2204 exception_error("hideAuxDlg", e);
2205 }
2206 }
2207
2208 function displayNewContentPrompt(id) {
2209 try {
2210 var msg = __("New articles in &laquo;%s&raquo;.") +
2211 " <a href='#' onclick='viewfeed("+id+")'>" + __('Click to view') + "</a>.";
2212
2213 msg = msg.replace("%s", getFeedName(id));
2214
2215 $('auxDlg').innerHTML = msg;
2216
2217 Element.show('auxDlg');
2218
2219 } catch (e) {
2220 exception_error("displayNewContentPrompt", e);
2221 }
2222 }