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