]> git.wh0rd.org - tt-rss.git/blame - functions.js
css: more font size tweaking
[tt-rss.git] / functions.js
CommitLineData
760966c1 1var hotkeys_enabled = true;
730dbf19 2var notify_silent = false;
99509451 3var last_progress_point = 0;
6cc1fab3 4var async_counters_work = false;
61992f57 5
b07b61da
AD
6/* add method to remove element from array */
7
8Array.prototype.remove = function(s) {
9 for (var i=0; i < this.length; i++) {
10 if (s == this[i]) this.splice(i, 1);
11 }
12}
13
7c620da8 14function is_opera() {
ee8768db 15 return window.opera;
583c58b8
AD
16}
17
273d1e29 18function exception_error(location, e, ext_info) {
e8a429e3 19 var msg = format_exception_error(location, e);
e8a429e3 20
91743a49
AD
21 if (!ext_info) ext_info = "N/A";
22
e8a429e3
AD
23 disableHotkeys();
24
273d1e29 25 try {
e8a429e3 26
acac8448 27 var ebc = $("xebContent");
273d1e29
AD
28
29 if (ebc) {
30
31 Element.show("dialog_overlay");
32 Element.show("errorBoxShadow");
33
34 if (ext_info) {
35 if (ext_info.responseText) {
36 ext_info = ext_info.responseText;
37 }
e8a429e3 38 }
273d1e29
AD
39
40 ebc.innerHTML =
41 "<div><b>Error message:</b></div>" +
42 "<pre>" + msg + "</pre>" +
43 "<div><b>Additional information:</b></div>" +
44 "<textarea readonly=\"1\">" + ext_info + "</textarea>";
45
46 } else {
47 alert(msg);
e8a429e3
AD
48 }
49
273d1e29 50 } catch (e) {
e8a429e3 51 alert(msg);
e8a429e3 52
e8a429e3 53 }
273d1e29 54
e8a429e3
AD
55}
56
57function format_exception_error(location, e) {
83f043bb
AD
58 var msg;
59
60 if (e.fileName) {
61 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
62
63 msg = "Exception: " + e.name + ", " + e.message +
64 "\nFunction: " + location + "()" +
65 "\nLocation: " + base_fname + ":" + e.lineNumber;
f74cfded
AD
66
67 } else if (e.description) {
68 msg = "Exception: " + e.description + "\nFunction: " + location + "()";
83f043bb
AD
69 } else {
70 msg = "Exception: " + e + "\nFunction: " + location + "()";
71 }
72
ee1f45f4
AD
73 debug("<b>EXCEPTION: " + msg + "</b>");
74
e8a429e3 75 return msg;
7719618b
AD
76}
77
e8a429e3 78
760966c1
AD
79function disableHotkeys() {
80 hotkeys_enabled = false;
81}
82
83function enableHotkeys() {
84 hotkeys_enabled = true;
85}
86
d395a942
AD
87function open_article_callback(transport) {
88 try {
298f3f78 89
d395a942 90 if (transport.responseXML) {
06925d9e 91
d395a942
AD
92 var link = transport.responseXML.getElementsByTagName("link")[0];
93 var id = transport.responseXML.getElementsByTagName("id")[0];
298f3f78 94
06925d9e
AD
95 debug("open_article_callback, received link: " + link);
96
04e91733 97 if (link && id) {
06925d9e 98
04e91733
AD
99 var wname = "ttrss_article_" + id.firstChild.nodeValue;
100
101 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
102
103 var w = window.open(link.firstChild.nodeValue, wname);
4298481d
AD
104
105 if (!w) { notify_error("Failed to load article in new window"); }
e2ccbfab 106
d395a942
AD
107 if (id) {
108 id = id.firstChild.nodeValue;
acac8448 109 if (!$("headlinesList")) {
d395a942 110 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
e2ccbfab 111 }
298f3f78 112 }
06925d9e
AD
113 } else {
114 notify_error("Can't open article: received invalid article link");
298f3f78 115 }
06925d9e
AD
116 } else {
117 notify_error("Can't open article: received invalid XML");
01a87dff 118 }
01a87dff 119
d395a942
AD
120 } catch (e) {
121 exception_error("open_article_callback", e);
9cfc649a
AD
122 }
123}
124
7726fa02
AD
125function param_escape(arg) {
126 if (typeof encodeURIComponent != 'undefined')
127 return encodeURIComponent(arg);
128 else
129 return escape(arg);
130}
131
132function param_unescape(arg) {
133 if (typeof decodeURIComponent != 'undefined')
134 return decodeURIComponent(arg);
135 else
136 return unescape(arg);
137}
138
508a81e1
AD
139function delay(gap) {
140 var then,now;
141 then=new Date().getTime();
142 now=then;
143 while((now-then)<gap) {
144 now=new Date().getTime();
145 }
146}
7726fa02 147
ce3bf408 148var notify_hide_timerid = false;
59a543f0 149
ce3bf408 150function hide_notify() {
acac8448 151 var n = $("notify");
42c32916 152 if (n) {
d05514a4 153 n.style.display = "none";
8dcfffd0 154 }
d05514a4 155}
c05608c2 156
730dbf19
AD
157function notify_silent_next() {
158 notify_silent = true;
159}
160
42c32916 161function notify_real(msg, no_hide, n_type) {
7726fa02 162
730dbf19
AD
163 if (notify_silent) {
164 notify_silent = false;
165 return;
166 }
167
acac8448
AD
168 var n = $("notify");
169 var nb = $("notify_body");
7726fa02 170
c05608c2 171 if (!n || !nb) return;
f0601b87 172
0655a1d5
AD
173 if (notify_hide_timerid) {
174 window.clearTimeout(notify_hide_timerid);
175 }
176
8dcfffd0 177 if (msg == "") {
0655a1d5
AD
178 if (n.style.display == "block") {
179 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
180 }
181 return;
7726fa02 182 } else {
0ceded7a 183 n.style.display = "block";
8dcfffd0 184 }
7726fa02 185
42c32916
AD
186 /* types:
187
188 1 - generic
189 2 - progress
190 3 - error
191 4 - info
192
193 */
194
f3977cf5
AD
195 if (typeof __ != 'undefined') {
196 msg = __(msg);
197 }
198
42c32916
AD
199 if (n_type == 1) {
200 n.className = "notify";
201 } else if (n_type == 2) {
202 n.className = "notifyProgress";
203 msg = "<img src='images/indicator_white.gif'> " + msg;
204 } else if (n_type == 3) {
f407c086 205 n.className = "notifyError";
e780d1d2 206 msg = "<img src='images/sign_excl.gif'> " + msg;
42c32916
AD
207 } else if (n_type == 4) {
208 n.className = "notifyInfo";
e780d1d2 209 msg = "<img src='images/sign_info.gif'> " + msg;
0530ddd8
AD
210 }
211
106689b0
AD
212// msg = "<img src='images/live_com_loading.gif'> " + msg;
213
0ceded7a
AD
214 nb.innerHTML = msg;
215
4d4200a8 216 if (!no_hide) {
292a8a12 217 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 218 }
ce3bf408
AD
219}
220
42c32916
AD
221function notify(msg, no_hide) {
222 notify_real(msg, no_hide, 1);
ce3bf408
AD
223}
224
42c32916
AD
225function notify_progress(msg, no_hide) {
226 notify_real(msg, no_hide, 2);
227}
228
229function notify_error(msg, no_hide) {
230 notify_real(msg, no_hide, 3);
231
232}
233
234function notify_info(msg, no_hide) {
235 notify_real(msg, no_hide, 4);
7726fa02
AD
236}
237
508a81e1 238function printLockingError() {
42c32916
AD
239 notify_info("Please wait until operation finishes.");
240}
508a81e1 241
e828e31e 242function cleanSelected(element) {
acac8448 243 var content = $(element);
f0601b87
AD
244
245 for (i = 0; i < content.rows.length; i++) {
246 content.rows[i].className = content.rows[i].className.replace("Selected", "");
247 }
f0601b87
AD
248}
249
250function getVisibleUnreadHeadlines() {
acac8448 251 var content = $("headlinesList");
f0601b87
AD
252
253 var rows = new Array();
254
3a40e8a2
AD
255 if (!content) return rows;
256
f0601b87
AD
257 for (i = 0; i < content.rows.length; i++) {
258 var row_id = content.rows[i].id.replace("RROW-", "");
259 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
260 rows.push(row_id);
261 }
262 }
263 return rows;
264}
265
266function getVisibleHeadlineIds() {
267
acac8448 268 var content = $("headlinesList");
f0601b87
AD
269
270 var rows = new Array();
271
3a40e8a2
AD
272 if (!content) return rows;
273
f0601b87
AD
274 for (i = 0; i < content.rows.length; i++) {
275 var row_id = content.rows[i].id.replace("RROW-", "");
276 if (row_id.length > 0) {
277 rows.push(row_id);
278 }
279 }
280 return rows;
281}
282
283function getFirstVisibleHeadlineId() {
5ad9d132
AD
284 if (isCdmMode()) {
285 var rows = cdmGetVisibleArticles();
286 return rows[0];
287 } else {
288 var rows = getVisibleHeadlineIds();
289 return rows[0];
290 }
f0601b87
AD
291}
292
293function getLastVisibleHeadlineId() {
5ad9d132
AD
294 if (isCdmMode()) {
295 var rows = cdmGetVisibleArticles();
296 return rows[rows.length-1];
297 } else {
298 var rows = getVisibleHeadlineIds();
299 return rows[rows.length-1];
300 }
f0601b87
AD
301}
302
303function markHeadline(id) {
acac8448 304 var row = $("RROW-" + id);
f0601b87 305 if (row) {
35f3c923
AD
306 var is_active = false;
307
308 if (row.className.match("Active")) {
309 is_active = true;
310 }
311 row.className = row.className.replace("Selected", "");
312 row.className = row.className.replace("Active", "");
313 row.className = row.className.replace("Insensitive", "");
314
315 if (is_active) {
316 row.className = row.className = "Active";
317 }
318
acac8448 319 var check = $("RCHK-" + id);
72020095
AD
320
321 if (check) {
322 check.checked = true;
323 }
324
35f3c923
AD
325 row.className = row.className + "Selected";
326
f0601b87
AD
327 }
328}
329
330function getFeedIds() {
acac8448 331 var content = $("feedsList");
f0601b87
AD
332
333 var rows = new Array();
334
335 for (i = 0; i < content.rows.length; i++) {
336 var id = content.rows[i].id.replace("FEEDR-", "");
337 if (id.length > 0) {
338 rows.push(id);
339 }
340 }
341
342 return rows;
343}
13ad9102 344
76b4eae1
AD
345function setCookie(name, value, lifetime, path, domain, secure) {
346
347 var d = false;
348
349 if (lifetime) {
350 d = new Date();
be0801a1 351 d.setTime(d.getTime() + (lifetime * 1000));
76b4eae1 352 }
cdbb6dc6
AD
353
354 debug("setCookie: " + name + " => " + value + ": " + d);
76b4eae1
AD
355
356 int_setCookie(name, value, d, path, domain, secure);
357
358}
359
360function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
361 document.cookie= name + "=" + escape(value) +
362 ((expires) ? "; expires=" + expires.toGMTString() : "") +
363 ((path) ? "; path=" + path : "") +
364 ((domain) ? "; domain=" + domain : "") +
365 ((secure) ? "; secure" : "");
366}
367
76b4eae1
AD
368function delCookie(name, path, domain) {
369 if (getCookie(name)) {
370 document.cookie = name + "=" +
371 ((path) ? ";path=" + path : "") +
372 ((domain) ? ";domain=" + domain : "" ) +
373 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
374 }
375}
376
377
ac43eba1
AD
378function getCookie(name) {
379
380 var dc = document.cookie;
381 var prefix = name + "=";
382 var begin = dc.indexOf("; " + prefix);
383 if (begin == -1) {
384 begin = dc.indexOf(prefix);
385 if (begin != 0) return null;
386 }
387 else {
388 begin += 2;
389 }
390 var end = document.cookie.indexOf(";", begin);
391 if (end == -1) {
392 end = dc.length;
393 }
394 return unescape(dc.substring(begin + prefix.length, end));
395}
396
1a66d16e
AD
397function disableContainerChildren(id, disable, doc) {
398
399 if (!doc) doc = document;
400
acac8448 401 var container = $(id);
ac43eba1 402
4220b0bd
AD
403 if (!container) {
404 //alert("disableContainerChildren: element " + id + " not found");
405 return;
406 }
407
ac43eba1
AD
408 for (var i = 0; i < container.childNodes.length; i++) {
409 var child = container.childNodes[i];
410
d5224f0d
AD
411 try {
412 child.disabled = disable;
413 } catch (E) {
414
415 }
ac43eba1
AD
416
417 if (disable) {
418 if (child.className && child.className.match("button")) {
419 child.className = "disabledButton";
420 }
421 } else {
422 if (child.className && child.className.match("disabledButton")) {
423 child.className = "button";
424 }
d5224f0d 425 }
ac43eba1
AD
426 }
427
428}
7726fa02 429
e828e31e
AD
430function gotoPreferences() {
431 document.location.href = "prefs.php";
432}
433
434function gotoMain() {
435 document.location.href = "tt-rss.php";
436}
437
8158c57a
AD
438function gotoExportOpml() {
439 document.location.href = "opml.php?op=Export";
440}
86741347 441
ac378ad4 442function parse_counters(reply, scheduled_call) {
1a6a9555 443 try {
ac378ad4 444
9e397d0f
AD
445 var feeds_found = 0;
446
85bd574b 447 var elems = reply.getElementsByTagName("counter");
f54f515f 448
85bd574b 449 for (var l = 0; l < elems.length; l++) {
6043fb7e 450
85bd574b
AD
451 var id = elems[l].getAttribute("id");
452 var t = elems[l].getAttribute("type");
453 var ctr = elems[l].getAttribute("counter");
454 var error = elems[l].getAttribute("error");
455 var has_img = elems[l].getAttribute("hi");
456 var updated = elems[l].getAttribute("updated");
4ffa126e 457 var title = elems[l].getAttribute("title");
bdb7369b
AD
458 var xmsg = elems[l].getAttribute("xmsg");
459
1a6a9555 460 if (id == "global-unread") {
0cd6bb46 461
65c0779b
AD
462 if (ctr > global_unread) {
463 offlineDownloadStart(1);
0cd6bb46
AD
464 }
465
0feab655
AD
466 global_unread = ctr;
467 updateTitle();
1a6a9555
AD
468 continue;
469 }
7bf7e4d3
AD
470
471 if (id == "subscribed-feeds") {
472 feeds_found = ctr;
473 continue;
474 }
1a6a9555
AD
475
476 if (t == "category") {
acac8448 477 var catctr = $("FCATCTR-" + id);
1a6a9555 478 if (catctr) {
67dabe1a
AD
479 catctr.innerHTML = "(" + ctr + ")";
480 if (ctr > 0) {
481 catctr.className = "catCtrHasUnread";
482 } else {
483 catctr.className = "catCtrNoUnread";
484 }
1a6a9555
AD
485 }
486 continue;
487 }
488
acac8448
AD
489 var feedctr = $("FEEDCTR-" + id);
490 var feedu = $("FEEDU-" + id);
491 var feedr = $("FEEDR-" + id);
492 var feed_img = $("FIMG-" + id);
493 var feedlink = $("FEEDL-" + id);
494 var feedupd = $("FLUPD-" + id);
fb1fb4ab
AD
495
496 if (updated && feedlink) {
497 if (error) {
498 feedlink.title = "Error: " + error + " (" + updated + ")";
499 } else {
500 feedlink.title = "Updated: " + updated;
501 }
502 }
023fe037 503
bdb7369b
AD
504 if (feedupd) {
505 if (!updated) updated = "";
506
78d5212c 507 if (error) {
bdb7369b
AD
508 if (xmsg) {
509 feedupd.innerHTML = updated + " " + xmsg + " (Error)";
510 } else {
511 feedupd.innerHTML = updated + " (Error)";
512 }
78d5212c 513 } else {
bdb7369b
AD
514 if (xmsg) {
515 feedupd.innerHTML = updated + " " + xmsg;
516 } else {
517 feedupd.innerHTML = updated;
518 }
78d5212c
AD
519 }
520 }
521
f74cfded 522 if (has_img && feed_img) {
f780548a
AD
523 if (!feed_img.src.match(id + ".ico")) {
524 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
525 }
527c3bf0
AD
526 }
527
4ffa126e
AD
528 if (feedlink && title) {
529 feedlink.innerHTML = title;
530 }
531
1a6a9555 532 if (feedctr && feedu && feedr) {
e8ef3b97 533
0ac73f91
AD
534 if (parseInt(ctr) > 0 &&
535 parseInt(feedu.innerHTML) < parseInt(ctr) &&
536 id == getActiveFeedId() && scheduled_call) {
537
37e93d6c 538 displayNewContentPrompt(id);
e8ef3b97 539 }
8e9141ed
AD
540
541 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
542
1a6a9555 543 feedu.innerHTML = ctr;
023fe037 544
426d3c57
AD
545 if (error) {
546 feedr.className = feedr.className.replace("feed", "error");
547 } else if (id > 0) {
548 feedr.className = feedr.className.replace("error", "feed");
023fe037 549 }
1a6a9555
AD
550
551 if (ctr > 0) {
d7e83df7 552 feedctr.className = "feedCtrHasUnread";
1a6a9555
AD
553 if (!feedr.className.match("Unread")) {
554 var is_selected = feedr.className.match("Selected");
555
556 feedr.className = feedr.className.replace("Selected", "");
557 feedr.className = feedr.className.replace("Unread", "");
558
559 feedr.className = feedr.className + "Unread";
560
561 if (is_selected) {
562 feedr.className = feedr.className + "Selected";
8e9141ed
AD
563 }
564
565 }
566
567 if (row_needs_hl) {
1341ea0d
AD
568 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
569 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
d9d0db0f
AD
570
571 cache_invalidate("F:" + id);
1a6a9555
AD
572 }
573 } else {
d7e83df7 574 feedctr.className = "feedCtrNoUnread";
1a6a9555
AD
575 feedr.className = feedr.className.replace("Unread", "");
576 }
577 }
578 }
9e397d0f 579
60ea2377 580 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
7553dd8b 581
0feab655 582 var feeds_stored = number_of_feeds;
9e397d0f
AD
583
584 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
585
586 if (feeds_stored != feeds_found) {
0feab655 587 number_of_feeds = feeds_found;
7bf7e4d3 588
2fe69e22 589 if (feeds_stored != 0 && feeds_found != 0) {
9e397d0f 590 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 591 setTimeout('updateFeedList(false, false)', 50);
9e397d0f 592 }
4f7743a9 593 } else {
acac8448 594/* var fl = $("feeds-frame").innerHTML;
3e2937fc
AD
595 if (fl) {
596 cache_invalidate("FEEDLIST");
597 cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
87b16a0a 598 } */
9e397d0f
AD
599 }
600
1a6a9555 601 } catch (e) {
83f043bb 602 exception_error("parse_counters", e);
1a6a9555
AD
603 }
604}
605
288487e4 606function parse_counters_reply(transport, scheduled_call) {
5854573a 607
288487e4 608 if (!transport.responseXML) {
42c32916 609 notify_error("Backend did not return valid XML", true);
5854573a
AD
610 return;
611 }
612
288487e4 613 var reply = transport.responseXML.firstChild;
5854573a
AD
614
615 if (!reply) {
42c32916 616 notify_error("Backend did not return expected XML object", true);
5854573a
AD
617 updateTitle("");
618 return;
619 }
5854573a 620
2184738a 621 if (!transport_error_check(transport)) return;
5854573a 622
36e05046 623 var counters = reply.getElementsByTagName("counters")[0];
5854573a 624
3ac2f3c7 625 parse_counters(counters, scheduled_call);
5854573a 626
36e05046 627 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
5854573a
AD
628
629 parse_runtime_info(runtime_info);
630
61a20560
AD
631 if (feedsSortByUnread()) {
632 resort_feedlist();
633 }
5854573a 634
60ea2377 635 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
5854573a
AD
636
637}
638
6cc1fab3 639function all_counters_callback2(transport, async_call) {
1341ea0d 640 try {
6cc1fab3 641 if (async_call) async_counters_work = true;
c8a9fe5b
AD
642
643 if (offline_mode) return;
6cc1fab3 644
1341ea0d
AD
645 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
646 parse_counters_reply(transport);
647 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
648
649 } catch (e) {
273d1e29 650 exception_error("all_counters_callback2", e, transport);
1341ea0d
AD
651 }
652}
653
8e9dd206
AD
654function get_feed_unread(id) {
655 try {
acac8448 656 return parseInt($("FEEDU-" + id).innerHTML);
8e9dd206 657 } catch (e) {
8e9dd206
AD
658 return -1;
659 }
660}
661
ec37f4f1
AD
662function get_cat_unread(id) {
663 try {
acac8448 664 var ctr = $("FCATCTR-" + id).innerHTML;
ec37f4f1
AD
665 ctr = ctr.replace("(", "");
666 ctr = ctr.replace(")", "");
667 return parseInt(ctr);
668 } catch (e) {
ec37f4f1
AD
669 return -1;
670 }
671}
672
60ea2377 673function get_feed_entry_unread(elem) {
c9268ed5
AD
674
675 var id = elem.id.replace("FEEDR-", "");
676
677 if (id <= 0) {
678 return -1;
679 }
680
681 try {
acac8448 682 return parseInt($("FEEDU-" + id).innerHTML);
c9268ed5
AD
683 } catch (e) {
684 return -1;
685 }
686}
687
61a20560
AD
688function get_feed_entry_name(elem) {
689 var id = elem.id.replace("FEEDR-", "");
690 return getFeedName(id);
691}
692
693
95d0edcc 694function resort_category(node, cat_mode) {
c9268ed5 695
d6586c1d 696 try {
61a20560 697
95d0edcc 698 debug("resort_category: " + node + " CM=" + cat_mode);
d6586c1d
AD
699
700 var by_unread = feedsSortByUnread();
701
702 var list = node.getElementsByTagName("LI");
703
704 for (i = 0; i < list.length; i++) {
705
706 for (j = i+1; j < list.length; j++) {
707
708 var tmp_val = get_feed_entry_unread(list[i]);
709 var cur_val = get_feed_entry_unread(list[j]);
710
711 var tmp_name = get_feed_entry_name(list[i]);
712 var cur_name = get_feed_entry_name(list[j]);
95d0edcc
AD
713
714 var valid_pair = cat_mode || (list[i].id.match(/FEEDR-[0-9]/) &&
715 list[j].id.match(/FEEDR-[0-9]/));
716
717 if (valid_pair && ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name)))) {
d6586c1d
AD
718 tempnode_i = list[i].cloneNode(true);
719 tempnode_j = list[j].cloneNode(true);
720 node.replaceChild(tempnode_i, list[j]);
721 node.replaceChild(tempnode_j, list[i]);
c9268ed5
AD
722 }
723 }
c9268ed5 724 }
d6586c1d
AD
725
726 } catch (e) {
727 exception_error("resort_category", e);
c9268ed5
AD
728 }
729
730}
731
732function resort_feedlist() {
733 debug("resort_feedlist");
734
acac8448 735 if ($("FCATLIST--1")) {
c9268ed5 736
60ea2377 737 var lists = document.getElementsByTagName("UL");
c9268ed5 738
60ea2377
AD
739 for (var i = 0; i < lists.length; i++) {
740 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
95d0edcc 741 resort_category(lists[i], true);
c9268ed5 742 }
c9268ed5
AD
743 }
744
745 } else {
95d0edcc 746 resort_category($("feedList"), false);
c9268ed5
AD
747 }
748}
749
b6644d29
AD
750/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
751 * * @author Sundar Dorai-Raj
752 * * Email: sdoraira@vt.edu
753 * * This program is free software; you can redistribute it and/or
754 * * modify it under the terms of the GNU General Public License
755 * * as published by the Free Software Foundation; either version 2
756 * * of the License, or (at your option) any later version,
757 * * provided that any use properly credits the author.
758 * * This program is distributed in the hope that it will be useful,
759 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
760 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
761 * * GNU General Public License for more details at http://www.gnu.org * * */
762
763 var numbers=".0123456789";
764 function isNumeric(x) {
765 // is x a String or a character?
766 if(x.length>1) {
767 // remove negative sign
768 x=Math.abs(x)+"";
769 for(j=0;j<x.length;j++) {
770 // call isNumeric recursively for each character
771 number=isNumeric(x.substring(j,j+1));
772 if(!number) return number;
773 }
774 return number;
775 }
776 else {
777 // if x is number return true
778 if(numbers.indexOf(x)>=0) return true;
779 return false;
780 }
781 }
782
3745788e 783
60ea2377 784function hideOrShowFeeds(hide) {
3745788e 785
60ea2377 786 try {
293fa942 787
60ea2377 788 debug("hideOrShowFeeds: " + hide);
293fa942 789
acac8448 790 if ($("FCATLIST--1")) {
293fa942 791
60ea2377 792 var lists = document.getElementsByTagName("UL");
293fa942 793
60ea2377
AD
794 for (var i = 0; i < lists.length; i++) {
795 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
293fa942 796
60ea2377
AD
797 var id = lists[i].id.replace("FCATLIST-", "");
798 hideOrShowFeedsCategory(id, hide);
293fa942 799 }
293fa942
AD
800 }
801
802 } else {
60ea2377 803 hideOrShowFeedsCategory(null, hide);
293fa942 804 }
293fa942 805
60ea2377
AD
806 } catch (e) {
807 exception_error("hideOrShowFeeds", e);
4724a093 808 }
60ea2377 809}
4724a093 810
60ea2377 811function hideOrShowFeedsCategory(id, hide) {
2c2b019b 812
60ea2377
AD
813 try {
814
815 var node = null;
816 var cat_node = null;
bbf4d0b2 817
60ea2377 818 if (id) {
acac8448
AD
819 node = $("FCATLIST-" + id);
820 cat_node = $("FCAT-" + id);
60ea2377 821 } else {
acac8448 822 node = $("feedList"); // no categories
60ea2377 823 }
293fa942 824
60ea2377 825 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
b31c2311 826
60ea2377 827 var cat_unread = 0;
b31c2311 828
60ea2377
AD
829 if (!node) {
830 debug("hideOrShowFeeds: passed node is null, aborting");
831 return;
832 }
b31c2311 833
60ea2377
AD
834 // debug("cat: " + node.id);
835
836 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
837 for (i = 0; i < node.childNodes.length; i++) {
838 if (node.childNodes[i].nodeName != "LI") { continue; }
b31c2311 839
60ea2377
AD
840 if (node.childNodes[i].style != undefined) {
841
842 var has_unread = (node.childNodes[i].className != "feed" &&
843 node.childNodes[i].className != "label" &&
844 !(!getInitParam("hide_read_shows_special") &&
845 node.childNodes[i].className == "virt") &&
846 node.childNodes[i].className != "error" &&
847 node.childNodes[i].className != "tag");
848
849 // debug(node.childNodes[i].id + " --> " + has_unread);
850
851 if (hide && !has_unread) {
852 //node.childNodes[i].style.display = "none";
853 var id = node.childNodes[i].id;
854 Effect.Fade(node.childNodes[i], {duration : 0.3,
855 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
856 }
857
858 if (!hide) {
859 node.childNodes[i].style.display = "list-item";
860 //Effect.Appear(node.childNodes[i], {duration : 0.3});
861 }
862
863 if (has_unread) {
864 node.childNodes[i].style.display = "list-item";
865 cat_unread++;
866 //Effect.Appear(node.childNodes[i], {duration : 0.3});
867 //Effect.Highlight(node.childNodes[i]);
868 }
b31c2311 869 }
293fa942 870 }
60ea2377
AD
871 }
872
873 // debug("end cat: " + node.id + " unread " + cat_unread);
f4ce1f83
AD
874
875 if (cat_node) {
876
877 if (cat_unread == 0) {
878 if (cat_node.style == undefined) {
879 debug("ERROR: supplied cat_node " + cat_node +
880 " has no styles. WTF?");
881 return;
882 }
883 if (hide) {
884 //cat_node.style.display = "none";
885 Effect.Fade(cat_node, {duration : 0.3,
886 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
887 } else {
888 cat_node.style.display = "list-item";
889 }
60ea2377 890 } else {
f4ce1f83
AD
891 try {
892 cat_node.style.display = "list-item";
893 } catch (e) {
894 debug(e);
895 }
60ea2377 896 }
0ac2faea 897 }
3745788e 898
293fa942 899// debug("unread for category: " + cat_unread);
60ea2377
AD
900
901 } catch (e) {
902 exception_error("hideOrShowFeedsCategory", e);
903 }
3745788e
AD
904}
905
35f3c923
AD
906function selectTableRow(r, do_select) {
907 r.className = r.className.replace("Selected", "");
908
909 if (do_select) {
910 r.className = r.className + "Selected";
911 }
912}
913
6c12c809
AD
914function selectTableRowById(elem_id, check_id, do_select) {
915
916 try {
917
acac8448 918 var row = $(elem_id);
6c12c809
AD
919
920 if (row) {
921 selectTableRow(row, do_select);
922 }
923
acac8448 924 var check = $(check_id);
6c12c809
AD
925
926 if (check) {
927 check.checked = do_select;
928 }
929 } catch (e) {
930 exception_error("selectTableRowById", e);
931 }
932}
933
1572afe5 934function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 935 classcheck, reset_others) {
3745788e 936
acac8448 937 var content = $(content_id);
35f3c923
AD
938
939 if (!content) {
940 alert("[selectTableRows] Element " + content_id + " not found.");
941 return;
942 }
943
944 for (i = 0; i < content.rows.length; i++) {
7a822893
AD
945 if (Element.visible(content.rows[i])) {
946 if (!classcheck || content.rows[i].className.match(classcheck)) {
947
948 if (content.rows[i].id.match(prefix)) {
949 selectTableRow(content.rows[i], do_select);
950
951 var row_id = content.rows[i].id.replace(prefix, "");
acac8448 952 var check = $(check_prefix + row_id);
7a822893
AD
953
954 if (check) {
955 check.checked = do_select;
956 }
957 } else if (reset_others) {
958 selectTableRow(content.rows[i], false);
959
960 var row_id = content.rows[i].id.replace(prefix, "");
acac8448 961 var check = $(check_prefix + row_id);
7a822893
AD
962
963 if (check) {
964 check.checked = false;
965 }
1572afe5 966
649e0af9
AD
967 }
968 } else if (reset_others) {
969 selectTableRow(content.rows[i], false);
7a822893 970
7d8d10c6 971 var row_id = content.rows[i].id.replace(prefix, "");
acac8448 972 var check = $(check_prefix + row_id);
7a822893 973
7d8d10c6
AD
974 if (check) {
975 check.checked = false;
976 }
7a822893 977
7d8d10c6 978 }
3055bc41 979 }
35f3c923 980 }
295f9b42 981}
91ff844a
AD
982
983function getSelectedTableRowIds(content_id, prefix) {
984
acac8448 985 var content = $(content_id);
91ff844a
AD
986
987 if (!content) {
988 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
989 return;
990 }
991
992 var sel_rows = new Array();
993
994 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
995 if (content.rows[i].id.match(prefix) &&
996 content.rows[i].className.match("Selected")) {
997
91ff844a
AD
998 var row_id = content.rows[i].id.replace(prefix + "-", "");
999 sel_rows.push(row_id);
1000 }
1001 }
1002
1003 return sel_rows;
1004
1005}
1006
386cbf27 1007function toggleSelectRowById(sender, id) {
acac8448 1008 var row = $(id);
386cbf27
AD
1009
1010 if (sender.checked) {
1011 if (!row.className.match("Selected")) {
1012 row.className = row.className + "Selected";
1013 }
1014 } else {
1015 if (row.className.match("Selected")) {
1016 row.className = row.className.replace("Selected", "");
1017 }
1018 }
1019}
1020
b92e6209
AD
1021function toggleSelectListRow(sender) {
1022 var parent_row = sender.parentNode;
1023
1024 if (sender.checked) {
1025 if (!parent_row.className.match("Selected")) {
1026 parent_row.className = parent_row.className + "Selected";
1027 }
1028 } else {
1029 if (parent_row.className.match("Selected")) {
1030 parent_row.className = parent_row.className.replace("Selected", "");
1031 }
1032 }
1033}
1034
67343d9f
AD
1035function tSR(sender) {
1036 return toggleSelectRow(sender);
1037}
386cbf27 1038
1572afe5
AD
1039function toggleSelectRow(sender) {
1040 var parent_row = sender.parentNode.parentNode;
1041
1042 if (sender.checked) {
1043 if (!parent_row.className.match("Selected")) {
1044 parent_row.className = parent_row.className + "Selected";
1045 }
1046 } else {
1047 if (parent_row.className.match("Selected")) {
1048 parent_row.className = parent_row.className.replace("Selected", "");
1049 }
1050 }
1051}
1052
f46192bb
AD
1053function getNextUnreadCat(id) {
1054 try {
acac8448 1055 var rows = $("feedList").getElementsByTagName("LI");
f46192bb
AD
1056 var feeds = new Array();
1057
1058 var unread_only = true;
1059 var is_cat = true;
1060
1061 for (var i = 0; i < rows.length; i++) {
1062 if (rows[i].id.match("FCAT-")) {
1063 if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1064
1065 var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
1066
1067 if (cat_id >= 0) {
1068 if (!unread_only || get_cat_unread(cat_id) > 0) {
1069 feeds.push(cat_id);
1070 }
1071 }
1072 }
1073 }
1074 }
1075
1076 var idx = feeds.indexOf(id);
1077 if (idx != -1 && idx < feeds.length) {
1078 return feeds[idx+1];
1079 } else {
1080 return feeds.shift();
1081 }
1082
1083 } catch (e) {
1084 exception_error("getNextUnreadCat", e);
1085 }
1086}
ec37f4f1
AD
1087
1088function getRelativeFeedId2(id, is_cat, direction, unread_only) {
1089 try {
1090
1091// alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
1092
acac8448 1093 var rows = $("feedList").getElementsByTagName("LI");
ec37f4f1
AD
1094 var feeds = new Array();
1095
1096 for (var i = 0; i < rows.length; i++) {
1097 if (rows[i].id.match("FEEDR-")) {
1098
1099 if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1100
1101 if (!unread_only ||
1102 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1103 feeds.push(rows[i].id.replace("FEEDR-", ""));
1104 }
1105 }
1106 }
1107
1108 if (rows[i].id.match("FCAT-")) {
1109 if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1110
1111 var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
1112
1113 if (cat_id >= 0) {
1114 if (!unread_only || get_cat_unread(cat_id) > 0) {
1115 feeds.push("CAT:"+cat_id);
1116 }
1117 }
1118 }
1119 }
1120 }
1121
1122// alert(feeds.toString());
1123
1124 if (!id) {
1125 if (direction == "next") {
1126 return feeds.shift();
1127 } else {
1128 return feeds.pop();
1129 }
1130 } else {
1131 if (direction == "next") {
1132 if (is_cat) id = "CAT:" + id;
1133 var idx = feeds.indexOf(id);
1134 if (idx != -1 && idx < feeds.length) {
1135 return feeds[idx+1];
1136 } else {
1137 return getRelativeFeedId2(false, is_cat, direction, unread_only);
1138 }
1139 } else {
1140 if (is_cat) id = "CAT:" + id;
1141 var idx = feeds.indexOf(id);
1142 if (idx > 0) {
1143 return feeds[idx-1];
1144 } else {
1145 return getRelativeFeedId2(false, is_cat, direction, unread_only);
1146 }
1147 }
1148
1149 }
1150
1151 } catch (e) {
1152 exception_error("getRelativeFeedId2", e);
1153 }
1154}
1155
1156
1da76274 1157function getRelativeFeedId(list, id, direction, unread_only) {
731b05f4
AD
1158 var rows = list.getElementsByTagName("LI");
1159 var feeds = new Array();
1160
1161 for (var i = 0; i < rows.length; i++) {
1162 if (rows[i].id.match("FEEDR-")) {
1163
8809f484 1164 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
731b05f4
AD
1165
1166 if (!unread_only ||
1167 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1168 feeds.push(rows[i].id.replace("FEEDR-", ""));
1169 }
1170 }
1171 }
1172 }
1173
7b433d8c 1174 if (!id) {
731b05f4
AD
1175 if (direction == "next") {
1176 return feeds.shift();
1177 } else {
1178 return feeds.pop();
1179 }
1180 } else {
1181 if (direction == "next") {
1182 var idx = feeds.indexOf(id);
1183 if (idx != -1 && idx < feeds.length) {
1184 return feeds[idx+1];
07a67863
AD
1185 } else {
1186 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1187 }
1188 } else {
1189 var idx = feeds.indexOf(id);
1190 if (idx > 0) {
1191 return feeds[idx-1];
07a67863
AD
1192 } else {
1193 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1194 }
1195 }
1196
1197 }
7b433d8c 1198}
36aab70f 1199
f27de515 1200function showBlockElement(id, h_id) {
acac8448 1201 var elem = $(id);
36aab70f
AD
1202
1203 if (elem) {
1204 elem.style.display = "block";
f27de515
AD
1205
1206 if (h_id) {
acac8448 1207 elem = $(h_id);
f27de515
AD
1208 if (elem) {
1209 elem.style.display = "none";
1210 }
1211 }
36aab70f
AD
1212 } else {
1213 alert("[showBlockElement] can't find element with id " + id);
1214 }
1215}
1216
b9073cd9
AD
1217function appearBlockElement_afh(effect) {
1218
1219}
1220
1221function checkboxToggleElement(elem, id) {
1222 if (elem.checked) {
ecace165 1223 Effect.Appear(id, {duration : 0.5});
b9073cd9 1224 } else {
ecace165 1225 Effect.Fade(id, {duration : 0.5});
b9073cd9
AD
1226 }
1227}
1228
1229function appearBlockElement(id, h_id) {
1230
1231 try {
a04c8e8d
AD
1232 if (h_id) {
1233 Effect.Fade(h_id);
1234 }
b9073cd9
AD
1235 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1236 } catch (e) {
1237 exception_error("appearBlockElement", e);
1238 }
1239
1240}
1241
a9b0bfd5
AD
1242function hideParentElement(e) {
1243 e.parentNode.style.display = "none";
1244}
1b0809ae
AD
1245
1246function dropboxSelect(e, v) {
1247 for (i = 0; i < e.length; i++) {
1248 if (e[i].value == v) {
1249 e.selectedIndex = i;
1250 break;
1251 }
1252 }
1253}
0ee1d1a0
AD
1254
1255// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1256// bugfixed just a little bit :-)
1257function getURLParam(strParamName){
1258 var strReturn = "";
1259 var strHref = window.location.href;
1260
1261 if (strHref.indexOf("#") == strHref.length-1) {
1262 strHref = strHref.substring(0, strHref.length-1);
1263 }
1264
1265 if ( strHref.indexOf("?") > -1 ){
1266 var strQueryString = strHref.substr(strHref.indexOf("?"));
1267 var aQueryString = strQueryString.split("&");
1268 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1269 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1270 var aParam = aQueryString[iParam].split("=");
1271 strReturn = aParam[1];
1272 break;
1273 }
1274 }
1275 }
1276 return strReturn;
1277}
1278
cf1bc085
AD
1279function leading_zero(p) {
1280 var s = String(p);
1281 if (s.length == 1) s = "0" + s;
1282 return s;
1283}
c38c2b69 1284
e8a429e3 1285function closeErrorBox() {
5ede560f 1286
273d1e29 1287 if (Element.visible("errorBoxShadow")) {
e8a429e3 1288 Element.hide("dialog_overlay");
273d1e29 1289 Element.hide("errorBoxShadow");
e5d758e3 1290
e8a429e3 1291 enableHotkeys();
e5d758e3
AD
1292 }
1293
e8a429e3
AD
1294 return false;
1295}
86b682ce 1296
e8a429e3
AD
1297function closeInfoBox(cleanup) {
1298
588e4dc3
AD
1299 try {
1300 enableHotkeys();
e8a429e3 1301
588e4dc3
AD
1302 if (Element.visible("infoBoxShadow")) {
1303 Element.hide("dialog_overlay");
1304 Element.hide("infoBoxShadow");
e8a429e3 1305
588e4dc3
AD
1306 if (cleanup) $("infoBoxShadow").innerHTML = "&nbsp;";
1307 }
1308 } catch (e) {
1309 exception_error("closeInfoBox", e);
e8a429e3 1310 }
588e4dc3 1311
90ac84df 1312 return false;
e5d758e3
AD
1313}
1314
1315
7b5c6012
AD
1316function displayDlg(id, param) {
1317
35a03bdd 1318 notify_progress("Loading, please wait...", true);
7b5c6012 1319
7b5c6012 1320 disableHotkeys();
2371c520 1321
b4e75b2a 1322 var query = "?op=dlg&id=" +
288487e4
AD
1323 param_escape(id) + "&param=" + param_escape(param);
1324
b4e75b2a
AD
1325 new Ajax.Request("backend.php", {
1326 parameters: query,
288487e4
AD
1327 onComplete: function (transport) {
1328 infobox_callback2(transport);
1329 } });
1330
90ac84df 1331 return false;
7b5c6012
AD
1332}
1333
288487e4
AD
1334function infobox_submit_callback2(transport) {
1335 closeInfoBox();
79f3553b 1336
288487e4
AD
1337 try {
1338 // called from prefs, reload tab
438f2ce9 1339 if (typeof active_tab != 'undefined' && active_tab) {
288487e4 1340 selectTab(active_tab, false);
5e6f933a 1341 }
288487e4 1342 } catch (e) { }
79f3553b 1343
288487e4
AD
1344 if (transport.responseText) {
1345 notify_info(transport.responseText);
1346 }
7b5c6012
AD
1347}
1348
d395a942
AD
1349function infobox_callback2(transport) {
1350 try {
5ede560f 1351
d395a942 1352 debug("infobox_callback2");
5ede560f 1353
acac8448 1354 var box = $('infoBox');
de85cac2 1355
d395a942 1356 if (box) {
1dc47c41 1357
de85cac2
AD
1358 if (!getInitParam("infobox_disable_overlay")) {
1359 Element.show("dialog_overlay");
aa8716da 1360 }
de85cac2
AD
1361
1362 box.innerHTML=transport.responseText;
1363 Element.show("infoBoxShadow");
1364 //Effect.SlideDown("infoBoxShadow", {duration : 1.0});
1365
1366
d395a942 1367 }
05fcdf52 1368
d395a942 1369 /* FIXME this needs to be moved out somewhere */
05fcdf52 1370
acac8448 1371 if ($("tags_choices")) {
d395a942
AD
1372 new Ajax.Autocompleter('tags_str', 'tags_choices',
1373 "backend.php?op=rpc&subop=completeTags",
1374 { tokens: ',', paramName: "search" });
442d77f1 1375 }
d395a942 1376
6068d33b
AD
1377 disableHotkeys();
1378
d395a942
AD
1379 notify("");
1380 } catch (e) {
1381 exception_error("infobox_callback2", e);
442d77f1
AD
1382 }
1383}
1384
18ab3d7a 1385function createFilter() {
7b5c6012 1386
438f2ce9 1387 try {
6068d33b 1388
438f2ce9
AD
1389 var form = document.forms['filter_add_form'];
1390 var reg_exp = form.reg_exp.value;
1391
1392 if (reg_exp == "") {
1393 alert(__("Can't add filter: nothing to match on."));
1394 return false;
1395 }
288487e4 1396
438f2ce9
AD
1397 var query = Form.serialize("filter_add_form");
1398
1399 // we can be called from some other tab in Prefs
1400 if (typeof active_tab != 'undefined' && active_tab) {
1401 active_tab = "filterConfig";
1402 }
1403
1404 new Ajax.Request("backend.php?" + query, {
1405 onComplete: function (transport) {
1406 infobox_submit_callback2(transport);
1407 } });
1408
1409 return true;
1410
1411 } catch (e) {
1412 exception_error("createFilter", e);
1413 }
7b5c6012
AD
1414}
1415
2371c520
AD
1416function toggleSubmitNotEmpty(e, submit_id) {
1417 try {
acac8448 1418 $(submit_id).disabled = (e.value == "")
2371c520
AD
1419 } catch (e) {
1420 exception_error("toggleSubmitNotEmpty", e);
1421 }
1422}
1d7bf5a0 1423
605f7d46 1424function isValidURL(s) {
0d32b41e 1425 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
605f7d46 1426}
07eb9178 1427
18ab3d7a 1428function subscribeToFeed() {
07eb9178 1429
c91c2249
AD
1430 var form = document.forms['feed_add_form'];
1431 var feed_url = form.feed_url.value;
1432
1433 if (feed_url == "") {
89cb787e 1434 alert(__("Can't subscribe: no feed URL given."));
c91c2249
AD
1435 return false;
1436 }
1437
1ba6daf7 1438 notify_progress(__("Subscribing to feed..."), true);
07eb9178
AD
1439
1440 closeInfoBox();
1441
0feab655 1442 var feeds_doc = document;
07eb9178 1443
80e4dc34 1444// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1445
1446 var query = Form.serialize("feed_add_form");
1447
f27de515
AD
1448 debug("subscribe q: " + query);
1449
288487e4
AD
1450 new Ajax.Request("backend.php", {
1451 parameters: query,
1452 onComplete: function(transport) {
1453 dlg_frefresh_callback(transport);
1454 } });
7bc4f251
AD
1455
1456 return false;
07eb9178
AD
1457}
1458
6e6504bc 1459function filterCR(e, f)
86b682ce
AD
1460{
1461 var key;
1462
1463 if(window.event)
1464 key = window.event.keyCode; //IE
1465 else
1466 key = e.which; //firefox
1467
6e6504bc
AD
1468 if (key == 13) {
1469 if (typeof f != 'undefined') {
1470 f();
1471 return false;
1472 } else {
1473 return false;
1474 }
1475 } else {
1476 return true;
1477 }
86b682ce
AD
1478}
1479
e8614131
AD
1480var debug_last_class = "even";
1481
ac378ad4 1482function debug(msg) {
ac378ad4 1483
0feab655
AD
1484 if (debug_last_class == "even") {
1485 debug_last_class = "odd";
e8614131 1486 } else {
0feab655 1487 debug_last_class = "even";
e8614131
AD
1488 }
1489
acac8448 1490 var c = $('debug_output');
8836613c 1491 if (c && Element.visible(c)) {
c9268ed5 1492 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1493 c.removeChild(c.lastChild);
1494 }
1495
1496 var d = new Date();
1497 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1498 ":" + leading_zero(d.getSeconds());
0feab655 1499 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1500 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1501 }
1502}
1503
33d13e72 1504function getInitParam(key) {
40496720 1505 return init_params[key];
33d13e72 1506}
3ac2b520 1507
dbfc9522 1508function setInitParam(key, value) {
5158ced9 1509 init_params[key] = value;
be0801a1
AD
1510}
1511
273d1e29 1512function fatalError(code, msg, ext_info) {
a7565293 1513 try {
a7565293 1514
91743a49
AD
1515 if (!ext_info) ext_info = "N/A";
1516
b4c27af7 1517 if (code == 6) {
206d4967 1518 window.location.href = "tt-rss.php";
b4c27af7
AD
1519 } else if (code == 5) {
1520 window.location.href = "update.php";
1521 } else {
4724a093 1522
273d1e29 1523 if (msg == "") msg = "Unknown error";
42c32916 1524
acac8448 1525 var ebc = $("xebContent");
4724a093 1526
273d1e29
AD
1527 if (ebc) {
1528
1529 Element.show("dialog_overlay");
1530 Element.show("errorBoxShadow");
1531 Element.hide("xebBtn");
1532
1533 if (ext_info) {
1534 if (ext_info.responseText) {
1535 ext_info = ext_info.responseText;
1536 }
1537 }
1538
1539 ebc.innerHTML =
1540 "<div><b>Error message:</b></div>" +
1541 "<pre>" + msg + "</pre>" +
1542 "<div><b>Additional information:</b></div>" +
1543 "<textarea readonly=\"1\">" + ext_info + "</textarea>";
1544 }
4724a093 1545 }
a7565293
AD
1546
1547 } catch (e) {
1548 exception_error("fatalError", e);
1549 }
1550}
1551
234e467c 1552function getFeedName(id, is_cat) {
234e467c
AD
1553 var e;
1554
1555 if (is_cat) {
acac8448 1556 e = $("FCATN-" + id);
234e467c 1557 } else {
acac8448 1558 e = $("FEEDN-" + id);
234e467c 1559 }
64a2875d
AD
1560 if (e) {
1561 return e.innerHTML.stripTags();
1562 } else {
1563 return null;
1564 }
1565}
0bd411db 1566
d0da85c2
AD
1567function filterDlgCheckType(sender) {
1568
1569 try {
1570
1571 var ftype = sender[sender.selectedIndex].value;
1572
1573 var form = document.forms["filter_add_form"];
1574
1575 if (!form) {
1576 form = document.forms["filter_edit_form"];
1577 }
1578
1579 if (!form) {
1580 debug("filterDlgCheckType: can't find form!");
1581 return;
1582 }
1583
1584 // if selected filter type is 5 (Date) enable the modifier dropbox
1585 if (ftype == 5) {
1586 Element.show("filter_dlg_date_mod_box");
1587 Element.show("filter_dlg_date_chk_box");
1588 } else {
1589 Element.hide("filter_dlg_date_mod_box");
1590 Element.hide("filter_dlg_date_chk_box");
1591
1592 }
1593
1594 } catch (e) {
1595 exception_error("filterDlgCheckType", e);
1596 }
1597
1598}
1599
350f0ad1
AD
1600function filterDlgCheckAction(sender) {
1601
1602 try {
1603
1604 var action = sender[sender.selectedIndex].value;
1605
1606 var form = document.forms["filter_add_form"];
1607
1608 if (!form) {
1609 form = document.forms["filter_edit_form"];
1610 }
1611
1612 if (!form) {
1613 debug("filterDlgCheckAction: can't find form!");
1614 return;
1615 }
1616
acac8448 1617 var action_param = $("filter_dlg_param_box");
350f0ad1
AD
1618
1619 if (!action_param) {
143a4973 1620 debug("filterDlgCheckAction: can't find action param box!");
350f0ad1
AD
1621 return;
1622 }
1623
1624 // if selected action supports parameters, enable params field
ceb30ba4 1625 if (action == 4 || action == 6 || action == 7) {
143a4973 1626 Element.show(action_param);
ceb30ba4
AD
1627 if (action != 7) {
1628 Element.show(form.action_param);
1629 Element.hide(form.action_param_label);
1630 } else {
1631 Element.show(form.action_param_label);
1632 Element.hide(form.action_param);
1633 }
350f0ad1 1634 } else {
143a4973 1635 Element.hide(action_param);
350f0ad1
AD
1636 }
1637
1638 } catch (e) {
438f2ce9 1639 exception_error("filterDlgCheckAction", e);
350f0ad1
AD
1640 }
1641
1642}
ef16ae37 1643
d0da85c2
AD
1644function filterDlgCheckDate() {
1645 try {
1646 var form = document.forms["filter_add_form"];
1647
1648 if (!form) {
1649 form = document.forms["filter_edit_form"];
1650 }
1651
1652 if (!form) {
1653 debug("filterDlgCheckAction: can't find form!");
1654 return;
1655 }
1656
1657 var reg_exp = form.reg_exp.value;
1658
b4e75b2a 1659 var query = "?op=rpc&subop=checkDate&date=" + reg_exp;
d0da85c2 1660
b4e75b2a
AD
1661 new Ajax.Request("backend.php", {
1662 parameters: query,
d0da85c2
AD
1663 onComplete: function(transport) {
1664
1665 var form = document.forms["filter_add_form"];
1666
1667 if (!form) {
1668 form = document.forms["filter_edit_form"];
1669 }
1670
1671 if (transport.responseXML) {
1672 var result = transport.responseXML.getElementsByTagName("result")[0];
1673
1674 if (result && result.firstChild) {
1675 if (result.firstChild.nodeValue == "1") {
1676
1677 new Effect.Highlight(form.reg_exp, {startcolor : '#00ff00'});
1678
1679 return;
1680 }
1681 }
1682 }
1683
1684 new Effect.Highlight(form.reg_exp, {startcolor : '#ff0000'});
1685
1686 } });
1687
1688
1689 } catch (e) {
1690 exception_error("filterDlgCheckDate", e);
1691 }
1692}
1693
ef16ae37
AD
1694function explainError(code) {
1695 return displayDlg("explainError", code);
1696}
01a87dff 1697
e097e8be 1698// this only searches loaded headlines list, not in CDM
aa0fa9df 1699function getRelativePostIds(id, limit) {
e097e8be 1700
aa0fa9df
AD
1701 if (!limit) limit = 3;
1702
1703 debug("getRelativePostIds: " + id + " limit=" + limit);
e097e8be
AD
1704
1705 var ids = new Array();
acac8448 1706 var container = $("headlinesList");
e097e8be
AD
1707
1708 if (container) {
1709 var rows = container.rows;
1710
1711 for (var i = 0; i < rows.length; i++) {
1712 var r_id = rows[i].id.replace("RROW-", "");
1713
1714 if (r_id == id) {
aa0fa9df
AD
1715 for (var k = 1; k <= limit; k++) {
1716 var nid = false;
1717
1718 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1719 if (nid) ids.push(nid);
1720
1721 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1722 if (nid) ids.push(nid);
1723 }
e097e8be
AD
1724
1725 return ids;
1726 }
1727 }
1728 }
1729
1730 return false;
1731}
298f3f78
AD
1732
1733function openArticleInNewWindow(id) {
1734 try {
298f3f78
AD
1735 debug("openArticleInNewWindow: " + id);
1736
b4e75b2a 1737 var query = "?op=rpc&subop=getArticleLink&id=" + id;
04e91733
AD
1738 var wname = "ttrss_article_" + id;
1739
1740 debug(query + " " + wname);
1741
1742 var w = window.open("", wname);
298f3f78 1743
04e91733 1744 if (!w) notify_error("Failed to open window for the article");
298f3f78 1745
b4e75b2a
AD
1746 new Ajax.Request("backend.php", {
1747 parameters: query,
d395a942
AD
1748 onComplete: function(transport) {
1749 open_article_callback(transport);
1750 } });
1751
298f3f78
AD
1752
1753 } catch (e) {
1754 exception_error("openArticleInNewWindow", e);
1755 }
1756}
e4914b62 1757
537625c6
AD
1758/* http://textsnippets.com/posts/show/835 */
1759
1760Position.GetWindowSize = function(w) {
1761 w = w ? w : window;
1762 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1763 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1764 return [width, height]
1765}
1766
1767/* http://textsnippets.com/posts/show/836 */
1768
1769Position.Center = function(element, parent) {
1770 var w, h, pw, ph;
1771 var d = Element.getDimensions(element);
1772 w = d.width;
1773 h = d.height;
1774 Position.prepare();
1775 if (!parent) {
1776 var ws = Position.GetWindowSize();
1777 pw = ws[0];
1778 ph = ws[1];
1779 } else {
1780 pw = parent.offsetWidth;
1781 ph = parent.offsetHeight;
1782 }
1783 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1784 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1785}
1786
768858f1 1787
288487e4
AD
1788function labeltest_callback(transport) {
1789 try {
acac8448 1790 var container = $('label_test_result');
288487e4
AD
1791
1792 container.innerHTML = transport.responseText;
768858f1
AD
1793 if (!Element.visible(container)) {
1794 Effect.SlideDown(container, { duration : 0.5 });
1795 }
288487e4 1796
6f151277 1797 notify("");
288487e4
AD
1798 } catch (e) {
1799 exception_error("labeltest_callback", e);
6f151277
AD
1800 }
1801}
1802
1803function labelTest() {
1804
288487e4 1805 try {
acac8448 1806 var container = $('label_test_result');
288487e4
AD
1807
1808 var form = document.forms['label_edit_form'];
1809
1810 var sql_exp = form.sql_exp.value;
1811 var description = form.description.value;
1812
1813 notify_progress("Loading, please wait...");
1814
b4e75b2a 1815 var query = "?op=pref-labels&subop=test&expr=" +
288487e4
AD
1816 param_escape(sql_exp) + "&descr=" + param_escape(description);
1817
b4e75b2a
AD
1818 new Ajax.Request("backend.php", {
1819 parameters: query,
288487e4
AD
1820 onComplete: function (transport) {
1821 labeltest_callback(transport);
1822 } });
1823
1824 return false;
6f151277 1825
288487e4
AD
1826 } catch (e) {
1827 exception_error("labelTest", e);
1828 }
6f151277
AD
1829}
1830
c32cd48a 1831function isCdmMode() {
acac8448 1832 return !$("headlinesList");
c32cd48a
AD
1833}
1834
1835function getSelectedArticleIds2() {
1836 var rows = new Array();
1837 var cdm_mode = isCdmMode();
1838
1839 if (cdm_mode) {
1840 rows = cdmGetSelectedArticles();
1841 } else {
1842 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1843 }
1844
1845 var ids = new Array();
1846
1847 for (var i = 0; i < rows.length; i++) {
acac8448 1848 var chk = $("RCHK-" + rows[i]);
c32cd48a
AD
1849 if (chk && chk.checked) {
1850 ids.push(rows[i]);
1851 }
1852 }
1853
1854 return ids;
1855}
c4a36709 1856
f6d40ed2 1857function displayHelpInfobox(topic_id) {
c4a36709 1858
f6d40ed2
AD
1859 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1860
1861 var w = window.open(url, "ttrss_help",
1862 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1863
f6d40ed2 1864}
e635d56a 1865
477402d8 1866function focus_element(id) {
61992f57 1867 try {
acac8448 1868 var e = $(id);
477402d8 1869 if (e) e.focus();
61992f57 1870 } catch (e) {
438f2ce9 1871 exception_error("focus_element", e);
61992f57 1872 }
477402d8 1873 return false;
61992f57 1874}
e635d56a 1875
99509451 1876function loading_set_progress(p) {
730dbf19 1877 try {
fca95d5f
AD
1878 if (p < last_progress_point || !Element.visible("overlay")) return;
1879
1880 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
99509451 1881
acac8448 1882 var o = $("l_progress_i");
99509451 1883
673c9946
AD
1884// o.style.width = (p * 2) + "px";
1885
99509451
AD
1886 new Effect.Scale(o, p, {
1887 scaleY : false,
1888 scaleFrom : last_progress_point,
1889 scaleMode: { originalWidth : 200 },
673c9946 1890 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
99509451
AD
1891
1892 last_progress_point = p;
730dbf19
AD
1893
1894 } catch (e) {
1895 exception_error("loading_set_progress", e);
1896 }
1897}
08827aaf
AD
1898
1899function remove_splash() {
1900 if (Element.visible("overlay")) {
1901 debug("about to remove splash, OMG!");
1902 Element.hide("overlay");
1903 debug("removed splash!");
1904 }
1905}
071ec48f
AD
1906
1907function addLabelExample() {
1908 try {
1909 var form = document.forms["label_edit_form"];
1910
1911 var text = form.sql_exp;
1912 var op = form.label_fields[form.label_fields.selectedIndex];
1913 var p = form.label_fields_param;
1914
1915 if (op) {
1916 op = op.value;
1917
1918 var tmp = "";
1919
1920 if (text.value != "") {
1921 if (text.value.substring(text.value.length-3, 3).toUpperCase() != "AND") {
1922 tmp = " AND ";
1923 } else {
1924 tmp = " ";
1925 }
1926 }
1927
1928 if (op == "unread") {
1929 tmp = tmp + "unread = true";
1930 }
1931
1932 if (op == "updated") {
1933 tmp = tmp + "last_read is null and unread = false";
1934 }
1935
1936 if (op == "kw_title") {
8c96d4b1
AD
1937 if (p.value == "") {
1938 alert("This action requires a parameter.");
1939 return false;
1940 }
071ec48f
AD
1941 tmp = tmp + "ttrss_entries.title like '%"+p.value+"%'";
1942 }
8c96d4b1 1943
071ec48f 1944 if (op == "kw_content") {
8c96d4b1
AD
1945 if (p.value == "") {
1946 alert("This action requires a parameter.");
1947 return false;
1948 }
1949
071ec48f
AD
1950 tmp = tmp + "ttrss_entries.content like '%"+p.value+"%'";
1951 }
1952
1953 if (op == "scoreE") {
8c96d4b1
AD
1954 if (isNaN(parseInt(p.value))) {
1955 alert("This action expects numeric parameter.");
1956 return false;
1957 }
071ec48f
AD
1958 tmp = tmp + "score = " + p.value;
1959 }
1960
1961 if (op == "scoreG") {
8c96d4b1
AD
1962 if (isNaN(parseInt(p.value))) {
1963 alert("This action expects numeric parameter.");
1964 return false;
1965 }
071ec48f
AD
1966 tmp = tmp + "score > " + p.value;
1967 }
1968
1969 if (op == "scoreL") {
8c96d4b1
AD
1970 if (isNaN(parseInt(p.value))) {
1971 alert("This action expects numeric parameter.");
1972 return false;
1973 }
071ec48f
AD
1974 tmp = tmp + "score < " + p.value;
1975 }
1976
1977 if (op == "newerD") {
e176b01a 1978 if (isNaN(parseInt(p.value))) {
071ec48f
AD
1979 alert("This action expects numeric parameter.");
1980 return false;
1981 }
1982 tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" days'";
1983 }
1984
1985 if (op == "newerH") {
e176b01a 1986 if (isNaN(parseInt(p.value))) {
071ec48f
AD
1987 alert("This action expects numeric parameter.");
1988 return false;
1989 }
1990
1991 tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" hours'";
1992 }
1993
1994 text.value = text.value + tmp;
1995
1996 p.value = "";
1997
1998 }
1999
2000 } catch (e) {
2001 exception_error("addLabelExample", e);
2002 }
2003
2004 return false;
2005}
2006
2007function labelFieldsCheck(elem) {
2008 try {
2009 var op = elem[elem.selectedIndex].value;
2010
2011 var p = document.forms["label_edit_form"].label_fields_param;
2012
2013 if (op == "kw_title" || op == "kw_content" || op == "scoreL" ||
2014 op == "scoreG" || op == "scoreE" || op == "newerD" ||
2015 op == "newerH" ) {
2016 Element.show(p);
2017 } else {
2018 Element.hide(p);
2019 }
2020
2021 } catch (e) {
2022 exception_error("labelFieldsCheck", e);
2023
2024 }
2025}
c2913898
AD
2026
2027function getSelectedFeedsFromBrowser() {
2028
acac8448
AD
2029 var list = $("browseFeedList");
2030 if (!list) list = $("browseBigFeedList");
c2913898
AD
2031
2032 var selected = new Array();
2033
2034 for (i = 0; i < list.childNodes.length; i++) {
2035 var child = list.childNodes[i];
2036 if (child.id && child.id.match("FBROW-")) {
2037 var id = child.id.replace("FBROW-", "");
2038
acac8448 2039 var cb = $("FBCHK-" + id);
c2913898
AD
2040
2041 if (cb.checked) {
2042 selected.push(id);
2043 }
2044 }
2045 }
2046
2047 return selected;
2048}
2049
2bab8824
AD
2050function updateFeedBrowser() {
2051 try {
2052
082ae95b 2053 var options = Form.serialize("feed_browser");
2bab8824 2054
082ae95b 2055 var query = "?op=rpc&subop=feedBrowser&" + options;
2bab8824 2056
f4280bdd
AD
2057 //notify_progress("Loading, please wait...", true);
2058
2059 Element.show('feed_browser_spinner');
2bab8824 2060
b4e75b2a
AD
2061 new Ajax.Request("backend.php", {
2062 parameters: query,
2bab8824
AD
2063 onComplete: function(transport) {
2064 notify('');
2065
f4280bdd
AD
2066 Element.hide('feed_browser_spinner');
2067
acac8448 2068 var c = $("browseFeedList");
2bab8824
AD
2069 var r = transport.responseXML.getElementsByTagName("content")[0];
2070 var nr = transport.responseXML.getElementsByTagName("num-results")[0];
2bab8824
AD
2071
2072 if (c && r) {
2073 c.innerHTML = r.firstChild.nodeValue;
2074 }
2075
2bab8824
AD
2076 } });
2077
2bab8824
AD
2078 } catch (e) {
2079 exception_error("updateFeedBrowser", e);
2080 }
082ae95b 2081
2bab8824
AD
2082}
2083
350468d0
AD
2084function browseFeeds(limit) {
2085
2086 try {
2087
b4e75b2a 2088 var query = "?op=pref-feeds&subop=browse";
350468d0
AD
2089
2090 notify_progress("Loading, please wait...", true);
2091
b4e75b2a
AD
2092 new Ajax.Request("backend.php", {
2093 parameters: query,
350468d0
AD
2094 onComplete: function(transport) {
2095 infobox_callback2(transport);
2096 } });
2097
2098 return false;
2099 } catch (e) {
2100 exception_error("browseFeeds", e);
2101 }
2102}
2103
2184738a
AD
2104function transport_error_check(transport) {
2105 try {
2106 if (transport.responseXML) {
2107 var error = transport.responseXML.getElementsByTagName("error")[0];
2108
2109 if (error) {
2110 var code = error.getAttribute("error-code");
2111 var msg = error.getAttribute("error-msg");
2112 if (code != 0) {
2113 fatalError(code, msg);
2114 return false;
2115 }
2116 }
2117 }
2118 } catch (e) {
2119 exception_error("check_for_error_xml", e);
2120 }
2121 return true;
2122}
2bab8824 2123
261b88b3
AD
2124function strip_tags(s) {
2125 return s.replace(/<\/?[^>]+(>|$)/g, "");
2126}
2127
2128function truncate_string(s, length) {
2129 if (!length) length = 30;
2130 var tmp = s.substring(0, length);
2131 if (s.length > length) tmp += "&hellip;";
2132 return tmp;
2133}
ab553f9a
AD
2134
2135/*
95f67d2e 2136function switchToFlash(e) {
9324c2c2
AD
2137 try {
2138 var targ = e;
2139 if (!e) var e = window.event;
2140 if (e.target) targ = e.target;
2141 else if (e.srcElement) targ = e.srcElement;
2142 if (targ.nodeType == 3) // defeat Safari bug
2143 targ = targ.parentNode;
2144
2145 //targ is the link that was clicked
2146 var audioTag=targ;
2147 do {
2148 audioTag=audioTag.previousSibling;
2149 } while(audioTag && audioTag.nodeType != 1)
2150
2151 var flashPlayer = audioTag.getElementsByTagName('span')[0];
2152 targ.parentNode.insertBefore(flashPlayer,targ);
2153 targ.parentNode.removeChild(targ);
2154 audioTag.parentNode.removeChild(audioTag);
2155
2156 return false;
2157 } catch (e) {
2158 exception_error("switchToFlash", e);
2159 }
95f67d2e 2160}
ab553f9a 2161
95f67d2e
AD
2162function html5AudioOrFlash(type) {
2163 var audioTag = document.createElement('audio');
8086c222
AD
2164 if(! audioTag.canPlayType || audioTag.canPlayType(type) == "no" ||
2165 audioTag.canPlayType(type) == ""){
95f67d2e
AD
2166 if($('switchToFlashLink')){
2167 switchToFlash($('switchToFlashLink'));
2168 }
2169 }
ab553f9a 2170} */
78935092
AD
2171
2172function hotkey_prefix_timeout() {
2173 try {
2174
2175 var date = new Date();
2176 var ts = Math.round(date.getTime() / 1000);
2177
2178 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
2179 debug("hotkey_prefix seems to be stuck, aborting");
2180 hotkey_prefix_pressed = false;
2181 hotkey_prefix = false;
2182 Element.hide('cmdline');
2183 }
2184
2185 setTimeout("hotkey_prefix_timeout()", 1000);
2186
2187 } catch (e) {
2188 exception_error("hotkey_prefix_timeout", e);
2189 }
2190}
2191
37e93d6c
AD
2192function hideAuxDlg() {
2193 try {
2194 Element.hide('auxDlg');
2195 } catch (e) {
2196 exception_error("hideAuxDlg", e);
2197 }
2198}
2199
2200function displayNewContentPrompt(id) {
2201 try {
85e5c67d
AD
2202
2203 var msg = "<a href='#' onclick='viewfeed("+id+")'>" +
2204 __("New articles available (Click to show)") + "</a>";
78935092 2205
37e93d6c
AD
2206 msg = msg.replace("%s", getFeedName(id));
2207
2208 $('auxDlg').innerHTML = msg;
2209
2210 Element.show('auxDlg');
2211
2212 } catch (e) {
2213 exception_error("displayNewContentPrompt", e);
2214 }
2215}