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