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