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