Skip to content

Commit

Permalink
Released 0.9.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreavis committed Mar 21, 2014
1 parent 4fcad2d commit d6a6f53
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 69 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "selectize",
"keywords": ["select", "ui", "form", "input", "control", "autocomplete", "tagging", "tag"],
"description": "Selectize is a jQuery-based custom <select> UI control. Useful for tagging, contact lists, country selectors, etc.",
"version": "0.8.5",
"version": "0.9.0",
"license": "Apache License, Version 2.0",
"readmeFilename": "README.md",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion dist/css/selectize.bootstrap2.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* selectize.bootstrap2.css (v0.8.5) - Bootstrap 2 Theme
* selectize.bootstrap2.css (v0.9.0) - Bootstrap 2 Theme
* Copyright (c) 2013 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
Expand Down
2 changes: 1 addition & 1 deletion dist/css/selectize.bootstrap3.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* selectize.bootstrap3.css (v0.8.5) - Bootstrap 3 Theme
* selectize.bootstrap3.css (v0.9.0) - Bootstrap 3 Theme
* Copyright (c) 2013 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
Expand Down
2 changes: 1 addition & 1 deletion dist/css/selectize.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* selectize.css (v0.8.5)
* selectize.css (v0.9.0)
* Copyright (c) 2013 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
Expand Down
2 changes: 1 addition & 1 deletion dist/css/selectize.default.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* selectize.default.css (v0.8.5) - Default Theme
* selectize.default.css (v0.9.0) - Default Theme
* Copyright (c) 2013 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
Expand Down
2 changes: 1 addition & 1 deletion dist/css/selectize.legacy.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* selectize.legacy.css (v0.8.5) - Default Theme
* selectize.legacy.css (v0.9.0) - Default Theme
* Copyright (c) 2013 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
Expand Down
82 changes: 59 additions & 23 deletions dist/js/selectize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* selectize.js (v0.8.5)
* selectize.js (v0.9.0)
* Copyright (c) 2013 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
Expand All @@ -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 @@ -1100,10 +1119,7 @@
setValue: function(value) {
debounce_events(this, ['change'], function() {
this.clear();
var items = $.isArray(value) ? value : [value];
for (var i = 0, n = items.length; i < n; i++) {
this.addItem(items[i]);
}
this.addItems(value);
});
},

Expand Down Expand Up @@ -1669,6 +1685,20 @@
return this.getElementWithValue(value, this.$control.children());
},

/**
* "Selects" multiple items at once. Adds them to the list
* at the current caret position.
*
* @param {string} value
*/
addItems: function(values) {
var items = $.isArray(values) ? values : [values];
for (var i = 0, n = items.length; i < n; i++) {
this.isPending = (i < n - 1);
this.addItem(items[i]);
}
},

/**
* "Selects" an item. Adds it to the list
* at the current caret position.
Expand All @@ -1677,10 +1707,10 @@
*/
addItem: function(value) {
debounce_events(this, ['change'], function() {
var $item, $option;
var $item, $option, $options;
var self = this;
var inputMode = self.settings.mode;
var i, active, options, value_next;
var i, active, value_next;
value = hash_key(value);

if (self.items.indexOf(value) !== -1) {
Expand All @@ -1698,18 +1728,20 @@
self.refreshState();

if (self.isSetup) {
options = self.$dropdown_content.find('[data-selectable]');

// update menu / remove the option
$option = self.getOption(value);
value_next = self.getAdjacentOption($option, 1).attr('data-value');
self.refreshOptions(self.isFocused && inputMode !== 'single');
if (value_next) {
self.setActiveOption(self.getOption(value_next));
$options = self.$dropdown_content.find('[data-selectable]');

// update menu / remove the option (if this is not one item being added as part of series)
if (!this.isPending) {
$option = self.getOption(value);
value_next = self.getAdjacentOption($option, 1).attr('data-value');
self.refreshOptions(self.isFocused && inputMode !== 'single');
if (value_next) {
self.setActiveOption(self.getOption(value_next));
}
}

// hide the menu if the maximum number of items have been selected or no options are left
if (!options.length || (self.settings.maxItems !== null && self.items.length >= self.settings.maxItems)) {
if (!$options.length || (self.settings.maxItems !== null && self.items.length >= self.settings.maxItems)) {
self.close();
} else {
self.positionDropdown();
Expand Down Expand Up @@ -1771,13 +1803,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 +1832,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 +2740,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
6 changes: 3 additions & 3 deletions dist/js/selectize.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit d6a6f53

Please sign in to comment.