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