From 02b80e99b3db5f00a7e7ed75100e997338ffa3fa Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 8 Jun 2010 11:35:22 -0600 Subject: [PATCH] Fix blur/focus handling in autocomplete.js document.activeElement does not work in all browsers, but it is the only way to reliably get focused element. Works on all recent browsers. --- horde/js/autocomplete.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/horde/js/autocomplete.js b/horde/js/autocomplete.js index d02efdf15..0cb4df0eb 100644 --- a/horde/js/autocomplete.js +++ b/horde/js/autocomplete.js @@ -28,7 +28,7 @@ Autocompleter.Base = Class.create({ baseInitialize: function(elt, opts) { this.elt = elt = $(elt); - this.changed = this.hasFocus = false; + this.changed = false; this.observer = null; this.oldval = $F(elt); this.opts = Object.extend({ @@ -50,14 +50,14 @@ Autocompleter.Base = Class.create({ } elt.writeAttribute('autocomplete', 'off'); - elt.observe("blur", function() { this.hasFocus = false; }.bind(this)); - elt.observe("focus", function() { this.hasFocus = true; }.bind(this)); elt.observe("keydown", this._onKeyDown.bindAsEventListener(this)); }, _onKeyDown: function(e) { - if (this.hasFocus) { + var a = document.activeElement; + + if (Object.isUndefined(a) || a == this.elt) { switch (e.keyCode) { case 0: if (!Prototype.Browser.WebKit) { @@ -86,9 +86,10 @@ Autocompleter.Base = Class.create({ updateChoices: function(choices) { - var c = [], re; + var a = document.activeElement, c = [], re; - if (this.changed || !this.hasFocus) { + if (this.changed || + (Object.isUndefined(a) || a != this.elt)) { return; } -- 2.11.0