X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=public%2Fjs%2Futils.js;h=348e3a70425033b7859c767cddac9d2929f7e9e8;hb=f0cec87e660f4c34740d6a8c6256f534c67bb8b1;hp=f437d150d8f821000afa9adda7253547deb0c0eb;hpb=6cc4b3cd4538430770c935bd3192f1f72d75d96b;p=syj.git diff --git a/public/js/utils.js b/public/js/utils.js index f437d15..348e3a7 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -10,14 +10,18 @@ var CloseBtn = Class.create({ return; } + if (typeof options !== "object") { + options = {}; + } + style = Object.extend({ float: "right", margin: "2px", fontWeight: "bold", padding: "0px" - }, typeof options === "object" ? options.style: {}); + }, options.style); - imgsrc = (options && options.closeBtnSrc) || "icons/close.png"; + imgsrc = (options.closeBtnSrc) || "icons/close.png"; btn = new Element("input", { type: "image", src: imgsrc, alt: "X"}).setStyle(style); elt.insert({top: btn}); btn.observe("click", function(evt) { @@ -31,31 +35,46 @@ var CloseBtn = Class.create({ }); var Toggler = Class.create({ - initialize: function(target, options) { - options = Object.extend({}, options); - target = $(target).hide(); + options: {}, - var openIcn = options.openIcn || 'icons/bullet_arrow_right.png', - closeIcn = options.closeIcn || 'icons/bullet_arrow_down.png'; + close: function() { + this.element.src = this.options.openIcn; + this.target.hide(); + document.fire('toggler:close', this); + }, - this.element = new Element("img", { src: openIcn }) - .setStyle({ border: 'none', // in firefox, in image inside an anchor has a border - verticalAlign: "middle"}); + open: function() { + this.element.src = this.options.closeIcn; + this.target.show(); + document.fire('toggler:open', this); + }, - this.element.observe('click', function(evt) { - if (target.visible()) { - evt.target.src = openIcn; - target.hide(); - } else { - evt.target.src = closeIcn; - target.show(); - } + toggle: function(evt) { + if (evt && typeof evt.stop === "function") { evt.stop(); - }); + } + if (this.target.visible()) { + this.close(); + } else { + this.open(); + } + }, - if (options.initialShow) { - target.show(); - this.element.src = closeIcn; + initialize: function(target, options) { + this.options = Object.extend({ + openIcn: 'icons/bullet_arrow_right.png', + closeIcn: 'icons/bullet_arrow_down.png' + }, options); + + this.target = $(target).hide(); + this.element = new Element("img").setStyle({ border: 'none', // in firefox, in image inside an anchor has a border + verticalAlign: "middle"}); + this.element.observe('click', this.toggle.bindAsEventListener(this)); + + if (this.options.autoOpen) { + this.open(); + } else { + this.close(); } } }); @@ -212,11 +231,37 @@ Element.addMethods('form', { reqoptions.method = this.method; } + if (reqoptions.onFailure) { + reqoptions.onFailure = reqoptions.onFailure.wrap(function(proceed, transport, json) { + form.enable(); + proceed(transport, json); + }); + } else { + reqoptions.onFailure = function() { + form.enable(); + }; + } + + if (reqoptions.onSuccess) { + reqoptions.onSuccess = reqoptions.onSuccess.wrap(function(proceed, transport, json) { + form.enable(); + proceed(transport, json); + }); + } else { + reqoptions.onSuccess = function() { + form.enable(); + }; + } + new Ajax.TimedRequest(action, options.delay || 20, reqoptions); if (Object.isFunction(options.postsubmit)) { options.postsubmit(this); } + Form.getElements(form).each(function(elt) { + elt.blur(); + elt.disable(); + }); }); },