]> git.wh0rd.org - tt-rss.git/blame - functions.js
enable collapsing of virtual category
[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 }
8e9141ed
AD
689
690 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
691
1a6a9555 692 feedu.innerHTML = ctr;
023fe037 693
426d3c57
AD
694 if (error) {
695 feedr.className = feedr.className.replace("feed", "error");
696 } else if (id > 0) {
697 feedr.className = feedr.className.replace("error", "feed");
023fe037 698 }
1a6a9555
AD
699
700 if (ctr > 0) {
701 feedctr.className = "odd";
702 if (!feedr.className.match("Unread")) {
703 var is_selected = feedr.className.match("Selected");
704
705 feedr.className = feedr.className.replace("Selected", "");
706 feedr.className = feedr.className.replace("Unread", "");
707
708 feedr.className = feedr.className + "Unread";
709
710 if (is_selected) {
711 feedr.className = feedr.className + "Selected";
8e9141ed
AD
712 }
713
714 }
715
716 if (row_needs_hl) {
07a67863 717 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5"});
1a6a9555
AD
718 }
719 } else {
720 feedctr.className = "invisible";
721 feedr.className = feedr.className.replace("Unread", "");
722 }
723 }
724 }
9e397d0f 725
0feab655 726 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
7553dd8b 727
0feab655 728 var feeds_stored = number_of_feeds;
9e397d0f
AD
729
730 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
731
732 if (feeds_stored != feeds_found) {
0feab655 733 number_of_feeds = feeds_found;
7bf7e4d3
AD
734
735 if (feeds_stored != 0) {
9e397d0f 736 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 737 setTimeout('updateFeedList(false, false)', 50);
9e397d0f
AD
738 }
739 }
740
1a6a9555 741 } catch (e) {
83f043bb 742 exception_error("parse_counters", e);
1a6a9555
AD
743 }
744}
745
3ac2f3c7 746function parse_counters_reply(xmlhttp, scheduled_call) {
5854573a
AD
747
748 if (!xmlhttp.responseXML) {
42c32916 749 notify_error("Backend did not return valid XML", true);
5854573a
AD
750 return;
751 }
752
753 var reply = xmlhttp.responseXML.firstChild;
754
755 if (!reply) {
42c32916 756 notify_error("Backend did not return expected XML object", true);
5854573a
AD
757 updateTitle("");
758 return;
759 }
760
761 var error_code = false;
762 var error_msg = false;
763
764 if (reply.firstChild) {
765 error_code = reply.firstChild.getAttribute("error-code");
766 error_msg = reply.firstChild.getAttribute("error-msg");
767 }
768
769 if (!error_code) {
770 error_code = reply.getAttribute("error-code");
771 error_msg = reply.getAttribute("error-msg");
772 }
773
774 if (error_code && error_code != 0) {
775 debug("refetch_callback: got error code " + error_code);
776 return fatalError(error_code, error_msg);
777 }
778
779 var counters = reply.firstChild;
780
3ac2f3c7 781 parse_counters(counters, scheduled_call);
5854573a
AD
782
783 var runtime_info = counters.nextSibling;
784
785 parse_runtime_info(runtime_info);
786
787 if (getInitParam("feeds_sort_by_unread") == 1) {
788 resort_feedlist();
789 }
790
791 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
792
793}
794
4f3a84f4 795function all_counters_callback() {
090e250b 796 if (xmlhttp_rpc.readyState == 4) {
7719618b 797 try {
5854573a 798/* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
b00ed196 799 debug("[all_counters_callback] backend did not return valid XML");
7719618b
AD
800 return;
801 }
894ebcf5 802
6b4163cb 803 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
1cb7492d 804
7719618b 805 var reply = xmlhttp_rpc.responseXML.firstChild;
280ee9a3 806
f54f515f
AD
807 var counters = reply.firstChild;
808
809 parse_counters(counters);
1cb7492d
AD
810
811 var runtime = counters.nextSibling;
812
813 if (runtime) {
0feab655 814 parse_runtime_info(runtime);
1cb7492d 815 }
c9268ed5 816
cea51014 817 if (getInitParam("feeds_sort_by_unread") == 1) {
c9268ed5
AD
818 resort_feedlist();
819 }
293fa942 820
5854573a
AD
821 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
822
823 debug("in all_counters_callback");
824
825 parse_counters_reply(xmlhttp_rpc);
293fa942 826
7719618b
AD
827 } catch (e) {
828 exception_error("all_counters_callback", e);
090e250b
AD
829 }
830 }
831}
832
c9268ed5
AD
833function get_feed_entry_unread(doc, elem) {
834
835 var id = elem.id.replace("FEEDR-", "");
836
837 if (id <= 0) {
838 return -1;
839 }
840
841 try {
842 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
843 } catch (e) {
844 return -1;
845 }
846}
847
848function resort_category(doc, node) {
849 debug("resort_category: " + node);
850
851 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
852 for (i = 0; i < node.childNodes.length; i++) {
853 if (node.childNodes[i].nodeName != "LI") { continue; }
854
855 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
856 continue;
857 }
858
859 for (j = i+1; j < node.childNodes.length; j++) {
860 if (node.childNodes[j].nodeName != "LI") { continue; }
861
862 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
863 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
864
865 if (cur_val > tmp_val) {
866 tempnode_i = node.childNodes[i].cloneNode(true);
867 tempnode_j = node.childNodes[j].cloneNode(true);
868 node.replaceChild(tempnode_i, node.childNodes[j]);
869 node.replaceChild(tempnode_j, node.childNodes[i]);
870 }
871 }
872
873 }
874 }
875
876}
877
878function resort_feedlist() {
879 debug("resort_feedlist");
880
0feab655 881 var fd = document;
c9268ed5
AD
882
883 if (fd.getElementById("feedCatHolder")) {
884
885 var feeds = fd.getElementById("feedList");
886 var child = feeds.firstChild;
887
888 while (child) {
889
890 if (child.id == "feedCatHolder") {
891 resort_category(fd, child.firstChild);
892 }
893
894 child = child.nextSibling;
895 }
896
897 } else {
898 resort_category(fd, fd.getElementById("feedList"));
899 }
900}
901
4f3a84f4 902function update_all_counters(feed) {
090e250b 903 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 904 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
905
906 if (feed > 0) {
907 query = query + "&aid=" + feed;
908 }
909
cf4d339c
AD
910 if (tagsAreDisplayed()) {
911 query = query + "&omode=lt";
3fd7138f
AD
912 } else {
913 query = query + "&omode=flc";
cf4d339c
AD
914 }
915
916 debug("update_all_counters QUERY: " + query);
917
86173d9a
AD
918 var date = new Date();
919 var timestamp = Math.round(date.getTime() / 1000);
920 query = query + "&ts=" + timestamp
921
090e250b 922 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 923 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
924 xmlhttp_rpc.send(null);
925 }
926}
7dc66a61
AD
927
928function popupHelp(tid) {
929 var w = window.open("backend.php?op=help&tid=" + tid,
930 "Popup Help",
931 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
932}
b6644d29
AD
933
934/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
935 * * @author Sundar Dorai-Raj
936 * * Email: sdoraira@vt.edu
937 * * This program is free software; you can redistribute it and/or
938 * * modify it under the terms of the GNU General Public License
939 * * as published by the Free Software Foundation; either version 2
940 * * of the License, or (at your option) any later version,
941 * * provided that any use properly credits the author.
942 * * This program is distributed in the hope that it will be useful,
943 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
944 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
945 * * GNU General Public License for more details at http://www.gnu.org * * */
946
947 var numbers=".0123456789";
948 function isNumeric(x) {
949 // is x a String or a character?
950 if(x.length>1) {
951 // remove negative sign
952 x=Math.abs(x)+"";
953 for(j=0;j<x.length;j++) {
954 // call isNumeric recursively for each character
955 number=isNumeric(x.substring(j,j+1));
956 if(!number) return number;
957 }
958 return number;
959 }
960 else {
961 // if x is number return true
962 if(numbers.indexOf(x)>=0) return true;
963 return false;
964 }
965 }
966
3745788e
AD
967
968function hideOrShowFeeds(doc, hide) {
969
7553dd8b
AD
970 debug("hideOrShowFeeds: " + doc + ", " + hide);
971
0feab655 972 var fd = document;
293fa942
AD
973
974 var list = fd.getElementById("feedList");
975
976 if (fd.getElementById("feedCatHolder")) {
977
978 var feeds = fd.getElementById("feedList");
979 var child = feeds.firstChild;
980
981 while (child) {
982
983 if (child.id == "feedCatHolder") {
984 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
985 }
986
987 child = child.nextSibling;
988 }
989
990 } else {
991 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
992 }
993}
994
995function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
996
997// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 998
293fa942 999 var cat_unread = 0;
3745788e 1000
4724a093
AD
1001 if (!node) {
1002 debug("hideOrShowFeeds: passed node is null, aborting");
1003 return;
1004 }
1005
293fa942
AD
1006 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
1007 for (i = 0; i < node.childNodes.length; i++) {
1008 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 1009
b31c2311 1010 if (node.childNodes[i].style != undefined) {
293fa942 1011
947c6186 1012 var has_unread = (node.childNodes[i].className != "feed" &&
7a64852c 1013 node.childNodes[i].className != "label" &&
947c6186 1014 node.childNodes[i].className != "tag");
b31c2311
AD
1015
1016 // debug(node.childNodes[i].id + " --> " + has_unread);
1017
1018 if (hide && !has_unread) {
225ec0d4 1019 //node.childNodes[i].style.display = "none";
7a27bf83 1020 Effect.Fade(node.childNodes[i], {duration : 0.3});
b31c2311
AD
1021 }
1022
1023 if (!hide) {
1024 node.childNodes[i].style.display = "list-item";
225ec0d4 1025 //Effect.Appear(node.childNodes[i], {duration : 0.3});
b31c2311
AD
1026 }
1027
1028 if (has_unread) {
7553dd8b 1029 node.childNodes[i].style.display = "list-item";
b31c2311 1030 cat_unread++;
225ec0d4
AD
1031 //Effect.Appear(node.childNodes[i], {duration : 0.3});
1032 //Effect.Highlight(node.childNodes[i]);
b31c2311 1033 }
293fa942 1034 }
3745788e 1035 }
b31c2311 1036 }
3745788e 1037
293fa942 1038 if (cat_unread == 0) {
b31c2311
AD
1039 if (cat_node.style == undefined) {
1040 debug("ERROR: supplied cat_node " + cat_node +
1041 " has no styles. WTF?");
1042 return;
1043 }
293fa942 1044 if (hide) {
38c142d9
AD
1045 //cat_node.style.display = "none";
1046 Effect.Fade(cat_node, {duration : 0.3});
293fa942
AD
1047 } else {
1048 cat_node.style.display = "list-item";
1049 }
7553dd8b 1050 } else {
0ac2faea
AD
1051 try {
1052 cat_node.style.display = "list-item";
1053 } catch (e) {
1054 debug(e);
1055 }
293fa942 1056 }
3745788e 1057
293fa942 1058// debug("unread for category: " + cat_unread);
3745788e
AD
1059}
1060
35f3c923
AD
1061function selectTableRow(r, do_select) {
1062 r.className = r.className.replace("Selected", "");
1063
1064 if (do_select) {
1065 r.className = r.className + "Selected";
1066 }
1067}
1068
6c12c809
AD
1069function selectTableRowById(elem_id, check_id, do_select) {
1070
1071 try {
1072
1073 var row = document.getElementById(elem_id);
1074
1075 if (row) {
1076 selectTableRow(row, do_select);
1077 }
1078
1079 var check = document.getElementById(check_id);
1080
1081 if (check) {
1082 check.checked = do_select;
1083 }
1084 } catch (e) {
1085 exception_error("selectTableRowById", e);
1086 }
1087}
1088
1572afe5 1089function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 1090 classcheck, reset_others) {
3745788e 1091
35f3c923
AD
1092 var content = document.getElementById(content_id);
1093
1094 if (!content) {
1095 alert("[selectTableRows] Element " + content_id + " not found.");
1096 return;
1097 }
1098
1099 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
1100 if (!classcheck || content.rows[i].className.match(classcheck)) {
1101
1102 if (content.rows[i].id.match(prefix)) {
1103 selectTableRow(content.rows[i], do_select);
649e0af9
AD
1104
1105 var row_id = content.rows[i].id.replace(prefix, "");
1106 var check = document.getElementById(check_prefix + row_id);
3055bc41 1107
649e0af9
AD
1108 if (check) {
1109 check.checked = do_select;
1110 }
1111 } else if (reset_others) {
1112 selectTableRow(content.rows[i], false);
7d8d10c6
AD
1113
1114 var row_id = content.rows[i].id.replace(prefix, "");
1115 var check = document.getElementById(check_prefix + row_id);
1116
1117 if (check) {
1118 check.checked = false;
1119 }
1120
1572afe5 1121 }
649e0af9
AD
1122 } else if (reset_others) {
1123 selectTableRow(content.rows[i], false);
7d8d10c6
AD
1124
1125 var row_id = content.rows[i].id.replace(prefix, "");
1126 var check = document.getElementById(check_prefix + row_id);
1127
1128 if (check) {
1129 check.checked = false;
1130 }
1131
3055bc41 1132 }
35f3c923 1133 }
295f9b42 1134}
91ff844a
AD
1135
1136function getSelectedTableRowIds(content_id, prefix) {
1137
1138 var content = document.getElementById(content_id);
1139
1140 if (!content) {
1141 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
1142 return;
1143 }
1144
1145 var sel_rows = new Array();
1146
1147 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
1148 if (content.rows[i].id.match(prefix) &&
1149 content.rows[i].className.match("Selected")) {
1150
91ff844a
AD
1151 var row_id = content.rows[i].id.replace(prefix + "-", "");
1152 sel_rows.push(row_id);
1153 }
1154 }
1155
1156 return sel_rows;
1157
1158}
1159
386cbf27
AD
1160function toggleSelectRowById(sender, id) {
1161 var row = document.getElementById(id);
1162
1163 if (sender.checked) {
1164 if (!row.className.match("Selected")) {
1165 row.className = row.className + "Selected";
1166 }
1167 } else {
1168 if (row.className.match("Selected")) {
1169 row.className = row.className.replace("Selected", "");
1170 }
1171 }
1172}
1173
b92e6209
AD
1174function toggleSelectListRow(sender) {
1175 var parent_row = sender.parentNode;
1176
1177 if (sender.checked) {
1178 if (!parent_row.className.match("Selected")) {
1179 parent_row.className = parent_row.className + "Selected";
1180 }
1181 } else {
1182 if (parent_row.className.match("Selected")) {
1183 parent_row.className = parent_row.className.replace("Selected", "");
1184 }
1185 }
1186}
1187
67343d9f
AD
1188function tSR(sender) {
1189 return toggleSelectRow(sender);
1190}
386cbf27 1191
1572afe5
AD
1192function toggleSelectRow(sender) {
1193 var parent_row = sender.parentNode.parentNode;
1194
1195 if (sender.checked) {
1196 if (!parent_row.className.match("Selected")) {
1197 parent_row.className = parent_row.className + "Selected";
1198 }
1199 } else {
1200 if (parent_row.className.match("Selected")) {
1201 parent_row.className = parent_row.className.replace("Selected", "");
1202 }
1203 }
1204}
1205
3866b046
AD
1206function openExternalUrl(url) {
1207 var w = window.open(url);
1208}
1572afe5 1209
1da76274 1210function getRelativeFeedId(list, id, direction, unread_only) {
731b05f4
AD
1211 var rows = list.getElementsByTagName("LI");
1212 var feeds = new Array();
1213
1214 for (var i = 0; i < rows.length; i++) {
1215 if (rows[i].id.match("FEEDR-")) {
1216
8809f484 1217 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
731b05f4
AD
1218
1219 if (!unread_only ||
1220 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1221 feeds.push(rows[i].id.replace("FEEDR-", ""));
1222 }
1223 }
1224 }
1225 }
1226
7b433d8c 1227 if (!id) {
731b05f4
AD
1228 if (direction == "next") {
1229 return feeds.shift();
1230 } else {
1231 return feeds.pop();
1232 }
1233 } else {
1234 if (direction == "next") {
1235 var idx = feeds.indexOf(id);
1236 if (idx != -1 && idx < feeds.length) {
1237 return feeds[idx+1];
07a67863
AD
1238 } else {
1239 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1240 }
1241 } else {
1242 var idx = feeds.indexOf(id);
1243 if (idx > 0) {
1244 return feeds[idx-1];
07a67863
AD
1245 } else {
1246 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1247 }
1248 }
1249
1250 }
1251
1252/* if (!id) {
7b433d8c
AD
1253 if (direction == "next") {
1254 for (i = 0; i < list.childNodes.length; i++) {
1255 var child = list.childNodes[i];
1da76274 1256 if (child.id && child.id == "feedCatHolder") {
c3f348c2 1257 if (child.lastChild) {
d05514a4 1258 var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only);
7b433d8c
AD
1259 if (cr) return cr;
1260 }
1da76274 1261 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
1262 return child.id.replace('FEEDR-', '');
1263 }
1264 }
1265 }
1266
1267 // FIXME select last feed doesn't work when only unread feeds are visible
1268
1269 if (direction == "prev") {
1270 for (i = list.childNodes.length-1; i >= 0; i--) {
1271 var child = list.childNodes[i];
731b05f4 1272 if (child.id == "feedCatHolder" && Element.visible(child)) {
7b433d8c
AD
1273 if (child.firstChild) {
1274 var cr = getRelativeFeedId(child.firstChild, id, direction);
1275 if (cr) return cr;
1276 }
1277 } else if (child.id.match("FEEDR-")) {
1278
e8bd0da9 1279 if (getInitParam("hide_read_feeds") == 1) {
7b433d8c 1280 if (child.className != "feed") {
4e38b6c3 1281// alert(child.className);
7b433d8c
AD
1282 return child.id.replace('FEEDR-', '');
1283 }
1284 } else {
1285 return child.id.replace('FEEDR-', '');
1286 }
1287 }
1288 }
1289 }
1290 } else {
1291
d05514a4 1292 var feed = list.ownerDocument.getElementById("FEEDR-" + id);
7b433d8c 1293
e8bd0da9 1294 if (getInitParam("hide_read_feeds") == 1) {
1da76274
AD
1295 unread_only = true;
1296 }
1297
7b433d8c
AD
1298 if (direction == "next") {
1299
1da76274 1300 var e = feed;
7b433d8c 1301
1da76274 1302 while (e) {
7b433d8c 1303
1da76274
AD
1304 if (e.nextSibling) {
1305
1306 e = e.nextSibling;
1307
1308 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 1309
1da76274 1310 var this_cat = e.parentNode.parentNode;
7b433d8c 1311
1da76274 1312 e = false;
7b433d8c 1313
1da76274
AD
1314 if (this_cat && this_cat.nextSibling) {
1315 while (!e && this_cat.nextSibling) {
1316 this_cat = this_cat.nextSibling;
1317 if (this_cat.id == "feedCatHolder") {
1318 e = this_cat.firstChild.firstChild;
7b433d8c
AD
1319 }
1320 }
7b433d8c 1321 }
1da76274
AD
1322
1323 } else {
1324 e = false;
1325 }
1326
1327 if (e) {
d05514a4 1328 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1329 e.className.match("feed"))) {
731b05f4
AD
1330 if (e.parentNode.parentNode &&
1331 Element.visible(e.parentNode.parentNode)) {
4e38b6c3
AD
1332 return e.id.replace("FEEDR-", "");
1333 }
1da76274
AD
1334 }
1335 }
7b433d8c 1336 }
1da76274 1337
7b433d8c
AD
1338 } else if (direction == "prev") {
1339
1da76274 1340 var e = feed;
7b433d8c 1341
1da76274 1342 while (e) {
7b433d8c 1343
1da76274
AD
1344 if (e.previousSibling) {
1345
1346 e = e.previousSibling;
1347
1348 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 1349
1da76274 1350 var this_cat = e.parentNode.parentNode;
7b433d8c 1351
1da76274
AD
1352 e = false;
1353
1354 if (this_cat && this_cat.previousSibling) {
1355 while (!e && this_cat.previousSibling) {
1356 this_cat = this_cat.previousSibling;
1357 if (this_cat.id == "feedCatHolder") {
1358 e = this_cat.firstChild.lastChild;
7b433d8c
AD
1359 }
1360 }
7b433d8c 1361 }
1da76274
AD
1362
1363 } else {
1364 e = false;
1365 }
1366
1367 if (e) {
e686782e 1368 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1369 e.className.match("feed"))) {
731b05f4
AD
1370 if (e.parentNode.parentNode &&
1371 Element.visible(e.parentNode.parentNode)) {
4e38b6c3
AD
1372 return e.id.replace("FEEDR-", "");
1373 }
1da76274
AD
1374 }
1375 }
1376 }
7b433d8c 1377 }
731b05f4 1378 } */
7b433d8c 1379}
36aab70f 1380
f27de515 1381function showBlockElement(id, h_id) {
36aab70f
AD
1382 var elem = document.getElementById(id);
1383
1384 if (elem) {
1385 elem.style.display = "block";
f27de515
AD
1386
1387 if (h_id) {
1388 elem = document.getElementById(h_id);
1389 if (elem) {
1390 elem.style.display = "none";
1391 }
1392 }
36aab70f
AD
1393 } else {
1394 alert("[showBlockElement] can't find element with id " + id);
1395 }
1396}
1397
b9073cd9
AD
1398function appearBlockElement_afh(effect) {
1399
1400}
1401
1402function checkboxToggleElement(elem, id) {
1403 if (elem.checked) {
b1085d24 1404 Effect.SlideDown(id, {duration : 0.5});
b9073cd9 1405 } else {
b1085d24 1406 Effect.SlideUp(id, {duration : 0.5});
b9073cd9
AD
1407 }
1408}
1409
1410function appearBlockElement(id, h_id) {
1411
1412 try {
1413 Effect.Fade(h_id);
1414 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1415 } catch (e) {
1416 exception_error("appearBlockElement", e);
1417 }
1418
1419}
1420
1421
a9b0bfd5
AD
1422function hideParentElement(e) {
1423 e.parentNode.style.display = "none";
1424}
1b0809ae
AD
1425
1426function dropboxSelect(e, v) {
1427 for (i = 0; i < e.length; i++) {
1428 if (e[i].value == v) {
1429 e.selectedIndex = i;
1430 break;
1431 }
1432 }
1433}
0ee1d1a0
AD
1434
1435// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1436// bugfixed just a little bit :-)
1437function getURLParam(strParamName){
1438 var strReturn = "";
1439 var strHref = window.location.href;
1440
1441 if (strHref.indexOf("#") == strHref.length-1) {
1442 strHref = strHref.substring(0, strHref.length-1);
1443 }
1444
1445 if ( strHref.indexOf("?") > -1 ){
1446 var strQueryString = strHref.substr(strHref.indexOf("?"));
1447 var aQueryString = strQueryString.split("&");
1448 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1449 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1450 var aParam = aQueryString[iParam].split("=");
1451 strReturn = aParam[1];
1452 break;
1453 }
1454 }
1455 }
1456 return strReturn;
1457}
1458
cf1bc085
AD
1459function leading_zero(p) {
1460 var s = String(p);
1461 if (s.length == 1) s = "0" + s;
1462 return s;
1463}
c38c2b69 1464
86b682ce 1465function closeInfoBox(cleanup) {
5ede560f 1466
465ff90b 1467 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
5ede560f
AD
1468 var overlay = document.getElementById("dialog_overlay");
1469 if (overlay) {
1470 overlay.style.display = "none";
1471 }
1472 }
1473
e5d758e3
AD
1474 var box = document.getElementById('infoBox');
1475 var shadow = document.getElementById('infoBoxShadow');
1476
1477 if (shadow) {
1478 shadow.style.display = "none";
1479 } else if (box) {
1480 box.style.display = "none";
1481 }
1482
86b682ce
AD
1483 if (cleanup) box.innerHTML = "&nbsp;";
1484
e5d758e3 1485 enableHotkeys();
c14b5566 1486
90ac84df 1487 return false;
e5d758e3
AD
1488}
1489
1490
7b5c6012
AD
1491function displayDlg(id, param) {
1492
1493 if (!xmlhttp_ready(xmlhttp)) {
1494 printLockingError();
1495 return
1496 }
1497
35a03bdd 1498 notify_progress("Loading, please wait...", true);
7b5c6012
AD
1499
1500 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1501 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 1502 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
1503 xmlhttp.send(null);
1504
1505 disableHotkeys();
2371c520 1506
90ac84df 1507 return false;
7b5c6012
AD
1508}
1509
e5d758e3 1510function infobox_submit_callback() {
7b5c6012 1511 if (xmlhttp.readyState == 4) {
e5d758e3 1512 closeInfoBox();
7b5c6012 1513
6e6504bc
AD
1514 try {
1515 // called from prefs, reload tab
1516 if (active_tab) {
1517 selectTab(active_tab, false);
1518 }
1519 } catch (e) { }
79f3553b 1520
5e6f933a
AD
1521 if (xmlhttp.responseText) {
1522 notify_info(xmlhttp.responseText);
1523 }
79f3553b 1524
7b5c6012
AD
1525 }
1526}
1527
e5d758e3 1528function infobox_callback() {
7b5c6012 1529 if (xmlhttp.readyState == 4) {
5ede560f 1530
aa8716da 1531 try {
5ede560f 1532
aa8716da
AD
1533 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1534 var overlay = document.getElementById("dialog_overlay");
1535 if (overlay) {
1536 overlay.style.display = "block";
1537 }
442d77f1 1538 }
aa8716da
AD
1539
1540 var box = document.getElementById('infoBox');
1541 var shadow = document.getElementById('infoBoxShadow');
1542 if (box) {
1dc47c41 1543
68a89c30
AD
1544 if (!is_safari()) {
1545 new Draggable(shadow);
1546 }
1dc47c41 1547
aa8716da
AD
1548 box.innerHTML=xmlhttp.responseText;
1549 if (shadow) {
1550 shadow.style.display = "block";
1551 } else {
1552 box.style.display = "block";
1553 }
1554 }
05fcdf52
AD
1555
1556 /* FIXME this needs to be moved out somewhere */
1557
1558 if (document.getElementById("tags_choices")) {
1559 new Ajax.Autocompleter('tags_str', 'tags_choices',
1560 "backend.php?op=rpc&subop=completeTags",
1561 { tokens: ',', paramName: "search" });
1562 }
1563
aa8716da
AD
1564 notify("");
1565 } catch (e) {
1566 exception_error("infobox_callback", e);
442d77f1 1567 }
442d77f1
AD
1568 }
1569}
1570
1571function helpbox_callback() {
1572 if (xmlhttp.readyState == 4) {
1573 var box = document.getElementById('helpBox');
1574 var shadow = document.getElementById('helpBoxShadow');
1575 if (box) {
1576 box.innerHTML=xmlhttp.responseText;
e5d758e3
AD
1577 if (shadow) {
1578 shadow.style.display = "block";
1579 } else {
1580 box.style.display = "block";
1581 }
1582 }
9c483746 1583 notify("");
e5d758e3 1584 }
7b5c6012
AD
1585}
1586
5e6f933a 1587function addFilter() {
7b5c6012
AD
1588
1589 if (!xmlhttp_ready(xmlhttp)) {
1590 printLockingError();
1591 return
1592 }
1593
c91c2249
AD
1594 var form = document.forms['filter_add_form'];
1595 var reg_exp = form.reg_exp.value;
1596
1597 if (reg_exp == "") {
89cb787e 1598 alert(__("Can't add filter: nothing to match on."));
c91c2249
AD
1599 return false;
1600 }
1601
79f3553b 1602 var query = Form.serialize("filter_add_form");
7b5c6012 1603
79f3553b
AD
1604 xmlhttp.open("GET", "backend.php?" + query, true);
1605 xmlhttp.onreadystatechange=infobox_submit_callback;
1606 xmlhttp.send(null);
7b5c6012 1607
c14b5566 1608 return true;
7b5c6012
AD
1609}
1610
2371c520
AD
1611function toggleSubmitNotEmpty(e, submit_id) {
1612 try {
1613 document.getElementById(submit_id).disabled = (e.value == "")
1614 } catch (e) {
1615 exception_error("toggleSubmitNotEmpty", e);
1616 }
1617}
1d7bf5a0 1618
605f7d46 1619function isValidURL(s) {
0d32b41e 1620 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
605f7d46 1621}
07eb9178 1622
5e6f933a 1623function qaddFeed() {
07eb9178
AD
1624
1625 if (!xmlhttp_ready(xmlhttp)) {
1626 printLockingError();
1627 return
1628 }
1629
c91c2249
AD
1630 var form = document.forms['feed_add_form'];
1631 var feed_url = form.feed_url.value;
1632
1633 if (feed_url == "") {
89cb787e 1634 alert(__("Can't subscribe: no feed URL given."));
c91c2249
AD
1635 return false;
1636 }
1637
1ba6daf7 1638 notify_progress(__("Subscribing to feed..."), true);
07eb9178
AD
1639
1640 closeInfoBox();
1641
0feab655 1642 var feeds_doc = document;
07eb9178 1643
80e4dc34 1644// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1645
1646 var query = Form.serialize("feed_add_form");
1647
f27de515
AD
1648 debug("subscribe q: " + query);
1649
bce7001f 1650/* xmlhttp.open("GET", "backend.php?" + query, true);
07eb9178 1651 xmlhttp.onreadystatechange=dlg_frefresh_callback;
bce7001f
AD
1652 xmlhttp.send(null); */
1653
1654 xmlhttp.open("POST", "backend.php", true);
1655 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1656 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1657 xmlhttp.send(query);
7bc4f251
AD
1658
1659 return false;
07eb9178
AD
1660}
1661
6e6504bc 1662function filterCR(e, f)
86b682ce
AD
1663{
1664 var key;
1665
1666 if(window.event)
1667 key = window.event.keyCode; //IE
1668 else
1669 key = e.which; //firefox
1670
6e6504bc
AD
1671 if (key == 13) {
1672 if (typeof f != 'undefined') {
1673 f();
1674 return false;
1675 } else {
1676 return false;
1677 }
1678 } else {
1679 return true;
1680 }
86b682ce
AD
1681}
1682
ac378ad4 1683function getMainContext() {
6b4163cb 1684 return this.window;
ac378ad4
AD
1685}
1686
33d13e72 1687function getFeedsContext() {
6b4163cb 1688 return this.window;
33d13e72
AD
1689}
1690
0bd411db 1691function getContentContext() {
6b4163cb 1692 return this.window;
0bd411db
AD
1693}
1694
ee1f45f4 1695function getHeadlinesContext() {
6b4163cb 1696 return this.window;
ee1f45f4
AD
1697}
1698
e8614131
AD
1699var debug_last_class = "even";
1700
ac378ad4 1701function debug(msg) {
ac378ad4 1702
0feab655
AD
1703 if (debug_last_class == "even") {
1704 debug_last_class = "odd";
e8614131 1705 } else {
0feab655 1706 debug_last_class = "even";
e8614131
AD
1707 }
1708
0feab655 1709 var c = document.getElementById('debug_output');
ac378ad4 1710 if (c && c.style.display == "block") {
c9268ed5 1711 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1712 c.removeChild(c.lastChild);
1713 }
1714
1715 var d = new Date();
1716 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1717 ":" + leading_zero(d.getSeconds());
0feab655 1718 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1719 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1720 }
1721}
1722
33d13e72 1723function getInitParam(key) {
40496720 1724 return init_params[key];
33d13e72 1725}
3ac2b520 1726
be0801a1 1727function storeInitParam(key, value) {
40496720 1728 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
5158ced9 1729 init_params[key] = value;
be0801a1
AD
1730}
1731
a7565293
AD
1732function fatalError(code, message) {
1733 try {
a7565293 1734
b4c27af7 1735 if (code == 6) {
8e849206 1736 window.location.href = "tt-rss.php";
b4c27af7
AD
1737 } else if (code == 5) {
1738 window.location.href = "update.php";
1739 } else {
4724a093
AD
1740 var fe = document.getElementById("fatal_error");
1741 var fc = document.getElementById("fatal_error_msg");
1742
42c32916
AD
1743 if (message == "") message = "Unknown error";
1744
1745 fc.innerHTML = "<img src='images/sign_excl.png'> " + message + " (Code " + code + ")";
4724a093
AD
1746
1747 fe.style.display = "block";
4724a093 1748 }
a7565293
AD
1749
1750 } catch (e) {
1751 exception_error("fatalError", e);
1752 }
1753}
1754
234e467c 1755function getFeedName(id, is_cat) {
64a2875d 1756 var d = getFeedsContext().document;
234e467c
AD
1757
1758 var e;
1759
1760 if (is_cat) {
1761 e = d.getElementById("FCATN-" + id);
1762 } else {
1763 e = d.getElementById("FEEDN-" + id);
1764 }
64a2875d
AD
1765 if (e) {
1766 return e.innerHTML.stripTags();
1767 } else {
1768 return null;
1769 }
1770}
0bd411db
AD
1771
1772function viewContentUrl(url) {
1773 getContentContext().location = url;
1774}
350f0ad1
AD
1775
1776function filterDlgCheckAction(sender) {
1777
1778 try {
1779
1780 var action = sender[sender.selectedIndex].value;
1781
1782 var form = document.forms["filter_add_form"];
1783
1784 if (!form) {
1785 form = document.forms["filter_edit_form"];
1786 }
1787
1788 if (!form) {
1789 debug("filterDlgCheckAction: can't find form!");
1790 return;
1791 }
1792
1793 var action_param = form.action_param;
1794
1795 if (!action_param) {
1796 debug("filterDlgCheckAction: can't find action param!");
1797 return;
1798 }
1799
1800 // if selected action supports parameters, enable params field
1801 if (action == 4) {
1802 action_param.disabled = false;
1803 } else {
1804 action_param.disabled = true;
1805 }
1806
1807 } catch (e) {
1808 exception_error(e, "filterDlgCheckAction");
1809 }
1810
1811}
ef16ae37
AD
1812
1813function explainError(code) {
1814 return displayDlg("explainError", code);
1815}
01a87dff
AD
1816
1817function logoutUser() {
1818 try {
1819 if (xmlhttp_ready(xmlhttp_rpc)) {
64f6db90 1820
42c32916 1821 notify_progress("Logging out, please wait...", true);
64f6db90 1822
01a87dff
AD
1823 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=logout", true);
1824 xmlhttp_rpc.onreadystatechange=logout_callback;
1825 xmlhttp_rpc.send(null);
1826 } else {
1827 printLockingError();
1828 }
1829 } catch (e) {
1830 exception_error("logoutUser", e);
1831 }
1832}
e097e8be
AD
1833
1834// this only searches loaded headlines list, not in CDM
1835function getRelativePostIds(id) {
1836
1837 debug("getRelativePostIds: " + id);
1838
1839 var ids = new Array();
1840 var container = document.getElementById("headlinesList");
1841
1842 if (container) {
1843 var rows = container.rows;
1844
1845 for (var i = 0; i < rows.length; i++) {
1846 var r_id = rows[i].id.replace("RROW-", "");
1847
1848 if (r_id == id) {
1849 if (i > 0) ids.push(rows[i-1].id.replace("RROW-", ""));
1850 if (i > 1) ids.push(rows[i-2].id.replace("RROW-", ""));
1851 if (i > 2) ids.push(rows[i-3].id.replace("RROW-", ""));
1852
fed4387d
AD
1853 if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", ""));
1854 if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", ""));
1855 if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", ""));
e097e8be
AD
1856
1857 return ids;
1858 }
1859 }
1860 }
1861
1862 return false;
1863}
298f3f78
AD
1864
1865function openArticleInNewWindow(id) {
1866 try {
1867
1868 if (!xmlhttp_ready(xmlhttp_rpc)) {
1869 printLockingError();
1870 return
1871 }
1872
1873 debug("openArticleInNewWindow: " + id);
1874
1875 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1876
1877 debug(query);
1878
1879 xmlhttp_rpc.open("GET", query, true);
1880 xmlhttp_rpc.onreadystatechange=open_article_callback;
1881 xmlhttp_rpc.send(null);
1882
1883 } catch (e) {
1884 exception_error("openArticleInNewWindow", e);
1885 }
1886}
e4914b62 1887