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