diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-02-12 20:10:59 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-02-12 20:10:59 +0000 |
commit | 8dc4f4623354b65a639ac3c8981e1c362801d722 (patch) | |
tree | eb67d25728e0fb63d752c2e429a72fbbf9ecee6e /actionpack/lib/action_view/helpers/javascripts/prototype.js | |
parent | ebdb766e7956520e9e5a784e280a8f1916f50511 (diff) | |
download | rails-8dc4f4623354b65a639ac3c8981e1c362801d722.tar.gz rails-8dc4f4623354b65a639ac3c8981e1c362801d722.tar.bz2 rails-8dc4f4623354b65a639ac3c8981e1c362801d722.zip |
Also support replace and replace_html and some refactoring in JavaScriptElementProxy [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3588 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts/prototype.js')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/prototype.js | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js index f37149127f..62ee54efc1 100644 --- a/actionpack/lib/action_view/helpers/javascripts/prototype.js +++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js @@ -436,7 +436,8 @@ var Enumerable = { var collections = [this].concat(args).map($A); return this.map(function(value, index) { - return iterator(collections.pluck(index)); + iterator(value = collections.pluck(index)); + return value; }); }, @@ -942,19 +943,6 @@ Object.extend(Element, { setTimeout(function() {html.evalScripts()}, 10); }, - replace: function(element, html) { - element = $(element); - if (element.outerHTML) { - element.outerHTML = html.stripScripts(); - } else { - var range = element.ownerDocument.createRange(); - range.selectNodeContents(element); - element.parentNode.replaceChild( - range.createContextualFragment(html.stripScripts()), element); - } - setTimeout(function() {html.evalScripts()}, 10); - }, - getHeight: function(element) { element = $(element); return element.offsetHeight; @@ -1317,8 +1305,18 @@ var Field = { $(arguments[i]).value = ''; }, - focus: function(element) { - $(element).focus(); + // Pass the field id or element as the first parameter and optionally a triggering delay in micro-seconds as the second. + // The delay is useful when the focus is part of effects that won't finish instantly since they prevent the focus from + // taking hold. Set the delay to right after the effect finishes and the focus will work. + focus: function() { + element = $(arguments[0]); + delay = arguments[1]; + + if (delay) { + setTimeout(function() { $(element).focus(); }, delay) + } else { + $(element).focus(); + } }, present: function() { @@ -1551,15 +1549,16 @@ Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { Abstract.EventObserver = function() {} Abstract.EventObserver.prototype = { - initialize: function(element, callback) { - this.element = $(element); - this.callback = callback; + initialize: function() { + this.element = $(arguments[0]); + this.callback = arguments[1]; + this.trigger = arguments[2]; this.lastValue = this.getValue(); if (this.element.tagName.toLowerCase() == 'form') this.registerFormCallbacks(); else - this.registerCallback(this.element); + this.registerCallback(this.element, this.trigger); }, onElementEvent: function() { @@ -1573,11 +1572,13 @@ Abstract.EventObserver.prototype = { registerFormCallbacks: function() { var elements = Form.getElements(this.element); for (var i = 0; i < elements.length; i++) - this.registerCallback(elements[i]); + this.registerCallback(elements[i], this.trigger); }, - registerCallback: function(element) { - if (element.type) { + registerCallback: function(element, trigger) { + if (trigger && element.type) { + Event.observe(element, trigger, this.onElementEvent.bind(this)); + } else if (element.type) { switch (element.type.toLowerCase()) { case 'checkbox': case 'radio': |