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