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