]> git.wh0rd.org - tt-rss.git/blame - functions.js
misc code cleanups
[tt-rss.git] / functions.js
CommitLineData
760966c1 1var hotkeys_enabled = true;
a7565293 2var xmlhttp_rpc = Ajax.getTransport();
730dbf19 3var notify_silent = false;
99509451 4var last_progress_point = 0;
61992f57 5
b07b61da
AD
6/* add method to remove element from array */
7
8Array.prototype.remove = function(s) {
9 for (var i=0; i < this.length; i++) {
10 if (s == this[i]) this.splice(i, 1);
11 }
12}
13
7c620da8 14function is_opera() {
ee8768db 15 return window.opera;
583c58b8
AD
16}
17
55160955 18function exception_error(location, e, silent) {
83f043bb
AD
19 var msg;
20
21 if (e.fileName) {
22 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
23
24 msg = "Exception: " + e.name + ", " + e.message +
25 "\nFunction: " + location + "()" +
26 "\nLocation: " + base_fname + ":" + e.lineNumber;
f74cfded
AD
27
28 } else if (e.description) {
29 msg = "Exception: " + e.description + "\nFunction: " + location + "()";
83f043bb
AD
30 } else {
31 msg = "Exception: " + e + "\nFunction: " + location + "()";
32 }
33
ee1f45f4
AD
34 debug("<b>EXCEPTION: " + msg + "</b>");
35
55160955
AD
36 if (!silent) {
37 alert(msg);
38 }
7719618b
AD
39}
40
760966c1
AD
41function disableHotkeys() {
42 hotkeys_enabled = false;
43}
44
45function enableHotkeys() {
46 hotkeys_enabled = true;
47}
48
c0e5a40e
AD
49function xmlhttp_ready(obj) {
50 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
51}
52
d395a942
AD
53function open_article_callback(transport) {
54 try {
298f3f78 55
d395a942 56 if (transport.responseXML) {
06925d9e 57
d395a942
AD
58 var link = transport.responseXML.getElementsByTagName("link")[0];
59 var id = transport.responseXML.getElementsByTagName("id")[0];
298f3f78 60
06925d9e
AD
61 debug("open_article_callback, received link: " + link);
62
04e91733 63 if (link && id) {
06925d9e 64
04e91733
AD
65 var wname = "ttrss_article_" + id.firstChild.nodeValue;
66
67 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
68
69 var w = window.open(link.firstChild.nodeValue, wname);
4298481d
AD
70
71 if (!w) { notify_error("Failed to load article in new window"); }
e2ccbfab 72
d395a942
AD
73 if (id) {
74 id = id.firstChild.nodeValue;
75 if (!document.getElementById("headlinesList")) {
76 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
e2ccbfab 77 }
298f3f78 78 }
06925d9e
AD
79 } else {
80 notify_error("Can't open article: received invalid article link");
298f3f78 81 }
06925d9e
AD
82 } else {
83 notify_error("Can't open article: received invalid XML");
01a87dff 84 }
01a87dff 85
d395a942
AD
86 } catch (e) {
87 exception_error("open_article_callback", e);
9cfc649a
AD
88 }
89}
90
7726fa02
AD
91function param_escape(arg) {
92 if (typeof encodeURIComponent != 'undefined')
93 return encodeURIComponent(arg);
94 else
95 return escape(arg);
96}
97
98function param_unescape(arg) {
99 if (typeof decodeURIComponent != 'undefined')
100 return decodeURIComponent(arg);
101 else
102 return unescape(arg);
103}
104
508a81e1
AD
105function delay(gap) {
106 var then,now;
107 then=new Date().getTime();
108 now=then;
109 while((now-then)<gap) {
110 now=new Date().getTime();
111 }
112}
7726fa02 113
ce3bf408 114var notify_hide_timerid = false;
59a543f0 115
ce3bf408 116function hide_notify() {
42c32916
AD
117 var n = document.getElementById("notify");
118 if (n) {
d05514a4 119 n.style.display = "none";
8dcfffd0 120 }
d05514a4 121}
c05608c2 122
730dbf19
AD
123function notify_silent_next() {
124 notify_silent = true;
125}
126
42c32916 127function notify_real(msg, no_hide, n_type) {
7726fa02 128
730dbf19
AD
129 if (notify_silent) {
130 notify_silent = false;
131 return;
132 }
133
42c32916
AD
134 var n = document.getElementById("notify");
135 var nb = document.getElementById("notify_body");
7726fa02 136
c05608c2 137 if (!n || !nb) return;
f0601b87 138
0655a1d5
AD
139 if (notify_hide_timerid) {
140 window.clearTimeout(notify_hide_timerid);
141 }
142
8dcfffd0 143 if (msg == "") {
0655a1d5
AD
144 if (n.style.display == "block") {
145 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
146 }
147 return;
7726fa02 148 } else {
0ceded7a 149 n.style.display = "block";
8dcfffd0 150 }
7726fa02 151
42c32916
AD
152 /* types:
153
154 1 - generic
155 2 - progress
156 3 - error
157 4 - info
158
159 */
160
f3977cf5
AD
161 if (typeof __ != 'undefined') {
162 msg = __(msg);
163 }
164
42c32916
AD
165 if (n_type == 1) {
166 n.className = "notify";
167 } else if (n_type == 2) {
168 n.className = "notifyProgress";
169 msg = "<img src='images/indicator_white.gif'> " + msg;
170 } else if (n_type == 3) {
f407c086 171 n.className = "notifyError";
e780d1d2 172 msg = "<img src='images/sign_excl.gif'> " + msg;
42c32916
AD
173 } else if (n_type == 4) {
174 n.className = "notifyInfo";
e780d1d2 175 msg = "<img src='images/sign_info.gif'> " + msg;
0530ddd8
AD
176 }
177
106689b0
AD
178// msg = "<img src='images/live_com_loading.gif'> " + msg;
179
0ceded7a
AD
180 nb.innerHTML = msg;
181
4d4200a8 182 if (!no_hide) {
292a8a12 183 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 184 }
ce3bf408
AD
185}
186
42c32916
AD
187function notify(msg, no_hide) {
188 notify_real(msg, no_hide, 1);
ce3bf408
AD
189}
190
42c32916
AD
191function notify_progress(msg, no_hide) {
192 notify_real(msg, no_hide, 2);
193}
194
195function notify_error(msg, no_hide) {
196 notify_real(msg, no_hide, 3);
197
198}
199
200function notify_info(msg, no_hide) {
201 notify_real(msg, no_hide, 4);
7726fa02
AD
202}
203
508a81e1 204function printLockingError() {
42c32916
AD
205 notify_info("Please wait until operation finishes.");
206}
508a81e1 207
e828e31e 208function cleanSelectedList(element) {
f0601b87
AD
209 var content = document.getElementById(element);
210
703b632e
AD
211 if (!document.getElementById("feedCatHolder")) {
212 for (i = 0; i < content.childNodes.length; i++) {
213 var child = content.childNodes[i];
d0bb308e
AD
214 try {
215 child.className = child.className.replace("Selected", "");
216 } catch (e) {
217 //
218 }
703b632e
AD
219 }
220 } else {
221 for (i = 0; i < content.childNodes.length; i++) {
222 var child = content.childNodes[i];
703b632e 223 if (child.id == "feedCatHolder") {
9cb99906 224 debug(child.id);
c3f348c2 225 var fcat = child.lastChild;
703b632e 226 for (j = 0; j < fcat.childNodes.length; j++) {
befc807f 227 var feed = fcat.childNodes[j];
703b632e
AD
228 feed.className = feed.className.replace("Selected", "");
229 }
230 }
befc807f 231 }
703b632e 232 }
e828e31e
AD
233}
234
235
236function cleanSelected(element) {
237 var content = document.getElementById(element);
f0601b87
AD
238
239 for (i = 0; i < content.rows.length; i++) {
240 content.rows[i].className = content.rows[i].className.replace("Selected", "");
241 }
f0601b87
AD
242}
243
244function getVisibleUnreadHeadlines() {
245 var content = document.getElementById("headlinesList");
246
247 var rows = new Array();
248
3a40e8a2
AD
249 if (!content) return rows;
250
f0601b87
AD
251 for (i = 0; i < content.rows.length; i++) {
252 var row_id = content.rows[i].id.replace("RROW-", "");
253 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
254 rows.push(row_id);
255 }
256 }
257 return rows;
258}
259
260function getVisibleHeadlineIds() {
261
262 var content = document.getElementById("headlinesList");
263
264 var rows = new Array();
265
3a40e8a2
AD
266 if (!content) return rows;
267
f0601b87
AD
268 for (i = 0; i < content.rows.length; i++) {
269 var row_id = content.rows[i].id.replace("RROW-", "");
270 if (row_id.length > 0) {
271 rows.push(row_id);
272 }
273 }
274 return rows;
275}
276
277function getFirstVisibleHeadlineId() {
5ad9d132
AD
278 if (isCdmMode()) {
279 var rows = cdmGetVisibleArticles();
280 return rows[0];
281 } else {
282 var rows = getVisibleHeadlineIds();
283 return rows[0];
284 }
f0601b87
AD
285}
286
287function getLastVisibleHeadlineId() {
5ad9d132
AD
288 if (isCdmMode()) {
289 var rows = cdmGetVisibleArticles();
290 return rows[rows.length-1];
291 } else {
292 var rows = getVisibleHeadlineIds();
293 return rows[rows.length-1];
294 }
f0601b87
AD
295}
296
297function markHeadline(id) {
298 var row = document.getElementById("RROW-" + id);
299 if (row) {
35f3c923
AD
300 var is_active = false;
301
302 if (row.className.match("Active")) {
303 is_active = true;
304 }
305 row.className = row.className.replace("Selected", "");
306 row.className = row.className.replace("Active", "");
307 row.className = row.className.replace("Insensitive", "");
308
309 if (is_active) {
310 row.className = row.className = "Active";
311 }
312
72020095
AD
313 var check = document.getElementById("RCHK-" + id);
314
315 if (check) {
316 check.checked = true;
317 }
318
35f3c923
AD
319 row.className = row.className + "Selected";
320
f0601b87
AD
321 }
322}
323
324function getFeedIds() {
325 var content = document.getElementById("feedsList");
326
327 var rows = new Array();
328
329 for (i = 0; i < content.rows.length; i++) {
330 var id = content.rows[i].id.replace("FEEDR-", "");
331 if (id.length > 0) {
332 rows.push(id);
333 }
334 }
335
336 return rows;
337}
13ad9102 338
76b4eae1
AD
339function setCookie(name, value, lifetime, path, domain, secure) {
340
341 var d = false;
342
343 if (lifetime) {
344 d = new Date();
be0801a1 345 d.setTime(d.getTime() + (lifetime * 1000));
76b4eae1 346 }
cdbb6dc6
AD
347
348 debug("setCookie: " + name + " => " + value + ": " + d);
76b4eae1
AD
349
350 int_setCookie(name, value, d, path, domain, secure);
351
352}
353
354function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
355 document.cookie= name + "=" + escape(value) +
356 ((expires) ? "; expires=" + expires.toGMTString() : "") +
357 ((path) ? "; path=" + path : "") +
358 ((domain) ? "; domain=" + domain : "") +
359 ((secure) ? "; secure" : "");
360}
361
76b4eae1
AD
362function delCookie(name, path, domain) {
363 if (getCookie(name)) {
364 document.cookie = name + "=" +
365 ((path) ? ";path=" + path : "") +
366 ((domain) ? ";domain=" + domain : "" ) +
367 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
368 }
369}
370
371
ac43eba1
AD
372function getCookie(name) {
373
374 var dc = document.cookie;
375 var prefix = name + "=";
376 var begin = dc.indexOf("; " + prefix);
377 if (begin == -1) {
378 begin = dc.indexOf(prefix);
379 if (begin != 0) return null;
380 }
381 else {
382 begin += 2;
383 }
384 var end = document.cookie.indexOf(";", begin);
385 if (end == -1) {
386 end = dc.length;
387 }
388 return unescape(dc.substring(begin + prefix.length, end));
389}
390
1a66d16e
AD
391function disableContainerChildren(id, disable, doc) {
392
393 if (!doc) doc = document;
394
395 var container = doc.getElementById(id);
ac43eba1 396
4220b0bd
AD
397 if (!container) {
398 //alert("disableContainerChildren: element " + id + " not found");
399 return;
400 }
401
ac43eba1
AD
402 for (var i = 0; i < container.childNodes.length; i++) {
403 var child = container.childNodes[i];
404
d5224f0d
AD
405 try {
406 child.disabled = disable;
407 } catch (E) {
408
409 }
ac43eba1
AD
410
411 if (disable) {
412 if (child.className && child.className.match("button")) {
413 child.className = "disabledButton";
414 }
415 } else {
416 if (child.className && child.className.match("disabledButton")) {
417 child.className = "button";
418 }
d5224f0d 419 }
ac43eba1
AD
420 }
421
422}
7726fa02 423
e828e31e
AD
424function gotoPreferences() {
425 document.location.href = "prefs.php";
426}
427
428function gotoMain() {
429 document.location.href = "tt-rss.php";
430}
431
8158c57a
AD
432function gotoExportOpml() {
433 document.location.href = "opml.php?op=Export";
434}
86741347
AD
435
436function getActiveFeedId() {
33d13e72
AD
437// return getCookie("ttrss_vf_actfeed");
438 try {
0feab655
AD
439 debug("gAFID: " + active_feed_id);
440 return active_feed_id;
33d13e72
AD
441 } catch (e) {
442 exception_error("getActiveFeedId", e);
443 }
86741347
AD
444}
445
0a6c4846 446function activeFeedIsCat() {
0feab655 447 return active_feed_is_cat;
0a6c4846
AD
448}
449
86741347 450function setActiveFeedId(id) {
33d13e72
AD
451// return setCookie("ttrss_vf_actfeed", id);
452 try {
5c365f60 453 debug("sAFID(" + id + ")");
0feab655 454 active_feed_id = id;
33d13e72
AD
455 } catch (e) {
456 exception_error("setActiveFeedId", e);
457 }
86741347 458}
090e250b 459
ac378ad4 460function parse_counters(reply, scheduled_call) {
1a6a9555 461 try {
ac378ad4 462
9e397d0f
AD
463 var feeds_found = 0;
464
85bd574b 465 var elems = reply.getElementsByTagName("counter");
f54f515f 466
85bd574b 467 for (var l = 0; l < elems.length; l++) {
6043fb7e 468
85bd574b
AD
469 var id = elems[l].getAttribute("id");
470 var t = elems[l].getAttribute("type");
471 var ctr = elems[l].getAttribute("counter");
472 var error = elems[l].getAttribute("error");
473 var has_img = elems[l].getAttribute("hi");
474 var updated = elems[l].getAttribute("updated");
4ffa126e 475 var title = elems[l].getAttribute("title");
bdb7369b
AD
476 var xmsg = elems[l].getAttribute("xmsg");
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
bdb7369b
AD
517 if (feedupd) {
518 if (!updated) updated = "";
519
78d5212c 520 if (error) {
bdb7369b
AD
521 if (xmsg) {
522 feedupd.innerHTML = updated + " " + xmsg + " (Error)";
523 } else {
524 feedupd.innerHTML = updated + " (Error)";
525 }
78d5212c 526 } else {
bdb7369b
AD
527 if (xmsg) {
528 feedupd.innerHTML = updated + " " + xmsg;
529 } else {
530 feedupd.innerHTML = updated;
531 }
78d5212c
AD
532 }
533 }
534
f74cfded 535 if (has_img && feed_img) {
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
569720c5 1160 Element.hide("dialog_overlay");
5ede560f 1161
e5d758e3
AD
1162 var box = document.getElementById('infoBox');
1163 var shadow = document.getElementById('infoBoxShadow');
1164
1165 if (shadow) {
1166 shadow.style.display = "none";
1167 } else if (box) {
1168 box.style.display = "none";
1169 }
1170
86b682ce
AD
1171 if (cleanup) box.innerHTML = "&nbsp;";
1172
e5d758e3 1173 enableHotkeys();
c14b5566 1174
90ac84df 1175 return false;
e5d758e3
AD
1176}
1177
1178
7b5c6012
AD
1179function displayDlg(id, param) {
1180
35a03bdd 1181 notify_progress("Loading, please wait...", true);
7b5c6012 1182
7b5c6012 1183 disableHotkeys();
2371c520 1184
288487e4
AD
1185 var query = "backend.php?op=dlg&id=" +
1186 param_escape(id) + "&param=" + param_escape(param);
1187
1188 new Ajax.Request(query, {
1189 onComplete: function (transport) {
1190 infobox_callback2(transport);
1191 } });
1192
90ac84df 1193 return false;
7b5c6012
AD
1194}
1195
288487e4
AD
1196function infobox_submit_callback2(transport) {
1197 closeInfoBox();
79f3553b 1198
288487e4
AD
1199 try {
1200 // called from prefs, reload tab
438f2ce9 1201 if (typeof active_tab != 'undefined' && active_tab) {
288487e4 1202 selectTab(active_tab, false);
5e6f933a 1203 }
288487e4 1204 } catch (e) { }
79f3553b 1205
288487e4
AD
1206 if (transport.responseText) {
1207 notify_info(transport.responseText);
1208 }
7b5c6012
AD
1209}
1210
d395a942
AD
1211function infobox_callback2(transport) {
1212 try {
5ede560f 1213
d395a942 1214 debug("infobox_callback2");
5ede560f 1215
569720c5
AD
1216 if (!getInitParam("infobox_disable_overlay")) {
1217 Element.show("dialog_overlay");
d395a942
AD
1218 }
1219
1220 var box = document.getElementById('infoBox');
1221 var shadow = document.getElementById('infoBoxShadow');
1222 if (box) {
1dc47c41 1223
d395a942
AD
1224 box.innerHTML=transport.responseText;
1225 if (shadow) {
1226 shadow.style.display = "block";
1227 } else {
1228 box.style.display = "block";
aa8716da 1229 }
d395a942 1230 }
05fcdf52 1231
d395a942 1232 /* FIXME this needs to be moved out somewhere */
05fcdf52 1233
d395a942
AD
1234 if (document.getElementById("tags_choices")) {
1235 new Ajax.Autocompleter('tags_str', 'tags_choices',
1236 "backend.php?op=rpc&subop=completeTags",
1237 { tokens: ',', paramName: "search" });
442d77f1 1238 }
d395a942 1239
6068d33b
AD
1240 disableHotkeys();
1241
d395a942
AD
1242 notify("");
1243 } catch (e) {
1244 exception_error("infobox_callback2", e);
442d77f1
AD
1245 }
1246}
1247
18ab3d7a 1248function createFilter() {
7b5c6012 1249
438f2ce9 1250 try {
6068d33b 1251
438f2ce9
AD
1252 var form = document.forms['filter_add_form'];
1253 var reg_exp = form.reg_exp.value;
1254
1255 if (reg_exp == "") {
1256 alert(__("Can't add filter: nothing to match on."));
1257 return false;
1258 }
288487e4 1259
438f2ce9
AD
1260 var query = Form.serialize("filter_add_form");
1261
1262 // we can be called from some other tab in Prefs
1263 if (typeof active_tab != 'undefined' && active_tab) {
1264 active_tab = "filterConfig";
1265 }
1266
1267 new Ajax.Request("backend.php?" + query, {
1268 onComplete: function (transport) {
1269 infobox_submit_callback2(transport);
1270 } });
1271
1272 return true;
1273
1274 } catch (e) {
1275 exception_error("createFilter", e);
1276 }
7b5c6012
AD
1277}
1278
2371c520
AD
1279function toggleSubmitNotEmpty(e, submit_id) {
1280 try {
1281 document.getElementById(submit_id).disabled = (e.value == "")
1282 } catch (e) {
1283 exception_error("toggleSubmitNotEmpty", e);
1284 }
1285}
1d7bf5a0 1286
605f7d46 1287function isValidURL(s) {
0d32b41e 1288 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
605f7d46 1289}
07eb9178 1290
18ab3d7a 1291function subscribeToFeed() {
07eb9178 1292
c91c2249
AD
1293 var form = document.forms['feed_add_form'];
1294 var feed_url = form.feed_url.value;
1295
1296 if (feed_url == "") {
89cb787e 1297 alert(__("Can't subscribe: no feed URL given."));
c91c2249
AD
1298 return false;
1299 }
1300
1ba6daf7 1301 notify_progress(__("Subscribing to feed..."), true);
07eb9178
AD
1302
1303 closeInfoBox();
1304
0feab655 1305 var feeds_doc = document;
07eb9178 1306
80e4dc34 1307// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1308
1309 var query = Form.serialize("feed_add_form");
1310
f27de515
AD
1311 debug("subscribe q: " + query);
1312
288487e4
AD
1313 new Ajax.Request("backend.php", {
1314 parameters: query,
1315 onComplete: function(transport) {
1316 dlg_frefresh_callback(transport);
1317 } });
7bc4f251
AD
1318
1319 return false;
07eb9178
AD
1320}
1321
6e6504bc 1322function filterCR(e, f)
86b682ce
AD
1323{
1324 var key;
1325
1326 if(window.event)
1327 key = window.event.keyCode; //IE
1328 else
1329 key = e.which; //firefox
1330
6e6504bc
AD
1331 if (key == 13) {
1332 if (typeof f != 'undefined') {
1333 f();
1334 return false;
1335 } else {
1336 return false;
1337 }
1338 } else {
1339 return true;
1340 }
86b682ce
AD
1341}
1342
ac378ad4 1343function getMainContext() {
6b4163cb 1344 return this.window;
ac378ad4
AD
1345}
1346
33d13e72 1347function getFeedsContext() {
6b4163cb 1348 return this.window;
33d13e72
AD
1349}
1350
0bd411db 1351function getContentContext() {
6b4163cb 1352 return this.window;
0bd411db
AD
1353}
1354
ee1f45f4 1355function getHeadlinesContext() {
6b4163cb 1356 return this.window;
ee1f45f4
AD
1357}
1358
e8614131
AD
1359var debug_last_class = "even";
1360
ac378ad4 1361function debug(msg) {
ac378ad4 1362
0feab655
AD
1363 if (debug_last_class == "even") {
1364 debug_last_class = "odd";
e8614131 1365 } else {
0feab655 1366 debug_last_class = "even";
e8614131
AD
1367 }
1368
0feab655 1369 var c = document.getElementById('debug_output');
8836613c 1370 if (c && Element.visible(c)) {
c9268ed5 1371 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1372 c.removeChild(c.lastChild);
1373 }
1374
1375 var d = new Date();
1376 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1377 ":" + leading_zero(d.getSeconds());
0feab655 1378 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1379 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1380 }
1381}
1382
33d13e72 1383function getInitParam(key) {
40496720 1384 return init_params[key];
33d13e72 1385}
3ac2b520 1386
be0801a1 1387function storeInitParam(key, value) {
40496720 1388 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
5158ced9 1389 init_params[key] = value;
be0801a1
AD
1390}
1391
a7565293
AD
1392function fatalError(code, message) {
1393 try {
a7565293 1394
b4c27af7 1395 if (code == 6) {
8e849206 1396 window.location.href = "tt-rss.php";
b4c27af7
AD
1397 } else if (code == 5) {
1398 window.location.href = "update.php";
1399 } else {
4724a093
AD
1400 var fe = document.getElementById("fatal_error");
1401 var fc = document.getElementById("fatal_error_msg");
1402
42c32916
AD
1403 if (message == "") message = "Unknown error";
1404
a0a63217 1405 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
4724a093
AD
1406
1407 fe.style.display = "block";
4724a093 1408 }
a7565293
AD
1409
1410 } catch (e) {
1411 exception_error("fatalError", e);
1412 }
1413}
1414
234e467c 1415function getFeedName(id, is_cat) {
64a2875d 1416 var d = getFeedsContext().document;
234e467c
AD
1417
1418 var e;
1419
1420 if (is_cat) {
1421 e = d.getElementById("FCATN-" + id);
1422 } else {
1423 e = d.getElementById("FEEDN-" + id);
1424 }
64a2875d
AD
1425 if (e) {
1426 return e.innerHTML.stripTags();
1427 } else {
1428 return null;
1429 }
1430}
0bd411db
AD
1431
1432function viewContentUrl(url) {
1433 getContentContext().location = url;
1434}
350f0ad1
AD
1435
1436function filterDlgCheckAction(sender) {
1437
1438 try {
1439
1440 var action = sender[sender.selectedIndex].value;
1441
1442 var form = document.forms["filter_add_form"];
1443
1444 if (!form) {
1445 form = document.forms["filter_edit_form"];
1446 }
1447
1448 if (!form) {
1449 debug("filterDlgCheckAction: can't find form!");
1450 return;
1451 }
1452
1453 var action_param = form.action_param;
1454
1455 if (!action_param) {
1456 debug("filterDlgCheckAction: can't find action param!");
1457 return;
1458 }
1459
1460 // if selected action supports parameters, enable params field
48ddbb33 1461 if (action == 4 || action == 6) {
350f0ad1
AD
1462 action_param.disabled = false;
1463 } else {
1464 action_param.disabled = true;
1465 }
1466
1467 } catch (e) {
438f2ce9 1468 exception_error("filterDlgCheckAction", e);
350f0ad1
AD
1469 }
1470
1471}
ef16ae37
AD
1472
1473function explainError(code) {
1474 return displayDlg("explainError", code);
1475}
01a87dff 1476
e097e8be 1477// this only searches loaded headlines list, not in CDM
aa0fa9df 1478function getRelativePostIds(id, limit) {
e097e8be 1479
aa0fa9df
AD
1480 if (!limit) limit = 3;
1481
1482 debug("getRelativePostIds: " + id + " limit=" + limit);
e097e8be
AD
1483
1484 var ids = new Array();
1485 var container = document.getElementById("headlinesList");
1486
1487 if (container) {
1488 var rows = container.rows;
1489
1490 for (var i = 0; i < rows.length; i++) {
1491 var r_id = rows[i].id.replace("RROW-", "");
1492
1493 if (r_id == id) {
aa0fa9df
AD
1494 for (var k = 1; k <= limit; k++) {
1495 var nid = false;
1496
1497 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1498 if (nid) ids.push(nid);
1499
1500 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1501 if (nid) ids.push(nid);
1502 }
e097e8be
AD
1503
1504 return ids;
1505 }
1506 }
1507 }
1508
1509 return false;
1510}
298f3f78
AD
1511
1512function openArticleInNewWindow(id) {
1513 try {
298f3f78
AD
1514 debug("openArticleInNewWindow: " + id);
1515
1516 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
04e91733
AD
1517 var wname = "ttrss_article_" + id;
1518
1519 debug(query + " " + wname);
1520
1521 var w = window.open("", wname);
298f3f78 1522
04e91733 1523 if (!w) notify_error("Failed to open window for the article");
298f3f78 1524
d395a942
AD
1525 new Ajax.Request(query, {
1526 onComplete: function(transport) {
1527 open_article_callback(transport);
1528 } });
1529
298f3f78
AD
1530
1531 } catch (e) {
1532 exception_error("openArticleInNewWindow", e);
1533 }
1534}
e4914b62 1535
537625c6
AD
1536/* http://textsnippets.com/posts/show/835 */
1537
1538Position.GetWindowSize = function(w) {
1539 w = w ? w : window;
1540 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1541 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1542 return [width, height]
1543}
1544
1545/* http://textsnippets.com/posts/show/836 */
1546
1547Position.Center = function(element, parent) {
1548 var w, h, pw, ph;
1549 var d = Element.getDimensions(element);
1550 w = d.width;
1551 h = d.height;
1552 Position.prepare();
1553 if (!parent) {
1554 var ws = Position.GetWindowSize();
1555 pw = ws[0];
1556 ph = ws[1];
1557 } else {
1558 pw = parent.offsetWidth;
1559 ph = parent.offsetHeight;
1560 }
1561 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1562 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1563}
1564
768858f1 1565
288487e4
AD
1566function labeltest_callback(transport) {
1567 try {
1568 var container = document.getElementById('label_test_result');
1569
1570 container.innerHTML = transport.responseText;
768858f1
AD
1571 if (!Element.visible(container)) {
1572 Effect.SlideDown(container, { duration : 0.5 });
1573 }
288487e4 1574
6f151277 1575 notify("");
288487e4
AD
1576 } catch (e) {
1577 exception_error("labeltest_callback", e);
6f151277
AD
1578 }
1579}
1580
1581function labelTest() {
1582
288487e4
AD
1583 try {
1584 var container = document.getElementById('label_test_result');
1585
1586 var form = document.forms['label_edit_form'];
1587
1588 var sql_exp = form.sql_exp.value;
1589 var description = form.description.value;
1590
1591 notify_progress("Loading, please wait...");
1592
1593 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1594 param_escape(sql_exp) + "&descr=" + param_escape(description);
1595
1596 new Ajax.Request(query, {
1597 onComplete: function (transport) {
1598 labeltest_callback(transport);
1599 } });
1600
1601 return false;
6f151277 1602
288487e4
AD
1603 } catch (e) {
1604 exception_error("labelTest", e);
1605 }
6f151277
AD
1606}
1607
c32cd48a
AD
1608function isCdmMode() {
1609 return !document.getElementById("headlinesList");
1610}
1611
1612function getSelectedArticleIds2() {
1613 var rows = new Array();
1614 var cdm_mode = isCdmMode();
1615
1616 if (cdm_mode) {
1617 rows = cdmGetSelectedArticles();
1618 } else {
1619 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1620 }
1621
1622 var ids = new Array();
1623
1624 for (var i = 0; i < rows.length; i++) {
1625 var chk = document.getElementById("RCHK-" + rows[i]);
1626 if (chk && chk.checked) {
1627 ids.push(rows[i]);
1628 }
1629 }
1630
1631 return ids;
1632}
c4a36709 1633
f6d40ed2 1634function displayHelpInfobox(topic_id) {
c4a36709 1635
f6d40ed2
AD
1636 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1637
1638 var w = window.open(url, "ttrss_help",
1639 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1640
1641 return false;
1642}
e635d56a 1643
477402d8 1644function focus_element(id) {
61992f57 1645 try {
477402d8
AD
1646 var e = document.getElementById(id);
1647 if (e) e.focus();
61992f57 1648 } catch (e) {
438f2ce9 1649 exception_error("focus_element", e);
61992f57 1650 }
477402d8 1651 return false;
61992f57 1652}
e635d56a 1653
99509451 1654function loading_set_progress(p) {
730dbf19 1655 try {
fca95d5f
AD
1656 if (p < last_progress_point || !Element.visible("overlay")) return;
1657
1658 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
99509451 1659
730dbf19 1660 var o = document.getElementById("l_progress_i");
99509451 1661
673c9946
AD
1662// o.style.width = (p * 2) + "px";
1663
99509451
AD
1664 new Effect.Scale(o, p, {
1665 scaleY : false,
1666 scaleFrom : last_progress_point,
1667 scaleMode: { originalWidth : 200 },
673c9946 1668 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
99509451
AD
1669
1670 last_progress_point = p;
730dbf19
AD
1671
1672 } catch (e) {
1673 exception_error("loading_set_progress", e);
1674 }
1675}
08827aaf
AD
1676
1677function remove_splash() {
1678 if (Element.visible("overlay")) {
1679 debug("about to remove splash, OMG!");
1680 Element.hide("overlay");
1681 debug("removed splash!");
1682 }
1683}