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