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