]>
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 | if (ext_info) { | |
31 | if (ext_info.responseText) { | |
32 | ext_info = ext_info.responseText; | |
33 | } | |
34 | } | |
35 | ||
36 | var content = "<div class=\"fatalError\">" + | |
37 | "<pre>" + msg + "</pre>"; | |
38 | ||
39 | if (ext_info) { | |
40 | content += "<div><b>Additional information:</b></div>" + | |
41 | "<textarea readonly=\"1\">" + ext_info + "</textarea>"; | |
42 | } | |
43 | ||
44 | content += "<div><b>Stack trace:</b></div>" + | |
45 | "<textarea readonly=\"1\">" + e.stack + "</textarea>"; | |
46 | ||
47 | content += "<div style='text-align : center'>" + | |
48 | "<button onclick=\"closeInfoBox()\">" + | |
49 | "Close this window" + "</button></div>"; | |
50 | ||
51 | // TODO: add code to automatically report errors to tt-rss.org | |
52 | ||
53 | Modalbox.show(content, {title: "Unhandled exception", width: 600, | |
54 | resizeDuration: 0, transitions: false}); | |
55 | ||
56 | } catch (e) { | |
57 | alert(msg); | |
58 | } | |
59 | ||
60 | } | |
61 | ||
62 | function format_exception_error(location, e) { | |
63 | var msg; | |
64 | ||
65 | if (e.fileName) { | |
66 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
67 | ||
68 | msg = "Exception: " + e.name + ", " + e.message + | |
69 | "\nFunction: " + location + "()" + | |
70 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
71 | ||
72 | } else if (e.description) { | |
73 | msg = "Exception: " + e.description + "\nFunction: " + location + "()"; | |
74 | } else { | |
75 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
76 | } | |
77 | ||
78 | console.error("EXCEPTION: " + msg); | |
79 | ||
80 | return msg; | |
81 | } | |
82 | ||
83 | ||
84 | function disableHotkeys() { | |
85 | hotkeys_enabled = false; | |
86 | } | |
87 | ||
88 | function enableHotkeys() { | |
89 | hotkeys_enabled = true; | |
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 | var notify_hide_timerid = false; | |
107 | ||
108 | function hide_notify() { | |
109 | var n = $("notify"); | |
110 | if (n) { | |
111 | n.style.display = "none"; | |
112 | } | |
113 | } | |
114 | ||
115 | function notify_silent_next() { | |
116 | notify_silent = true; | |
117 | } | |
118 | ||
119 | function notify_real(msg, no_hide, n_type) { | |
120 | ||
121 | if (notify_silent) { | |
122 | notify_silent = false; | |
123 | return; | |
124 | } | |
125 | ||
126 | var n = $("notify"); | |
127 | var nb = $("notify_body"); | |
128 | ||
129 | if (!n || !nb) return; | |
130 | ||
131 | if (notify_hide_timerid) { | |
132 | window.clearTimeout(notify_hide_timerid); | |
133 | } | |
134 | ||
135 | if (msg == "") { | |
136 | if (n.style.display == "block") { | |
137 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
138 | } | |
139 | return; | |
140 | } else { | |
141 | n.style.display = "block"; | |
142 | } | |
143 | ||
144 | /* types: | |
145 | ||
146 | 1 - generic | |
147 | 2 - progress | |
148 | 3 - error | |
149 | 4 - info | |
150 | ||
151 | */ | |
152 | ||
153 | if (typeof __ != 'undefined') { | |
154 | msg = __(msg); | |
155 | } | |
156 | ||
157 | if (n_type == 1) { | |
158 | n.className = "notify"; | |
159 | } else if (n_type == 2) { | |
160 | n.className = "notifyProgress"; | |
161 | msg = "<img src='"+getInitParam("sign_progress")+"'> " + msg; | |
162 | } else if (n_type == 3) { | |
163 | n.className = "notifyError"; | |
164 | msg = "<img src='"+getInitParam("sign_excl")+"'> " + msg; | |
165 | } else if (n_type == 4) { | |
166 | n.className = "notifyInfo"; | |
167 | msg = "<img src='"+getInitParam("sign_info")+"'> " + msg; | |
168 | } | |
169 | ||
170 | // msg = "<img src='images/live_com_loading.gif'> " + msg; | |
171 | ||
172 | nb.innerHTML = msg; | |
173 | ||
174 | if (!no_hide) { | |
175 | notify_hide_timerid = window.setTimeout("hide_notify()", 3000); | |
176 | } | |
177 | } | |
178 | ||
179 | function notify(msg, no_hide) { | |
180 | notify_real(msg, no_hide, 1); | |
181 | } | |
182 | ||
183 | function notify_progress(msg, no_hide) { | |
184 | notify_real(msg, no_hide, 2); | |
185 | } | |
186 | ||
187 | function notify_error(msg, no_hide) { | |
188 | notify_real(msg, no_hide, 3); | |
189 | ||
190 | } | |
191 | ||
192 | function notify_info(msg, no_hide) { | |
193 | notify_real(msg, no_hide, 4); | |
194 | } | |
195 | ||
196 | function setCookie(name, value, lifetime, path, domain, secure) { | |
197 | ||
198 | var d = false; | |
199 | ||
200 | if (lifetime) { | |
201 | d = new Date(); | |
202 | d.setTime(d.getTime() + (lifetime * 1000)); | |
203 | } | |
204 | ||
205 | console.log("setCookie: " + name + " => " + value + ": " + d); | |
206 | ||
207 | int_setCookie(name, value, d, path, domain, secure); | |
208 | ||
209 | } | |
210 | ||
211 | function int_setCookie(name, value, expires, path, domain, secure) { | |
212 | document.cookie= name + "=" + escape(value) + | |
213 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
214 | ((path) ? "; path=" + path : "") + | |
215 | ((domain) ? "; domain=" + domain : "") + | |
216 | ((secure) ? "; secure" : ""); | |
217 | } | |
218 | ||
219 | function delCookie(name, path, domain) { | |
220 | if (getCookie(name)) { | |
221 | document.cookie = name + "=" + | |
222 | ((path) ? ";path=" + path : "") + | |
223 | ((domain) ? ";domain=" + domain : "" ) + | |
224 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
225 | } | |
226 | } | |
227 | ||
228 | ||
229 | function getCookie(name) { | |
230 | ||
231 | var dc = document.cookie; | |
232 | var prefix = name + "="; | |
233 | var begin = dc.indexOf("; " + prefix); | |
234 | if (begin == -1) { | |
235 | begin = dc.indexOf(prefix); | |
236 | if (begin != 0) return null; | |
237 | } | |
238 | else { | |
239 | begin += 2; | |
240 | } | |
241 | var end = document.cookie.indexOf(";", begin); | |
242 | if (end == -1) { | |
243 | end = dc.length; | |
244 | } | |
245 | return unescape(dc.substring(begin + prefix.length, end)); | |
246 | } | |
247 | ||
248 | function gotoPreferences() { | |
249 | document.location.href = "prefs.php"; | |
250 | } | |
251 | ||
252 | function gotoMain() { | |
253 | document.location.href = "tt-rss.php"; | |
254 | } | |
255 | ||
256 | function gotoExportOpml() { | |
257 | document.location.href = "opml.php?op=Export"; | |
258 | } | |
259 | ||
260 | ||
261 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj | |
262 | * * @author Sundar Dorai-Raj | |
263 | * * Email: sdoraira@vt.edu | |
264 | * * This program is free software; you can redistribute it and/or | |
265 | * * modify it under the terms of the GNU General Public License | |
266 | * * as published by the Free Software Foundation; either version 2 | |
267 | * * of the License, or (at your option) any later version, | |
268 | * * provided that any use properly credits the author. | |
269 | * * This program is distributed in the hope that it will be useful, | |
270 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
271 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
272 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
273 | ||
274 | var numbers=".0123456789"; | |
275 | function isNumeric(x) { | |
276 | // is x a String or a character? | |
277 | if(x.length>1) { | |
278 | // remove negative sign | |
279 | x=Math.abs(x)+""; | |
280 | for(j=0;j<x.length;j++) { | |
281 | // call isNumeric recursively for each character | |
282 | number=isNumeric(x.substring(j,j+1)); | |
283 | if(!number) return number; | |
284 | } | |
285 | return number; | |
286 | } | |
287 | else { | |
288 | // if x is number return true | |
289 | if(numbers.indexOf(x)>=0) return true; | |
290 | return false; | |
291 | } | |
292 | } | |
293 | ||
294 | ||
295 | function toggleSelectRowById(sender, id) { | |
296 | var row = $(id); | |
297 | return toggleSelectRow(sender, row); | |
298 | } | |
299 | ||
300 | function toggleSelectListRow(sender) { | |
301 | var row = sender.parentNode; | |
302 | return toggleSelectRow(sender, row); | |
303 | } | |
304 | ||
305 | function tSR(sender, row) { | |
306 | return toggleSelectRow(sender, row); | |
307 | } | |
308 | ||
309 | function toggleSelectRow(sender, row) { | |
310 | ||
311 | if (!row) row = sender.parentNode.parentNode; | |
312 | ||
313 | if (sender.checked && !row.hasClassName('Selected')) | |
314 | row.addClassName('Selected'); | |
315 | else | |
316 | row.removeClassName('Selected'); | |
317 | } | |
318 | ||
319 | function checkboxToggleElement(elem, id) { | |
320 | if (elem.checked) { | |
321 | Effect.Appear(id, {duration : 0.5, | |
322 | afterSetup: function() { | |
323 | Modalbox.resizeToContent(); | |
324 | }}); | |
325 | } else { | |
326 | Effect.Fade(id, {duration : 0.5}); | |
327 | } | |
328 | } | |
329 | ||
330 | function dropboxSelect(e, v) { | |
331 | for (i = 0; i < e.length; i++) { | |
332 | if (e[i].value == v) { | |
333 | e.selectedIndex = i; | |
334 | break; | |
335 | } | |
336 | } | |
337 | } | |
338 | ||
339 | // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z | |
340 | // bugfixed just a little bit :-) | |
341 | function getURLParam(strParamName){ | |
342 | var strReturn = ""; | |
343 | var strHref = window.location.href; | |
344 | ||
345 | if (strHref.indexOf("#") == strHref.length-1) { | |
346 | strHref = strHref.substring(0, strHref.length-1); | |
347 | } | |
348 | ||
349 | if ( strHref.indexOf("?") > -1 ){ | |
350 | var strQueryString = strHref.substr(strHref.indexOf("?")); | |
351 | var aQueryString = strQueryString.split("&"); | |
352 | for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ | |
353 | if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ | |
354 | var aParam = aQueryString[iParam].split("="); | |
355 | strReturn = aParam[1]; | |
356 | break; | |
357 | } | |
358 | } | |
359 | } | |
360 | return strReturn; | |
361 | } | |
362 | ||
363 | function leading_zero(p) { | |
364 | var s = String(p); | |
365 | if (s.length == 1) s = "0" + s; | |
366 | return s; | |
367 | } | |
368 | ||
369 | function make_timestamp() { | |
370 | var d = new Date(); | |
371 | ||
372 | return leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) + | |
373 | ":" + leading_zero(d.getSeconds()); | |
374 | } | |
375 | ||
376 | ||
377 | function closeErrorBox() { | |
378 | ||
379 | if (Element.visible("errorBoxShadow")) { | |
380 | Element.hide("dialog_overlay"); | |
381 | Element.hide("errorBoxShadow"); | |
382 | ||
383 | enableHotkeys(); | |
384 | } | |
385 | ||
386 | return false; | |
387 | } | |
388 | ||
389 | function closeInfoBox(cleanup) { | |
390 | ||
391 | try { | |
392 | enableHotkeys(); | |
393 | Modalbox.hide(); | |
394 | ||
395 | } catch (e) { | |
396 | //exception_error("closeInfoBox", e); | |
397 | } | |
398 | return false; | |
399 | } | |
400 | ||
401 | ||
402 | function displayDlg(id, param, callback) { | |
403 | ||
404 | disableHotkeys(); | |
405 | notify_progress("Loading, please wait...", true); | |
406 | ||
407 | var query = "?op=dlg&id=" + | |
408 | param_escape(id) + "¶m=" + param_escape(param); | |
409 | ||
410 | new Ajax.Request("backend.php", { | |
411 | parameters: query, | |
412 | onComplete: function (transport) { | |
413 | infobox_callback2(transport); | |
414 | if (callback) callback(transport); | |
415 | } }); | |
416 | ||
417 | return false; | |
418 | } | |
419 | ||
420 | function infobox_submit_callback2(transport) { | |
421 | closeInfoBox(); | |
422 | ||
423 | try { | |
424 | // called from prefs, reload tab | |
425 | if (typeof active_tab != 'undefined' && active_tab) { | |
426 | selectTab(active_tab, false); | |
427 | } | |
428 | } catch (e) { } | |
429 | ||
430 | if (transport.responseText) { | |
431 | notify_info(transport.responseText); | |
432 | } | |
433 | } | |
434 | ||
435 | function infobox_callback2(transport) { | |
436 | try { | |
437 | ||
438 | //console.log("infobox_callback2"); | |
439 | notify(''); | |
440 | ||
441 | var content; | |
442 | var dtitle = "Dialog"; | |
443 | ||
444 | if (transport.responseXML) { | |
445 | var dlg = transport.responseXML.getElementsByTagName("dlg")[0]; | |
446 | ||
447 | var title = transport.responseXML.getElementsByTagName("title")[0]; | |
448 | if (title) | |
449 | dtitle = title.firstChild.nodeValue; | |
450 | ||
451 | var content = transport.responseXML.getElementsByTagName("content")[0]; | |
452 | ||
453 | content = content.firstChild.nodeValue; | |
454 | ||
455 | } else { | |
456 | content = transport.responseText; | |
457 | } | |
458 | ||
459 | Modalbox.show(content, {title: dtitle, width: 600, | |
460 | transitions: true, resizeDuration: 0 }); | |
461 | ||
462 | disableHotkeys(); | |
463 | ||
464 | notify(""); | |
465 | } catch (e) { | |
466 | exception_error("infobox_callback2", e); | |
467 | } | |
468 | } | |
469 | ||
470 | function createFilter() { | |
471 | ||
472 | try { | |
473 | ||
474 | var form = document.forms['filter_add_form']; | |
475 | var reg_exp = form.reg_exp.value; | |
476 | ||
477 | if (reg_exp == "") { | |
478 | alert(__("Can't add filter: nothing to match on.")); | |
479 | return false; | |
480 | } | |
481 | ||
482 | var query = "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp); | |
483 | ||
484 | notify_progress("Verifying regular expression..."); | |
485 | ||
486 | new Ajax.Request("backend.php", { | |
487 | parameters: query, | |
488 | onComplete: function(transport) { | |
489 | handle_rpc_reply(transport); | |
490 | ||
491 | var response = transport.responseXML; | |
492 | ||
493 | if (response) { | |
494 | var s = response.getElementsByTagName("status")[0].firstChild.nodeValue; | |
495 | ||
496 | notify(''); | |
497 | ||
498 | if (s == "INVALID") { | |
499 | alert("Match regular expression seems to be invalid."); | |
500 | return; | |
501 | } else { | |
502 | ||
503 | var query = Form.serialize("filter_add_form"); | |
504 | ||
505 | // we can be called from some other tab in Prefs | |
506 | if (typeof active_tab != 'undefined' && active_tab) { | |
507 | active_tab = "filterConfig"; | |
508 | } | |
509 | ||
510 | new Ajax.Request("backend.php?" + query, { | |
511 | onComplete: function (transport) { | |
512 | infobox_submit_callback2(transport); | |
513 | } }); | |
514 | ||
515 | return true; | |
516 | } | |
517 | } | |
518 | ||
519 | } }); | |
520 | ||
521 | } catch (e) { | |
522 | exception_error("createFilter", e); | |
523 | } | |
524 | } | |
525 | ||
526 | function isValidURL(s) { | |
527 | return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null; | |
528 | } | |
529 | ||
530 | function subscribeToFeed() { | |
531 | ||
532 | try { | |
533 | ||
534 | var form = document.forms['feed_add_form']; | |
535 | var feed_url = form.feed_url.value; | |
536 | ||
537 | if (feed_url == "") { | |
538 | alert(__("Can't subscribe: no feed URL given.")); | |
539 | return false; | |
540 | } | |
541 | ||
542 | notify_progress(__("Subscribing to feed..."), true); | |
543 | ||
544 | var query = Form.serialize("feed_add_form"); | |
545 | ||
546 | console.log("subscribe q: " + query); | |
547 | ||
548 | Form.disable("feed_add_form"); | |
549 | ||
550 | new Ajax.Request("backend.php", { | |
551 | parameters: query, | |
552 | onComplete: function(transport) { | |
553 | //dlg_frefresh_callback(transport); | |
554 | ||
555 | try { | |
556 | ||
557 | if (!transport.responseXML) { | |
558 | console.log(transport.responseText); | |
559 | alert(__("Server error while trying to subscribe to specified feed.")); | |
560 | return; | |
561 | } | |
562 | ||
563 | var result = transport.responseXML.getElementsByTagName('result')[0]; | |
564 | var rc = parseInt(result.getAttribute('code')); | |
565 | ||
566 | Form.enable("feed_add_form"); | |
567 | ||
568 | notify(''); | |
569 | ||
570 | switch (rc) { | |
571 | case 1: | |
572 | closeInfoBox(); | |
573 | notify_info(__("Subscribed to %s").replace("%s", feed_url)); | |
574 | ||
575 | if (inPreferences()) { | |
576 | updateFeedList(); | |
577 | } else { | |
578 | setTimeout('updateFeedList(false, false)', 50); | |
579 | } | |
580 | break; | |
581 | case 2: | |
582 | alert(__("Specified URL seems to be invalid.")); | |
583 | break; | |
584 | case 3: | |
585 | alert(__("Specified URL doesn't seem to contain any feeds.")); | |
586 | break; | |
587 | case 4: | |
588 | new Ajax.Request("backend.php", { | |
589 | parameters: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url), | |
590 | onComplete: function(transport) { | |
591 | var result = transport.responseXML.getElementsByTagName('urls')[0]; | |
592 | var feeds = JSON.parse(result.firstChild.nodeValue); | |
593 | var select = document.getElementById("faad_feeds_container_select"); | |
594 | ||
595 | while (select.hasChildNodes()) { | |
596 | select.removeChild(elem.firstChild); | |
597 | } | |
598 | var count = 0; | |
599 | for (var feedUrl in feeds) { | |
600 | select.insert(new Option(feeds[feedUrl], feedUrl, false)); | |
601 | count++; | |
602 | } | |
603 | if (count > 5) count = 5; | |
604 | select.size = count; | |
605 | ||
606 | Effect.Appear('fadd_feeds_container', {duration : 0.5, | |
607 | afterSetup: function() { | |
608 | Modalbox.resizeToContent() | |
609 | }}); | |
610 | } | |
611 | }); | |
612 | break; | |
613 | case 5: | |
614 | alert(__("Couldn't download the specified URL.")); | |
615 | break; | |
616 | case 0: | |
617 | alert(__("You are already subscribed to this feed.")); | |
618 | break; | |
619 | } | |
620 | ||
621 | } catch (e) { | |
622 | exception_error("subscribeToFeed", e); | |
623 | } | |
624 | ||
625 | } }); | |
626 | ||
627 | } catch (e) { | |
628 | exception_error("subscribeToFeed", e); | |
629 | } | |
630 | ||
631 | return false; | |
632 | } | |
633 | ||
634 | function filterCR(e, f) | |
635 | { | |
636 | var key; | |
637 | ||
638 | if(window.event) | |
639 | key = window.event.keyCode; //IE | |
640 | else | |
641 | key = e.which; //firefox | |
642 | ||
643 | if (key == 13) { | |
644 | if (typeof f != 'undefined') { | |
645 | f(); | |
646 | return false; | |
647 | } else { | |
648 | return false; | |
649 | } | |
650 | } else { | |
651 | return true; | |
652 | } | |
653 | } | |
654 | ||
655 | function getInitParam(key) { | |
656 | return init_params[key]; | |
657 | } | |
658 | ||
659 | function setInitParam(key, value) { | |
660 | init_params[key] = value; | |
661 | } | |
662 | ||
663 | function fatalError(code, msg, ext_info) { | |
664 | try { | |
665 | ||
666 | if (!ext_info) ext_info = "N/A"; | |
667 | ||
668 | if (code == 6) { | |
669 | window.location.href = "tt-rss.php"; | |
670 | } else if (code == 5) { | |
671 | window.location.href = "db-updater.php"; | |
672 | } else { | |
673 | ||
674 | if (msg == "") msg = "Unknown error"; | |
675 | ||
676 | var ebc = $("xebContent"); | |
677 | ||
678 | if (ebc) { | |
679 | ||
680 | Element.show("dialog_overlay"); | |
681 | Element.show("errorBoxShadow"); | |
682 | Element.hide("xebBtn"); | |
683 | ||
684 | if (ext_info) { | |
685 | if (ext_info.responseText) { | |
686 | ext_info = ext_info.responseText; | |
687 | } | |
688 | } | |
689 | ||
690 | ebc.innerHTML = | |
691 | "<div><b>Error message:</b></div>" + | |
692 | "<pre>" + msg + "</pre>" + | |
693 | "<div><b>Additional information:</b></div>" + | |
694 | "<textarea readonly=\"1\">" + ext_info + "</textarea>"; | |
695 | } | |
696 | } | |
697 | ||
698 | } catch (e) { | |
699 | exception_error("fatalError", e); | |
700 | } | |
701 | } | |
702 | ||
703 | function filterDlgCheckType(sender) { | |
704 | ||
705 | try { | |
706 | ||
707 | var ftype = sender[sender.selectedIndex].value; | |
708 | ||
709 | var form = document.forms["filter_add_form"]; | |
710 | ||
711 | if (!form) { | |
712 | form = document.forms["filter_edit_form"]; | |
713 | } | |
714 | ||
715 | if (!form) { | |
716 | console.log("filterDlgCheckType: can't find form!"); | |
717 | return; | |
718 | } | |
719 | ||
720 | // if selected filter type is 5 (Date) enable the modifier dropbox | |
721 | if (ftype == 5) { | |
722 | Element.show("filter_dlg_date_mod_box"); | |
723 | Element.show("filter_dlg_date_chk_box"); | |
724 | } else { | |
725 | Element.hide("filter_dlg_date_mod_box"); | |
726 | Element.hide("filter_dlg_date_chk_box"); | |
727 | ||
728 | } | |
729 | ||
730 | } catch (e) { | |
731 | exception_error("filterDlgCheckType", e); | |
732 | } | |
733 | ||
734 | } | |
735 | ||
736 | function filterDlgCheckAction(sender) { | |
737 | ||
738 | try { | |
739 | ||
740 | var action = sender[sender.selectedIndex].value; | |
741 | ||
742 | var form = document.forms["filter_add_form"]; | |
743 | ||
744 | if (!form) { | |
745 | form = document.forms["filter_edit_form"]; | |
746 | } | |
747 | ||
748 | if (!form) { | |
749 | console.log("filterDlgCheckAction: can't find form!"); | |
750 | return; | |
751 | } | |
752 | ||
753 | var action_param = $("filter_dlg_param_box"); | |
754 | ||
755 | if (!action_param) { | |
756 | console.log("filterDlgCheckAction: can't find action param box!"); | |
757 | return; | |
758 | } | |
759 | ||
760 | // if selected action supports parameters, enable params field | |
761 | if (action == 4 || action == 6 || action == 7) { | |
762 | Element.show(action_param); | |
763 | if (action != 7) { | |
764 | Element.show(form.action_param); | |
765 | Element.hide(form.action_param_label); | |
766 | } else { | |
767 | Element.show(form.action_param_label); | |
768 | Element.hide(form.action_param); | |
769 | } | |
770 | } else { | |
771 | Element.hide(action_param); | |
772 | } | |
773 | ||
774 | } catch (e) { | |
775 | exception_error("filterDlgCheckAction", e); | |
776 | } | |
777 | ||
778 | } | |
779 | ||
780 | function filterDlgCheckDate() { | |
781 | try { | |
782 | var form = document.forms["filter_add_form"]; | |
783 | ||
784 | if (!form) { | |
785 | form = document.forms["filter_edit_form"]; | |
786 | } | |
787 | ||
788 | if (!form) { | |
789 | console.log("filterDlgCheckAction: can't find form!"); | |
790 | return; | |
791 | } | |
792 | ||
793 | var reg_exp = form.reg_exp.value; | |
794 | ||
795 | var query = "?op=rpc&subop=checkDate&date=" + reg_exp; | |
796 | ||
797 | new Ajax.Request("backend.php", { | |
798 | parameters: query, | |
799 | onComplete: function(transport) { | |
800 | ||
801 | var form = document.forms["filter_add_form"]; | |
802 | ||
803 | if (!form) { | |
804 | form = document.forms["filter_edit_form"]; | |
805 | } | |
806 | ||
807 | if (transport.responseXML) { | |
808 | var result = transport.responseXML.getElementsByTagName("result")[0]; | |
809 | ||
810 | if (result && result.firstChild) { | |
811 | if (result.firstChild.nodeValue == "1") { | |
812 | ||
813 | new Effect.Highlight(form.reg_exp, {startcolor : '#00ff00'}); | |
814 | ||
815 | return; | |
816 | } | |
817 | } | |
818 | } | |
819 | ||
820 | new Effect.Highlight(form.reg_exp, {startcolor : '#ff0000'}); | |
821 | ||
822 | } }); | |
823 | ||
824 | ||
825 | } catch (e) { | |
826 | exception_error("filterDlgCheckDate", e); | |
827 | } | |
828 | } | |
829 | ||
830 | function explainError(code) { | |
831 | return displayDlg("explainError", code); | |
832 | } | |
833 | ||
834 | function displayHelpInfobox(topic_id) { | |
835 | ||
836 | var url = "backend.php?op=help&tid=" + param_escape(topic_id); | |
837 | ||
838 | var w = window.open(url, "ttrss_help", | |
839 | "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0"); | |
840 | ||
841 | } | |
842 | ||
843 | function loading_set_progress(p) { | |
844 | try { | |
845 | if (p < last_progress_point || !Element.visible("overlay")) return; | |
846 | ||
847 | console.log("loading_set_progress : " + p + " (" + last_progress_point + ")"); | |
848 | ||
849 | var o = $("l_progress_i"); | |
850 | ||
851 | // o.style.width = (p * 2) + "px"; | |
852 | ||
853 | new Effect.Scale(o, p, { | |
854 | scaleY : false, | |
855 | scaleFrom : last_progress_point, | |
856 | scaleMode: { originalWidth : 200 }, | |
857 | queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); | |
858 | ||
859 | last_progress_point = p; | |
860 | ||
861 | } catch (e) { | |
862 | exception_error("loading_set_progress", e); | |
863 | } | |
864 | } | |
865 | ||
866 | function remove_splash() { | |
867 | if (Element.visible("overlay")) { | |
868 | console.log("about to remove splash, OMG!"); | |
869 | Element.hide("overlay"); | |
870 | console.log("removed splash!"); | |
871 | } | |
872 | } | |
873 | ||
874 | function getSelectedFeedsFromBrowser() { | |
875 | ||
876 | var list = $$("#browseFeedList li[id*=FBROW]"); | |
877 | ||
878 | var selected = new Array(); | |
879 | ||
880 | list.each(function(child) { | |
881 | var id = child.id.replace("FBROW-", ""); | |
882 | var cb = $("FBCHK-" + id); | |
883 | ||
884 | if (cb.checked) { | |
885 | selected.push(id); | |
886 | } | |
887 | }); | |
888 | ||
889 | return selected; | |
890 | } | |
891 | ||
892 | function updateFeedBrowser() { | |
893 | try { | |
894 | ||
895 | var query = Form.serialize("feed_browser"); | |
896 | ||
897 | Element.show('feed_browser_spinner'); | |
898 | ||
899 | new Ajax.Request("backend.php", { | |
900 | parameters: query, | |
901 | onComplete: function(transport) { | |
902 | notify(''); | |
903 | ||
904 | Element.hide('feed_browser_spinner'); | |
905 | ||
906 | var c = $("browseFeedList"); | |
907 | var r = transport.responseXML.getElementsByTagName("content")[0]; | |
908 | var nr = transport.responseXML.getElementsByTagName("num-results")[0]; | |
909 | var mode = transport.responseXML.getElementsByTagName("mode")[0]; | |
910 | ||
911 | if (c && r) { | |
912 | c.innerHTML = r.firstChild.nodeValue; | |
913 | } | |
914 | ||
915 | if (parseInt(mode.getAttribute("value")) == 2) { | |
916 | Element.show('feed_archive_remove'); | |
917 | } else { | |
918 | Element.hide('feed_archive_remove'); | |
919 | } | |
920 | ||
921 | } }); | |
922 | ||
923 | } catch (e) { | |
924 | exception_error("updateFeedBrowser", e); | |
925 | } | |
926 | ||
927 | } | |
928 | ||
929 | function transport_error_check(transport) { | |
930 | try { | |
931 | if (transport.responseXML) { | |
932 | var error = transport.responseXML.getElementsByTagName("error")[0]; | |
933 | ||
934 | if (error) { | |
935 | var code = error.getAttribute("error-code"); | |
936 | var msg = error.getAttribute("error-msg"); | |
937 | if (code != 0) { | |
938 | fatalError(code, msg); | |
939 | return false; | |
940 | } | |
941 | } | |
942 | } | |
943 | } catch (e) { | |
944 | exception_error("check_for_error_xml", e); | |
945 | } | |
946 | return true; | |
947 | } | |
948 | ||
949 | function strip_tags(s) { | |
950 | return s.replace(/<\/?[^>]+(>|$)/g, ""); | |
951 | } | |
952 | ||
953 | function truncate_string(s, length) { | |
954 | if (!length) length = 30; | |
955 | var tmp = s.substring(0, length); | |
956 | if (s.length > length) tmp += "…"; | |
957 | return tmp; | |
958 | } | |
959 | ||
960 | function hotkey_prefix_timeout() { | |
961 | try { | |
962 | ||
963 | var date = new Date(); | |
964 | var ts = Math.round(date.getTime() / 1000); | |
965 | ||
966 | if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { | |
967 | console.log("hotkey_prefix seems to be stuck, aborting"); | |
968 | hotkey_prefix_pressed = false; | |
969 | hotkey_prefix = false; | |
970 | Element.hide('cmdline'); | |
971 | } | |
972 | ||
973 | setTimeout("hotkey_prefix_timeout()", 1000); | |
974 | ||
975 | } catch (e) { | |
976 | exception_error("hotkey_prefix_timeout", e); | |
977 | } | |
978 | } | |
979 | ||
980 | function hideAuxDlg() { | |
981 | try { | |
982 | Element.hide('auxDlg'); | |
983 | } catch (e) { | |
984 | exception_error("hideAuxDlg", e); | |
985 | } | |
986 | } | |
987 | ||
988 | function feedBrowserSubscribe() { | |
989 | try { | |
990 | ||
991 | var selected = getSelectedFeedsFromBrowser(); | |
992 | ||
993 | var mode = document.forms['feed_browser'].mode; | |
994 | ||
995 | mode = mode[mode.selectedIndex].value; | |
996 | ||
997 | if (selected.length > 0) { | |
998 | closeInfoBox(); | |
999 | ||
1000 | notify_progress("Loading, please wait...", true); | |
1001 | ||
1002 | var query = "?op=rpc&subop=massSubscribe&ids="+ | |
1003 | param_escape(selected.toString()) + "&mode=" + param_escape(mode); | |
1004 | ||
1005 | new Ajax.Request("backend.php", { | |
1006 | parameters: query, | |
1007 | onComplete: function(transport) { | |
1008 | ||
1009 | var nf = transport.responseXML.getElementsByTagName('num-feeds')[0]; | |
1010 | var nf_value = nf.getAttribute("value"); | |
1011 | ||
1012 | notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value)); | |
1013 | ||
1014 | if (inPreferences()) { | |
1015 | updateFeedList(); | |
1016 | } else { | |
1017 | setTimeout('updateFeedList(false, false)', 50); | |
1018 | } | |
1019 | } }); | |
1020 | ||
1021 | } else { | |
1022 | alert(__("No feeds are selected.")); | |
1023 | } | |
1024 | ||
1025 | } catch (e) { | |
1026 | exception_error("feedBrowserSubscribe", e); | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | function feedArchiveRemove() { | |
1031 | try { | |
1032 | ||
1033 | var selected = getSelectedFeedsFromBrowser(); | |
1034 | ||
1035 | if (selected.length > 0) { | |
1036 | ||
1037 | var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); | |
1038 | ||
1039 | if (confirm(pr)) { | |
1040 | Element.show('feed_browser_spinner'); | |
1041 | ||
1042 | var query = "?op=rpc&subop=remarchived&ids=" + | |
1043 | param_escape(selected.toString());; | |
1044 | ||
1045 | new Ajax.Request("backend.php", { | |
1046 | parameters: query, | |
1047 | onComplete: function(transport) { | |
1048 | updateFeedBrowser(); | |
1049 | } }); | |
1050 | } | |
1051 | ||
1052 | } else { | |
1053 | alert(__("No feeds are selected.")); | |
1054 | } | |
1055 | ||
1056 | } catch (e) { | |
1057 | exception_error("feedArchiveRemove", e); | |
1058 | } | |
1059 | } | |
1060 | ||
1061 | function uploadIconHandler(rc) { | |
1062 | try { | |
1063 | switch (rc) { | |
1064 | case 0: | |
1065 | notify_info("Upload complete."); | |
1066 | if (inPreferences()) { | |
1067 | updateFeedList(); | |
1068 | } else { | |
1069 | setTimeout('updateFeedList(false, false)', 50); | |
1070 | } | |
1071 | break; | |
1072 | case 1: | |
1073 | notify_error("Upload failed: icon is too big."); | |
1074 | break; | |
1075 | case 2: | |
1076 | notify_error("Upload failed."); | |
1077 | break; | |
1078 | } | |
1079 | ||
1080 | } catch (e) { | |
1081 | exception_error("uploadIconHandler", e); | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | function removeFeedIcon(id) { | |
1086 | ||
1087 | try { | |
1088 | ||
1089 | if (confirm(__("Remove stored feed icon?"))) { | |
1090 | var query = "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id); | |
1091 | ||
1092 | console.log(query); | |
1093 | ||
1094 | notify_progress("Removing feed icon...", true); | |
1095 | ||
1096 | new Ajax.Request("backend.php", { | |
1097 | parameters: query, | |
1098 | onComplete: function(transport) { | |
1099 | notify_info("Feed icon removed."); | |
1100 | if (inPreferences()) { | |
1101 | updateFeedList(); | |
1102 | } else { | |
1103 | setTimeout('updateFeedList(false, false)', 50); | |
1104 | } | |
1105 | } }); | |
1106 | } | |
1107 | ||
1108 | return false; | |
1109 | } catch (e) { | |
1110 | exception_error("uploadFeedIcon", e); | |
1111 | } | |
1112 | } | |
1113 | ||
1114 | function uploadFeedIcon() { | |
1115 | ||
1116 | try { | |
1117 | ||
1118 | var file = $("icon_file"); | |
1119 | ||
1120 | if (file.value.length == 0) { | |
1121 | alert(__("Please select an image file to upload.")); | |
1122 | } else { | |
1123 | if (confirm(__("Upload new icon for this feed?"))) { | |
1124 | notify_progress("Uploading, please wait...", true); | |
1125 | return true; | |
1126 | } | |
1127 | } | |
1128 | ||
1129 | return false; | |
1130 | ||
1131 | } catch (e) { | |
1132 | exception_error("uploadFeedIcon", e); | |
1133 | } | |
1134 | } | |
1135 | ||
1136 | function addLabel(select, callback) { | |
1137 | ||
1138 | try { | |
1139 | ||
1140 | var caption = prompt(__("Please enter label caption:"), ""); | |
1141 | ||
1142 | if (caption != undefined) { | |
1143 | ||
1144 | if (caption == "") { | |
1145 | alert(__("Can't create label: missing caption.")); | |
1146 | return false; | |
1147 | } | |
1148 | ||
1149 | var query = "?op=pref-labels&subop=add&caption=" + | |
1150 | param_escape(caption); | |
1151 | ||
1152 | if (select) | |
1153 | query += "&output=select"; | |
1154 | ||
1155 | notify_progress("Loading, please wait...", true); | |
1156 | ||
1157 | if (inPreferences() && !select) active_tab = "labelConfig"; | |
1158 | ||
1159 | new Ajax.Request("backend.php", { | |
1160 | parameters: query, | |
1161 | onComplete: function(transport) { | |
1162 | if (callback) { | |
1163 | callback(transport); | |
1164 | } else if (inPreferences()) { | |
1165 | infobox_submit_callback2(transport); | |
1166 | } else { | |
1167 | updateFeedList(); | |
1168 | } | |
1169 | } }); | |
1170 | ||
1171 | } | |
1172 | ||
1173 | } catch (e) { | |
1174 | exception_error("addLabel", e); | |
1175 | } | |
1176 | } | |
1177 | ||
1178 | function quickAddFeed() { | |
1179 | displayDlg('quickAddFeed', '', | |
1180 | function () {$('feed_url').focus();}); | |
1181 | } | |
1182 | ||
1183 | function quickAddFilter() { | |
1184 | displayDlg('quickAddFilter', '', | |
1185 | function () {document.forms['filter_add_form'].reg_exp.focus();}); | |
1186 | } | |
1187 | ||
1188 | function unsubscribeFeed(feed_id, title) { | |
1189 | ||
1190 | var msg = __("Unsubscribe from %s?").replace("%s", title); | |
1191 | ||
1192 | if (title == undefined || confirm(msg)) { | |
1193 | notify_progress("Removing feed..."); | |
1194 | ||
1195 | var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id; | |
1196 | ||
1197 | new Ajax.Request("backend.php", { | |
1198 | parameters: query, | |
1199 | onComplete: function(transport) { | |
1200 | ||
1201 | closeInfoBox(); | |
1202 | ||
1203 | if (inPreferences()) { | |
1204 | updateFeedList(); | |
1205 | } else { | |
1206 | dlg_frefresh_callback(transport, feed_id); | |
1207 | } | |
1208 | ||
1209 | } }); | |
1210 | } | |
1211 | ||
1212 | return false; | |
1213 | } | |
1214 | ||
1215 | ||
1216 | function backend_sanity_check_callback(transport) { | |
1217 | ||
1218 | try { | |
1219 | ||
1220 | if (sanity_check_done) { | |
1221 | fatalError(11, "Sanity check request received twice. This can indicate "+ | |
1222 | "presence of Firebug or some other disrupting extension. "+ | |
1223 | "Please disable it and try again."); | |
1224 | return; | |
1225 | } | |
1226 | ||
1227 | if (!transport.responseXML) { | |
1228 | if (!store) { | |
1229 | fatalError(3, "Sanity check: Received reply is not XML", | |
1230 | transport.responseText); | |
1231 | return; | |
1232 | } | |
1233 | } | |
1234 | ||
1235 | var reply = transport.responseXML.getElementsByTagName("error")[0]; | |
1236 | ||
1237 | if (!reply) { | |
1238 | fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); | |
1239 | return; | |
1240 | } | |
1241 | ||
1242 | var error_code = reply.getAttribute("error-code"); | |
1243 | ||
1244 | if (error_code && error_code != 0) { | |
1245 | return fatalError(error_code, reply.getAttribute("error-msg")); | |
1246 | } | |
1247 | ||
1248 | console.log("sanity check ok"); | |
1249 | ||
1250 | var params = transport.responseXML.getElementsByTagName("init-params")[0]; | |
1251 | ||
1252 | if (params) { | |
1253 | console.log('reading init-params...'); | |
1254 | ||
1255 | params = JSON.parse(params.firstChild.nodeValue); | |
1256 | ||
1257 | if (params) { | |
1258 | for (k in params) { | |
1259 | var v = params[k]; | |
1260 | console.log("IP: " + k + " => " + v); | |
1261 | } | |
1262 | } | |
1263 | ||
1264 | init_params = params; | |
1265 | } | |
1266 | ||
1267 | sanity_check_done = true; | |
1268 | ||
1269 | init_second_stage(); | |
1270 | ||
1271 | } catch (e) { | |
1272 | exception_error("backend_sanity_check_callback", e, transport); | |
1273 | } | |
1274 | } | |
1275 | ||
1276 | function has_local_storage() { | |
1277 | return false; | |
1278 | /* try { | |
1279 | return 'localStorage' in window && window['localStorage'] != null; | |
1280 | } catch (e) { | |
1281 | return false; | |
1282 | } */ | |
1283 | } | |
1284 | ||
1285 | function catSelectOnChange(elem) { | |
1286 | try { | |
1287 | var value = elem[elem.selectedIndex].value; | |
1288 | var def = elem.getAttribute('default'); | |
1289 | ||
1290 | if (value == "ADD_CAT") { | |
1291 | ||
1292 | if (def) | |
1293 | dropboxSelect(elem, def); | |
1294 | else | |
1295 | elem.selectedIndex = 0; | |
1296 | ||
1297 | quickAddCat(elem); | |
1298 | } | |
1299 | ||
1300 | } catch (e) { | |
1301 | exception_error("catSelectOnChange", e); | |
1302 | } | |
1303 | } | |
1304 | ||
1305 | function quickAddCat(elem) { | |
1306 | try { | |
1307 | var cat = prompt(__("Please enter category title:")); | |
1308 | ||
1309 | if (cat) { | |
1310 | ||
1311 | var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat); | |
1312 | ||
1313 | notify_progress("Loading, please wait...", true); | |
1314 | ||
1315 | new Ajax.Request("backend.php", { | |
1316 | parameters: query, | |
1317 | onComplete: function (transport) { | |
1318 | var response = transport.responseXML; | |
1319 | var select = response.getElementsByTagName("select")[0]; | |
1320 | var options = select.getElementsByTagName("option"); | |
1321 | ||
1322 | dropbox_replace_options(elem, options); | |
1323 | ||
1324 | notify(''); | |
1325 | ||
1326 | } }); | |
1327 | ||
1328 | } | |
1329 | ||
1330 | } catch (e) { | |
1331 | exception_error("quickAddCat", e); | |
1332 | } | |
1333 | } | |
1334 | ||
1335 | function genUrlChangeKey(feed, is_cat) { | |
1336 | ||
1337 | try { | |
1338 | var ok = confirm(__("Generate new syndication address for this feed?")); | |
1339 | ||
1340 | if (ok) { | |
1341 | ||
1342 | notify_progress("Trying to change address...", true); | |
1343 | ||
1344 | var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) + | |
1345 | "&is_cat=" + param_escape(is_cat); | |
1346 | ||
1347 | new Ajax.Request("backend.php", { | |
1348 | parameters: query, | |
1349 | onComplete: function(transport) { | |
1350 | var new_link = transport.responseXML.getElementsByTagName("link")[0]; | |
1351 | ||
1352 | var e = $('gen_feed_url'); | |
1353 | ||
1354 | if (new_link) { | |
1355 | ||
1356 | new_link = new_link.firstChild.nodeValue; | |
1357 | ||
1358 | e.innerHTML = e.innerHTML.replace(/\&key=.*$/, | |
1359 | "&key=" + new_link); | |
1360 | ||
1361 | e.href = e.href.replace(/\&key=.*$/, | |
1362 | "&key=" + new_link); | |
1363 | ||
1364 | new Effect.Highlight(e); | |
1365 | ||
1366 | notify(''); | |
1367 | ||
1368 | } else { | |
1369 | notify_error("Could not change feed URL."); | |
1370 | } | |
1371 | } }); | |
1372 | } | |
1373 | } catch (e) { | |
1374 | exception_error("genUrlChangeKey", e); | |
1375 | } | |
1376 | return false; | |
1377 | } | |
1378 | ||
1379 | function labelSelectOnChange(elem) { | |
1380 | try { | |
1381 | var value = elem[elem.selectedIndex].value; | |
1382 | var def = elem.getAttribute('default'); | |
1383 | ||
1384 | if (value == "ADD_LABEL") { | |
1385 | ||
1386 | if (def) | |
1387 | dropboxSelect(elem, def); | |
1388 | else | |
1389 | elem.selectedIndex = 0; | |
1390 | ||
1391 | addLabel(elem, function(transport) { | |
1392 | ||
1393 | try { | |
1394 | ||
1395 | var response = transport.responseXML; | |
1396 | var select = response.getElementsByTagName("select")[0]; | |
1397 | var options = select.getElementsByTagName("option"); | |
1398 | ||
1399 | dropbox_replace_options(elem, options); | |
1400 | ||
1401 | notify(''); | |
1402 | } catch (e) { | |
1403 | exception_error("addLabel", e); | |
1404 | } | |
1405 | }); | |
1406 | } | |
1407 | ||
1408 | } catch (e) { | |
1409 | exception_error("labelSelectOnChange", e); | |
1410 | } | |
1411 | } | |
1412 | ||
1413 | function dropbox_replace_options(elem, options) { | |
1414 | ||
1415 | try { | |
1416 | while (elem.hasChildNodes()) | |
1417 | elem.removeChild(elem.firstChild); | |
1418 | ||
1419 | var sel_idx = -1; | |
1420 | ||
1421 | for (var i = 0; i < options.length; i++) { | |
1422 | var text = options[i].firstChild.nodeValue; | |
1423 | var value = options[i].getAttribute("value"); | |
1424 | ||
1425 | if (value == undefined) value = text; | |
1426 | ||
1427 | var issel = options[i].getAttribute("selected") == "1"; | |
1428 | ||
1429 | var option = new Option(text, value, issel); | |
1430 | ||
1431 | if (options[i].getAttribute("disabled")) | |
1432 | option.setAttribute("disabled", true); | |
1433 | ||
1434 | elem.insert(option); | |
1435 | ||
1436 | if (issel) sel_idx = i; | |
1437 | } | |
1438 | ||
1439 | // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true) | |
1440 | if (sel_idx >= 0) elem.selectedIndex = sel_idx; | |
1441 | ||
1442 | } catch (e) { | |
1443 | exception_error("dropbox_replace_options", e); | |
1444 | } | |
1445 | } | |
1446 | ||
1447 | // mode = all, none, invert | |
1448 | function selectTableRows(id, mode) { | |
1449 | try { | |
1450 | var rows = $(id).rows; | |
1451 | ||
1452 | for (var i = 0; i < rows.length; i++) { | |
1453 | var row = rows[i]; | |
1454 | var cb = false; | |
1455 | ||
1456 | if (row.id && row.className) { | |
1457 | var bare_id = row.id.replace(/^[A-Z]*?-/, ""); | |
1458 | var inputs = rows[i].getElementsByTagName("input"); | |
1459 | ||
1460 | for (var j = 0; j < inputs.length; j++) { | |
1461 | var input = inputs[j]; | |
1462 | ||
1463 | if (input.getAttribute("type") == "checkbox" && | |
1464 | input.id.match(bare_id)) { | |
1465 | ||
1466 | cb = input; | |
1467 | break; | |
1468 | } | |
1469 | } | |
1470 | ||
1471 | if (cb) { | |
1472 | var issel = row.hasClassName("Selected"); | |
1473 | ||
1474 | if (mode == "all" && !issel) { | |
1475 | row.addClassName("Selected"); | |
1476 | cb.checked = true; | |
1477 | } else if (mode == "none" && issel) { | |
1478 | row.removeClassName("Selected"); | |
1479 | cb.checked = false; | |
1480 | } else if (mode == "invert") { | |
1481 | ||
1482 | if (issel) { | |
1483 | row.removeClassName("Selected"); | |
1484 | cb.checked = false; | |
1485 | } else { | |
1486 | row.addClassName("Selected"); | |
1487 | cb.checked = true; | |
1488 | } | |
1489 | } | |
1490 | } | |
1491 | } | |
1492 | } | |
1493 | ||
1494 | } catch (e) { | |
1495 | exception_error("selectTableRows", e); | |
1496 | ||
1497 | } | |
1498 | } | |
1499 | ||
1500 | function getSelectedTableRowIds(id) { | |
1501 | var rows = []; | |
1502 | ||
1503 | try { | |
1504 | var elem_rows = $(id).rows; | |
1505 | ||
1506 | for (i = 0; i < elem_rows.length; i++) { | |
1507 | if (elem_rows[i].hasClassName("Selected")) { | |
1508 | var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); | |
1509 | rows.push(bare_id); | |
1510 | } | |
1511 | } | |
1512 | ||
1513 | } catch (e) { | |
1514 | exception_error("getSelectedTableRowIds", e); | |
1515 | } | |
1516 | ||
1517 | return rows; | |
1518 | } | |
1519 |