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