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