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