From: Michael J. Rubinsky Date: Fri, 19 Feb 2010 00:33:50 +0000 (-0500) Subject: Allow specifying the element that observe the knl's keydown handler. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4e53431d9caa24de6db1f0e36bde7e144a4f4e39;p=horde.git Allow specifying the element that observe the knl's keydown handler. This is needed in the case when there are other keydown events registered on the document. There is no guarantee what order they will fire. So, in Kronolith for example, the event detail form would receive an enter press and save the event before the autocompleter's knl would receive the event. --- diff --git a/horde/js/KeyNavList.js b/horde/js/KeyNavList.js index 47af1153e..435b8f848 100644 --- a/horde/js/KeyNavList.js +++ b/horde/js/KeyNavList.js @@ -19,6 +19,10 @@ * list container element. * 'onShow' - (function) Called when the list is shown. Passed the * list container element. + * 'domParent' - (Element) Specifies the parent element. Defaults to + * document.body + * 'keydownObserver - (Element) The element to register the keydown handler + * on. Defaults to document. * }); * * [base = (Element) The element to use for display positioning purposes] @@ -43,7 +47,8 @@ var KeyNavList = Class.create({ onChoose: Prototype.emptyFunction, onHide: Prototype.emptyFunction, onShow: Prototype.emptyFunction, - domParent: null + domParent: null, + keydownObserver: document }, opts || {}); this.div = new Element('DIV', { className: 'KeyNavList' }).hide().insert(new Element('UL')); @@ -59,7 +64,7 @@ var KeyNavList = Class.create({ document.observe('click', this.onClickFunc); this.onKeyDownFunc = this.onKeyDown.bindAsEventListener(this); - document.observe('keydown', this.onKeyDownFunc); + $(this.opts.keydownObserver).observe('keydown', this.onKeyDownFunc); this.resizeFunc = this.hide.bind(this); Event.observe(window, 'resize', this.resizeFunc); diff --git a/horde/js/autocomplete.js b/horde/js/autocomplete.js index 1fd898170..7cb070227 100644 --- a/horde/js/autocomplete.js +++ b/horde/js/autocomplete.js @@ -39,7 +39,8 @@ Autocompleter.Base = Class.create({ onShow: Prototype.K, onType: Prototype.K, paramName: elt.readAttribute('name'), - tokens: [] + tokens: [], + keydownObserver: this.elt }, (this._setOptions ? this._setOptions(opts) : (opts || {}))); // Force carriage returns as token delimiters anyway @@ -116,7 +117,8 @@ Autocompleter.Base = Class.create({ if (!this.knl) { this.knl = new KeyNavList(this.elt, { onChoose: this.onSelect.bind(this), onShow: this.opts.onShow.bind(this), - domParent: this.opts.domParent }); + domParent: this.opts.domParent, + keydownObserver: this.opts.keydownObserver}); } this.knl.show(c);