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