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