diff --git a/dist/js/i18n/en.js b/dist/js/i18n/en.js index 05256fdb..d250115b 100644 --- a/dist/js/i18n/en.js +++ b/dist/js/i18n/en.js @@ -1 +1 @@ -window.$=window.$||{},function(){$&&$.fn&&$.fn.select2&&$.fn.select2.amd&&(define=$.fn.select2.amd.define,require=$.fn.select2.amd.require),define("select2/i18n/en",[],function(){return{noResults:function(){return"No results found"}}}),require("jquery.select2"),$.fn.select2.amd={define:define,require:require}}(); \ No newline at end of file +window.$=window.$||{},function(){$&&$.fn&&$.fn.select2&&$.fn.select2.amd&&(define=$.fn.select2.amd.define,require=$.fn.select2.amd.require),define("select2/i18n/en",[],function(){return{inputTooShort:function(e){var t=e.minimum-e.input.length,n="Please enter "+t+" or more character";return t!=1&&(n+="s"),n},noResults:function(){return"No results found"}}}),require("jquery.select2"),$.fn.select2.amd={define:define,require:require}}(); \ No newline at end of file diff --git a/dist/js/select2.amd.full.js b/dist/js/select2.amd.full.js index 653d3f84..5dec9b82 100644 --- a/dist/js/select2.amd.full.js +++ b/dist/js/select2.amd.full.js @@ -183,19 +183,25 @@ define('select2/results',[ this.$results.empty(); }; - Results.prototype.empty = function () { - var $empty = $('
  • '); + Results.prototype.displayMessage = function (params) { + this.clear(); - $empty.text(this.options.get('translations').get('noResults')); + var $message = $('
  • '); - this.$results.append($empty); + var message = this.options.get('translations').get(params.message); + + $message.text(message(params.args)); + + this.$results.append($message); }; Results.prototype.append = function (data) { var $options = []; if (data.length === 0) { - this.empty(); + this.trigger('results:message', { + message: 'noResults' + }); return; } @@ -449,6 +455,14 @@ define('select2/results',[ params.element.addClass('highlighted'); }); + container.on('results:message', function (params) { + self.trigger('results:message', params); + }); + + this.on('results:message', function (params) { + self.displayMessage(params); + }); + this.$results.on('mouseup', '.option[aria-selected]', function (evt) { var $this = $(this); @@ -741,10 +755,7 @@ define('select2/selection/multiple',[ '../utils' ], function (BaseSelection, Utils) { function MultipleSelection ($element, options) { - this.$element = $element; - this.options = options; - - MultipleSelection.__super__.constructor.call(this); + MultipleSelection.__super__.constructor.apply(this, arguments); } Utils.Extend(MultipleSelection, BaseSelection); @@ -1361,6 +1372,37 @@ define('select2/data/tags',[ return Tags; }); +define('select2/data/minimumInputLength',[ + +], function () { + function MinimumInputLength (decorated, $e, options) { + this.minimumInputLength = options.get('minimumInputLength'); + + decorated.call(this, $e, options); + } + + MinimumInputLength.prototype.query = function (decorated, params, callback) { + params.term = params.term || ''; + + if (params.term.length < this.minimumInputLength) { + this.trigger('results:message', { + message: 'inputTooShort', + args: { + minimum: this.minimumInputLength, + input: params.term, + params: params + } + }); + + return; + } + + decorated.call(this, params, callback); + }; + + return MinimumInputLength; +}); + define('select2/dropdown',[ './utils' ], function (Utils) { @@ -1421,13 +1463,7 @@ define('select2/dropdown/search',[ }); this.$search.on('keyup', function (evt) { - if (!self._keyUpPrevented) { - self.trigger('query', { - term: $(this).val() - }); - } - - self._keyUpPrevented = false; + self.handleSearch(evt); }); container.on('open', function () { @@ -1453,6 +1489,18 @@ define('select2/dropdown/search',[ }); }; + Search.prototype.handleSearch = function (evt) { + if (!this._keyUpPrevented) { + var input = this.$search.val(); + + this.trigger('query', { + term: input + }); + } + + this._keyUpPrevented = false; + }; + Search.prototype.showSearch = function (_, params) { return true; }; @@ -1505,6 +1553,17 @@ define('select2/dropdown/hidePlaceholder',[ define('select2/i18n/en',[],function () { return { + inputTooShort: function (args) { + var remainingChars = args.minimum - args.input.length; + + var message = 'Please enter ' + remainingChars + ' or more character'; + + if (remainingChars != 1) { + message += 's'; + } + + return message; + }, noResults: function () { return 'No results found'; } @@ -1526,6 +1585,7 @@ define('select2/defaults',[ './data/array', './data/ajax', './data/tags', + './data/minimumInputLength', './dropdown', './dropdown/search', @@ -1535,7 +1595,7 @@ define('select2/defaults',[ ], function ($, ResultsList, SingleSelection, MultipleSelection, Placeholder, Utils, Translation, - SelectData, ArrayData, AjaxData, Tags, + SelectData, ArrayData, AjaxData, Tags, MinimumInputLength, Dropdown, Search, HidePlaceholder, EnglishTranslation) { function Defaults () { @@ -1555,6 +1615,14 @@ define('select2/defaults',[ } } + + if (options.minimumInputLength > 0) { + options.dataAdapter = Utils.Decorate( + options.dataAdapter, + MinimumInputLength + ); + } + if (options.tags != null) { options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags); } @@ -1627,6 +1695,7 @@ define('select2/defaults',[ Defaults.prototype.reset = function () { this.defaults = { language: ['select2/i18n/en'], + minimumInputLength: 0, templateResult: function (result) { return result.text; }, @@ -1731,6 +1800,7 @@ define('select2/core',[ this._registerDomEvents(); // Register any internal event handlers + this._registerDataEvents(); this._registerSelectionEvents(); this._registerDropdownEvents(); this._registerResultsEvents(); @@ -1812,6 +1882,14 @@ define('select2/core',[ }); }; + Select2.prototype._registerDataEvents = function () { + var self = this; + + this.data.on('results:message', function (params) { + self.trigger('results:message', params); + }); + }; + Select2.prototype._registerSelectionEvents = function () { var self = this; diff --git a/dist/js/select2.amd.js b/dist/js/select2.amd.js index 653d3f84..5dec9b82 100644 --- a/dist/js/select2.amd.js +++ b/dist/js/select2.amd.js @@ -183,19 +183,25 @@ define('select2/results',[ this.$results.empty(); }; - Results.prototype.empty = function () { - var $empty = $('
  • '); + Results.prototype.displayMessage = function (params) { + this.clear(); - $empty.text(this.options.get('translations').get('noResults')); + var $message = $('
  • '); - this.$results.append($empty); + var message = this.options.get('translations').get(params.message); + + $message.text(message(params.args)); + + this.$results.append($message); }; Results.prototype.append = function (data) { var $options = []; if (data.length === 0) { - this.empty(); + this.trigger('results:message', { + message: 'noResults' + }); return; } @@ -449,6 +455,14 @@ define('select2/results',[ params.element.addClass('highlighted'); }); + container.on('results:message', function (params) { + self.trigger('results:message', params); + }); + + this.on('results:message', function (params) { + self.displayMessage(params); + }); + this.$results.on('mouseup', '.option[aria-selected]', function (evt) { var $this = $(this); @@ -741,10 +755,7 @@ define('select2/selection/multiple',[ '../utils' ], function (BaseSelection, Utils) { function MultipleSelection ($element, options) { - this.$element = $element; - this.options = options; - - MultipleSelection.__super__.constructor.call(this); + MultipleSelection.__super__.constructor.apply(this, arguments); } Utils.Extend(MultipleSelection, BaseSelection); @@ -1361,6 +1372,37 @@ define('select2/data/tags',[ return Tags; }); +define('select2/data/minimumInputLength',[ + +], function () { + function MinimumInputLength (decorated, $e, options) { + this.minimumInputLength = options.get('minimumInputLength'); + + decorated.call(this, $e, options); + } + + MinimumInputLength.prototype.query = function (decorated, params, callback) { + params.term = params.term || ''; + + if (params.term.length < this.minimumInputLength) { + this.trigger('results:message', { + message: 'inputTooShort', + args: { + minimum: this.minimumInputLength, + input: params.term, + params: params + } + }); + + return; + } + + decorated.call(this, params, callback); + }; + + return MinimumInputLength; +}); + define('select2/dropdown',[ './utils' ], function (Utils) { @@ -1421,13 +1463,7 @@ define('select2/dropdown/search',[ }); this.$search.on('keyup', function (evt) { - if (!self._keyUpPrevented) { - self.trigger('query', { - term: $(this).val() - }); - } - - self._keyUpPrevented = false; + self.handleSearch(evt); }); container.on('open', function () { @@ -1453,6 +1489,18 @@ define('select2/dropdown/search',[ }); }; + Search.prototype.handleSearch = function (evt) { + if (!this._keyUpPrevented) { + var input = this.$search.val(); + + this.trigger('query', { + term: input + }); + } + + this._keyUpPrevented = false; + }; + Search.prototype.showSearch = function (_, params) { return true; }; @@ -1505,6 +1553,17 @@ define('select2/dropdown/hidePlaceholder',[ define('select2/i18n/en',[],function () { return { + inputTooShort: function (args) { + var remainingChars = args.minimum - args.input.length; + + var message = 'Please enter ' + remainingChars + ' or more character'; + + if (remainingChars != 1) { + message += 's'; + } + + return message; + }, noResults: function () { return 'No results found'; } @@ -1526,6 +1585,7 @@ define('select2/defaults',[ './data/array', './data/ajax', './data/tags', + './data/minimumInputLength', './dropdown', './dropdown/search', @@ -1535,7 +1595,7 @@ define('select2/defaults',[ ], function ($, ResultsList, SingleSelection, MultipleSelection, Placeholder, Utils, Translation, - SelectData, ArrayData, AjaxData, Tags, + SelectData, ArrayData, AjaxData, Tags, MinimumInputLength, Dropdown, Search, HidePlaceholder, EnglishTranslation) { function Defaults () { @@ -1555,6 +1615,14 @@ define('select2/defaults',[ } } + + if (options.minimumInputLength > 0) { + options.dataAdapter = Utils.Decorate( + options.dataAdapter, + MinimumInputLength + ); + } + if (options.tags != null) { options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags); } @@ -1627,6 +1695,7 @@ define('select2/defaults',[ Defaults.prototype.reset = function () { this.defaults = { language: ['select2/i18n/en'], + minimumInputLength: 0, templateResult: function (result) { return result.text; }, @@ -1731,6 +1800,7 @@ define('select2/core',[ this._registerDomEvents(); // Register any internal event handlers + this._registerDataEvents(); this._registerSelectionEvents(); this._registerDropdownEvents(); this._registerResultsEvents(); @@ -1812,6 +1882,14 @@ define('select2/core',[ }); }; + Select2.prototype._registerDataEvents = function () { + var self = this; + + this.data.on('results:message', function (params) { + self.trigger('results:message', params); + }); + }; + Select2.prototype._registerSelectionEvents = function () { var self = this; diff --git a/dist/js/select2.full.js b/dist/js/select2.full.js index 0e2efbf2..9a6a9e83 100644 --- a/dist/js/select2.full.js +++ b/dist/js/select2.full.js @@ -9718,19 +9718,25 @@ define('select2/results',[ this.$results.empty(); }; - Results.prototype.empty = function () { - var $empty = $('
  • '); + Results.prototype.displayMessage = function (params) { + this.clear(); - $empty.text(this.options.get('translations').get('noResults')); + var $message = $('
  • '); - this.$results.append($empty); + var message = this.options.get('translations').get(params.message); + + $message.text(message(params.args)); + + this.$results.append($message); }; Results.prototype.append = function (data) { var $options = []; if (data.length === 0) { - this.empty(); + this.trigger('results:message', { + message: 'noResults' + }); return; } @@ -9984,6 +9990,14 @@ define('select2/results',[ params.element.addClass('highlighted'); }); + container.on('results:message', function (params) { + self.trigger('results:message', params); + }); + + this.on('results:message', function (params) { + self.displayMessage(params); + }); + this.$results.on('mouseup', '.option[aria-selected]', function (evt) { var $this = $(this); @@ -10276,10 +10290,7 @@ define('select2/selection/multiple',[ '../utils' ], function (BaseSelection, Utils) { function MultipleSelection ($element, options) { - this.$element = $element; - this.options = options; - - MultipleSelection.__super__.constructor.call(this); + MultipleSelection.__super__.constructor.apply(this, arguments); } Utils.Extend(MultipleSelection, BaseSelection); @@ -10896,6 +10907,37 @@ define('select2/data/tags',[ return Tags; }); +define('select2/data/minimumInputLength',[ + +], function () { + function MinimumInputLength (decorated, $e, options) { + this.minimumInputLength = options.get('minimumInputLength'); + + decorated.call(this, $e, options); + } + + MinimumInputLength.prototype.query = function (decorated, params, callback) { + params.term = params.term || ''; + + if (params.term.length < this.minimumInputLength) { + this.trigger('results:message', { + message: 'inputTooShort', + args: { + minimum: this.minimumInputLength, + input: params.term, + params: params + } + }); + + return; + } + + decorated.call(this, params, callback); + }; + + return MinimumInputLength; +}); + define('select2/dropdown',[ './utils' ], function (Utils) { @@ -10956,13 +10998,7 @@ define('select2/dropdown/search',[ }); this.$search.on('keyup', function (evt) { - if (!self._keyUpPrevented) { - self.trigger('query', { - term: $(this).val() - }); - } - - self._keyUpPrevented = false; + self.handleSearch(evt); }); container.on('open', function () { @@ -10988,6 +11024,18 @@ define('select2/dropdown/search',[ }); }; + Search.prototype.handleSearch = function (evt) { + if (!this._keyUpPrevented) { + var input = this.$search.val(); + + this.trigger('query', { + term: input + }); + } + + this._keyUpPrevented = false; + }; + Search.prototype.showSearch = function (_, params) { return true; }; @@ -11040,6 +11088,17 @@ define('select2/dropdown/hidePlaceholder',[ define('select2/i18n/en',[],function () { return { + inputTooShort: function (args) { + var remainingChars = args.minimum - args.input.length; + + var message = 'Please enter ' + remainingChars + ' or more character'; + + if (remainingChars != 1) { + message += 's'; + } + + return message; + }, noResults: function () { return 'No results found'; } @@ -11061,6 +11120,7 @@ define('select2/defaults',[ './data/array', './data/ajax', './data/tags', + './data/minimumInputLength', './dropdown', './dropdown/search', @@ -11070,7 +11130,7 @@ define('select2/defaults',[ ], function ($, ResultsList, SingleSelection, MultipleSelection, Placeholder, Utils, Translation, - SelectData, ArrayData, AjaxData, Tags, + SelectData, ArrayData, AjaxData, Tags, MinimumInputLength, Dropdown, Search, HidePlaceholder, EnglishTranslation) { function Defaults () { @@ -11090,6 +11150,14 @@ define('select2/defaults',[ } } + + if (options.minimumInputLength > 0) { + options.dataAdapter = Utils.Decorate( + options.dataAdapter, + MinimumInputLength + ); + } + if (options.tags != null) { options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags); } @@ -11162,6 +11230,7 @@ define('select2/defaults',[ Defaults.prototype.reset = function () { this.defaults = { language: ['select2/i18n/en'], + minimumInputLength: 0, templateResult: function (result) { return result.text; }, @@ -11266,6 +11335,7 @@ define('select2/core',[ this._registerDomEvents(); // Register any internal event handlers + this._registerDataEvents(); this._registerSelectionEvents(); this._registerDropdownEvents(); this._registerResultsEvents(); @@ -11347,6 +11417,14 @@ define('select2/core',[ }); }; + Select2.prototype._registerDataEvents = function () { + var self = this; + + this.data.on('results:message', function (params) { + self.trigger('results:message', params); + }); + }; + Select2.prototype._registerSelectionEvents = function () { var self = this; diff --git a/dist/js/select2.full.min.js b/dist/js/select2.full.min.js index e3601a4b..ee2c8218 100644 --- a/dist/js/select2.full.min.js +++ b/dist/js/select2.full.min.js @@ -1,4 +1,4 @@ window.$=window.$||{},function(){$&&$.fn&&$.fn.select2&&$.fn.select2.amd&&(c=$.fn.select2.amd.define,b=$.fn.select2.amd.require);var a,b,c;!function(d){function e(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n=b&&b.split("/"),o=s.map,p=o&&o["*"]||{};if(a&&"."===a.charAt(0))if(b){for(n=n.slice(0,n.length-1),a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),a=n.concat(a),k=0;k0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}else 0===a.indexOf("./")&&(a=a.substring(2));if((n||p)&&o){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),n)for(l=n.length;l>0;l-=1)if(e=o[n.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&p&&p[d]&&(i=p[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(a,b){return function(){return n.apply(d,v.call(arguments,0).concat([a,b]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(a){if(e(r,a)){var b=r[a];delete r[a],t[a]=!0,m.apply(d,b)}if(!e(q,a)&&!e(t,a))throw new Error("No "+a);return q[a]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(a,b,c,f){var h,k,l,m,n,s,u=[],v=typeof c;if(f=f||a,"undefined"===v||"function"===v){for(b=!b.length&&c.length?["require","exports","module"]:b,n=0;n0&&b-1 in a}function e(a,b,c){if(bb.isFunction(b))return bb.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return bb.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(ib.test(b))return bb.filter(b,a,c);b=bb.filter(b,a)}return bb.grep(a,function(a){return V.call(b,a)>=0!==c})}function f(a,b){for(;(a=a[b])&&1!==a.nodeType;);return a}function g(a){var b=pb[a]={};return bb.each(a.match(ob)||[],function(a,c){b[c]=!0}),b}function h(){_.removeEventListener("DOMContentLoaded",h,!1),a.removeEventListener("load",h,!1),bb.ready()}function i(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=bb.expando+Math.random()}function j(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(vb,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:ub.test(c)?bb.parseJSON(c):c}catch(e){}tb.set(a,b,c)}else c=void 0;return c}function k(){return!0}function l(){return!1}function m(){try{return _.activeElement}catch(a){}}function n(a,b){return bb.nodeName(a,"table")&&bb.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function o(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function p(a){var b=Lb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function q(a,b){for(var c=0,d=a.length;d>c;c++)sb.set(a[c],"globalEval",!b||sb.get(b[c],"globalEval"))}function r(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(sb.hasData(a)&&(f=sb.access(a),g=sb.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)bb.event.add(b,e,j[e][c])}tb.hasData(a)&&(h=tb.access(a),i=bb.extend({},h),tb.set(b,i))}}function s(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&bb.nodeName(a,b)?bb.merge([a],c):c}function t(a,b){var c=b.nodeName.toLowerCase();"input"===c&&zb.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}function u(b,c){var d=bb(c.createElement(b)).appendTo(c.body),e=a.getDefaultComputedStyle?a.getDefaultComputedStyle(d[0]).display:bb.css(d[0],"display");return d.detach(),e}function v(a){var b=_,c=Pb[a];return c||(c=u(a,b),"none"!==c&&c||(Ob=(Ob||bb("