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