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