]> git.wh0rd.org - tt-rss.git/blame - functions.js
new option: ENABLE_GZIP_OUTPUT
[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
AD
477 var title = elems[l].getAttribute("title");
478
1a6a9555 479 if (id == "global-unread") {
0feab655
AD
480 global_unread = ctr;
481 updateTitle();
1a6a9555
AD
482 continue;
483 }
7bf7e4d3
AD
484
485 if (id == "subscribed-feeds") {
486 feeds_found = ctr;
487 continue;
488 }
1a6a9555
AD
489
490 if (t == "category") {
0feab655 491 var catctr = document.getElementById("FCATCTR-" + id);
1a6a9555 492 if (catctr) {
67dabe1a
AD
493 catctr.innerHTML = "(" + ctr + ")";
494 if (ctr > 0) {
495 catctr.className = "catCtrHasUnread";
496 } else {
497 catctr.className = "catCtrNoUnread";
498 }
1a6a9555
AD
499 }
500 continue;
501 }
502
0feab655
AD
503 var feedctr = document.getElementById("FEEDCTR-" + id);
504 var feedu = document.getElementById("FEEDU-" + id);
505 var feedr = document.getElementById("FEEDR-" + id);
506 var feed_img = document.getElementById("FIMG-" + id);
507 var feedlink = document.getElementById("FEEDL-" + id);
508 var feedupd = document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
509
510 if (updated && feedlink) {
511 if (error) {
512 feedlink.title = "Error: " + error + " (" + updated + ")";
513 } else {
514 feedlink.title = "Updated: " + updated;
515 }
516 }
023fe037 517
78d5212c
AD
518 if (updated && feedupd) {
519 if (error) {
520 feedupd.innerHTML = updated + " (Error)";
521 } else {
522 feedupd.innerHTML = updated;
523 }
524 }
525
527c3bf0 526 if (has_img && feed_img && !is_msie()) {
f780548a
AD
527 if (!feed_img.src.match(id + ".ico")) {
528 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
529 }
527c3bf0
AD
530 }
531
4ffa126e
AD
532 if (feedlink && title) {
533 feedlink.innerHTML = title;
534 }
535
1a6a9555 536 if (feedctr && feedu && feedr) {
e8ef3b97
AD
537
538 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
5b064721 539 viewCurrentFeed();
e8ef3b97 540 }
8e9141ed
AD
541
542 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
543
1a6a9555 544 feedu.innerHTML = ctr;
023fe037 545
426d3c57
AD
546 if (error) {
547 feedr.className = feedr.className.replace("feed", "error");
548 } else if (id > 0) {
549 feedr.className = feedr.className.replace("error", "feed");
023fe037 550 }
1a6a9555
AD
551
552 if (ctr > 0) {
553 feedctr.className = "odd";
554 if (!feedr.className.match("Unread")) {
555 var is_selected = feedr.className.match("Selected");
556
557 feedr.className = feedr.className.replace("Selected", "");
558 feedr.className = feedr.className.replace("Unread", "");
559
560 feedr.className = feedr.className + "Unread";
561
562 if (is_selected) {
563 feedr.className = feedr.className + "Selected";
8e9141ed
AD
564 }
565
566 }
567
568 if (row_needs_hl) {
1341ea0d
AD
569 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
570 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
1a6a9555
AD
571 }
572 } else {
573 feedctr.className = "invisible";
574 feedr.className = feedr.className.replace("Unread", "");
575 }
576 }
577 }
9e397d0f 578
0feab655 579 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
7553dd8b 580
0feab655 581 var feeds_stored = number_of_feeds;
9e397d0f
AD
582
583 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
584
585 if (feeds_stored != feeds_found) {
0feab655 586 number_of_feeds = feeds_found;
7bf7e4d3 587
2fe69e22 588 if (feeds_stored != 0 && feeds_found != 0) {
9e397d0f 589 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 590 setTimeout('updateFeedList(false, false)', 50);
9e397d0f
AD
591 }
592 }
593
1a6a9555 594 } catch (e) {
83f043bb 595 exception_error("parse_counters", e);
1a6a9555
AD
596 }
597}
598
288487e4 599function parse_counters_reply(transport, scheduled_call) {
5854573a 600
288487e4 601 if (!transport.responseXML) {
42c32916 602 notify_error("Backend did not return valid XML", true);
5854573a
AD
603 return;
604 }
605
288487e4 606 var reply = transport.responseXML.firstChild;
5854573a
AD
607
608 if (!reply) {
42c32916 609 notify_error("Backend did not return expected XML object", true);
5854573a
AD
610 updateTitle("");
611 return;
612 }
613
614 var error_code = false;
615 var error_msg = false;
616
617 if (reply.firstChild) {
618 error_code = reply.firstChild.getAttribute("error-code");
619 error_msg = reply.firstChild.getAttribute("error-msg");
620 }
621
622 if (!error_code) {
623 error_code = reply.getAttribute("error-code");
624 error_msg = reply.getAttribute("error-msg");
625 }
626
627 if (error_code && error_code != 0) {
628 debug("refetch_callback: got error code " + error_code);
629 return fatalError(error_code, error_msg);
630 }
631
36e05046 632 var counters = reply.getElementsByTagName("counters")[0];
5854573a 633
3ac2f3c7 634 parse_counters(counters, scheduled_call);
5854573a 635
36e05046 636 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
5854573a
AD
637
638 parse_runtime_info(runtime_info);
639
640 if (getInitParam("feeds_sort_by_unread") == 1) {
641 resort_feedlist();
642 }
643
644 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
645
646}
647
1341ea0d
AD
648function all_counters_callback2(transport) {
649 try {
650 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
651 parse_counters_reply(transport);
652 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
653
654 } catch (e) {
655 exception_error("all_counters_callback2", e);
656 }
657}
658
8e9dd206
AD
659function get_feed_unread(id) {
660 try {
661 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);
662 } catch (e) {
663 exception_error("get_feed_unread", e, true);
664 return -1;
665 }
666}
667
c9268ed5
AD
668function get_feed_entry_unread(doc, elem) {
669
670 var id = elem.id.replace("FEEDR-", "");
671
672 if (id <= 0) {
673 return -1;
674 }
675
676 try {
677 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
678 } catch (e) {
679 return -1;
680 }
681}
682
683function resort_category(doc, node) {
684 debug("resort_category: " + node);
685
686 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
687 for (i = 0; i < node.childNodes.length; i++) {
688 if (node.childNodes[i].nodeName != "LI") { continue; }
689
690 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
691 continue;
692 }
693
694 for (j = i+1; j < node.childNodes.length; j++) {
695 if (node.childNodes[j].nodeName != "LI") { continue; }
696
697 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
698 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
699
700 if (cur_val > tmp_val) {
701 tempnode_i = node.childNodes[i].cloneNode(true);
702 tempnode_j = node.childNodes[j].cloneNode(true);
703 node.replaceChild(tempnode_i, node.childNodes[j]);
704 node.replaceChild(tempnode_j, node.childNodes[i]);
705 }
706 }
707
708 }
709 }
710
711}
712
713function resort_feedlist() {
714 debug("resort_feedlist");
715
0feab655 716 var fd = document;
c9268ed5
AD
717
718 if (fd.getElementById("feedCatHolder")) {
719
720 var feeds = fd.getElementById("feedList");
721 var child = feeds.firstChild;
722
723 while (child) {
724
725 if (child.id == "feedCatHolder") {
726 resort_category(fd, child.firstChild);
727 }
728
729 child = child.nextSibling;
730 }
731
732 } else {
733 resort_category(fd, fd.getElementById("feedList"));
734 }
735}
736
b6644d29
AD
737/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
738 * * @author Sundar Dorai-Raj
739 * * Email: sdoraira@vt.edu
740 * * This program is free software; you can redistribute it and/or
741 * * modify it under the terms of the GNU General Public License
742 * * as published by the Free Software Foundation; either version 2
743 * * of the License, or (at your option) any later version,
744 * * provided that any use properly credits the author.
745 * * This program is distributed in the hope that it will be useful,
746 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
747 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
748 * * GNU General Public License for more details at http://www.gnu.org * * */
749
750 var numbers=".0123456789";
751 function isNumeric(x) {
752 // is x a String or a character?
753 if(x.length>1) {
754 // remove negative sign
755 x=Math.abs(x)+"";
756 for(j=0;j<x.length;j++) {
757 // call isNumeric recursively for each character
758 number=isNumeric(x.substring(j,j+1));
759 if(!number) return number;
760 }
761 return number;
762 }
763 else {
764 // if x is number return true
765 if(numbers.indexOf(x)>=0) return true;
766 return false;
767 }
768 }
769
3745788e
AD
770
771function hideOrShowFeeds(doc, hide) {
772
7553dd8b
AD
773 debug("hideOrShowFeeds: " + doc + ", " + hide);
774
0feab655 775 var fd = document;
293fa942
AD
776
777 var list = fd.getElementById("feedList");
778
779 if (fd.getElementById("feedCatHolder")) {
780
781 var feeds = fd.getElementById("feedList");
782 var child = feeds.firstChild;
783
784 while (child) {
785
786 if (child.id == "feedCatHolder") {
787 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
788 }
789
790 child = child.nextSibling;
791 }
792
793 } else {
794 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
795 }
796}
797
798function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
799
800// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 801
293fa942 802 var cat_unread = 0;
3745788e 803
4724a093
AD
804 if (!node) {
805 debug("hideOrShowFeeds: passed node is null, aborting");
806 return;
807 }
808
1a9b5b84 809// debug("cat: " + node.id);
2c2b019b 810
293fa942
AD
811 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
812 for (i = 0; i < node.childNodes.length; i++) {
813 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 814
b31c2311 815 if (node.childNodes[i].style != undefined) {
293fa942 816
947c6186 817 var has_unread = (node.childNodes[i].className != "feed" &&
7a64852c 818 node.childNodes[i].className != "label" &&
22f3e356
AD
819 !(!getInitParam("hide_read_shows_special") &&
820 node.childNodes[i].className == "virt") &&
88b47be7 821 node.childNodes[i].className != "error" &&
947c6186 822 node.childNodes[i].className != "tag");
b31c2311 823
2c2b019b 824// debug(node.childNodes[i].id + " --> " + has_unread);
b31c2311
AD
825
826 if (hide && !has_unread) {
225ec0d4 827 //node.childNodes[i].style.display = "none";
f03ce70e
AD
828 var id = node.childNodes[i].id;
829 Effect.Fade(node.childNodes[i], {duration : 0.3,
830 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
b31c2311
AD
831 }
832
833 if (!hide) {
834 node.childNodes[i].style.display = "list-item";
225ec0d4 835 //Effect.Appear(node.childNodes[i], {duration : 0.3});
b31c2311
AD
836 }
837
838 if (has_unread) {
7553dd8b 839 node.childNodes[i].style.display = "list-item";
b31c2311 840 cat_unread++;
225ec0d4
AD
841 //Effect.Appear(node.childNodes[i], {duration : 0.3});
842 //Effect.Highlight(node.childNodes[i]);
b31c2311 843 }
293fa942 844 }
3745788e 845 }
b31c2311 846 }
3745788e 847
1a9b5b84 848// debug("end cat: " + node.id + " unread " + cat_unread);
2c2b019b 849
293fa942 850 if (cat_unread == 0) {
b31c2311
AD
851 if (cat_node.style == undefined) {
852 debug("ERROR: supplied cat_node " + cat_node +
853 " has no styles. WTF?");
854 return;
855 }
293fa942 856 if (hide) {
38c142d9 857 //cat_node.style.display = "none";
f03ce70e 858 Effect.Fade(cat_node, {duration : 0.3,
70ee3028 859 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
293fa942
AD
860 } else {
861 cat_node.style.display = "list-item";
862 }
7553dd8b 863 } else {
0ac2faea
AD
864 try {
865 cat_node.style.display = "list-item";
866 } catch (e) {
867 debug(e);
868 }
293fa942 869 }
3745788e 870
293fa942 871// debug("unread for category: " + cat_unread);
3745788e
AD
872}
873
35f3c923
AD
874function selectTableRow(r, do_select) {
875 r.className = r.className.replace("Selected", "");
876
877 if (do_select) {
878 r.className = r.className + "Selected";
879 }
880}
881
6c12c809
AD
882function selectTableRowById(elem_id, check_id, do_select) {
883
884 try {
885
886 var row = document.getElementById(elem_id);
887
888 if (row) {
889 selectTableRow(row, do_select);
890 }
891
892 var check = document.getElementById(check_id);
893
894 if (check) {
895 check.checked = do_select;
896 }
897 } catch (e) {
898 exception_error("selectTableRowById", e);
899 }
900}
901
1572afe5 902function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 903 classcheck, reset_others) {
3745788e 904
35f3c923
AD
905 var content = document.getElementById(content_id);
906
907 if (!content) {
908 alert("[selectTableRows] Element " + content_id + " not found.");
909 return;
910 }
911
912 for (i = 0; i < content.rows.length; i++) {
7a822893
AD
913 if (Element.visible(content.rows[i])) {
914 if (!classcheck || content.rows[i].className.match(classcheck)) {
915
916 if (content.rows[i].id.match(prefix)) {
917 selectTableRow(content.rows[i], do_select);
918
919 var row_id = content.rows[i].id.replace(prefix, "");
920 var check = document.getElementById(check_prefix + row_id);
921
922 if (check) {
923 check.checked = do_select;
924 }
925 } else if (reset_others) {
926 selectTableRow(content.rows[i], false);
927
928 var row_id = content.rows[i].id.replace(prefix, "");
929 var check = document.getElementById(check_prefix + row_id);
930
931 if (check) {
932 check.checked = false;
933 }
1572afe5 934
649e0af9
AD
935 }
936 } else if (reset_others) {
937 selectTableRow(content.rows[i], false);
7a822893 938
7d8d10c6
AD
939 var row_id = content.rows[i].id.replace(prefix, "");
940 var check = document.getElementById(check_prefix + row_id);
7a822893 941
7d8d10c6
AD
942 if (check) {
943 check.checked = false;
944 }
7a822893 945
7d8d10c6 946 }
3055bc41 947 }
35f3c923 948 }
295f9b42 949}
91ff844a
AD
950
951function getSelectedTableRowIds(content_id, prefix) {
952
953 var content = document.getElementById(content_id);
954
955 if (!content) {
956 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
957 return;
958 }
959
960 var sel_rows = new Array();
961
962 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
963 if (content.rows[i].id.match(prefix) &&
964 content.rows[i].className.match("Selected")) {
965
91ff844a
AD
966 var row_id = content.rows[i].id.replace(prefix + "-", "");
967 sel_rows.push(row_id);
968 }
969 }
970
971 return sel_rows;
972
973}
974
386cbf27
AD
975function toggleSelectRowById(sender, id) {
976 var row = document.getElementById(id);
977
978 if (sender.checked) {
979 if (!row.className.match("Selected")) {
980 row.className = row.className + "Selected";
981 }
982 } else {
983 if (row.className.match("Selected")) {
984 row.className = row.className.replace("Selected", "");
985 }
986 }
987}
988
b92e6209
AD
989function toggleSelectListRow(sender) {
990 var parent_row = sender.parentNode;
991
992 if (sender.checked) {
993 if (!parent_row.className.match("Selected")) {
994 parent_row.className = parent_row.className + "Selected";
995 }
996 } else {
997 if (parent_row.className.match("Selected")) {
998 parent_row.className = parent_row.className.replace("Selected", "");
999 }
1000 }
1001}
1002
67343d9f
AD
1003function tSR(sender) {
1004 return toggleSelectRow(sender);
1005}
386cbf27 1006
1572afe5
AD
1007function toggleSelectRow(sender) {
1008 var parent_row = sender.parentNode.parentNode;
1009
1010 if (sender.checked) {
1011 if (!parent_row.className.match("Selected")) {
1012 parent_row.className = parent_row.className + "Selected";
1013 }
1014 } else {
1015 if (parent_row.className.match("Selected")) {
1016 parent_row.className = parent_row.className.replace("Selected", "");
1017 }
1018 }
1019}
1020
1da76274 1021function getRelativeFeedId(list, id, direction, unread_only) {
731b05f4
AD
1022 var rows = list.getElementsByTagName("LI");
1023 var feeds = new Array();
1024
1025 for (var i = 0; i < rows.length; i++) {
1026 if (rows[i].id.match("FEEDR-")) {
1027
8809f484 1028 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
731b05f4
AD
1029
1030 if (!unread_only ||
1031 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1032 feeds.push(rows[i].id.replace("FEEDR-", ""));
1033 }
1034 }
1035 }
1036 }
1037
7b433d8c 1038 if (!id) {
731b05f4
AD
1039 if (direction == "next") {
1040 return feeds.shift();
1041 } else {
1042 return feeds.pop();
1043 }
1044 } else {
1045 if (direction == "next") {
1046 var idx = feeds.indexOf(id);
1047 if (idx != -1 && idx < feeds.length) {
1048 return feeds[idx+1];
07a67863
AD
1049 } else {
1050 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1051 }
1052 } else {
1053 var idx = feeds.indexOf(id);
1054 if (idx > 0) {
1055 return feeds[idx-1];
07a67863
AD
1056 } else {
1057 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1058 }
1059 }
1060
1061 }
7b433d8c 1062}
36aab70f 1063
f27de515 1064function showBlockElement(id, h_id) {
36aab70f
AD
1065 var elem = document.getElementById(id);
1066
1067 if (elem) {
1068 elem.style.display = "block";
f27de515
AD
1069
1070 if (h_id) {
1071 elem = document.getElementById(h_id);
1072 if (elem) {
1073 elem.style.display = "none";
1074 }
1075 }
36aab70f
AD
1076 } else {
1077 alert("[showBlockElement] can't find element with id " + id);
1078 }
1079}
1080
b9073cd9
AD
1081function appearBlockElement_afh(effect) {
1082
1083}
1084
1085function checkboxToggleElement(elem, id) {
1086 if (elem.checked) {
b1085d24 1087 Effect.SlideDown(id, {duration : 0.5});
b9073cd9 1088 } else {
b1085d24 1089 Effect.SlideUp(id, {duration : 0.5});
b9073cd9
AD
1090 }
1091}
1092
1093function appearBlockElement(id, h_id) {
1094
1095 try {
a04c8e8d
AD
1096 if (h_id) {
1097 Effect.Fade(h_id);
1098 }
b9073cd9
AD
1099 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1100 } catch (e) {
1101 exception_error("appearBlockElement", e);
1102 }
1103
1104}
1105
a9b0bfd5
AD
1106function hideParentElement(e) {
1107 e.parentNode.style.display = "none";
1108}
1b0809ae
AD
1109
1110function dropboxSelect(e, v) {
1111 for (i = 0; i < e.length; i++) {
1112 if (e[i].value == v) {
1113 e.selectedIndex = i;
1114 break;
1115 }
1116 }
1117}
0ee1d1a0
AD
1118
1119// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1120// bugfixed just a little bit :-)
1121function getURLParam(strParamName){
1122 var strReturn = "";
1123 var strHref = window.location.href;
1124
1125 if (strHref.indexOf("#") == strHref.length-1) {
1126 strHref = strHref.substring(0, strHref.length-1);
1127 }
1128
1129 if ( strHref.indexOf("?") > -1 ){
1130 var strQueryString = strHref.substr(strHref.indexOf("?"));
1131 var aQueryString = strQueryString.split("&");
1132 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1133 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1134 var aParam = aQueryString[iParam].split("=");
1135 strReturn = aParam[1];
1136 break;
1137 }
1138 }
1139 }
1140 return strReturn;
1141}
1142
cf1bc085
AD
1143function leading_zero(p) {
1144 var s = String(p);
1145 if (s.length == 1) s = "0" + s;
1146 return s;
1147}
c38c2b69 1148
86b682ce 1149function closeInfoBox(cleanup) {
5ede560f 1150
465ff90b 1151 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
5ede560f
AD
1152 var overlay = document.getElementById("dialog_overlay");
1153 if (overlay) {
1154 overlay.style.display = "none";
1155 }
1156 }
1157
e5d758e3
AD
1158 var box = document.getElementById('infoBox');
1159 var shadow = document.getElementById('infoBoxShadow');
1160
1161 if (shadow) {
1162 shadow.style.display = "none";
1163 } else if (box) {
1164 box.style.display = "none";
1165 }
1166
86b682ce
AD
1167 if (cleanup) box.innerHTML = "&nbsp;";
1168
e5d758e3 1169 enableHotkeys();
c14b5566 1170
90ac84df 1171 return false;
e5d758e3
AD
1172}
1173
1174
7b5c6012
AD
1175function displayDlg(id, param) {
1176
35a03bdd 1177 notify_progress("Loading, please wait...", true);
7b5c6012 1178
7b5c6012 1179 disableHotkeys();
2371c520 1180
288487e4
AD
1181 var query = "backend.php?op=dlg&id=" +
1182 param_escape(id) + "&param=" + param_escape(param);
1183
1184 new Ajax.Request(query, {
1185 onComplete: function (transport) {
1186 infobox_callback2(transport);
1187 } });
1188
90ac84df 1189 return false;
7b5c6012
AD
1190}
1191
288487e4
AD
1192function infobox_submit_callback2(transport) {
1193 closeInfoBox();
79f3553b 1194
288487e4
AD
1195 try {
1196 // called from prefs, reload tab
438f2ce9 1197 if (typeof active_tab != 'undefined' && active_tab) {
288487e4 1198 selectTab(active_tab, false);
5e6f933a 1199 }
288487e4 1200 } catch (e) { }
79f3553b 1201
288487e4
AD
1202 if (transport.responseText) {
1203 notify_info(transport.responseText);
1204 }
7b5c6012
AD
1205}
1206
d395a942
AD
1207function infobox_callback2(transport) {
1208 try {
5ede560f 1209
d395a942 1210 debug("infobox_callback2");
5ede560f 1211
d395a942
AD
1212 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1213 var overlay = document.getElementById("dialog_overlay");
1214 if (overlay) {
1215 overlay.style.display = "block";
442d77f1 1216 }
d395a942
AD
1217 }
1218
1219 var box = document.getElementById('infoBox');
1220 var shadow = document.getElementById('infoBoxShadow');
1221 if (box) {
1dc47c41 1222
d395a942
AD
1223 box.innerHTML=transport.responseText;
1224 if (shadow) {
1225 shadow.style.display = "block";
1226 } else {
1227 box.style.display = "block";
aa8716da 1228 }
d395a942 1229 }
05fcdf52 1230
d395a942 1231 /* FIXME this needs to be moved out somewhere */
05fcdf52 1232
d395a942
AD
1233 if (document.getElementById("tags_choices")) {
1234 new Ajax.Autocompleter('tags_str', 'tags_choices',
1235 "backend.php?op=rpc&subop=completeTags",
1236 { tokens: ',', paramName: "search" });
442d77f1 1237 }
d395a942 1238
6068d33b
AD
1239 disableHotkeys();
1240
d395a942
AD
1241 notify("");
1242 } catch (e) {
1243 exception_error("infobox_callback2", e);
442d77f1
AD
1244 }
1245}
1246
18ab3d7a 1247function createFilter() {
7b5c6012 1248
438f2ce9 1249 try {
6068d33b 1250
438f2ce9
AD
1251 var form = document.forms['filter_add_form'];
1252 var reg_exp = form.reg_exp.value;
1253
1254 if (reg_exp == "") {
1255 alert(__("Can't add filter: nothing to match on."));
1256 return false;
1257 }
288487e4 1258
438f2ce9
AD
1259 var query = Form.serialize("filter_add_form");
1260
1261 // we can be called from some other tab in Prefs
1262 if (typeof active_tab != 'undefined' && active_tab) {
1263 active_tab = "filterConfig";
1264 }
1265
1266 new Ajax.Request("backend.php?" + query, {
1267 onComplete: function (transport) {
1268 infobox_submit_callback2(transport);
1269 } });
1270
1271 return true;
1272
1273 } catch (e) {
1274 exception_error("createFilter", e);
1275 }
7b5c6012
AD
1276}
1277
2371c520
AD
1278function toggleSubmitNotEmpty(e, submit_id) {
1279 try {
1280 document.getElementById(submit_id).disabled = (e.value == "")
1281 } catch (e) {
1282 exception_error("toggleSubmitNotEmpty", e);
1283 }
1284}
1d7bf5a0 1285
605f7d46 1286function isValidURL(s) {
0d32b41e 1287 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
605f7d46 1288}
07eb9178 1289
18ab3d7a 1290function subscribeToFeed() {
07eb9178 1291
c91c2249
AD
1292 var form = document.forms['feed_add_form'];
1293 var feed_url = form.feed_url.value;
1294
1295 if (feed_url == "") {
89cb787e 1296 alert(__("Can't subscribe: no feed URL given."));
c91c2249
AD
1297 return false;
1298 }
1299
1ba6daf7 1300 notify_progress(__("Subscribing to feed..."), true);
07eb9178
AD
1301
1302 closeInfoBox();
1303
0feab655 1304 var feeds_doc = document;
07eb9178 1305
80e4dc34 1306// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1307
1308 var query = Form.serialize("feed_add_form");
1309
f27de515
AD
1310 debug("subscribe q: " + query);
1311
288487e4
AD
1312 new Ajax.Request("backend.php", {
1313 parameters: query,
1314 onComplete: function(transport) {
1315 dlg_frefresh_callback(transport);
1316 } });
7bc4f251
AD
1317
1318 return false;
07eb9178
AD
1319}
1320
6e6504bc 1321function filterCR(e, f)
86b682ce
AD
1322{
1323 var key;
1324
1325 if(window.event)
1326 key = window.event.keyCode; //IE
1327 else
1328 key = e.which; //firefox
1329
6e6504bc
AD
1330 if (key == 13) {
1331 if (typeof f != 'undefined') {
1332 f();
1333 return false;
1334 } else {
1335 return false;
1336 }
1337 } else {
1338 return true;
1339 }
86b682ce
AD
1340}
1341
ac378ad4 1342function getMainContext() {
6b4163cb 1343 return this.window;
ac378ad4
AD
1344}
1345
33d13e72 1346function getFeedsContext() {
6b4163cb 1347 return this.window;
33d13e72
AD
1348}
1349
0bd411db 1350function getContentContext() {
6b4163cb 1351 return this.window;
0bd411db
AD
1352}
1353
ee1f45f4 1354function getHeadlinesContext() {
6b4163cb 1355 return this.window;
ee1f45f4
AD
1356}
1357
e8614131
AD
1358var debug_last_class = "even";
1359
ac378ad4 1360function debug(msg) {
ac378ad4 1361
0feab655
AD
1362 if (debug_last_class == "even") {
1363 debug_last_class = "odd";
e8614131 1364 } else {
0feab655 1365 debug_last_class = "even";
e8614131
AD
1366 }
1367
0feab655 1368 var c = document.getElementById('debug_output');
8836613c 1369 if (c && Element.visible(c)) {
c9268ed5 1370 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1371 c.removeChild(c.lastChild);
1372 }
1373
1374 var d = new Date();
1375 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1376 ":" + leading_zero(d.getSeconds());
0feab655 1377 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1378 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1379 }
1380}
1381
33d13e72 1382function getInitParam(key) {
40496720 1383 return init_params[key];
33d13e72 1384}
3ac2b520 1385
be0801a1 1386function storeInitParam(key, value) {
40496720 1387 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
5158ced9 1388 init_params[key] = value;
be0801a1
AD
1389}
1390
a7565293
AD
1391function fatalError(code, message) {
1392 try {
a7565293 1393
b4c27af7 1394 if (code == 6) {
8e849206 1395 window.location.href = "tt-rss.php";
b4c27af7
AD
1396 } else if (code == 5) {
1397 window.location.href = "update.php";
1398 } else {
4724a093
AD
1399 var fe = document.getElementById("fatal_error");
1400 var fc = document.getElementById("fatal_error_msg");
1401
42c32916
AD
1402 if (message == "") message = "Unknown error";
1403
a0a63217 1404 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
4724a093
AD
1405
1406 fe.style.display = "block";
4724a093 1407 }
a7565293
AD
1408
1409 } catch (e) {
1410 exception_error("fatalError", e);
1411 }
1412}
1413
234e467c 1414function getFeedName(id, is_cat) {
64a2875d 1415 var d = getFeedsContext().document;
234e467c
AD
1416
1417 var e;
1418
1419 if (is_cat) {
1420 e = d.getElementById("FCATN-" + id);
1421 } else {
1422 e = d.getElementById("FEEDN-" + id);
1423 }
64a2875d
AD
1424 if (e) {
1425 return e.innerHTML.stripTags();
1426 } else {
1427 return null;
1428 }
1429}
0bd411db
AD
1430
1431function viewContentUrl(url) {
1432 getContentContext().location = url;
1433}
350f0ad1
AD
1434
1435function filterDlgCheckAction(sender) {
1436
1437 try {
1438
1439 var action = sender[sender.selectedIndex].value;
1440
1441 var form = document.forms["filter_add_form"];
1442
1443 if (!form) {
1444 form = document.forms["filter_edit_form"];
1445 }
1446
1447 if (!form) {
1448 debug("filterDlgCheckAction: can't find form!");
1449 return;
1450 }
1451
1452 var action_param = form.action_param;
1453
1454 if (!action_param) {
1455 debug("filterDlgCheckAction: can't find action param!");
1456 return;
1457 }
1458
1459 // if selected action supports parameters, enable params field
48ddbb33 1460 if (action == 4 || action == 6) {
350f0ad1
AD
1461 action_param.disabled = false;
1462 } else {
1463 action_param.disabled = true;
1464 }
1465
1466 } catch (e) {
438f2ce9 1467 exception_error("filterDlgCheckAction", e);
350f0ad1
AD
1468 }
1469
1470}
ef16ae37
AD
1471
1472function explainError(code) {
1473 return displayDlg("explainError", code);
1474}
01a87dff 1475
e097e8be 1476// this only searches loaded headlines list, not in CDM
aa0fa9df 1477function getRelativePostIds(id, limit) {
e097e8be 1478
aa0fa9df
AD
1479 if (!limit) limit = 3;
1480
1481 debug("getRelativePostIds: " + id + " limit=" + limit);
e097e8be
AD
1482
1483 var ids = new Array();
1484 var container = document.getElementById("headlinesList");
1485
1486 if (container) {
1487 var rows = container.rows;
1488
1489 for (var i = 0; i < rows.length; i++) {
1490 var r_id = rows[i].id.replace("RROW-", "");
1491
1492 if (r_id == id) {
aa0fa9df
AD
1493 for (var k = 1; k <= limit; k++) {
1494 var nid = false;
1495
1496 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1497 if (nid) ids.push(nid);
1498
1499 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1500 if (nid) ids.push(nid);
1501 }
e097e8be
AD
1502
1503 return ids;
1504 }
1505 }
1506 }
1507
1508 return false;
1509}
298f3f78
AD
1510
1511function openArticleInNewWindow(id) {
1512 try {
298f3f78
AD
1513 debug("openArticleInNewWindow: " + id);
1514
1515 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
04e91733
AD
1516 var wname = "ttrss_article_" + id;
1517
1518 debug(query + " " + wname);
1519
1520 var w = window.open("", wname);
298f3f78 1521
04e91733 1522 if (!w) notify_error("Failed to open window for the article");
298f3f78 1523
d395a942
AD
1524 new Ajax.Request(query, {
1525 onComplete: function(transport) {
1526 open_article_callback(transport);
1527 } });
1528
298f3f78
AD
1529
1530 } catch (e) {
1531 exception_error("openArticleInNewWindow", e);
1532 }
1533}
e4914b62 1534
537625c6
AD
1535/* http://textsnippets.com/posts/show/835 */
1536
1537Position.GetWindowSize = function(w) {
1538 w = w ? w : window;
1539 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1540 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1541 return [width, height]
1542}
1543
1544/* http://textsnippets.com/posts/show/836 */
1545
1546Position.Center = function(element, parent) {
1547 var w, h, pw, ph;
1548 var d = Element.getDimensions(element);
1549 w = d.width;
1550 h = d.height;
1551 Position.prepare();
1552 if (!parent) {
1553 var ws = Position.GetWindowSize();
1554 pw = ws[0];
1555 ph = ws[1];
1556 } else {
1557 pw = parent.offsetWidth;
1558 ph = parent.offsetHeight;
1559 }
1560 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1561 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1562}
1563
768858f1 1564
288487e4
AD
1565function labeltest_callback(transport) {
1566 try {
1567 var container = document.getElementById('label_test_result');
1568
1569 container.innerHTML = transport.responseText;
768858f1
AD
1570 if (!Element.visible(container)) {
1571 Effect.SlideDown(container, { duration : 0.5 });
1572 }
288487e4 1573
6f151277 1574 notify("");
288487e4
AD
1575 } catch (e) {
1576 exception_error("labeltest_callback", e);
6f151277
AD
1577 }
1578}
1579
1580function labelTest() {
1581
288487e4
AD
1582 try {
1583 var container = document.getElementById('label_test_result');
1584
1585 var form = document.forms['label_edit_form'];
1586
1587 var sql_exp = form.sql_exp.value;
1588 var description = form.description.value;
1589
1590 notify_progress("Loading, please wait...");
1591
1592 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1593 param_escape(sql_exp) + "&descr=" + param_escape(description);
1594
1595 new Ajax.Request(query, {
1596 onComplete: function (transport) {
1597 labeltest_callback(transport);
1598 } });
1599
1600 return false;
6f151277 1601
288487e4
AD
1602 } catch (e) {
1603 exception_error("labelTest", e);
1604 }
6f151277
AD
1605}
1606
c32cd48a
AD
1607function isCdmMode() {
1608 return !document.getElementById("headlinesList");
1609}
1610
1611function getSelectedArticleIds2() {
1612 var rows = new Array();
1613 var cdm_mode = isCdmMode();
1614
1615 if (cdm_mode) {
1616 rows = cdmGetSelectedArticles();
1617 } else {
1618 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1619 }
1620
1621 var ids = new Array();
1622
1623 for (var i = 0; i < rows.length; i++) {
1624 var chk = document.getElementById("RCHK-" + rows[i]);
1625 if (chk && chk.checked) {
1626 ids.push(rows[i]);
1627 }
1628 }
1629
1630 return ids;
1631}
c4a36709 1632
f6d40ed2 1633function displayHelpInfobox(topic_id) {
c4a36709 1634
f6d40ed2
AD
1635 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1636
1637 var w = window.open(url, "ttrss_help",
1638 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1639
1640 return false;
1641}
e635d56a 1642
477402d8 1643function focus_element(id) {
61992f57 1644 try {
477402d8
AD
1645 var e = document.getElementById(id);
1646 if (e) e.focus();
61992f57 1647 } catch (e) {
438f2ce9 1648 exception_error("focus_element", e);
61992f57 1649 }
477402d8 1650 return false;
61992f57 1651}
e635d56a 1652
99509451 1653function loading_set_progress(p) {
730dbf19 1654 try {
fca95d5f
AD
1655 if (p < last_progress_point || !Element.visible("overlay")) return;
1656
1657 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
99509451 1658
730dbf19 1659 var o = document.getElementById("l_progress_i");
99509451 1660
673c9946
AD
1661// o.style.width = (p * 2) + "px";
1662
99509451
AD
1663 new Effect.Scale(o, p, {
1664 scaleY : false,
1665 scaleFrom : last_progress_point,
1666 scaleMode: { originalWidth : 200 },
673c9946 1667 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
99509451
AD
1668
1669 last_progress_point = p;
730dbf19
AD
1670
1671 } catch (e) {
1672 exception_error("loading_set_progress", e);
1673 }
1674}
08827aaf
AD
1675
1676function remove_splash() {
1677 if (Element.visible("overlay")) {
1678 debug("about to remove splash, OMG!");
1679 Element.hide("overlay");
1680 debug("removed splash!");
1681 }
1682}