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