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