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