]> git.wh0rd.org - tt-rss.git/blob - functions.js
make updating feeds notify persistent, remove p_notify calls
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2
3 function exception_error(location, e) {
4 var msg;
5
6 if (e.fileName) {
7 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
8
9 msg = "Exception: " + e.name + ", " + e.message +
10 "\nFunction: " + location + "()" +
11 "\nLocation: " + base_fname + ":" + e.lineNumber;
12 } else {
13 msg = "Exception: " + e + "\nFunction: " + location + "()";
14 }
15
16 alert(msg);
17 }
18
19 function disableHotkeys() {
20 hotkeys_enabled = false;
21 }
22
23 function enableHotkeys() {
24 hotkeys_enabled = true;
25 }
26
27 function xmlhttp_ready(obj) {
28 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
29 }
30
31 function notify_callback() {
32 var container = document.getElementById('notify');
33 if (xmlhttp.readyState == 4) {
34 container.innerHTML=xmlhttp.responseText;
35 }
36 }
37
38 function rpc_notify_callback() {
39 var container = document.getElementById('notify');
40 if (xmlhttp_rpc.readyState == 4) {
41 container.innerHTML=xmlhttp_rpc.responseText;
42 }
43 }
44
45 function rpc_pnotify_callback() {
46 var container = parent.document.getElementById('notify');
47 if (xmlhttp_rpc.readyState == 4) {
48 container.innerHTML=xmlhttp_rpc.responseText;
49 }
50 }
51
52 function param_escape(arg) {
53 if (typeof encodeURIComponent != 'undefined')
54 return encodeURIComponent(arg);
55 else
56 return escape(arg);
57 }
58
59 function param_unescape(arg) {
60 if (typeof decodeURIComponent != 'undefined')
61 return decodeURIComponent(arg);
62 else
63 return unescape(arg);
64 }
65
66 function delay(gap) {
67 var then,now;
68 then=new Date().getTime();
69 now=then;
70 while((now-then)<gap) {
71 now=new Date().getTime();
72 }
73 }
74
75 var notify_hide_timerid = false;
76 var notify_last_doc = false;
77
78 function hide_notify() {
79 if (notify_last_doc) {
80 var n = notify_last_doc.getElementById("notify");
81 if (navigator.userAgent.match("Firefox")) {
82 if (notify_opacity >= 0) {
83 notify_opacity = notify_opacity - 0.2;
84 n.style.opacity = notify_opacity;
85 notify_hide_timerid = window.setTimeout(hide_notify, 20);
86 } else {
87 n.style.display = "none";
88 n.style.opacity = 1;
89 }
90 } else {
91 n.style.display = "none";
92 }
93 }
94 }
95
96 function notify_real(msg, doc, no_hide) {
97
98 var n = doc.getElementById("notify");
99 var nb = doc.getElementById("notify_body");
100
101 if (!n || !nb) return;
102
103 if (msg == "") {
104 n.style.display = "none";
105 } else {
106 n.style.display = "block";
107 }
108
109 nb.innerHTML = msg;
110
111 if (notify_hide_timerid) {
112 window.clearTimeout(notify_hide_timerid);
113 }
114
115 notify_last_doc = doc;
116 notify_opacity = 1;
117
118 if (!no_hide) {
119 notify_hide_timerid = window.setTimeout(hide_notify, 3000);
120 }
121 }
122
123 function p_notify(msg, no_hide) {
124 notify_real(msg, parent.document, no_hide);
125 }
126
127 function notify(msg, no_hide) {
128 notify_real(msg, document, no_hide);
129 }
130
131 function printLockingError() {
132 notify("Please wait until operation finishes");}
133
134 var seq = "";
135
136 function hotkey_handler(e) {
137
138 var keycode;
139
140 if (!hotkeys_enabled) return;
141
142 if (window.event) {
143 keycode = window.event.keyCode;
144 } else if (e) {
145 keycode = e.which;
146 }
147
148 if (keycode == 13 || keycode == 27) {
149 seq = "";
150 } else {
151 seq = seq + "" + keycode;
152 }
153
154 if (document.getElementById("piggie")) {
155
156 if (seq.match("807371717369")) {
157 seq = "";
158 localPiggieFunction(true);
159 } else {
160 localPiggieFunction(false);
161 }
162 }
163
164 if (typeof localHotkeyHandler != 'undefined') {
165 try {
166 localHotkeyHandler(keycode);
167 } catch (e) {
168 exception_error("hotkey_handler", e);
169 }
170 }
171
172 }
173
174 function cleanSelectedList(element) {
175 var content = document.getElementById(element);
176
177 if (!document.getElementById("feedCatHolder")) {
178 for (i = 0; i < content.childNodes.length; i++) {
179 var child = content.childNodes[i];
180 try {
181 child.className = child.className.replace("Selected", "");
182 } catch (e) {
183 //
184 }
185 }
186 } else {
187 for (i = 0; i < content.childNodes.length; i++) {
188 var child = content.childNodes[i];
189 if (child.id == "feedCatHolder") {
190 parent.debug(child.id);
191 var fcat = child.lastChild;
192 for (j = 0; j < fcat.childNodes.length; j++) {
193 var feed = fcat.childNodes[j];
194 feed.className = feed.className.replace("Selected", "");
195 }
196 }
197 }
198 }
199 }
200
201
202 function cleanSelected(element) {
203 var content = document.getElementById(element);
204
205 for (i = 0; i < content.rows.length; i++) {
206 content.rows[i].className = content.rows[i].className.replace("Selected", "");
207 }
208 }
209
210 function getVisibleUnreadHeadlines() {
211 var content = document.getElementById("headlinesList");
212
213 var rows = new Array();
214
215 for (i = 0; i < content.rows.length; i++) {
216 var row_id = content.rows[i].id.replace("RROW-", "");
217 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
218 rows.push(row_id);
219 }
220 }
221 return rows;
222 }
223
224 function getVisibleHeadlineIds() {
225
226 var content = document.getElementById("headlinesList");
227
228 var rows = new Array();
229
230 for (i = 0; i < content.rows.length; i++) {
231 var row_id = content.rows[i].id.replace("RROW-", "");
232 if (row_id.length > 0) {
233 rows.push(row_id);
234 }
235 }
236 return rows;
237 }
238
239 function getFirstVisibleHeadlineId() {
240 var rows = getVisibleHeadlineIds();
241 return rows[0];
242 }
243
244 function getLastVisibleHeadlineId() {
245 var rows = getVisibleHeadlineIds();
246 return rows[rows.length-1];
247 }
248
249 function markHeadline(id) {
250 var row = document.getElementById("RROW-" + id);
251 if (row) {
252 var is_active = false;
253
254 if (row.className.match("Active")) {
255 is_active = true;
256 }
257 row.className = row.className.replace("Selected", "");
258 row.className = row.className.replace("Active", "");
259 row.className = row.className.replace("Insensitive", "");
260
261 if (is_active) {
262 row.className = row.className = "Active";
263 }
264
265 var check = document.getElementById("RCHK-" + id);
266
267 if (check) {
268 check.checked = true;
269 }
270
271 row.className = row.className + "Selected";
272
273 }
274 }
275
276 function getFeedIds() {
277 var content = document.getElementById("feedsList");
278
279 var rows = new Array();
280
281 for (i = 0; i < content.rows.length; i++) {
282 var id = content.rows[i].id.replace("FEEDR-", "");
283 if (id.length > 0) {
284 rows.push(id);
285 }
286 }
287
288 return rows;
289 }
290
291 function setCookie(name, value, lifetime, path, domain, secure) {
292
293 var d = false;
294
295 if (lifetime) {
296 d = new Date();
297 d.setTime(lifetime * 1000);
298 }
299
300 int_setCookie(name, value, d, path, domain, secure);
301
302 }
303
304 function int_setCookie(name, value, expires, path, domain, secure) {
305 document.cookie= name + "=" + escape(value) +
306 ((expires) ? "; expires=" + expires.toGMTString() : "") +
307 ((path) ? "; path=" + path : "") +
308 ((domain) ? "; domain=" + domain : "") +
309 ((secure) ? "; secure" : "");
310 }
311
312 function delCookie(name, path, domain) {
313 if (getCookie(name)) {
314 document.cookie = name + "=" +
315 ((path) ? ";path=" + path : "") +
316 ((domain) ? ";domain=" + domain : "" ) +
317 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
318 }
319 }
320
321
322 function getCookie(name) {
323
324 var dc = document.cookie;
325 var prefix = name + "=";
326 var begin = dc.indexOf("; " + prefix);
327 if (begin == -1) {
328 begin = dc.indexOf(prefix);
329 if (begin != 0) return null;
330 }
331 else {
332 begin += 2;
333 }
334 var end = document.cookie.indexOf(";", begin);
335 if (end == -1) {
336 end = dc.length;
337 }
338 return unescape(dc.substring(begin + prefix.length, end));
339 }
340
341 function disableContainerChildren(id, disable, doc) {
342
343 if (!doc) doc = document;
344
345 var container = doc.getElementById(id);
346
347 for (var i = 0; i < container.childNodes.length; i++) {
348 var child = container.childNodes[i];
349
350 try {
351 child.disabled = disable;
352 } catch (E) {
353
354 }
355
356 if (disable) {
357 if (child.className && child.className.match("button")) {
358 child.className = "disabledButton";
359 }
360 } else {
361 if (child.className && child.className.match("disabledButton")) {
362 child.className = "button";
363 }
364 }
365 }
366
367 }
368
369 function gotoPreferences() {
370 document.location.href = "prefs.php";
371 }
372
373 function gotoMain() {
374 document.location.href = "tt-rss.php";
375 }
376
377 function gotoExportOpml() {
378 document.location.href = "opml.php?op=Export";
379 }
380
381 function getActiveFeedId() {
382 return getCookie("ttrss_vf_actfeed");
383 }
384
385 function setActiveFeedId(id) {
386 return setCookie("ttrss_vf_actfeed", id);
387 }
388
389 var xmlhttp_rpc = false;
390
391 /*@cc_on @*/
392 /*@if (@_jscript_version >= 5)
393 // JScript gives us Conditional compilation, we can cope with old IE versions.
394 // and security blocked creation of the objects.
395 try {
396 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
397 } catch (e) {
398 try {
399 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
400 } catch (E) {
401 xmlhttp_rpc = false;
402 }
403 }
404 @end @*/
405
406 if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
407 xmlhttp_rpc = new XMLHttpRequest();
408 }
409
410 function parse_counters(reply, f_document, title_obj, scheduled_call) {
411 try {
412 for (var l = 0; l < reply.childNodes.length; l++) {
413 if (!reply.childNodes[l] ||
414 typeof(reply.childNodes[l].getAttribute) == "undefined") {
415 // where did this come from?
416 continue;
417 }
418
419 var id = reply.childNodes[l].getAttribute("id");
420 var t = reply.childNodes[l].getAttribute("type");
421 var ctr = reply.childNodes[l].getAttribute("counter");
422 var error = reply.childNodes[l].getAttribute("error");
423 var has_img = reply.childNodes[l].getAttribute("hi");
424 var updated = reply.childNodes[l].getAttribute("updated");
425
426 if (id == "global-unread") {
427 title_obj.global_unread = ctr;
428 title_obj.updateTitle();
429 continue;
430 }
431
432 if (t == "category") {
433 var catctr = f_document.getElementById("FCATCTR-" + id);
434 if (catctr) {
435 catctr.innerHTML = "(" + ctr + " unread)";
436 }
437 continue;
438 }
439
440 var feedctr = f_document.getElementById("FEEDCTR-" + id);
441 var feedu = f_document.getElementById("FEEDU-" + id);
442 var feedr = f_document.getElementById("FEEDR-" + id);
443 var feed_img = f_document.getElementById("FIMG-" + id);
444 var feedlink = f_document.getElementById("FEEDL-" + id);
445
446 if (updated && feedlink) {
447 if (error) {
448 feedlink.title = "Error: " + error + " (" + updated + ")";
449 } else {
450 feedlink.title = "Updated: " + updated;
451 }
452 }
453
454 if (feedctr && feedu && feedr) {
455
456 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
457 var hf = title_obj.parent.frames["headlines-frame"];
458 hf.location.reload(true);
459 }
460
461 feedu.innerHTML = ctr;
462
463 if (error) {
464 feedr.className = feedr.className.replace("feed", "error");
465 } else if (id > 0) {
466 feedr.className = feedr.className.replace("error", "feed");
467 }
468
469 if (ctr > 0) {
470 feedctr.className = "odd";
471 if (!feedr.className.match("Unread")) {
472 var is_selected = feedr.className.match("Selected");
473
474 feedr.className = feedr.className.replace("Selected", "");
475 feedr.className = feedr.className.replace("Unread", "");
476
477 feedr.className = feedr.className + "Unread";
478
479 if (is_selected) {
480 feedr.className = feedr.className + "Selected";
481 }
482
483 }
484 } else {
485 feedctr.className = "invisible";
486 feedr.className = feedr.className.replace("Unread", "");
487 }
488 }
489 }
490 } catch (e) {
491 exception_error("parse_counters", e);
492 }
493 }
494
495 // this one is called from feedlist context
496 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
497
498 function all_counters_callback() {
499 if (xmlhttp_rpc.readyState == 4) {
500 try {
501 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
502 notify("[all_counters_callback] backend did not return valid XML");
503 return;
504 }
505
506 if (!parent.frames["feeds-frame"]) {
507 notify("[all_counters_callback] no parent feeds-frame");
508 return;
509 }
510
511 var reply = xmlhttp_rpc.responseXML.firstChild;
512 var f_document = parent.frames["feeds-frame"].document;
513
514 parse_counters(reply, f_document, parent);
515
516 } catch (e) {
517 exception_error("all_counters_callback", e);
518 }
519 }
520 }
521
522 function update_all_counters(feed) {
523 if (xmlhttp_ready(xmlhttp_rpc)) {
524 var query = "backend.php?op=rpc&subop=getAllCounters";
525
526 if (feed > 0) {
527 query = query + "&aid=" + feed;
528 }
529
530 xmlhttp_rpc.open("GET", query, true);
531 xmlhttp_rpc.onreadystatechange=all_counters_callback;
532 xmlhttp_rpc.send(null);
533 }
534 }
535
536 function popupHelp(tid) {
537 var w = window.open("backend.php?op=help&tid=" + tid,
538 "Popup Help",
539 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
540 }
541
542 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
543 * * @author Sundar Dorai-Raj
544 * * Email: sdoraira@vt.edu
545 * * This program is free software; you can redistribute it and/or
546 * * modify it under the terms of the GNU General Public License
547 * * as published by the Free Software Foundation; either version 2
548 * * of the License, or (at your option) any later version,
549 * * provided that any use properly credits the author.
550 * * This program is distributed in the hope that it will be useful,
551 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
552 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
553 * * GNU General Public License for more details at http://www.gnu.org * * */
554
555 var numbers=".0123456789";
556 function isNumeric(x) {
557 // is x a String or a character?
558 if(x.length>1) {
559 // remove negative sign
560 x=Math.abs(x)+"";
561 for(j=0;j<x.length;j++) {
562 // call isNumeric recursively for each character
563 number=isNumeric(x.substring(j,j+1));
564 if(!number) return number;
565 }
566 return number;
567 }
568 else {
569 // if x is number return true
570 if(numbers.indexOf(x)>=0) return true;
571 return false;
572 }
573 }
574
575
576 function hideOrShowFeeds(doc, hide) {
577
578 if (!doc.styleSheets) return;
579
580 var css_rules = doc.styleSheets[0].cssRules;
581
582 if (!css_rules || !css_rules.length) return;
583
584 for (i = 0; i < css_rules.length; i++) {
585 var rule = css_rules[i];
586
587 if (rule.selectorText == "ul.feedList li.feed") {
588 if (!hide) {
589 rule.style.display = "block";
590 } else {
591 rule.style.display = "none";
592 }
593 }
594
595 }
596
597 }
598
599 function selectTableRow(r, do_select) {
600 r.className = r.className.replace("Selected", "");
601
602 if (do_select) {
603 r.className = r.className + "Selected";
604 }
605 }
606
607 function selectTableRowById(elem_id, check_id, do_select) {
608
609 try {
610
611 var row = document.getElementById(elem_id);
612
613 if (row) {
614 selectTableRow(row, do_select);
615 }
616
617 var check = document.getElementById(check_id);
618
619 if (check) {
620 check.checked = do_select;
621 }
622 } catch (e) {
623 exception_error("selectTableRowById", e);
624 }
625 }
626
627 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
628 classcheck, reset_others) {
629
630 var content = document.getElementById(content_id);
631
632 if (!content) {
633 alert("[selectTableRows] Element " + content_id + " not found.");
634 return;
635 }
636
637 for (i = 0; i < content.rows.length; i++) {
638 if (!classcheck || content.rows[i].className.match(classcheck)) {
639
640 if (content.rows[i].id.match(prefix)) {
641 selectTableRow(content.rows[i], do_select);
642
643 var row_id = content.rows[i].id.replace(prefix, "");
644 var check = document.getElementById(check_prefix + row_id);
645
646 if (check) {
647 check.checked = do_select;
648 }
649 } else if (reset_others) {
650 selectTableRow(content.rows[i], false);
651
652 var row_id = content.rows[i].id.replace(prefix, "");
653 var check = document.getElementById(check_prefix + row_id);
654
655 if (check) {
656 check.checked = false;
657 }
658
659 }
660 } else if (reset_others) {
661 selectTableRow(content.rows[i], false);
662
663 var row_id = content.rows[i].id.replace(prefix, "");
664 var check = document.getElementById(check_prefix + row_id);
665
666 if (check) {
667 check.checked = false;
668 }
669
670 }
671 }
672 }
673
674 function getSelectedTableRowIds(content_id, prefix) {
675
676 var content = document.getElementById(content_id);
677
678 if (!content) {
679 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
680 return;
681 }
682
683 var sel_rows = new Array();
684
685 for (i = 0; i < content.rows.length; i++) {
686 if (content.rows[i].id.match(prefix) &&
687 content.rows[i].className.match("Selected")) {
688
689 var row_id = content.rows[i].id.replace(prefix + "-", "");
690 sel_rows.push(row_id);
691 }
692 }
693
694 return sel_rows;
695
696 }
697
698 function toggleSelectRowById(sender, id) {
699 var row = document.getElementById(id);
700
701 if (sender.checked) {
702 if (!row.className.match("Selected")) {
703 row.className = row.className + "Selected";
704 }
705 } else {
706 if (row.className.match("Selected")) {
707 row.className = row.className.replace("Selected", "");
708 }
709 }
710 }
711
712 function toggleSelectListRow(sender) {
713 var parent_row = sender.parentNode;
714
715 if (sender.checked) {
716 if (!parent_row.className.match("Selected")) {
717 parent_row.className = parent_row.className + "Selected";
718 }
719 } else {
720 if (parent_row.className.match("Selected")) {
721 parent_row.className = parent_row.className.replace("Selected", "");
722 }
723 }
724 }
725
726
727 function toggleSelectRow(sender) {
728 var parent_row = sender.parentNode.parentNode;
729
730 if (sender.checked) {
731 if (!parent_row.className.match("Selected")) {
732 parent_row.className = parent_row.className + "Selected";
733 }
734 } else {
735 if (parent_row.className.match("Selected")) {
736 parent_row.className = parent_row.className.replace("Selected", "");
737 }
738 }
739 }
740
741 function openExternalUrl(url) {
742 var w = window.open(url);
743 }
744
745 function getRelativeFeedId(list, id, direction, unread_only) {
746 if (!id) {
747 if (direction == "next") {
748 for (i = 0; i < list.childNodes.length; i++) {
749 var child = list.childNodes[i];
750 if (child.id && child.id == "feedCatHolder") {
751 if (child.lastChild) {
752 var cr = getRelativeFeedId(child.firstChild, id, direction);
753 if (cr) return cr;
754 }
755 } else if (child.id && child.id.match("FEEDR-")) {
756 return child.id.replace('FEEDR-', '');
757 }
758 }
759 }
760
761 // FIXME select last feed doesn't work when only unread feeds are visible
762
763 if (direction == "prev") {
764 for (i = list.childNodes.length-1; i >= 0; i--) {
765 var child = list.childNodes[i];
766 if (child.id == "feedCatHolder") {
767 if (child.firstChild) {
768 var cr = getRelativeFeedId(child.firstChild, id, direction);
769 if (cr) return cr;
770 }
771 } else if (child.id.match("FEEDR-")) {
772
773 if (getCookie("ttrss_vf_hreadf") == 1) {
774 if (child.className != "feed") {
775 alert(child.className);
776 return child.id.replace('FEEDR-', '');
777 }
778 } else {
779 return child.id.replace('FEEDR-', '');
780 }
781 }
782 }
783 }
784 } else {
785
786 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
787
788 if (getCookie("ttrss_vf_hreadf") == 1) {
789 unread_only = true;
790 }
791
792 if (direction == "next") {
793
794 var e = feed;
795
796 while (e) {
797
798 if (e.nextSibling) {
799
800 e = e.nextSibling;
801
802 } else if (e.parentNode.parentNode.nextSibling) {
803
804 var this_cat = e.parentNode.parentNode;
805
806 e = false;
807
808 if (this_cat && this_cat.nextSibling) {
809 while (!e && this_cat.nextSibling) {
810 this_cat = this_cat.nextSibling;
811 if (this_cat.id == "feedCatHolder") {
812 e = this_cat.firstChild.firstChild;
813 }
814 }
815 }
816
817 } else {
818 e = false;
819 }
820
821 if (e) {
822 if (!unread_only || (unread_only && e.className != "feed" &&
823 e.className != "error")) {
824 return e.id.replace("FEEDR-", "");
825 }
826 }
827 }
828
829 } else if (direction == "prev") {
830
831 var e = feed;
832
833 while (e) {
834
835 if (e.previousSibling) {
836
837 e = e.previousSibling;
838
839 } else if (e.parentNode.parentNode.previousSibling) {
840
841 var this_cat = e.parentNode.parentNode;
842
843 e = false;
844
845 if (this_cat && this_cat.previousSibling) {
846 while (!e && this_cat.previousSibling) {
847 this_cat = this_cat.previousSibling;
848 if (this_cat.id == "feedCatHolder") {
849 e = this_cat.firstChild.lastChild;
850 }
851 }
852 }
853
854 } else {
855 e = false;
856 }
857
858 if (e) {
859 if (!unread_only || (unread_only && e.className != "feed" &&
860 e.className != "error")) {
861 return e.id.replace("FEEDR-", "");
862 }
863 }
864 }
865 }
866 }
867 }
868
869 function showBlockElement(id) {
870 var elem = document.getElementById(id);
871
872 if (elem) {
873 elem.style.display = "block";
874 } else {
875 alert("[showBlockElement] can't find element with id " + id);
876 }
877 }
878
879 function hideParentElement(e) {
880 e.parentNode.style.display = "none";
881 }
882
883 function dropboxSelect(e, v) {
884 for (i = 0; i < e.length; i++) {
885 if (e[i].value == v) {
886 e.selectedIndex = i;
887 break;
888 }
889 }
890 }
891
892 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
893 // bugfixed just a little bit :-)
894 function getURLParam(strParamName){
895 var strReturn = "";
896 var strHref = window.location.href;
897
898 if (strHref.indexOf("#") == strHref.length-1) {
899 strHref = strHref.substring(0, strHref.length-1);
900 }
901
902 if ( strHref.indexOf("?") > -1 ){
903 var strQueryString = strHref.substr(strHref.indexOf("?"));
904 var aQueryString = strQueryString.split("&");
905 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
906 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
907 var aParam = aQueryString[iParam].split("=");
908 strReturn = aParam[1];
909 break;
910 }
911 }
912 }
913 return strReturn;
914 }
915
916 function leading_zero(p) {
917 var s = String(p);
918 if (s.length == 1) s = "0" + s;
919 return s;
920 }
921
922 function center_element(e) {
923
924 try {
925 var c_width = document.body.clientWidth;
926 var c_height = document.body.clientHeight;
927
928 var c_scroll = document.body.scrollTop;
929
930 var e_width = e.clientWidth;
931 var e_height = e.clientHeight;
932
933 var set_y = (c_height / 2) + c_scroll - (e_height / 2);
934 var set_x = (c_width / 2) - (e_width / 2);
935
936 e.style.top = set_y + "px";
937 e.style.left = set_x + "px";
938 } catch (e) {
939 exception_error("center_element", e);
940 }
941 }
942
943 function closeInfoBox() {
944 var box = document.getElementById('infoBox');
945 var shadow = document.getElementById('infoBoxShadow');
946
947 if (shadow) {
948 shadow.style.display = "none";
949 } else if (box) {
950 box.style.display = "none";
951 }
952
953 enableHotkeys();
954 }
955
956
957 function displayDlg(id, param) {
958
959 if (!xmlhttp_ready(xmlhttp)) {
960 printLockingError();
961 return
962 }
963
964 notify("");
965
966 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
967 param_escape(id) + "&param=" + param_escape(param), true);
968 xmlhttp.onreadystatechange=infobox_callback;
969 xmlhttp.send(null);
970
971 disableHotkeys();
972
973 }
974
975 function infobox_submit_callback() {
976 if (xmlhttp.readyState == 4) {
977 notify(xmlhttp.responseText);
978 closeInfoBox();
979
980 // called from prefs, reload tab
981 if (active_tab) {
982 selectTab(active_tab, false);
983 }
984 }
985 }
986
987 function infobox_callback() {
988 if (xmlhttp.readyState == 4) {
989 var box = document.getElementById('infoBox');
990 var shadow = document.getElementById('infoBoxShadow');
991 if (box) {
992 box.innerHTML=xmlhttp.responseText;
993 if (shadow) {
994 shadow.style.display = "block";
995 } else {
996 box.style.display = "block";
997 }
998 }
999 }
1000 }
1001
1002 function qaddFilter() {
1003
1004 if (!xmlhttp_ready(xmlhttp)) {
1005 printLockingError();
1006 return
1007 }
1008
1009 var regexp = document.getElementById("fadd_regexp");
1010 var match = document.getElementById("fadd_match");
1011 var feed = document.getElementById("fadd_feed");
1012 var action = document.getElementById("fadd_action");
1013
1014 if (regexp.value.length == 0) {
1015 alert("Missing filter expression.");
1016 } else {
1017 notify("Adding filter...");
1018
1019 var v_match = match[match.selectedIndex].text;
1020 var feed_id = feed[feed.selectedIndex].id;
1021 var action_id = action[action.selectedIndex].id;
1022
1023 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add&regexp=" +
1024 param_escape(regexp.value) + "&match=" + v_match +
1025 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
1026
1027 xmlhttp.onreadystatechange=infobox_submit_callback;
1028 xmlhttp.send(null);
1029
1030 regexp.value = "";
1031 }
1032
1033 }
1034
1035 function toggleSubmitNotEmpty(e, submit_id) {
1036 try {
1037 document.getElementById(submit_id).disabled = (e.value == "")
1038 } catch (e) {
1039 exception_error("toggleSubmitNotEmpty", e);
1040 }
1041 }