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