diff --git a/dist/css/select2.css b/dist/css/select2.css index c98e3b89..06928db8 100644 --- a/dist/css/select2.css +++ b/dist/css/select2.css @@ -26,10 +26,16 @@ user-select: none; -webkit-user-select: none; } .select2-container .selection .multiple-select .rendered-selection { - display: block; + display: inline-block; overflow: hidden; padding-left: 8px; text-overflow: ellipsis; } +.select2-container .select2-search-inline { + float: left; } + .select2-container .select2-search-inline input { + border: none; + font-size: 100%; + margin-top: 5px; } .select2-container .dropdown { background-color: white; @@ -41,12 +47,6 @@ left: -100000px; width: 100%; z-index: 100; } - .select2-container .dropdown .search { - display: block; - padding: 4px; } - .select2-container .dropdown .search input { - padding: 4px; - width: 100%; } .select2-container .dropdown .results { display: block; } .select2-container .dropdown .results .options { @@ -59,6 +59,12 @@ -webkit-user-select: none; } .select2-container .dropdown .results .options .option[aria-selected] { cursor: pointer; } +.select2-container .select2-search { + display: block; + padding: 4px; } + .select2-container .select2-search input { + padding: 4px; + width: 100%; } .select2-container.open .dropdown { border-top: none; border-top-left-radius: 0; @@ -81,10 +87,10 @@ .select2-container.select2-theme-default .selection .multiple-select .rendered-selection { list-style: none; margin: 0; - padding: 5px; - padding-bottom: 0; } + padding: 0 5px; } .select2-container.select2-theme-default .selection .multiple-select .rendered-selection .placeholder { color: #999; + margin-top: 5px; float: left; } .select2-container.select2-theme-default .selection .multiple-select .rendered-selection .choice { background-color: #e4e4e4; @@ -92,7 +98,7 @@ border-radius: 4px; float: left; margin-right: 5px; - margin-bottom: 5px; + margin-top: 5px; padding: 0 5px; } .select2-container.select2-theme-default .selection .multiple-select .rendered-selection .choice .remove { color: #999; @@ -104,7 +110,7 @@ .select2-container.select2-theme-default.open .selection .single-select, .select2-container.select2-theme-default.open .selection .multiple-select { border-bottom-left-radius: 0; border-bottom-right-radius: 0; } -.select2-container.select2-theme-default .dropdown .search input { +.select2-container.select2-theme-default .select2-search input { border: 1px solid #aaa; } .select2-container.select2-theme-default .dropdown .results > .options { max-height: 200px; @@ -154,7 +160,7 @@ .select2-container.select2-theme-classic .dropdown { background-color: white; border-top: none; } - .select2-container.select2-theme-classic .dropdown .search input { + .select2-container.select2-theme-classic .dropdown .select2-search input { border: 1px solid #aaa; outline: 0; } .select2-container.select2-theme-classic .dropdown .results > .options { diff --git a/dist/css/select2.min.css b/dist/css/select2.min.css index e76f36b8..7833ee66 100644 --- a/dist/css/select2.min.css +++ b/dist/css/select2.min.css @@ -1 +1 @@ -.select2-container{box-sizing:border-box;display:inline-block;margin:0;position:relative;vertical-align:middle;}.select2-container .selection .single-select{box-sizing:border-box;cursor:pointer;display:block;height:28px;user-select:none;-webkit-user-select:none;}.select2-container .selection .single-select .rendered-selection{display:block;overflow:hidden;padding-left:8px;text-overflow:ellipsis;}.select2-container .selection .multiple-select{box-sizing:border-box;cursor:pointer;display:block;min-height:32px;user-select:none;-webkit-user-select:none;}.select2-container .selection .multiple-select .rendered-selection{display:block;overflow:hidden;padding-left:8px;text-overflow:ellipsis;}.select2-container .dropdown{background-color:white;border:1px solid #aaa;border-radius:4px;box-sizing:border-box;display:block;position:absolute;left:-100000px;width:100%;z-index:100;}.select2-container .dropdown .search{display:block;padding:4px;}.select2-container .dropdown .search input{padding:4px;width:100%;}.select2-container .dropdown .results{display:block;}.select2-container .dropdown .results .options{list-style:none;margin:0;padding:0;}.select2-container .dropdown .results .options .option{padding:6px;user-select:none;-webkit-user-select:none;}.select2-container .dropdown .results .options .option[aria-selected]{cursor:pointer;}.select2-container.open .dropdown{border-top:none;border-top-left-radius:0;border-top-right-radius:0;left:0;}.select2-container.select2-theme-default .selection .single-select{background-color:#fff;border:1px solid #aaa;border-radius:4px;}.select2-container.select2-theme-default .selection .single-select .rendered-selection{color:#444;line-height:28px;}.select2-container.select2-theme-default .selection .single-select .rendered-selection .placeholder{color:#999;}.select2-container.select2-theme-default .selection .multiple-select{background-color:white;border:1px solid #aaa;border-radius:4px;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection{list-style:none;margin:0;padding:5px;padding-bottom:0;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection .placeholder{color:#999;float:left;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection .choice{background-color:#e4e4e4;border:1px solid #aaa;border-radius:4px;float:left;margin-right:5px;margin-bottom:5px;padding:0 5px;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection .choice .remove{color:#999;display:inline-block;font-weight:bold;margin-right:2px;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection .choice .remove:hover{color:#333;}.select2-container.select2-theme-default.open .selection .single-select,.select2-container.select2-theme-default.open .selection .multiple-select{border-bottom-left-radius:0;border-bottom-right-radius:0;}.select2-container.select2-theme-default .dropdown .search input{border:1px solid #aaa;}.select2-container.select2-theme-default .dropdown .results>.options{max-height:200px;overflow-y:auto;}.select2-container.select2-theme-default .dropdown .results .options .option[role=group]{padding:0;}.select2-container.select2-theme-default .dropdown .results .options .option[role=group] .group-label{cursor:default;display:block;padding:6px;}.select2-container.select2-theme-default .dropdown .results .options .option[aria-disabled=true]{color:#999;}.select2-container.select2-theme-default .dropdown .results .options .option[aria-selected=true]{background-color:#ddd;}.select2-container.select2-theme-default .dropdown .results .options .option[aria-selected].highlighted{background-color:#5897fb;color:white;}.select2-container.select2-theme-classic .selection .single-select{background-color:#f6f6f6;border:1px solid #aaa;border-radius:4px;outline:0;background-image:-webkit-linear-gradient(top, #ffffff 50%, #eee 100%);background-image:-o-linear-gradient(top, #ffffff 50%, #eee 100%);background-image:linear-gradient(to bottom, #ffffff 50%, #eee 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eee', GradientType=0);}.select2-container.select2-theme-classic .selection .single-select:focus{border:1px solid #5897fb;}.select2-container.select2-theme-classic .selection .single-select .rendered-selection{color:#444;line-height:28px;}.select2-container.select2-theme-classic .selection .single-select .rendered-selection .placeholder{color:#999;}.select2-container.select2-theme-classic.open .selection .single-select{border:1px solid #5897fb;background-image:-webkit-linear-gradient(top, #eee 50%, #ffffff 100%);background-image:-o-linear-gradient(top, #eee 50%, #ffffff 100%);background-image:linear-gradient(to bottom, #eee 50%, #ffffff 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#eee', endColorstr='#ffffff', GradientType=0);}.select2-container.select2-theme-classic.open .selection .single-select,.select2-container.select2-theme-classic.open .selection .multiple-select{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0;}.select2-container.select2-theme-classic .dropdown{background-color:white;border-top:none;}.select2-container.select2-theme-classic .dropdown .search input{border:1px solid #aaa;outline:0;}.select2-container.select2-theme-classic .dropdown .results>.options{max-height:200px;overflow-y:auto;}.select2-container.select2-theme-classic .dropdown .results .options .option[role=group]{padding:0;}.select2-container.select2-theme-classic .dropdown .results .options .option[role=group] .group-label{cursor:default;display:block;padding:6px;}.select2-container.select2-theme-classic .dropdown .results .options .option[aria-disabled=true]{color:grey;}.select2-container.select2-theme-classic .dropdown .results .options .option[aria-selected].highlighted{background-color:#3875d7;color:white;}.select2-container.select2-theme-classic.open .dropdown{border:1px solid #5897fb;border-top:none;} \ No newline at end of file +.select2-container{box-sizing:border-box;display:inline-block;margin:0;position:relative;vertical-align:middle;}.select2-container .selection .single-select{box-sizing:border-box;cursor:pointer;display:block;height:28px;user-select:none;-webkit-user-select:none;}.select2-container .selection .single-select .rendered-selection{display:block;overflow:hidden;padding-left:8px;text-overflow:ellipsis;}.select2-container .selection .multiple-select{box-sizing:border-box;cursor:pointer;display:block;min-height:32px;user-select:none;-webkit-user-select:none;}.select2-container .selection .multiple-select .rendered-selection{display:inline-block;overflow:hidden;padding-left:8px;text-overflow:ellipsis;}.select2-container .select2-search-inline{float:left;}.select2-container .select2-search-inline input{border:none;font-size:100%;margin-top:5px;}.select2-container .dropdown{background-color:white;border:1px solid #aaa;border-radius:4px;box-sizing:border-box;display:block;position:absolute;left:-100000px;width:100%;z-index:100;}.select2-container .dropdown .results{display:block;}.select2-container .dropdown .results .options{list-style:none;margin:0;padding:0;}.select2-container .dropdown .results .options .option{padding:6px;user-select:none;-webkit-user-select:none;}.select2-container .dropdown .results .options .option[aria-selected]{cursor:pointer;}.select2-container .select2-search{display:block;padding:4px;}.select2-container .select2-search input{padding:4px;width:100%;}.select2-container.open .dropdown{border-top:none;border-top-left-radius:0;border-top-right-radius:0;left:0;}.select2-container.select2-theme-default .selection .single-select{background-color:#fff;border:1px solid #aaa;border-radius:4px;}.select2-container.select2-theme-default .selection .single-select .rendered-selection{color:#444;line-height:28px;}.select2-container.select2-theme-default .selection .single-select .rendered-selection .placeholder{color:#999;}.select2-container.select2-theme-default .selection .multiple-select{background-color:white;border:1px solid #aaa;border-radius:4px;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection{list-style:none;margin:0;padding:0 5px;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection .placeholder{color:#999;margin-top:5px;float:left;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection .choice{background-color:#e4e4e4;border:1px solid #aaa;border-radius:4px;float:left;margin-right:5px;margin-top:5px;padding:0 5px;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection .choice .remove{color:#999;display:inline-block;font-weight:bold;margin-right:2px;}.select2-container.select2-theme-default .selection .multiple-select .rendered-selection .choice .remove:hover{color:#333;}.select2-container.select2-theme-default.open .selection .single-select,.select2-container.select2-theme-default.open .selection .multiple-select{border-bottom-left-radius:0;border-bottom-right-radius:0;}.select2-container.select2-theme-default .select2-search input{border:1px solid #aaa;}.select2-container.select2-theme-default .dropdown .results>.options{max-height:200px;overflow-y:auto;}.select2-container.select2-theme-default .dropdown .results .options .option[role=group]{padding:0;}.select2-container.select2-theme-default .dropdown .results .options .option[role=group] .group-label{cursor:default;display:block;padding:6px;}.select2-container.select2-theme-default .dropdown .results .options .option[aria-disabled=true]{color:#999;}.select2-container.select2-theme-default .dropdown .results .options .option[aria-selected=true]{background-color:#ddd;}.select2-container.select2-theme-default .dropdown .results .options .option[aria-selected].highlighted{background-color:#5897fb;color:white;}.select2-container.select2-theme-classic .selection .single-select{background-color:#f6f6f6;border:1px solid #aaa;border-radius:4px;outline:0;background-image:-webkit-linear-gradient(top, #ffffff 50%, #eee 100%);background-image:-o-linear-gradient(top, #ffffff 50%, #eee 100%);background-image:linear-gradient(to bottom, #ffffff 50%, #eee 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eee', GradientType=0);}.select2-container.select2-theme-classic .selection .single-select:focus{border:1px solid #5897fb;}.select2-container.select2-theme-classic .selection .single-select .rendered-selection{color:#444;line-height:28px;}.select2-container.select2-theme-classic .selection .single-select .rendered-selection .placeholder{color:#999;}.select2-container.select2-theme-classic.open .selection .single-select{border:1px solid #5897fb;background-image:-webkit-linear-gradient(top, #eee 50%, #ffffff 100%);background-image:-o-linear-gradient(top, #eee 50%, #ffffff 100%);background-image:linear-gradient(to bottom, #eee 50%, #ffffff 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#eee', endColorstr='#ffffff', GradientType=0);}.select2-container.select2-theme-classic.open .selection .single-select,.select2-container.select2-theme-classic.open .selection .multiple-select{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0;}.select2-container.select2-theme-classic .dropdown{background-color:white;border-top:none;}.select2-container.select2-theme-classic .dropdown .select2-search input{border:1px solid #aaa;outline:0;}.select2-container.select2-theme-classic .dropdown .results>.options{max-height:200px;overflow-y:auto;}.select2-container.select2-theme-classic .dropdown .results .options .option[role=group]{padding:0;}.select2-container.select2-theme-classic .dropdown .results .options .option[role=group] .group-label{cursor:default;display:block;padding:6px;}.select2-container.select2-theme-classic .dropdown .results .options .option[aria-disabled=true]{color:grey;}.select2-container.select2-theme-classic .dropdown .results .options .option[aria-selected].highlighted{background-color:#3875d7;color:white;}.select2-container.select2-theme-classic.open .dropdown{border:1px solid #5897fb;border-top:none;} \ No newline at end of file diff --git a/dist/js/select2.amd.full.js b/dist/js/select2.amd.full.js index 71c53420..d8783a15 100644 --- a/dist/js/select2.amd.full.js +++ b/dist/js/select2.amd.full.js @@ -33,6 +33,10 @@ window.$ = window.$ || {};(function() { if ($ && $.fn && $.fn.select2 && $.fn.se continue; } + if (methodName === 'constructor') { + continue; + } + methods.push(methodName); } @@ -913,6 +917,15 @@ define('select2/selection/placeholder',[ return placeholder; }; + Placeholder.prototype.createPlaceholder = function (decorated, placeholder) { + var $placeholder = this.selectionContainer(); + + $placeholder.html(this.display(placeholder)); + $placeholder.addClass('placeholder').removeClass('choice'); + + return $placeholder; + }; + Placeholder.prototype.update = function (decorated, data) { var singlePlaceholder = ( data.length == 1 && data[0].id != this.placeholder.id @@ -925,10 +938,7 @@ define('select2/selection/placeholder',[ this.clear(); - var $placeholder = this.selectionContainer(); - - $placeholder.html(this.display(this.placeholder)); - $placeholder.addClass('placeholder').removeClass('choice'); + var $placeholder = this.createPlaceholder(this.placeholder); this.$selection.find('.rendered-selection').append($placeholder); }; @@ -936,6 +946,95 @@ define('select2/selection/placeholder',[ return Placeholder; }); +define('select2/selection/search',[ + '../utils' +], function (Utils) { + function Search (decorated, $element, options) { + decorated.call(this, $element, options); + } + + Search.prototype.render = function (decorated) { + var $search = $( + '
  • ' + + '' + + '
  • ' + ); + + this.$searchContainer = $search; + this.$search = $search.find('input'); + + var $rendered = decorated.call(this); + + return $rendered; + }; + + Search.prototype.bind = function (decorated, container, $container) { + var self = this; + + decorated.call(this, container, $container); + + this.$search.on('keydown', function (evt) { + self.trigger('keypress', evt); + + self._keyUpPrevented = evt.isDefaultPrevented(); + }); + + this.$search.on('keyup', function (evt) { + self.handleSearch(evt); + }); + + container.on('open', function () { + self.$search.attr('tabindex', 0); + + self.$search.focus(); + }); + + container.on('close', function () { + self.$search.attr('tabindex', -1); + + self.$search.val(''); + }); + + this.$search.off('keydown').on('keydown', function (evt) { + evt.stopPropagation(); + + self.trigger('keypress', evt); + + self._keyUpPrevented = evt.isDefaultPrevented(); + }); + }; + + Search.prototype.createPlaceholder = function (decorated, placeholder) { + this.$search.attr('placeholder', placeholder.text); + }; + + Search.prototype.update = function (decorated, data) { + this.$search.attr('placeholder', ''); + + decorated.call(this, data); + + this.$selection.find('.rendered-selection').append(this.$searchContainer); + }; + + 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; + }; + + return Search; +}); + define('select2/translation',[ ], function () { @@ -2404,8 +2503,8 @@ define('select2/dropdown/search',[ var $rendered = decorated.call(this); var $search = $( - '' + - '' + + '' + + '' + '' ); @@ -2659,6 +2758,7 @@ define('select2/defaults',[ './selection/single', './selection/multiple', './selection/placeholder', + './selection/search', './utils', './translation', @@ -2677,10 +2777,10 @@ define('select2/defaults',[ './i18n/en' ], function ($, ResultsList, - SingleSelection, MultipleSelection, Placeholder, + SingleSelection, MultipleSelection, Placeholder, SelectionSearch, Utils, Translation, DIACRITICS, SelectData, ArrayData, AjaxData, Tags, MinimumInputLength, - Dropdown, Search, HidePlaceholder, InfiniteScroll, + Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll, EnglishTranslation) { function Defaults () { this.reset(); @@ -2730,9 +2830,13 @@ define('select2/defaults',[ } if (options.dropdownAdapter == null) { - var SearchableDropdown = Utils.Decorate(Dropdown, Search); + if (options.multiple) { + options.dropdownAdapter = Dropdown; + } else { + var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch); - options.dropdownAdapter = SearchableDropdown; + options.dropdownAdapter = SearchableDropdown; + } } if (options.selectionAdapter == null) { @@ -2749,6 +2853,13 @@ define('select2/defaults',[ Placeholder ); } + + if (options.multiple) { + options.selectionAdapter = Utils.Decorate( + options.selectionAdapter, + SelectionSearch + ); + } } if (typeof options.language === 'string') { @@ -3073,6 +3184,10 @@ define('select2/core',[ self.close(); }); + this.selection.on('query', function (params) { + self.trigger('query', params); + }); + this.selection.on('keypress', function (e) { self.trigger('keypress', e); }); diff --git a/dist/js/select2.amd.js b/dist/js/select2.amd.js index 858dcf9f..9c1a8051 100644 --- a/dist/js/select2.amd.js +++ b/dist/js/select2.amd.js @@ -33,6 +33,10 @@ window.$ = window.$ || {};(function() { if ($ && $.fn && $.fn.select2 && $.fn.se continue; } + if (methodName === 'constructor') { + continue; + } + methods.push(methodName); } @@ -913,6 +917,15 @@ define('select2/selection/placeholder',[ return placeholder; }; + Placeholder.prototype.createPlaceholder = function (decorated, placeholder) { + var $placeholder = this.selectionContainer(); + + $placeholder.html(this.display(placeholder)); + $placeholder.addClass('placeholder').removeClass('choice'); + + return $placeholder; + }; + Placeholder.prototype.update = function (decorated, data) { var singlePlaceholder = ( data.length == 1 && data[0].id != this.placeholder.id @@ -925,10 +938,7 @@ define('select2/selection/placeholder',[ this.clear(); - var $placeholder = this.selectionContainer(); - - $placeholder.html(this.display(this.placeholder)); - $placeholder.addClass('placeholder').removeClass('choice'); + var $placeholder = this.createPlaceholder(this.placeholder); this.$selection.find('.rendered-selection').append($placeholder); }; @@ -936,6 +946,95 @@ define('select2/selection/placeholder',[ return Placeholder; }); +define('select2/selection/search',[ + '../utils' +], function (Utils) { + function Search (decorated, $element, options) { + decorated.call(this, $element, options); + } + + Search.prototype.render = function (decorated) { + var $search = $( + '
  • ' + + '' + + '
  • ' + ); + + this.$searchContainer = $search; + this.$search = $search.find('input'); + + var $rendered = decorated.call(this); + + return $rendered; + }; + + Search.prototype.bind = function (decorated, container, $container) { + var self = this; + + decorated.call(this, container, $container); + + this.$search.on('keydown', function (evt) { + self.trigger('keypress', evt); + + self._keyUpPrevented = evt.isDefaultPrevented(); + }); + + this.$search.on('keyup', function (evt) { + self.handleSearch(evt); + }); + + container.on('open', function () { + self.$search.attr('tabindex', 0); + + self.$search.focus(); + }); + + container.on('close', function () { + self.$search.attr('tabindex', -1); + + self.$search.val(''); + }); + + this.$search.off('keydown').on('keydown', function (evt) { + evt.stopPropagation(); + + self.trigger('keypress', evt); + + self._keyUpPrevented = evt.isDefaultPrevented(); + }); + }; + + Search.prototype.createPlaceholder = function (decorated, placeholder) { + this.$search.attr('placeholder', placeholder.text); + }; + + Search.prototype.update = function (decorated, data) { + this.$search.attr('placeholder', ''); + + decorated.call(this, data); + + this.$selection.find('.rendered-selection').append(this.$searchContainer); + }; + + 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; + }; + + return Search; +}); + define('select2/translation',[ ], function () { @@ -2404,8 +2503,8 @@ define('select2/dropdown/search',[ var $rendered = decorated.call(this); var $search = $( - '' + - '' + + '' + + '' + '' ); @@ -2659,6 +2758,7 @@ define('select2/defaults',[ './selection/single', './selection/multiple', './selection/placeholder', + './selection/search', './utils', './translation', @@ -2677,10 +2777,10 @@ define('select2/defaults',[ './i18n/en' ], function ($, ResultsList, - SingleSelection, MultipleSelection, Placeholder, + SingleSelection, MultipleSelection, Placeholder, SelectionSearch, Utils, Translation, DIACRITICS, SelectData, ArrayData, AjaxData, Tags, MinimumInputLength, - Dropdown, Search, HidePlaceholder, InfiniteScroll, + Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll, EnglishTranslation) { function Defaults () { this.reset(); @@ -2730,9 +2830,13 @@ define('select2/defaults',[ } if (options.dropdownAdapter == null) { - var SearchableDropdown = Utils.Decorate(Dropdown, Search); + if (options.multiple) { + options.dropdownAdapter = Dropdown; + } else { + var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch); - options.dropdownAdapter = SearchableDropdown; + options.dropdownAdapter = SearchableDropdown; + } } if (options.selectionAdapter == null) { @@ -2749,6 +2853,13 @@ define('select2/defaults',[ Placeholder ); } + + if (options.multiple) { + options.selectionAdapter = Utils.Decorate( + options.selectionAdapter, + SelectionSearch + ); + } } if (typeof options.language === 'string') { @@ -3073,6 +3184,10 @@ define('select2/core',[ self.close(); }); + this.selection.on('query', function (params) { + self.trigger('query', params); + }); + this.selection.on('keypress', function (e) { self.trigger('keypress', e); }); diff --git a/dist/js/select2.full.js b/dist/js/select2.full.js index 5e0142f7..7c79110b 100644 --- a/dist/js/select2.full.js +++ b/dist/js/select2.full.js @@ -9568,6 +9568,10 @@ define('select2/utils',[], function () { continue; } + if (methodName === 'constructor') { + continue; + } + methods.push(methodName); } @@ -10448,6 +10452,15 @@ define('select2/selection/placeholder',[ return placeholder; }; + Placeholder.prototype.createPlaceholder = function (decorated, placeholder) { + var $placeholder = this.selectionContainer(); + + $placeholder.html(this.display(placeholder)); + $placeholder.addClass('placeholder').removeClass('choice'); + + return $placeholder; + }; + Placeholder.prototype.update = function (decorated, data) { var singlePlaceholder = ( data.length == 1 && data[0].id != this.placeholder.id @@ -10460,10 +10473,7 @@ define('select2/selection/placeholder',[ this.clear(); - var $placeholder = this.selectionContainer(); - - $placeholder.html(this.display(this.placeholder)); - $placeholder.addClass('placeholder').removeClass('choice'); + var $placeholder = this.createPlaceholder(this.placeholder); this.$selection.find('.rendered-selection').append($placeholder); }; @@ -10471,6 +10481,95 @@ define('select2/selection/placeholder',[ return Placeholder; }); +define('select2/selection/search',[ + '../utils' +], function (Utils) { + function Search (decorated, $element, options) { + decorated.call(this, $element, options); + } + + Search.prototype.render = function (decorated) { + var $search = $( + '
  • ' + + '' + + '
  • ' + ); + + this.$searchContainer = $search; + this.$search = $search.find('input'); + + var $rendered = decorated.call(this); + + return $rendered; + }; + + Search.prototype.bind = function (decorated, container, $container) { + var self = this; + + decorated.call(this, container, $container); + + this.$search.on('keydown', function (evt) { + self.trigger('keypress', evt); + + self._keyUpPrevented = evt.isDefaultPrevented(); + }); + + this.$search.on('keyup', function (evt) { + self.handleSearch(evt); + }); + + container.on('open', function () { + self.$search.attr('tabindex', 0); + + self.$search.focus(); + }); + + container.on('close', function () { + self.$search.attr('tabindex', -1); + + self.$search.val(''); + }); + + this.$search.off('keydown').on('keydown', function (evt) { + evt.stopPropagation(); + + self.trigger('keypress', evt); + + self._keyUpPrevented = evt.isDefaultPrevented(); + }); + }; + + Search.prototype.createPlaceholder = function (decorated, placeholder) { + this.$search.attr('placeholder', placeholder.text); + }; + + Search.prototype.update = function (decorated, data) { + this.$search.attr('placeholder', ''); + + decorated.call(this, data); + + this.$selection.find('.rendered-selection').append(this.$searchContainer); + }; + + 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; + }; + + return Search; +}); + define('select2/translation',[ ], function () { @@ -11939,8 +12038,8 @@ define('select2/dropdown/search',[ var $rendered = decorated.call(this); var $search = $( - '' + - '' + + '' + + '' + '' ); @@ -12194,6 +12293,7 @@ define('select2/defaults',[ './selection/single', './selection/multiple', './selection/placeholder', + './selection/search', './utils', './translation', @@ -12212,10 +12312,10 @@ define('select2/defaults',[ './i18n/en' ], function ($, ResultsList, - SingleSelection, MultipleSelection, Placeholder, + SingleSelection, MultipleSelection, Placeholder, SelectionSearch, Utils, Translation, DIACRITICS, SelectData, ArrayData, AjaxData, Tags, MinimumInputLength, - Dropdown, Search, HidePlaceholder, InfiniteScroll, + Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll, EnglishTranslation) { function Defaults () { this.reset(); @@ -12265,9 +12365,13 @@ define('select2/defaults',[ } if (options.dropdownAdapter == null) { - var SearchableDropdown = Utils.Decorate(Dropdown, Search); + if (options.multiple) { + options.dropdownAdapter = Dropdown; + } else { + var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch); - options.dropdownAdapter = SearchableDropdown; + options.dropdownAdapter = SearchableDropdown; + } } if (options.selectionAdapter == null) { @@ -12284,6 +12388,13 @@ define('select2/defaults',[ Placeholder ); } + + if (options.multiple) { + options.selectionAdapter = Utils.Decorate( + options.selectionAdapter, + SelectionSearch + ); + } } if (typeof options.language === 'string') { @@ -12608,6 +12719,10 @@ define('select2/core',[ self.close(); }); + this.selection.on('query', function (params) { + self.trigger('query', params); + }); + this.selection.on('keypress', function (e) { self.trigger('keypress', e); }); diff --git a/dist/js/select2.full.min.js b/dist/js/select2.full.min.js index 6e1d347e..200b74d9 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("