From: Michael M Slusarz Date: Tue, 8 Jun 2010 17:35:22 +0000 (-0600) Subject: Fix blur/focus handling in autocomplete.js X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=02b80e99b3db5f00a7e7ed75100e997338ffa3fa;p=horde.git 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. --- 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; }