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