Skip to content

Commit

Permalink
Merge pull request #418 from yourlabs/feature/modern_events
Browse files Browse the repository at this point in the history
Fix #411: support Android
  • Loading branch information
jpic committed May 23, 2015
2 parents 8bcc137 + 733299f commit 500b566
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions autocomplete_light/static/autocomplete_light/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,29 @@ the constructor, setup is done in this method. This allows to:
- and *then* setup the instance.
*/
yourlabs.Autocomplete.prototype.initialize = function() {
var ie = yourlabs.getInternetExplorerVersion();

this.input
.on('blur.autocomplete', $.proxy(this.inputBlur, this))
.on('click.autocomplete', $.proxy(this.inputClick, this))
.on('keypress.autocomplete', $.proxy(this.inputKeypress, this))
.on('keyup.autocomplete', $.proxy(this.inputKeyup, this))
.on('keydown.autocomplete', $.proxy(this.inputKeydown, this));
.on('focus.autocomplete', $.proxy(this.inputClick, this))
.on('keydown.autocomplete', $.proxy(this.inputKeyup, this));

if (ie == -1 || ie > 9) {
this.input.on('input.autocomplete', $.proxy(this.refresh, this));
}
else
{
var events = [
'keyup.autocomplete',
'keypress.autocomplete',
'cut.autocomplete',
'paste.autocomplete'
]

this.input.on(events.join(' '), function($e) {
$.proxy(this.inputKeyup, this);
})
}

/*
Bind mouse events to fire signals. Because the same signals will be
Expand All @@ -274,10 +291,11 @@ yourlabs.Autocomplete.prototype.initialize = function() {
yourlabs.Autocomplete.prototype.destroy = function(input) {
input
.unbind('blur.autocomplete')
.unbind('click.autocomplete')
.unbind('focus.autocomplete')
.unbind('input.autocomplete')
.unbind('keydown.autocomplete')
.unbind('keypress.autocomplete')
.unbind('keyup.autocomplete')
.unbind('keydown.autocomplete');
};

yourlabs.Autocomplete.prototype.inputBlur = function(e) {
Expand Down Expand Up @@ -334,6 +352,7 @@ yourlabs.Autocomplete.prototype.inputKeyup = function(e) {
case 16: // shift
case 17: // ctrl
case 18: // alt
this.move(e);
break;

case 9: // tab
Expand Down Expand Up @@ -364,27 +383,6 @@ yourlabs.Autocomplete.prototype.inputKeyup = function(e) {
}
};

yourlabs.Autocomplete.prototype.inputKeydown = function(e) {
// Don't handle keypresses on hidden inputs (ie. with limited choices)
if (!this.input.is(':visible')) return;

// Avoid double call to move().
this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27]);

this.move(e);
};

// This function is in charge of keyboard usage.
yourlabs.Autocomplete.prototype.inputKeypress = function(e) {
// Don't handle keypresses on hidden inputs (ie. with limited choices)
if (!this.input.is(':visible')) return;

// Return if it already handled by inputKeydown.
if (this.suppressKeyPressRepeat) return;

this.move(e);
};

// This function is in charge of ensuring that a relevant autocomplete is
// shown.
yourlabs.Autocomplete.prototype.show = function(html) {
Expand Down

0 comments on commit 500b566

Please sign in to comment.