Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions dist/js/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery','sifter','microplugin'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('jquery'), require('sifter'), require('microplugin'));
} else {
root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin);
}
Expand Down Expand Up @@ -105,8 +107,10 @@
var KEY_ESC = 27;
var KEY_LEFT = 37;
var KEY_UP = 38;
var KEY_P = 80;
var KEY_RIGHT = 39;
var KEY_DOWN = 40;
var KEY_N = 78;
var KEY_BACKSPACE = 8;
var KEY_DELETE = 46;
var KEY_SHIFT = 16;
Expand All @@ -117,6 +121,7 @@
var TAG_SELECT = 1;
var TAG_INPUT = 2;


var isset = function(object) {
return typeof object !== 'undefined';
};
Expand Down Expand Up @@ -363,6 +368,10 @@
* @returns {int}
*/
var measureString = function(str, $parent) {
if (!str) {
return 0;
}

var $test = $('<test>').css({
position: 'absolute',
top: -99999,
Expand Down Expand Up @@ -396,6 +405,8 @@
* @param {object} $input
*/
var autoGrow = function($input) {
var currentWidth = null;

var update = function(e) {
var value, keyCode, printable, placeholder, width;
var shift, character, selection;
Expand Down Expand Up @@ -438,7 +449,8 @@
}

width = measureString(value, $input) + 4;
if (width !== $input.width()) {
if (width !== currentWidth) {
currentWidth = width;
$input.width(width);
$input.triggerHandler('resize');
}
Expand Down Expand Up @@ -560,7 +572,7 @@

$wrapper = $('<div>').addClass(settings.wrapperClass).addClass(classes).addClass(inputMode);
$control = $('<div>').addClass(settings.inputClass).addClass('items').appendTo($wrapper);
$control_input = $('<input type="text" autocomplete="off">').appendTo($control).attr('tabindex', tab_index);
$control_input = $('<input type="text" autocomplete="off" />').appendTo($control).attr('tabindex', tab_index);
$dropdown_parent = $(settings.dropdownParent || $wrapper);
$dropdown = $('<div>').addClass(settings.dropdownClass).addClass(classes).addClass(inputMode).hide().appendTo($dropdown_parent);
$dropdown_content = $('<div>').addClass(settings.dropdownContentClass).appendTo($dropdown);
Expand Down Expand Up @@ -680,7 +692,7 @@
self.trigger('initialize');

// preload options
if (settings.preload) {
if (settings.preload === true) {
self.onSearchChange('');
}
},
Expand Down Expand Up @@ -846,6 +858,8 @@
case KEY_ESC:
self.close();
return;
case KEY_N:
if (!e.ctrlKey) break;
case KEY_DOWN:
if (!self.isOpen && self.hasOptions) {
self.open();
Expand All @@ -856,6 +870,8 @@
}
e.preventDefault();
return;
case KEY_P:
if (!e.ctrlKey) break;
case KEY_UP:
if (self.$activeOption) {
self.ignoreHover = true;
Expand All @@ -877,6 +893,9 @@
self.advanceSelection(1, e);
return;
case KEY_TAB:
if (self.isOpen && self.$activeOption) {
self.onOptionSelect({currentTarget: self.$activeOption});
}
if (self.settings.create && self.createItem()) {
e.preventDefault();
}
Expand Down Expand Up @@ -970,7 +989,7 @@
if (self.ignoreFocus) return;

if (self.settings.create && self.settings.createOnBlur) {
self.createItem();
self.createItem(false);
}

self.close();
Expand Down Expand Up @@ -1771,13 +1790,17 @@
*
* @return {boolean}
*/
createItem: function() {
createItem: function(triggerDropdown) {
var self = this;
var input = $.trim(self.$control_input.val() || '');
var caret = self.caretPos;
if (!input.length) return false;
self.lock();

if (typeof triggerDropdown === 'undefined') {
triggerDropdown = true;
}

var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) {
var data = {};
data[self.settings.labelField] = input;
Expand All @@ -1796,7 +1819,7 @@
self.addOption(data);
self.setCaret(caret);
self.addItem(value);
self.refreshOptions(self.settings.mode !== 'single');
self.refreshOptions(triggerDropdown && self.settings.mode !== 'single');
});

var output = setup.apply(this, [input, create]);
Expand Down Expand Up @@ -2704,7 +2727,7 @@
e.preventDefault();
if (self.isLocked) return;

var $item = $(e.target).parent();
var $item = $(e.currentTarget).parent();
self.setActiveItem($item);
if (self.deleteSelection()) {
self.setCaret(self.items.length);
Expand Down Expand Up @@ -2745,4 +2768,4 @@
});

return Selectize;
}));
}));
4 changes: 2 additions & 2 deletions dist/js/selectize.min.js

Large diffs are not rendered by default.

39 changes: 31 additions & 8 deletions dist/js/standalone/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define('selectize', ['jquery','sifter','microplugin'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('jquery'), require('sifter'), require('microplugin'));
} else {
root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin);
}
Expand Down Expand Up @@ -689,8 +691,10 @@
var KEY_ESC = 27;
var KEY_LEFT = 37;
var KEY_UP = 38;
var KEY_P = 80;
var KEY_RIGHT = 39;
var KEY_DOWN = 40;
var KEY_N = 78;
var KEY_BACKSPACE = 8;
var KEY_DELETE = 46;
var KEY_SHIFT = 16;
Expand All @@ -701,6 +705,7 @@
var TAG_SELECT = 1;
var TAG_INPUT = 2;


var isset = function(object) {
return typeof object !== 'undefined';
};
Expand Down Expand Up @@ -947,6 +952,10 @@
* @returns {int}
*/
var measureString = function(str, $parent) {
if (!str) {
return 0;
}

var $test = $('<test>').css({
position: 'absolute',
top: -99999,
Expand Down Expand Up @@ -980,6 +989,8 @@
* @param {object} $input
*/
var autoGrow = function($input) {
var currentWidth = null;

var update = function(e) {
var value, keyCode, printable, placeholder, width;
var shift, character, selection;
Expand Down Expand Up @@ -1022,7 +1033,8 @@
}

width = measureString(value, $input) + 4;
if (width !== $input.width()) {
if (width !== currentWidth) {
currentWidth = width;
$input.width(width);
$input.triggerHandler('resize');
}
Expand Down Expand Up @@ -1144,7 +1156,7 @@

$wrapper = $('<div>').addClass(settings.wrapperClass).addClass(classes).addClass(inputMode);
$control = $('<div>').addClass(settings.inputClass).addClass('items').appendTo($wrapper);
$control_input = $('<input type="text" autocomplete="off">').appendTo($control).attr('tabindex', tab_index);
$control_input = $('<input type="text" autocomplete="off" />').appendTo($control).attr('tabindex', tab_index);
$dropdown_parent = $(settings.dropdownParent || $wrapper);
$dropdown = $('<div>').addClass(settings.dropdownClass).addClass(classes).addClass(inputMode).hide().appendTo($dropdown_parent);
$dropdown_content = $('<div>').addClass(settings.dropdownContentClass).appendTo($dropdown);
Expand Down Expand Up @@ -1264,7 +1276,7 @@
self.trigger('initialize');

// preload options
if (settings.preload) {
if (settings.preload === true) {
self.onSearchChange('');
}
},
Expand Down Expand Up @@ -1430,6 +1442,8 @@
case KEY_ESC:
self.close();
return;
case KEY_N:
if (!e.ctrlKey) break;
case KEY_DOWN:
if (!self.isOpen && self.hasOptions) {
self.open();
Expand All @@ -1440,6 +1454,8 @@
}
e.preventDefault();
return;
case KEY_P:
if (!e.ctrlKey) break;
case KEY_UP:
if (self.$activeOption) {
self.ignoreHover = true;
Expand All @@ -1461,6 +1477,9 @@
self.advanceSelection(1, e);
return;
case KEY_TAB:
if (self.isOpen && self.$activeOption) {
self.onOptionSelect({currentTarget: self.$activeOption});
}
if (self.settings.create && self.createItem()) {
e.preventDefault();
}
Expand Down Expand Up @@ -1554,7 +1573,7 @@
if (self.ignoreFocus) return;

if (self.settings.create && self.settings.createOnBlur) {
self.createItem();
self.createItem(false);
}

self.close();
Expand Down Expand Up @@ -2355,13 +2374,17 @@
*
* @return {boolean}
*/
createItem: function() {
createItem: function(triggerDropdown) {
var self = this;
var input = $.trim(self.$control_input.val() || '');
var caret = self.caretPos;
if (!input.length) return false;
self.lock();

if (typeof triggerDropdown === 'undefined') {
triggerDropdown = true;
}

var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) {
var data = {};
data[self.settings.labelField] = input;
Expand All @@ -2380,7 +2403,7 @@
self.addOption(data);
self.setCaret(caret);
self.addItem(value);
self.refreshOptions(self.settings.mode !== 'single');
self.refreshOptions(triggerDropdown && self.settings.mode !== 'single');
});

var output = setup.apply(this, [input, create]);
Expand Down Expand Up @@ -3288,7 +3311,7 @@
e.preventDefault();
if (self.isLocked) return;

var $item = $(e.target).parent();
var $item = $(e.currentTarget).parent();
self.setActiveItem($item);
if (self.deleteSelection()) {
self.setCaret(self.items.length);
Expand Down Expand Up @@ -3329,4 +3352,4 @@
});

return Selectize;
}));
}));
4 changes: 2 additions & 2 deletions dist/js/standalone/selectize.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/.wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery','sifter','microplugin'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('jquery'), require('sifter'), require('microplugin'));
} else {
root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin);
}
Expand All @@ -29,4 +31,4 @@
@@js

return Selectize;
}));
}));