diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-01-03 04:11:51 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-01-03 04:11:51 +0000 |
commit | 10cf9ecafc4b1953cf8289e530cab7a0a751b9c4 (patch) | |
tree | 53c4ad06e6b897d3bebd368e1701d0b264a816e9 /actionpack/lib/action_view/helpers/javascripts | |
parent | 987d9dbf31b6bb4fe1547bca17af920aa3d72ac5 (diff) | |
download | rails-10cf9ecafc4b1953cf8289e530cab7a0a751b9c4.tar.gz rails-10cf9ecafc4b1953cf8289e530cab7a0a751b9c4.tar.bz2 rails-10cf9ecafc4b1953cf8289e530cab7a0a751b9c4.zip |
Added assignment of the Autocompleter object created by JavaScriptMacroHelper#auto_complete_field to a local javascript variables [DHH] Added :on option for PrototypeHelper#observe_field that allows you to specify a different callback hook to have the observer trigger on [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3378 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/controls.js | 6 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/prototype.js | 17 |
2 files changed, 16 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/controls.js b/actionpack/lib/action_view/helpers/javascripts/controls.js index 3307f2e2fa..86f34a24f7 100644 --- a/actionpack/lib/action_view/helpers/javascripts/controls.js +++ b/actionpack/lib/action_view/helpers/javascripts/controls.js @@ -152,6 +152,12 @@ Autocompleter.Base.prototype = { setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000); }, + activate: function() { + this.changed = false; + this.hasFocus = true; + this.getUpdatedChoices(); + }, + onHover: function(event) { var element = Event.findElement(event, 'LI'); if(this.index != element.autocompleteIndex) diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js index 545f3af040..fdf4ef1bd2 100644 --- a/actionpack/lib/action_view/helpers/javascripts/prototype.js +++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js @@ -1398,15 +1398,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() { @@ -1420,11 +1421,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': |