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