]> git.wh0rd.org - tt-rss.git/blame - functions.js
remove obsolete get*Context functions
[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
61a20560
AD
621 if (feedsSortByUnread()) {
622 resort_feedlist();
623 }
5854573a 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
61a20560
AD
664function get_feed_entry_name(elem) {
665 var id = elem.id.replace("FEEDR-", "");
666 return getFeedName(id);
667}
668
669
60ea2377 670function resort_category(node) {
c9268ed5
AD
671 debug("resort_category: " + node);
672
61a20560
AD
673 var by_unread = feedsSortByUnread();
674
c9268ed5
AD
675 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
676 for (i = 0; i < node.childNodes.length; i++) {
677 if (node.childNodes[i].nodeName != "LI") { continue; }
678
60ea2377 679 if (get_feed_entry_unread(node.childNodes[i]) < 0) {
c9268ed5
AD
680 continue;
681 }
682
683 for (j = i+1; j < node.childNodes.length; j++) {
684 if (node.childNodes[j].nodeName != "LI") { continue; }
685
60ea2377
AD
686 var tmp_val = get_feed_entry_unread(node.childNodes[i]);
687 var cur_val = get_feed_entry_unread(node.childNodes[j]);
c9268ed5 688
61a20560
AD
689 var tmp_name = get_feed_entry_name(node.childNodes[i]);
690 var cur_name = get_feed_entry_name(node.childNodes[j]);
691
692 if ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name))) {
c9268ed5
AD
693 tempnode_i = node.childNodes[i].cloneNode(true);
694 tempnode_j = node.childNodes[j].cloneNode(true);
695 node.replaceChild(tempnode_i, node.childNodes[j]);
696 node.replaceChild(tempnode_j, node.childNodes[i]);
697 }
698 }
699
700 }
701 }
702
703}
704
705function resort_feedlist() {
706 debug("resort_feedlist");
707
60ea2377 708 if (document.getElementById("FCATLIST--1")) {
c9268ed5 709
60ea2377 710 var lists = document.getElementsByTagName("UL");
c9268ed5 711
60ea2377
AD
712 for (var i = 0; i < lists.length; i++) {
713 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
714 resort_category(lists[i]);
c9268ed5 715 }
c9268ed5
AD
716 }
717
718 } else {
60ea2377 719 resort_category(document.getElementById("feedList"));
c9268ed5
AD
720 }
721}
722
b6644d29
AD
723/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
724 * * @author Sundar Dorai-Raj
725 * * Email: sdoraira@vt.edu
726 * * This program is free software; you can redistribute it and/or
727 * * modify it under the terms of the GNU General Public License
728 * * as published by the Free Software Foundation; either version 2
729 * * of the License, or (at your option) any later version,
730 * * provided that any use properly credits the author.
731 * * This program is distributed in the hope that it will be useful,
732 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
733 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
734 * * GNU General Public License for more details at http://www.gnu.org * * */
735
736 var numbers=".0123456789";
737 function isNumeric(x) {
738 // is x a String or a character?
739 if(x.length>1) {
740 // remove negative sign
741 x=Math.abs(x)+"";
742 for(j=0;j<x.length;j++) {
743 // call isNumeric recursively for each character
744 number=isNumeric(x.substring(j,j+1));
745 if(!number) return number;
746 }
747 return number;
748 }
749 else {
750 // if x is number return true
751 if(numbers.indexOf(x)>=0) return true;
752 return false;
753 }
754 }
755
3745788e 756
60ea2377 757function hideOrShowFeeds(hide) {
3745788e 758
60ea2377 759 try {
293fa942 760
60ea2377 761 debug("hideOrShowFeeds: " + hide);
293fa942 762
60ea2377 763 if (document.getElementById("FCATLIST--1")) {
293fa942 764
60ea2377 765 var lists = document.getElementsByTagName("UL");
293fa942 766
60ea2377
AD
767 for (var i = 0; i < lists.length; i++) {
768 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
293fa942 769
60ea2377
AD
770 var id = lists[i].id.replace("FCATLIST-", "");
771 hideOrShowFeedsCategory(id, hide);
293fa942 772 }
293fa942
AD
773 }
774
775 } else {
60ea2377 776 hideOrShowFeedsCategory(null, hide);
293fa942 777 }
293fa942 778
60ea2377
AD
779 } catch (e) {
780 exception_error("hideOrShowFeeds", e);
4724a093 781 }
60ea2377 782}
4724a093 783
60ea2377 784function hideOrShowFeedsCategory(id, hide) {
2c2b019b 785
60ea2377
AD
786 try {
787
788 var node = null;
789 var cat_node = null;
bbf4d0b2 790
60ea2377
AD
791 if (id) {
792 node = document.getElementById("FCATLIST-" + id);
793 cat_node = document.getElementById("FCAT-" + id);
794 } else {
795 node = document.getElementById("feedList"); // no categories
796 }
293fa942 797
60ea2377 798 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
b31c2311 799
60ea2377 800 var cat_unread = 0;
b31c2311 801
60ea2377
AD
802 if (!node) {
803 debug("hideOrShowFeeds: passed node is null, aborting");
804 return;
805 }
b31c2311 806
60ea2377
AD
807 // debug("cat: " + node.id);
808
809 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
810 for (i = 0; i < node.childNodes.length; i++) {
811 if (node.childNodes[i].nodeName != "LI") { continue; }
b31c2311 812
60ea2377
AD
813 if (node.childNodes[i].style != undefined) {
814
815 var has_unread = (node.childNodes[i].className != "feed" &&
816 node.childNodes[i].className != "label" &&
817 !(!getInitParam("hide_read_shows_special") &&
818 node.childNodes[i].className == "virt") &&
819 node.childNodes[i].className != "error" &&
820 node.childNodes[i].className != "tag");
821
822 // debug(node.childNodes[i].id + " --> " + has_unread);
823
824 if (hide && !has_unread) {
825 //node.childNodes[i].style.display = "none";
826 var id = node.childNodes[i].id;
827 Effect.Fade(node.childNodes[i], {duration : 0.3,
828 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
829 }
830
831 if (!hide) {
832 node.childNodes[i].style.display = "list-item";
833 //Effect.Appear(node.childNodes[i], {duration : 0.3});
834 }
835
836 if (has_unread) {
837 node.childNodes[i].style.display = "list-item";
838 cat_unread++;
839 //Effect.Appear(node.childNodes[i], {duration : 0.3});
840 //Effect.Highlight(node.childNodes[i]);
841 }
b31c2311 842 }
293fa942 843 }
60ea2377
AD
844 }
845
846 // debug("end cat: " + node.id + " unread " + cat_unread);
847
848 if (cat_unread == 0) {
849 if (cat_node.style == undefined) {
850 debug("ERROR: supplied cat_node " + cat_node +
851 " has no styles. WTF?");
852 return;
853 }
854 if (hide) {
855 //cat_node.style.display = "none";
856 Effect.Fade(cat_node, {duration : 0.3,
857 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
858 } else {
859 cat_node.style.display = "list-item";
860 }
293fa942 861 } else {
60ea2377
AD
862 try {
863 cat_node.style.display = "list-item";
864 } catch (e) {
865 debug(e);
866 }
0ac2faea 867 }
3745788e 868
293fa942 869// debug("unread for category: " + cat_unread);
60ea2377
AD
870
871 } catch (e) {
872 exception_error("hideOrShowFeedsCategory", e);
873 }
3745788e
AD
874}
875
35f3c923
AD
876function selectTableRow(r, do_select) {
877 r.className = r.className.replace("Selected", "");
878
879 if (do_select) {
880 r.className = r.className + "Selected";
881 }
882}
883
6c12c809
AD
884function selectTableRowById(elem_id, check_id, do_select) {
885
886 try {
887
888 var row = document.getElementById(elem_id);
889
890 if (row) {
891 selectTableRow(row, do_select);
892 }
893
894 var check = document.getElementById(check_id);
895
896 if (check) {
897 check.checked = do_select;
898 }
899 } catch (e) {
900 exception_error("selectTableRowById", e);
901 }
902}
903
1572afe5 904function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 905 classcheck, reset_others) {
3745788e 906
35f3c923
AD
907 var content = document.getElementById(content_id);
908
909 if (!content) {
910 alert("[selectTableRows] Element " + content_id + " not found.");
911 return;
912 }
913
914 for (i = 0; i < content.rows.length; i++) {
7a822893
AD
915 if (Element.visible(content.rows[i])) {
916 if (!classcheck || content.rows[i].className.match(classcheck)) {
917
918 if (content.rows[i].id.match(prefix)) {
919 selectTableRow(content.rows[i], do_select);
920
921 var row_id = content.rows[i].id.replace(prefix, "");
922 var check = document.getElementById(check_prefix + row_id);
923
924 if (check) {
925 check.checked = do_select;
926 }
927 } else if (reset_others) {
928 selectTableRow(content.rows[i], false);
929
930 var row_id = content.rows[i].id.replace(prefix, "");
931 var check = document.getElementById(check_prefix + row_id);
932
933 if (check) {
934 check.checked = false;
935 }
1572afe5 936
649e0af9
AD
937 }
938 } else if (reset_others) {
939 selectTableRow(content.rows[i], false);
7a822893 940
7d8d10c6
AD
941 var row_id = content.rows[i].id.replace(prefix, "");
942 var check = document.getElementById(check_prefix + row_id);
7a822893 943
7d8d10c6
AD
944 if (check) {
945 check.checked = false;
946 }
7a822893 947
7d8d10c6 948 }
3055bc41 949 }
35f3c923 950 }
295f9b42 951}
91ff844a
AD
952
953function getSelectedTableRowIds(content_id, prefix) {
954
955 var content = document.getElementById(content_id);
956
957 if (!content) {
958 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
959 return;
960 }
961
962 var sel_rows = new Array();
963
964 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
965 if (content.rows[i].id.match(prefix) &&
966 content.rows[i].className.match("Selected")) {
967
91ff844a
AD
968 var row_id = content.rows[i].id.replace(prefix + "-", "");
969 sel_rows.push(row_id);
970 }
971 }
972
973 return sel_rows;
974
975}
976
386cbf27
AD
977function toggleSelectRowById(sender, id) {
978 var row = document.getElementById(id);
979
980 if (sender.checked) {
981 if (!row.className.match("Selected")) {
982 row.className = row.className + "Selected";
983 }
984 } else {
985 if (row.className.match("Selected")) {
986 row.className = row.className.replace("Selected", "");
987 }
988 }
989}
990
b92e6209
AD
991function toggleSelectListRow(sender) {
992 var parent_row = sender.parentNode;
993
994 if (sender.checked) {
995 if (!parent_row.className.match("Selected")) {
996 parent_row.className = parent_row.className + "Selected";
997 }
998 } else {
999 if (parent_row.className.match("Selected")) {
1000 parent_row.className = parent_row.className.replace("Selected", "");
1001 }
1002 }
1003}
1004
67343d9f
AD
1005function tSR(sender) {
1006 return toggleSelectRow(sender);
1007}
386cbf27 1008
1572afe5
AD
1009function toggleSelectRow(sender) {
1010 var parent_row = sender.parentNode.parentNode;
1011
1012 if (sender.checked) {
1013 if (!parent_row.className.match("Selected")) {
1014 parent_row.className = parent_row.className + "Selected";
1015 }
1016 } else {
1017 if (parent_row.className.match("Selected")) {
1018 parent_row.className = parent_row.className.replace("Selected", "");
1019 }
1020 }
1021}
1022
1da76274 1023function getRelativeFeedId(list, id, direction, unread_only) {
731b05f4
AD
1024 var rows = list.getElementsByTagName("LI");
1025 var feeds = new Array();
1026
1027 for (var i = 0; i < rows.length; i++) {
1028 if (rows[i].id.match("FEEDR-")) {
1029
8809f484 1030 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
731b05f4
AD
1031
1032 if (!unread_only ||
1033 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1034 feeds.push(rows[i].id.replace("FEEDR-", ""));
1035 }
1036 }
1037 }
1038 }
1039
7b433d8c 1040 if (!id) {
731b05f4
AD
1041 if (direction == "next") {
1042 return feeds.shift();
1043 } else {
1044 return feeds.pop();
1045 }
1046 } else {
1047 if (direction == "next") {
1048 var idx = feeds.indexOf(id);
1049 if (idx != -1 && idx < feeds.length) {
1050 return feeds[idx+1];
07a67863
AD
1051 } else {
1052 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1053 }
1054 } else {
1055 var idx = feeds.indexOf(id);
1056 if (idx > 0) {
1057 return feeds[idx-1];
07a67863
AD
1058 } else {
1059 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1060 }
1061 }
1062
1063 }
7b433d8c 1064}
36aab70f 1065
f27de515 1066function showBlockElement(id, h_id) {
36aab70f
AD
1067 var elem = document.getElementById(id);
1068
1069 if (elem) {
1070 elem.style.display = "block";
f27de515
AD
1071
1072 if (h_id) {
1073 elem = document.getElementById(h_id);
1074 if (elem) {
1075 elem.style.display = "none";
1076 }
1077 }
36aab70f
AD
1078 } else {
1079 alert("[showBlockElement] can't find element with id " + id);
1080 }
1081}
1082
b9073cd9
AD
1083function appearBlockElement_afh(effect) {
1084
1085}
1086
1087function checkboxToggleElement(elem, id) {
1088 if (elem.checked) {
b1085d24 1089 Effect.SlideDown(id, {duration : 0.5});
b9073cd9 1090 } else {
b1085d24 1091 Effect.SlideUp(id, {duration : 0.5});
b9073cd9
AD
1092 }
1093}
1094
1095function appearBlockElement(id, h_id) {
1096
1097 try {
a04c8e8d
AD
1098 if (h_id) {
1099 Effect.Fade(h_id);
1100 }
b9073cd9
AD
1101 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1102 } catch (e) {
1103 exception_error("appearBlockElement", e);
1104 }
1105
1106}
1107
a9b0bfd5
AD
1108function hideParentElement(e) {
1109 e.parentNode.style.display = "none";
1110}
1b0809ae
AD
1111
1112function dropboxSelect(e, v) {
1113 for (i = 0; i < e.length; i++) {
1114 if (e[i].value == v) {
1115 e.selectedIndex = i;
1116 break;
1117 }
1118 }
1119}
0ee1d1a0
AD
1120
1121// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1122// bugfixed just a little bit :-)
1123function getURLParam(strParamName){
1124 var strReturn = "";
1125 var strHref = window.location.href;
1126
1127 if (strHref.indexOf("#") == strHref.length-1) {
1128 strHref = strHref.substring(0, strHref.length-1);
1129 }
1130
1131 if ( strHref.indexOf("?") > -1 ){
1132 var strQueryString = strHref.substr(strHref.indexOf("?"));
1133 var aQueryString = strQueryString.split("&");
1134 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1135 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1136 var aParam = aQueryString[iParam].split("=");
1137 strReturn = aParam[1];
1138 break;
1139 }
1140 }
1141 }
1142 return strReturn;
1143}
1144
cf1bc085
AD
1145function leading_zero(p) {
1146 var s = String(p);
1147 if (s.length == 1) s = "0" + s;
1148 return s;
1149}
c38c2b69 1150
86b682ce 1151function closeInfoBox(cleanup) {
5ede560f 1152
569720c5 1153 Element.hide("dialog_overlay");
5ede560f 1154
e5d758e3
AD
1155 var box = document.getElementById('infoBox');
1156 var shadow = document.getElementById('infoBoxShadow');
1157
1158 if (shadow) {
1159 shadow.style.display = "none";
1160 } else if (box) {
1161 box.style.display = "none";
1162 }
1163
86b682ce
AD
1164 if (cleanup) box.innerHTML = "&nbsp;";
1165
e5d758e3 1166 enableHotkeys();
c14b5566 1167
90ac84df 1168 return false;
e5d758e3
AD
1169}
1170
1171
7b5c6012
AD
1172function displayDlg(id, param) {
1173
35a03bdd 1174 notify_progress("Loading, please wait...", true);
7b5c6012 1175
7b5c6012 1176 disableHotkeys();
2371c520 1177
288487e4
AD
1178 var query = "backend.php?op=dlg&id=" +
1179 param_escape(id) + "&param=" + param_escape(param);
1180
1181 new Ajax.Request(query, {
1182 onComplete: function (transport) {
1183 infobox_callback2(transport);
1184 } });
1185
90ac84df 1186 return false;
7b5c6012
AD
1187}
1188
288487e4
AD
1189function infobox_submit_callback2(transport) {
1190 closeInfoBox();
79f3553b 1191
288487e4
AD
1192 try {
1193 // called from prefs, reload tab
438f2ce9 1194 if (typeof active_tab != 'undefined' && active_tab) {
288487e4 1195 selectTab(active_tab, false);
5e6f933a 1196 }
288487e4 1197 } catch (e) { }
79f3553b 1198
288487e4
AD
1199 if (transport.responseText) {
1200 notify_info(transport.responseText);
1201 }
7b5c6012
AD
1202}
1203
d395a942
AD
1204function infobox_callback2(transport) {
1205 try {
5ede560f 1206
d395a942 1207 debug("infobox_callback2");
5ede560f 1208
569720c5
AD
1209 if (!getInitParam("infobox_disable_overlay")) {
1210 Element.show("dialog_overlay");
d395a942
AD
1211 }
1212
1213 var box = document.getElementById('infoBox');
1214 var shadow = document.getElementById('infoBoxShadow');
1215 if (box) {
1dc47c41 1216
d395a942
AD
1217 box.innerHTML=transport.responseText;
1218 if (shadow) {
1219 shadow.style.display = "block";
1220 } else {
1221 box.style.display = "block";
aa8716da 1222 }
d395a942 1223 }
05fcdf52 1224
d395a942 1225 /* FIXME this needs to be moved out somewhere */
05fcdf52 1226
d395a942
AD
1227 if (document.getElementById("tags_choices")) {
1228 new Ajax.Autocompleter('tags_str', 'tags_choices',
1229 "backend.php?op=rpc&subop=completeTags",
1230 { tokens: ',', paramName: "search" });
442d77f1 1231 }
d395a942 1232
6068d33b
AD
1233 disableHotkeys();
1234
d395a942
AD
1235 notify("");
1236 } catch (e) {
1237 exception_error("infobox_callback2", e);
442d77f1
AD
1238 }
1239}
1240
18ab3d7a 1241function createFilter() {
7b5c6012 1242
438f2ce9 1243 try {
6068d33b 1244
438f2ce9
AD
1245 var form = document.forms['filter_add_form'];
1246 var reg_exp = form.reg_exp.value;
1247
1248 if (reg_exp == "") {
1249 alert(__("Can't add filter: nothing to match on."));
1250 return false;
1251 }
288487e4 1252
438f2ce9
AD
1253 var query = Form.serialize("filter_add_form");
1254
1255 // we can be called from some other tab in Prefs
1256 if (typeof active_tab != 'undefined' && active_tab) {
1257 active_tab = "filterConfig";
1258 }
1259
1260 new Ajax.Request("backend.php?" + query, {
1261 onComplete: function (transport) {
1262 infobox_submit_callback2(transport);
1263 } });
1264
1265 return true;
1266
1267 } catch (e) {
1268 exception_error("createFilter", e);
1269 }
7b5c6012
AD
1270}
1271
2371c520
AD
1272function toggleSubmitNotEmpty(e, submit_id) {
1273 try {
1274 document.getElementById(submit_id).disabled = (e.value == "")
1275 } catch (e) {
1276 exception_error("toggleSubmitNotEmpty", e);
1277 }
1278}
1d7bf5a0 1279
605f7d46 1280function isValidURL(s) {
0d32b41e 1281 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
605f7d46 1282}
07eb9178 1283
18ab3d7a 1284function subscribeToFeed() {
07eb9178 1285
c91c2249
AD
1286 var form = document.forms['feed_add_form'];
1287 var feed_url = form.feed_url.value;
1288
1289 if (feed_url == "") {
89cb787e 1290 alert(__("Can't subscribe: no feed URL given."));
c91c2249
AD
1291 return false;
1292 }
1293
1ba6daf7 1294 notify_progress(__("Subscribing to feed..."), true);
07eb9178
AD
1295
1296 closeInfoBox();
1297
0feab655 1298 var feeds_doc = document;
07eb9178 1299
80e4dc34 1300// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1301
1302 var query = Form.serialize("feed_add_form");
1303
f27de515
AD
1304 debug("subscribe q: " + query);
1305
288487e4
AD
1306 new Ajax.Request("backend.php", {
1307 parameters: query,
1308 onComplete: function(transport) {
1309 dlg_frefresh_callback(transport);
1310 } });
7bc4f251
AD
1311
1312 return false;
07eb9178
AD
1313}
1314
6e6504bc 1315function filterCR(e, f)
86b682ce
AD
1316{
1317 var key;
1318
1319 if(window.event)
1320 key = window.event.keyCode; //IE
1321 else
1322 key = e.which; //firefox
1323
6e6504bc
AD
1324 if (key == 13) {
1325 if (typeof f != 'undefined') {
1326 f();
1327 return false;
1328 } else {
1329 return false;
1330 }
1331 } else {
1332 return true;
1333 }
86b682ce
AD
1334}
1335
e8614131
AD
1336var debug_last_class = "even";
1337
ac378ad4 1338function debug(msg) {
ac378ad4 1339
0feab655
AD
1340 if (debug_last_class == "even") {
1341 debug_last_class = "odd";
e8614131 1342 } else {
0feab655 1343 debug_last_class = "even";
e8614131
AD
1344 }
1345
0feab655 1346 var c = document.getElementById('debug_output');
8836613c 1347 if (c && Element.visible(c)) {
c9268ed5 1348 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1349 c.removeChild(c.lastChild);
1350 }
1351
1352 var d = new Date();
1353 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1354 ":" + leading_zero(d.getSeconds());
0feab655 1355 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1356 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1357 }
1358}
1359
33d13e72 1360function getInitParam(key) {
40496720 1361 return init_params[key];
33d13e72 1362}
3ac2b520 1363
be0801a1 1364function storeInitParam(key, value) {
40496720 1365 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
5158ced9 1366 init_params[key] = value;
be0801a1
AD
1367}
1368
a7565293
AD
1369function fatalError(code, message) {
1370 try {
a7565293 1371
b4c27af7 1372 if (code == 6) {
8e849206 1373 window.location.href = "tt-rss.php";
b4c27af7
AD
1374 } else if (code == 5) {
1375 window.location.href = "update.php";
1376 } else {
4724a093
AD
1377 var fe = document.getElementById("fatal_error");
1378 var fc = document.getElementById("fatal_error_msg");
1379
42c32916
AD
1380 if (message == "") message = "Unknown error";
1381
a0a63217 1382 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
4724a093
AD
1383
1384 fe.style.display = "block";
4724a093 1385 }
a7565293
AD
1386
1387 } catch (e) {
1388 exception_error("fatalError", e);
1389 }
1390}
1391
234e467c 1392function getFeedName(id, is_cat) {
234e467c
AD
1393 var e;
1394
1395 if (is_cat) {
5fc13f63 1396 e = document.getElementById("FCATN-" + id);
234e467c 1397 } else {
5fc13f63 1398 e = document.getElementById("FEEDN-" + id);
234e467c 1399 }
64a2875d
AD
1400 if (e) {
1401 return e.innerHTML.stripTags();
1402 } else {
1403 return null;
1404 }
1405}
0bd411db 1406
350f0ad1
AD
1407function filterDlgCheckAction(sender) {
1408
1409 try {
1410
1411 var action = sender[sender.selectedIndex].value;
1412
1413 var form = document.forms["filter_add_form"];
1414
1415 if (!form) {
1416 form = document.forms["filter_edit_form"];
1417 }
1418
1419 if (!form) {
1420 debug("filterDlgCheckAction: can't find form!");
1421 return;
1422 }
1423
1424 var action_param = form.action_param;
1425
1426 if (!action_param) {
1427 debug("filterDlgCheckAction: can't find action param!");
1428 return;
1429 }
1430
1431 // if selected action supports parameters, enable params field
48ddbb33 1432 if (action == 4 || action == 6) {
350f0ad1
AD
1433 action_param.disabled = false;
1434 } else {
1435 action_param.disabled = true;
1436 }
1437
1438 } catch (e) {
438f2ce9 1439 exception_error("filterDlgCheckAction", e);
350f0ad1
AD
1440 }
1441
1442}
ef16ae37
AD
1443
1444function explainError(code) {
1445 return displayDlg("explainError", code);
1446}
01a87dff 1447
e097e8be 1448// this only searches loaded headlines list, not in CDM
aa0fa9df 1449function getRelativePostIds(id, limit) {
e097e8be 1450
aa0fa9df
AD
1451 if (!limit) limit = 3;
1452
1453 debug("getRelativePostIds: " + id + " limit=" + limit);
e097e8be
AD
1454
1455 var ids = new Array();
1456 var container = document.getElementById("headlinesList");
1457
1458 if (container) {
1459 var rows = container.rows;
1460
1461 for (var i = 0; i < rows.length; i++) {
1462 var r_id = rows[i].id.replace("RROW-", "");
1463
1464 if (r_id == id) {
aa0fa9df
AD
1465 for (var k = 1; k <= limit; k++) {
1466 var nid = false;
1467
1468 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1469 if (nid) ids.push(nid);
1470
1471 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1472 if (nid) ids.push(nid);
1473 }
e097e8be
AD
1474
1475 return ids;
1476 }
1477 }
1478 }
1479
1480 return false;
1481}
298f3f78
AD
1482
1483function openArticleInNewWindow(id) {
1484 try {
298f3f78
AD
1485 debug("openArticleInNewWindow: " + id);
1486
1487 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
04e91733
AD
1488 var wname = "ttrss_article_" + id;
1489
1490 debug(query + " " + wname);
1491
1492 var w = window.open("", wname);
298f3f78 1493
04e91733 1494 if (!w) notify_error("Failed to open window for the article");
298f3f78 1495
d395a942
AD
1496 new Ajax.Request(query, {
1497 onComplete: function(transport) {
1498 open_article_callback(transport);
1499 } });
1500
298f3f78
AD
1501
1502 } catch (e) {
1503 exception_error("openArticleInNewWindow", e);
1504 }
1505}
e4914b62 1506
537625c6
AD
1507/* http://textsnippets.com/posts/show/835 */
1508
1509Position.GetWindowSize = function(w) {
1510 w = w ? w : window;
1511 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1512 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1513 return [width, height]
1514}
1515
1516/* http://textsnippets.com/posts/show/836 */
1517
1518Position.Center = function(element, parent) {
1519 var w, h, pw, ph;
1520 var d = Element.getDimensions(element);
1521 w = d.width;
1522 h = d.height;
1523 Position.prepare();
1524 if (!parent) {
1525 var ws = Position.GetWindowSize();
1526 pw = ws[0];
1527 ph = ws[1];
1528 } else {
1529 pw = parent.offsetWidth;
1530 ph = parent.offsetHeight;
1531 }
1532 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1533 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1534}
1535
768858f1 1536
288487e4
AD
1537function labeltest_callback(transport) {
1538 try {
1539 var container = document.getElementById('label_test_result');
1540
1541 container.innerHTML = transport.responseText;
768858f1
AD
1542 if (!Element.visible(container)) {
1543 Effect.SlideDown(container, { duration : 0.5 });
1544 }
288487e4 1545
6f151277 1546 notify("");
288487e4
AD
1547 } catch (e) {
1548 exception_error("labeltest_callback", e);
6f151277
AD
1549 }
1550}
1551
1552function labelTest() {
1553
288487e4
AD
1554 try {
1555 var container = document.getElementById('label_test_result');
1556
1557 var form = document.forms['label_edit_form'];
1558
1559 var sql_exp = form.sql_exp.value;
1560 var description = form.description.value;
1561
1562 notify_progress("Loading, please wait...");
1563
1564 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1565 param_escape(sql_exp) + "&descr=" + param_escape(description);
1566
1567 new Ajax.Request(query, {
1568 onComplete: function (transport) {
1569 labeltest_callback(transport);
1570 } });
1571
1572 return false;
6f151277 1573
288487e4
AD
1574 } catch (e) {
1575 exception_error("labelTest", e);
1576 }
6f151277
AD
1577}
1578
c32cd48a
AD
1579function isCdmMode() {
1580 return !document.getElementById("headlinesList");
1581}
1582
1583function getSelectedArticleIds2() {
1584 var rows = new Array();
1585 var cdm_mode = isCdmMode();
1586
1587 if (cdm_mode) {
1588 rows = cdmGetSelectedArticles();
1589 } else {
1590 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1591 }
1592
1593 var ids = new Array();
1594
1595 for (var i = 0; i < rows.length; i++) {
1596 var chk = document.getElementById("RCHK-" + rows[i]);
1597 if (chk && chk.checked) {
1598 ids.push(rows[i]);
1599 }
1600 }
1601
1602 return ids;
1603}
c4a36709 1604
f6d40ed2 1605function displayHelpInfobox(topic_id) {
c4a36709 1606
f6d40ed2
AD
1607 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1608
1609 var w = window.open(url, "ttrss_help",
1610 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1611
1612 return false;
1613}
e635d56a 1614
477402d8 1615function focus_element(id) {
61992f57 1616 try {
477402d8
AD
1617 var e = document.getElementById(id);
1618 if (e) e.focus();
61992f57 1619 } catch (e) {
438f2ce9 1620 exception_error("focus_element", e);
61992f57 1621 }
477402d8 1622 return false;
61992f57 1623}
e635d56a 1624
99509451 1625function loading_set_progress(p) {
730dbf19 1626 try {
fca95d5f
AD
1627 if (p < last_progress_point || !Element.visible("overlay")) return;
1628
1629 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
99509451 1630
730dbf19 1631 var o = document.getElementById("l_progress_i");
99509451 1632
673c9946
AD
1633// o.style.width = (p * 2) + "px";
1634
99509451
AD
1635 new Effect.Scale(o, p, {
1636 scaleY : false,
1637 scaleFrom : last_progress_point,
1638 scaleMode: { originalWidth : 200 },
673c9946 1639 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
99509451
AD
1640
1641 last_progress_point = p;
730dbf19
AD
1642
1643 } catch (e) {
1644 exception_error("loading_set_progress", e);
1645 }
1646}
08827aaf
AD
1647
1648function remove_splash() {
1649 if (Element.visible("overlay")) {
1650 debug("about to remove splash, OMG!");
1651 Element.hide("overlay");
1652 debug("removed splash!");
1653 }
1654}