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