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