X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=public%2Fjs%2Futils.js;h=f437d150d8f821000afa9adda7253547deb0c0eb;hb=6cc4b3cd4538430770c935bd3192f1f72d75d96b;hp=f5817d491a2087f3198089e5dad1d0d77bc87a18;hpb=ce001229accb2aff799560eec402344f0dbb1762;p=syj.git diff --git a/public/js/utils.js b/public/js/utils.js index f5817d4..f437d15 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -21,11 +21,45 @@ var CloseBtn = Class.create({ btn = new Element("input", { type: "image", src: imgsrc, alt: "X"}).setStyle(style); elt.insert({top: btn}); btn.observe("click", function(evt) { + evt.stop(); + if (typeof options.callback === "function") { + options.callback.call(elt); + } elt.hide(); }); } }); +var Toggler = Class.create({ + initialize: function(target, options) { + options = Object.extend({}, options); + target = $(target).hide(); + + var openIcn = options.openIcn || 'icons/bullet_arrow_right.png', + closeIcn = options.closeIcn || 'icons/bullet_arrow_down.png'; + + this.element = new Element("img", { src: openIcn }) + .setStyle({ border: 'none', // in firefox, in image inside an anchor has a border + verticalAlign: "middle"}); + + this.element.observe('click', function(evt) { + if (target.visible()) { + evt.target.src = openIcn; + target.hide(); + } else { + evt.target.src = closeIcn; + target.show(); + } + evt.stop(); + }); + + if (options.initialShow) { + target.show(); + this.element.src = closeIcn; + } + } +}); + var Deck = Class.create({ initialize: function(elt, options) { this.element = $(elt); @@ -115,12 +149,12 @@ Ajax.TimedRequest = Class.create(Ajax.Request, { }, request: function($super, url) { - this.timeout = (function() { + this.timeout = function() { if (this.options.onFailure) { this.options.onFailure(null); } this.abort(); - }).bind(this).delay(this.delay); + }.bind(this).delay(this.delay); $super(url); } }); @@ -186,7 +220,7 @@ Element.addMethods('form', { }); }, - focus: function(form) { + setfocus: function(form) { var tofocus, error; tofocus = null; @@ -307,9 +341,13 @@ Element.addMethods('div', { addMessage: function(div, message) { var node = (div.ownerDocument || document).createTextNode(message); - if (!div.empty()) { + + if ($A(div.childNodes).filter(function(node) { + return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br'); + }).length) { div.insert(new Element('br')); } + div.appendChild(node); return div.show(); },