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