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