diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-29 08:07:55 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-06-29 08:07:55 +0000 |
commit | 0ffcceffac52cc4ed373eb9db27d6c776b5d96b7 (patch) | |
tree | 7efee86b0c833e48c8a5099108041d6a9114d9b8 /actionpack/lib/action_view/helpers/javascripts/controls.js | |
parent | a551ba2c01f5fcc1c0eff13c8ef24082e55071b9 (diff) | |
download | rails-0ffcceffac52cc4ed373eb9db27d6c776b5d96b7.tar.gz rails-0ffcceffac52cc4ed373eb9db27d6c776b5d96b7.tar.bz2 rails-0ffcceffac52cc4ed373eb9db27d6c776b5d96b7.zip |
Script.aculo.us: autocompletion focus fix, setContentZoom fix #1546 [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1560 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts/controls.js')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/controls.js | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/controls.js b/actionpack/lib/action_view/helpers/javascripts/controls.js index 712784ee6d..90a5f1132b 100644 --- a/actionpack/lib/action_view/helpers/javascripts/controls.js +++ b/actionpack/lib/action_view/helpers/javascripts/controls.js @@ -61,6 +61,7 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({ this.observer = null; + Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this)); Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this)); Event.observe(document, "click", this.onBlur.bindAsEventListener(this)); }, @@ -108,9 +109,15 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({ } }, + addObservers: function(element) { + Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this)); + Event.observe(element, "click", this.onClick.bindAsEventListener(this)); + }, + onComplete: function(request) { - if(!this.changed) { + if(!this.changed && this.has_focus) { this.update.innerHTML = request.responseText; + Element.cleanWhitespace(this.update); Element.cleanWhitespace(this.update.firstChild); if(this.update.firstChild && this.update.firstChild.childNodes) { @@ -119,8 +126,7 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({ for (var i = 0; i < this.entry_count; i++) { entry = this.get_entry(i); entry.autocompleteIndex = i; - Event.observe(entry, "mouseover", this.onHover.bindAsEventListener(this)); - Event.observe(entry, "click", this.onClick.bindAsEventListener(this)); + this.addObservers(entry); } } else { this.entry_count = 0; @@ -171,26 +177,29 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({ }, onHover: function(event) { - element = Event.findElement(event, 'LI'); + var element = Event.findElement(event, 'LI'); if(this.index != element.autocompleteIndex) { this.index = element.autocompleteIndex; this.render(); } + Event.stop(event); }, onClick: function(event) { - element = Event.findElement(event, 'LI'); + var element = Event.findElement(event, 'LI'); this.index = element.autocompleteIndex; this.select_entry(); + Event.stop(event); }, onBlur: function(event) { - element = Event.element(event); + var element = Event.element(event); if(element==this.update) return; while(element.parentNode) { element = element.parentNode; if(element==this.update) return; } this.hide(); + this.has_focus = false; this.active = false; }, |