Allow specifying the element that observe the knl's keydown handler.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 19 Feb 2010 00:33:50 +0000 (19:33 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 19 Feb 2010 00:37:35 +0000 (19:37 -0500)
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.

horde/js/KeyNavList.js
horde/js/autocomplete.js

index 47af115..435b8f8 100644 (file)
  *                           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);
index 1fd8981..7cb0702 100644 (file)
@@ -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);