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