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