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