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