Skip to content

Commit

Permalink
Only trigger events once at most for an autocompleter
Browse files Browse the repository at this point in the history
Also correctly ignore events not intended for an autocompleter
(triggered on a specific autocompleter DOM parent element)
  • Loading branch information
slusarz committed Oct 2, 2014
1 parent 7274b6c commit 7a3f412
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions imp/js/autocomplete.js
Expand Up @@ -101,18 +101,26 @@ var IMP_Autocompleter = Class.create({

new PeriodicalExecuter(this.inputWatcher.bind(this), 0.25);

document.observe('AutoComplete:focus', function(e) {
if (e.memo == this.elt) {
this.focus();
e.stop();
}
}.bindAsEventListener(this));
document.observe('AutoComplete:reset', this.reset.bind(this));
document.observe('AutoComplete:update', this.processInput.bind(this));
document.observe('AutoComplete:focus', this.triggerEvent.bindAsEventListener(this, this.focus.bind(this)));
document.observe('AutoComplete:reset', this.triggerEvent.bindAsEventListener(this, this.reset.bind(this)));
document.observe('AutoComplete:update', this.triggerEvent.bindAsEventListener(this, this.processInput.bind(this)));

this.reset();
},

triggerEvent: function(e, func)
{
switch (e.element()) {
case this.elt:
e.stop();
/* falls through */

case document:
func();
break;
}
},

checkActiveElt: function(elt)
{
return (document.activeElement &&
Expand Down

0 comments on commit 7a3f412

Please sign in to comment.