Skip to content

Commit

Permalink
Prepping for 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
indrimuska committed Oct 13, 2016
1 parent 7acadde commit b0bd28e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-editable-select",
"version": "2.1.0",
"version": "2.2.0",
"authors": [
"Indri Muska <[email protected]>"
],
Expand Down
78 changes: 44 additions & 34 deletions dist/jquery-editable-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
this.$list = $('<ul class="es-list">');
this.utility = new EditableSelectUtility(this);

if (['focus', 'manual'].indexOf(this.options.trigger) < 0) this.options.trigger = 'focus';
if (['default', 'fade', 'slide'].indexOf(this.options.effects) < 0) this.options.effects = 'default';
if (isNaN(this.options.duration) || ['fast', 'slow'].indexOf(this.options.duration) < 0) this.options.duration = 'fast';

Expand All @@ -29,7 +30,7 @@
this.utility.initializeInput();
this.utility.trigger('created');
}
EditableSelect.DEFAULTS = { filter: true, effects: 'default', duration: 'fast' };
EditableSelect.DEFAULTS = { filter: true, effects: 'default', duration: 'fast', trigger: 'focus' };
EditableSelect.prototype.filter = function () {
var hiddens = 0;
var search = this.$input.val().toLowerCase().trim();
Expand Down Expand Up @@ -99,7 +100,7 @@
this.filter();
};
EditableSelect.prototype.destroy = function () {
this.$list.off('mousemove click mouseenter');
this.$list.off('mousemove mousedown mouseup');
this.$input.off('focus blur input keydown');
this.$input.replaceWith(this.$select);
this.$list.remove();
Expand Down Expand Up @@ -128,45 +129,54 @@
that.es.$list.find('.selected').removeClass('selected');
$(this).addClass('selected');
})
.on('click', 'li', function () {
.on('mousedown', 'li', function () {
that.es.select($(this));
})
.on('mouseenter', function () {
.on('mouseup', function () {
that.es.$list.find('li.selected').removeClass('selected');
});
};
EditableSelectUtility.prototype.initializeInput = function () {
var that = this;
that.es.$input
.on('focus', $.proxy(that.es.show, that.es))
.on('blur', $.proxy(that.es.hide, that.es))
.on('input keydown', function (e) {
switch (e.keyCode) {
case 38: // Up
var visibles = that.es.$list.find('li.es-visible');
var selected = visibles.index(visibles.filter('li.selected')) || 0;
that.highlight(selected - 1);
break;
case 40: // Down
var visibles = that.es.$list.find('li.es-visible');
var selected = visibles.index(visibles.filter('li.selected')) || 0;
that.highlight(selected + 1);
break;
case 13: // Enter
if (that.es.$list.is(':visible')) {
that.es.select(that.es.$list.find('li.selected'));
e.preventDefault();
}
case 9: // Tab
case 27: // Esc
that.es.hide();
break;
default:
that.es.filter();
that.highlight(0);
break;
}
});
switch (this.es.options.trigger) {
default:
case 'focus':
that.es.$input
.on('focus', $.proxy(that.es.show, that.es))
.on('blur', $.proxy(that.es.hide, that.es));
break;
case 'manual':
break;
}
that.es.$input.on('input keydown', function (e) {
switch (e.keyCode) {
case 38: // Up
var visibles = that.es.$list.find('li.es-visible');
var selected = visibles.index(visibles.filter('li.selected')) || 0;
that.highlight(selected - 1);
e.preventDefault();
break;
case 40: // Down
var visibles = that.es.$list.find('li.es-visible');
var selected = visibles.index(visibles.filter('li.selected')) || 0;
that.highlight(selected + 1);
e.preventDefault();
break;
case 13: // Enter
if (that.es.$list.is(':visible')) {
that.es.select(that.es.$list.find('li.selected'));
e.preventDefault();
}
case 9: // Tab
case 27: // Esc
that.es.hide();
break;
default:
that.es.filter();
that.highlight(0);
break;
}
});
};
EditableSelectUtility.prototype.highlight = function (index) {
var that = this;
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery-editable-select.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/jquery-editable-select.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-editable-select",
"version": "2.1.0",
"version": "2.2.0",
"description": "A simple jQuery Plugin that converts a select into an text field with suggestions.",
"main": "dist/jquery-editable-select.min.js",
"repository": {
Expand Down

0 comments on commit b0bd28e

Please sign in to comment.