Skip to content

Commit ff304db

Browse files
committed
Merge master into 0.8.
2 parents b453526 + 9e80f48 commit ff304db

20 files changed

+175
-78
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "selectize",
33
"keywords": ["select", "ui", "form", "input", "control", "autocomplete", "tagging", "tag"],
44
"description": "Selectize is a jQuery-based custom <select> UI control. Useful for tagging, contact lists, country selectors, etc.",
5-
"version": "0.7.5",
5+
"version": "0.7.7",
66
"license": "Apache License, Version 2.0",
77
"readmeFilename": "README.md",
88
"repository": {

dist/css/selectize.bootstrap2.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.bootstrap2.css (v0.7.5) - Bootstrap 2 Theme
2+
* selectize.bootstrap2.css (v0.7.7) - Bootstrap 2 Theme
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

dist/css/selectize.bootstrap3.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.bootstrap3.css (v0.7.5) - Bootstrap 3 Theme
2+
* selectize.bootstrap3.css (v0.7.7) - Bootstrap 3 Theme
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

dist/css/selectize.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.css (v0.7.5)
2+
* selectize.css (v0.7.7)
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

dist/css/selectize.default.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.default.css (v0.7.5) - Default Theme
2+
* selectize.default.css (v0.7.7) - Default Theme
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

dist/css/selectize.legacy.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.legacy.css (v0.7.5) - Default Theme
2+
* selectize.legacy.css (v0.7.7) - Default Theme
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

dist/js/selectize.js

+36-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.js (v0.7.5)
2+
* selectize.js (v0.7.7)
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
@@ -157,17 +157,6 @@
157157
.replace(/"/g, '&quot;');
158158
};
159159

160-
/**
161-
* Escapes quotation marks with backslashes. Useful
162-
* for escaping values for use in CSS attribute selectors.
163-
*
164-
* @param {string} str
165-
* @return {string}
166-
*/
167-
var escape_quotes = function(str) {
168-
return str.replace(/(['"])/g, '\\$1');
169-
};
170-
171160
var hook = {};
172161

173162
/**
@@ -1427,7 +1416,7 @@
14271416
*/
14281417
addOptionGroup: function(id, data) {
14291418
this.optgroups[id] = data;
1430-
this.trigger('optgroup_add', value, data);
1419+
this.trigger('optgroup_add', id, data);
14311420
},
14321421

14331422
/**
@@ -1525,8 +1514,7 @@
15251514
* @returns {object}
15261515
*/
15271516
getOption: function(value) {
1528-
value = hash_key(value);
1529-
return value ? this.$dropdown_content.find('[data-selectable]').filter('[data-value="' + escape_quotes(value) + '"]:first') : $();
1517+
return this.getElementWithValue(value, this.$dropdown_content.find('[data-selectable]'));
15301518
},
15311519

15321520
/**
@@ -1544,6 +1532,28 @@
15441532
return index >= 0 && index < $options.length ? $options.eq(index) : $();
15451533
},
15461534

1535+
/**
1536+
* Finds the first element with a "data-value" attribute
1537+
* that matches the given value.
1538+
*
1539+
* @param {mixed} value
1540+
* @param {object} $els
1541+
* @return {object}
1542+
*/
1543+
getElementWithValue: function(value, $els) {
1544+
value = hash_key(value);
1545+
1546+
if (value) {
1547+
for (var i = 0, n = $els.length; i < n; i++) {
1548+
if ($els[i].getAttribute('data-value') === value) {
1549+
return $($els[i]);
1550+
}
1551+
}
1552+
}
1553+
1554+
return $();
1555+
},
1556+
15471557
/**
15481558
* Returns the jQuery element of the item
15491559
* matching the given value.
@@ -1552,7 +1562,7 @@
15521562
* @returns {object}
15531563
*/
15541564
getItem: function(value) {
1555-
return this.$control.children('[data-value="' + escape_quotes(hash_key(value)) + '"]');
1565+
return this.getElementWithValue(value, this.$control.children());
15561566
},
15571567

15581568
/**
@@ -2161,7 +2171,7 @@
21612171

21622172
dataAttr: 'data-data',
21632173
optgroupField: 'optgroup',
2164-
sortField: null,
2174+
sortField: '$order',
21652175
sortDirection: 'asc',
21662176
valueField: 'value',
21672177
labelField: 'text',
@@ -2242,6 +2252,7 @@
22422252
var init_select = function($input, settings_element) {
22432253
var i, n, tagName;
22442254
var $children;
2255+
var order = 0;
22452256
settings_element.maxItems = !!$input.attr('multiple') ? null : 1;
22462257

22472258
var readData = function($el) {
@@ -2253,16 +2264,22 @@
22532264
};
22542265

22552266
var addOption = function($option, group) {
2267+
var value, option;
2268+
22562269
$option = $($option);
22572270

2258-
var value = $option.attr('value') || '';
2271+
value = $option.attr('value') || '';
22592272
if (!value.length) return;
22602273

2261-
settings_element.options[value] = readData($option) || {
2274+
option = readData($option) || {
22622275
'text' : $option.text(),
22632276
'value' : value,
22642277
'optgroup' : group
22652278
};
2279+
2280+
option.$order = ++order;
2281+
settings_element.options[value] = option;
2282+
22662283
if ($option.is(':selected')) {
22672284
settings_element.items.push(value);
22682285
}

dist/js/selectize.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/standalone/selectize.js

+49-25
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,7 @@
258258
var field = options.sort;
259259
var multiplier = options.direction === 'desc' ? -1 : 1;
260260
return function(a, b) {
261-
a = a && String(self.items[a.id][field] || '').toLowerCase();
262-
b = b && String(self.items[b.id][field] || '').toLowerCase();
263-
if (a > b) return 1 * multiplier;
264-
if (b > a) return -1 * multiplier;
265-
return 0;
261+
return cmp(self.items[a.id][field], self.items[b.id][field]) * multiplier;
266262
};
267263
})());
268264
}
@@ -280,6 +276,17 @@
280276
// utilities
281277
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
282278

279+
var cmp = function(a, b) {
280+
if (typeof a === 'number' && typeof b === 'number') {
281+
return a > b ? 1 : (a < b ? -1 : 0);
282+
}
283+
a = String(a || '').toLowerCase();
284+
b = String(b || '').toLowerCase();
285+
if (a > b) return 1;
286+
if (b > a) return -1;
287+
return 0;
288+
};
289+
283290
var extend = function(a, b) {
284291
var i, n, k, object;
285292
for (i = 1, n = arguments.length; i < n; i++) {
@@ -454,7 +461,7 @@
454461
};
455462

456463
var utils = {
457-
isArray: Array.isArray || function() {
464+
isArray: Array.isArray || function(vArg) {
458465
return Object.prototype.toString.call(vArg) === '[object Array]';
459466
}
460467
};
@@ -463,7 +470,7 @@
463470
}));
464471

465472
/**
466-
* selectize.js (v0.7.5)
473+
* selectize.js (v0.7.7)
467474
* Copyright (c) 2013 Brian Reavis & contributors
468475
*
469476
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
@@ -621,17 +628,6 @@
621628
.replace(/"/g, '&quot;');
622629
};
623630

624-
/**
625-
* Escapes quotation marks with backslashes. Useful
626-
* for escaping values for use in CSS attribute selectors.
627-
*
628-
* @param {string} str
629-
* @return {string}
630-
*/
631-
var escape_quotes = function(str) {
632-
return str.replace(/(['"])/g, '\\$1');
633-
};
634-
635631
var hook = {};
636632

637633
/**
@@ -1893,7 +1889,7 @@
18931889
*/
18941890
addOptionGroup: function(id, data) {
18951891
this.optgroups[id] = data;
1896-
this.trigger('optgroup_add', value, data);
1892+
this.trigger('optgroup_add', id, data);
18971893
},
18981894

18991895
/**
@@ -1991,8 +1987,7 @@
19911987
* @returns {object}
19921988
*/
19931989
getOption: function(value) {
1994-
value = hash_key(value);
1995-
return value ? this.$dropdown_content.find('[data-selectable]').filter('[data-value="' + escape_quotes(value) + '"]:first') : $();
1990+
return this.getElementWithValue(value, this.$dropdown_content.find('[data-selectable]'));
19961991
},
19971992

19981993
/**
@@ -2010,6 +2005,28 @@
20102005
return index >= 0 && index < $options.length ? $options.eq(index) : $();
20112006
},
20122007

2008+
/**
2009+
* Finds the first element with a "data-value" attribute
2010+
* that matches the given value.
2011+
*
2012+
* @param {mixed} value
2013+
* @param {object} $els
2014+
* @return {object}
2015+
*/
2016+
getElementWithValue: function(value, $els) {
2017+
value = hash_key(value);
2018+
2019+
if (value) {
2020+
for (var i = 0, n = $els.length; i < n; i++) {
2021+
if ($els[i].getAttribute('data-value') === value) {
2022+
return $($els[i]);
2023+
}
2024+
}
2025+
}
2026+
2027+
return $();
2028+
},
2029+
20132030
/**
20142031
* Returns the jQuery element of the item
20152032
* matching the given value.
@@ -2018,7 +2035,7 @@
20182035
* @returns {object}
20192036
*/
20202037
getItem: function(value) {
2021-
return this.$control.children('[data-value="' + escape_quotes(hash_key(value)) + '"]');
2038+
return this.getElementWithValue(value, this.$control.children());
20222039
},
20232040

20242041
/**
@@ -2627,7 +2644,7 @@
26272644

26282645
dataAttr: 'data-data',
26292646
optgroupField: 'optgroup',
2630-
sortField: null,
2647+
sortField: '$order',
26312648
sortDirection: 'asc',
26322649
valueField: 'value',
26332650
labelField: 'text',
@@ -2708,6 +2725,7 @@
27082725
var init_select = function($input, settings_element) {
27092726
var i, n, tagName;
27102727
var $children;
2728+
var order = 0;
27112729
settings_element.maxItems = !!$input.attr('multiple') ? null : 1;
27122730

27132731
var readData = function($el) {
@@ -2719,16 +2737,22 @@
27192737
};
27202738

27212739
var addOption = function($option, group) {
2740+
var value, option;
2741+
27222742
$option = $($option);
27232743

2724-
var value = $option.attr('value') || '';
2744+
value = $option.attr('value') || '';
27252745
if (!value.length) return;
27262746

2727-
settings_element.options[value] = readData($option) || {
2747+
option = readData($option) || {
27282748
'text' : $option.text(),
27292749
'value' : value,
27302750
'optgroup' : group
27312751
};
2752+
2753+
option.$order = ++order;
2754+
settings_element.options[value] = option;
2755+
27322756
if ($option.is(':selected')) {
27332757
settings_element.items.push(value);
27342758
}

dist/js/standalone/selectize.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/less/selectize.bootstrap2.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.bootstrap2.css (v0.7.5) - Bootstrap 2 Theme
2+
* selectize.bootstrap2.css (v0.7.7) - Bootstrap 2 Theme
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

dist/less/selectize.bootstrap3.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.bootstrap3.css (v0.7.5) - Bootstrap 3 Theme
2+
* selectize.bootstrap3.css (v0.7.7) - Bootstrap 3 Theme
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

dist/less/selectize.default.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.default.css (v0.7.5) - Default Theme
2+
* selectize.default.css (v0.7.7) - Default Theme
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

dist/less/selectize.legacy.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* selectize.legacy.css (v0.7.5) - Default Theme
2+
* selectize.legacy.css (v0.7.7) - Default Theme
33
* Copyright (c) 2013 Brian Reavis & contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "selectize",
33
"keywords": ["select", "ui", "form", "input", "control", "autocomplete", "tagging", "tag"],
44
"description": "Selectize is a jQuery-based custom <select> UI control. Useful for tagging, contact lists, country selectors, etc.",
5-
"version": "0.7.5",
5+
"version": "0.7.7",
66
"author": "Brian Reavis <[email protected]>",
77
"repository": {
88
"type": "git",

selectize.jquery.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selectize",
3-
"version": "0.7.5",
3+
"version": "0.7.7",
44
"title": "Selectize.js",
55
"author": {
66
"name": "Brian Reavis",

0 commit comments

Comments
 (0)