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