|
@@ -12181,6 +12181,93 @@ define('select2/data/tags',[
|
|
return Tags;
|
|
return Tags;
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+define('select2/data/tokenizer',[
|
|
|
|
+
|
|
|
|
+], function () {
|
|
|
|
+ function Tokenizer (decorated, $element, options) {
|
|
|
|
+ var tokenizer = options.get('tokenizer');
|
|
|
|
+
|
|
|
|
+ if (tokenizer !== undefined) {
|
|
|
|
+ this.tokenizer = tokenizer;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ decorated.call(this, $element, options);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Tokenizer.prototype.bind = function (decorated, container, $container) {
|
|
|
|
+ decorated.call(this, container, $container);
|
|
|
|
+
|
|
|
|
+ this.$search = container.dropdown.$search || container.selection.$search ||
|
|
|
|
+ $container.find('.select2-search__field');
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ Tokenizer.prototype.query = function (decorated, params, callback) {
|
|
|
|
+ var self = this;
|
|
|
|
+
|
|
|
|
+ function select (data) {
|
|
|
|
+ self.select(data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ params.term = params.term || '';
|
|
|
|
+
|
|
|
|
+ var tokenData = this.tokenizer(params, this.options, select);
|
|
|
|
+
|
|
|
|
+ if (tokenData.term !== params.term) {
|
|
|
|
+ // Replace the search term if we have the search box
|
|
|
|
+ if (this.$search.length) {
|
|
|
|
+ this.$search.val(tokenData.term);
|
|
|
|
+ this.$search.focus();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ params.term = tokenData.term;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ decorated.call(this, params, callback);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ Tokenizer.prototype.tokenizer = function (_, params, options, callback) {
|
|
|
|
+ var separators = options.get('tokenSeparators') || [];
|
|
|
|
+ var term = params.term;
|
|
|
|
+ var i = 0;
|
|
|
|
+
|
|
|
|
+ var createTag = this.createTag || function (params) {
|
|
|
|
+ return {
|
|
|
|
+ id: params.term,
|
|
|
|
+ text: params.term
|
|
|
|
+ };
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ while (i < term.length) {
|
|
|
|
+ var termChar = term[i];
|
|
|
|
+
|
|
|
|
+ if (separators.indexOf(termChar) === -1) {
|
|
|
|
+ i++;
|
|
|
|
+
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var part = term.substr(0, i);
|
|
|
|
+ var partParams = $.extend({}, params, {
|
|
|
|
+ term: part
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ var data = createTag(partParams);
|
|
|
|
+
|
|
|
|
+ callback(data);
|
|
|
|
+
|
|
|
|
+ // Reset the term to not include the tokenized portion
|
|
|
|
+ term = term.substr(i + 1) || '';
|
|
|
|
+ i = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ term: term
|
|
|
|
+ };
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return Tokenizer;
|
|
|
|
+});
|
|
|
|
+
|
|
define('select2/data/minimumInputLength',[
|
|
define('select2/data/minimumInputLength',[
|
|
|
|
|
|
], function () {
|
|
], function () {
|
|
@@ -12746,6 +12833,7 @@ define('select2/defaults',[
|
|
'./data/array',
|
|
'./data/array',
|
|
'./data/ajax',
|
|
'./data/ajax',
|
|
'./data/tags',
|
|
'./data/tags',
|
|
|
|
+ './data/tokenizer',
|
|
'./data/minimumInputLength',
|
|
'./data/minimumInputLength',
|
|
'./data/maximumInputLength',
|
|
'./data/maximumInputLength',
|
|
|
|
|
|
@@ -12764,7 +12852,7 @@ define('select2/defaults',[
|
|
|
|
|
|
Utils, Translation, DIACRITICS,
|
|
Utils, Translation, DIACRITICS,
|
|
|
|
|
|
- SelectData, ArrayData, AjaxData, Tags,
|
|
|
|
|
|
+ SelectData, ArrayData, AjaxData, Tags, Tokenizer,
|
|
MinimumInputLength, MaximumInputLength,
|
|
MinimumInputLength, MaximumInputLength,
|
|
|
|
|
|
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
|
|
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
|
|
@@ -12804,6 +12892,13 @@ define('select2/defaults',[
|
|
if (options.tags != null) {
|
|
if (options.tags != null) {
|
|
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
|
|
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (options.tokenSeparators != null || options.tokenizer != null) {
|
|
|
|
+ options.dataAdapter = Utils.Decorate(
|
|
|
|
+ options.dataAdapter,
|
|
|
|
+ Tokenizer
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (options.resultsAdapter == null) {
|
|
if (options.resultsAdapter == null) {
|