From c4e7427669f603f57d06ef1156a50edc503be158 Mon Sep 17 00:00:00 2001 From: alekseybobkov Date: Wed, 16 Sep 2015 20:06:30 -0700 Subject: [PATCH] Updating select2 --- .../ui/vendor/select2/js/select2.full.js | 138 +++++------------- 1 file changed, 36 insertions(+), 102 deletions(-) mode change 100644 => 100755 modules/system/assets/ui/vendor/select2/js/select2.full.js diff --git a/modules/system/assets/ui/vendor/select2/js/select2.full.js b/modules/system/assets/ui/vendor/select2/js/select2.full.js old mode 100644 new mode 100755 index 231689ccb..dd0e8bc74 --- a/modules/system/assets/ui/vendor/select2/js/select2.full.js +++ b/modules/system/assets/ui/vendor/select2/js/select2.full.js @@ -1319,7 +1319,7 @@ S2.define('select2/selection/base',[ }); this.$selection.on('blur', function (evt) { - self._handleBlur(evt); + self.trigger('blur', evt); }); this.$selection.on('keydown', function (evt) { @@ -1366,24 +1366,6 @@ S2.define('select2/selection/base',[ }); }; - BaseSelection.prototype._handleBlur = function (evt) { - var self = this; - - // This needs to be delayed as the actve element is the body when the tab - // key is pressed, possibly along with others. - window.setTimeout(function () { - // Don't trigger `blur` if the focus is still in the selection - if ( - (document.activeElement == self.$selection[0]) || - ($.contains(self.$selection[0], document.activeElement)) - ) { - return; - } - - self.trigger('blur', evt); - }, 1); - }; - BaseSelection.prototype._attachCloseHandler = function (container) { var self = this; @@ -1493,11 +1475,11 @@ S2.define('select2/selection/single',[ this.$selection.find('.select2-selection__rendered').empty(); }; - SingleSelection.prototype.display = function (data, container) { + SingleSelection.prototype.display = function (data) { var template = this.options.get('templateSelection'); var escapeMarkup = this.options.get('escapeMarkup'); - return escapeMarkup(template(data, container)); + return escapeMarkup(template(data)); }; SingleSelection.prototype.selectionContainer = function () { @@ -1512,9 +1494,9 @@ S2.define('select2/selection/single',[ var selection = data[0]; - var $rendered = this.$selection.find('.select2-selection__rendered'); - var formatted = this.display(selection, $rendered); + var formatted = this.display(selection); + var $rendered = this.$selection.find('.select2-selection__rendered'); $rendered.empty().append(formatted); $rendered.prop('title', selection.title || selection.text); }; @@ -1574,11 +1556,11 @@ S2.define('select2/selection/multiple',[ this.$selection.find('.select2-selection__rendered').empty(); }; - MultipleSelection.prototype.display = function (data, container) { + MultipleSelection.prototype.display = function (data) { var template = this.options.get('templateSelection'); var escapeMarkup = this.options.get('escapeMarkup'); - return escapeMarkup(template(data, container)); + return escapeMarkup(template(data)); }; MultipleSelection.prototype.selectionContainer = function () { @@ -1605,8 +1587,8 @@ S2.define('select2/selection/multiple',[ for (var d = 0; d < data.length; d++) { var selection = data[d]; + var formatted = this.display(selection); var $selection = this.selectionContainer(); - var formatted = this.display(selection, $selection); $selection.append(formatted); $selection.prop('title', selection.title || selection.text); @@ -1795,8 +1777,6 @@ S2.define('select2/selection/search',[ var $rendered = decorated.call(this); - this._transferTabIndex(); - return $rendered; }; @@ -1806,34 +1786,32 @@ S2.define('select2/selection/search',[ decorated.call(this, container, $container); container.on('open', function () { - self.$search.trigger('focus'); + self.$search.attr('tabindex', 0); + + self.$search.focus(); }); container.on('close', function () { + self.$search.attr('tabindex', -1); + self.$search.val(''); - self.$search.trigger('focus'); + self.$search.focus(); }); container.on('enable', function () { self.$search.prop('disabled', false); - - self._transferTabIndex(); }); container.on('disable', function () { self.$search.prop('disabled', true); }); - container.on('focus', function (evt) { - self.$search.trigger('focus'); - }); - this.$selection.on('focusin', '.select2-search--inline', function (evt) { self.trigger('focus', evt); }); this.$selection.on('focusout', '.select2-search--inline', function (evt) { - self._handleBlur(evt); + self.trigger('blur', evt); }); this.$selection.on('keydown', '.select2-search--inline', function (evt) { @@ -1841,7 +1819,7 @@ S2.define('select2/selection/search',[ self.trigger('keypress', evt); - self._keyUpPrevented = false; //evt.isDefaultPrevented(); + self._keyUpPrevented = evt.isDefaultPrevented(); var key = evt.which; @@ -1869,41 +1847,15 @@ S2.define('select2/selection/search',[ this.$selection.on('keyup.search input', '.select2-search--inline', function (evt) { - var key = evt.which; - - // We can freely ignore events from modifier keys - if (key == KEYS.SHIFT || key == KEYS.CTRL || key == KEYS.ALT) { - return; - } - - // Tabbing will be handled during the `keydown` phase - if (key == KEYS.TAB) { - return; - } - self.handleSearch(evt); }); }; - /** - * This method will transfer the tabindex attribute from the rendered - * selection to the search box. This allows for the search box to be used as - * the primary focus instead of the selection container. - * - * @private - */ - Search.prototype._transferTabIndex = function (decorated) { - this.$search.attr('tabindex', this.$selection.attr('tabindex')); - this.$selection.attr('tabindex', '-1'); - }; - Search.prototype.createPlaceholder = function (decorated, placeholder) { this.$search.attr('placeholder', placeholder.text); }; Search.prototype.update = function (decorated, data) { - var searchHadFocus = this.$search[0] == document.activeElement; - this.$search.attr('placeholder', ''); decorated.call(this, data); @@ -1912,9 +1864,6 @@ S2.define('select2/selection/search',[ .append(this.$searchContainer); this.resizeSearch(); - if (searchHadFocus) { - this.$search.focus(); - } }; Search.prototype.handleSearch = function () { @@ -1999,7 +1948,7 @@ S2.define('select2/selection/eventRelay',[ return; } - params.prevented = false; //evt.isDefaultPrevented(); + params.prevented = evt.isDefaultPrevented(); }); }; @@ -3310,7 +3259,7 @@ S2.define('select2/data/ajax',[ this.processResults = this.ajaxOptions.processResults; } - AjaxAdapter.__super__.constructor.call(this, $element, options); + ArrayAdapter.__super__.constructor.call(this, $element, options); } Utils.Extend(AjaxAdapter, ArrayAdapter); @@ -3774,7 +3723,7 @@ S2.define('select2/dropdown/search',[ this.$search.on('keydown', function (evt) { self.trigger('keypress', evt); - self._keyUpPrevented = false; //evt.isDefaultPrevented(); + self._keyUpPrevented = evt.isDefaultPrevented(); }); // Workaround for browsers which do not support the `input` event @@ -4919,8 +4868,8 @@ S2.define('select2/core',[ // Hide the original select $element.addClass('select2-hidden-accessible'); - $element.attr('aria-hidden', 'true'); - + $element.attr('aria-hidden', 'true'); + // Synchronize any monitored attributes this._syncAttributes(); @@ -5055,16 +5004,12 @@ S2.define('select2/core',[ Select2.prototype._registerSelectionEvents = function () { var self = this; - var nonRelayEvents = ['toggle', 'focus']; + var nonRelayEvents = ['toggle']; this.selection.on('toggle', function () { self.toggleDropdown(); }); - this.selection.on('focus', function (params) { - self.focus(params); - }); - this.selection.on('*', function (name, params) { if ($.inArray(name, nonRelayEvents) !== -1) { return; @@ -5109,6 +5054,10 @@ S2.define('select2/core',[ self.$container.addClass('select2-container--disabled'); }); + this.on('focus', function () { + self.$container.addClass('select2-container--focus'); + }); + this.on('blur', function () { self.$container.removeClass('select2-container--focus'); }); @@ -5139,12 +5088,7 @@ S2.define('select2/core',[ var key = evt.which; if (self.isOpen()) { - if (key === KEYS.ESC || key === KEYS.TAB || - (key === KEYS.UP && evt.altKey)) { - self.close(); - - evt.preventDefault(); - } else if (key === KEYS.ENTER) { + if (key === KEYS.ENTER) { self.trigger('results:select'); evt.preventDefault(); @@ -5159,11 +5103,15 @@ S2.define('select2/core',[ } else if (key === KEYS.DOWN) { self.trigger('results:next'); + evt.preventDefault(); + } else if (key === KEYS.ESC || key === KEYS.TAB) { + self.close(); + evt.preventDefault(); } } else { if (key === KEYS.ENTER || key === KEYS.SPACE || - (key === KEYS.DOWN && evt.altKey)) { + ((key === KEYS.DOWN || key === KEYS.UP) && evt.altKey)) { self.open(); evt.preventDefault(); @@ -5253,20 +5201,6 @@ S2.define('select2/core',[ return this.$container.hasClass('select2-container--open'); }; - Select2.prototype.hasFocus = function () { - return this.$container.hasClass('select2-container--focus'); - }; - - Select2.prototype.focus = function (data) { - // No need to re-trigger focus events if we are already focused - if (this.hasFocus()) { - return; - } - - this.$container.addClass('select2-container--focus'); - this.trigger('focus'); - }; - Select2.prototype.enable = function (args) { if (this.options.get('debug') && window.console && console.warn) { console.warn( @@ -5347,7 +5281,7 @@ S2.define('select2/core',[ this.$element.attr('tabindex', this.$element.data('old-tabindex')); this.$element.removeClass('select2-hidden-accessible'); - this.$element.attr('aria-hidden', 'false'); + this.$element.attr('aria-hidden', 'false'); this.$element.removeData('select2'); this.dataAdapter.destroy(); @@ -5451,7 +5385,7 @@ S2.define('select2/compat/containerCss',[ containerCssAdapter = containerCssAdapter || _containerAdapter; if (containerCssClass.indexOf(':all:') !== -1) { - containerCssClass = containerCssClass.replace(':all:', ''); + containerCssClass = containerCssClass.replace(':all', ''); var _cssAdapter = containerCssAdapter; @@ -5508,7 +5442,7 @@ S2.define('select2/compat/dropdownCss',[ dropdownCssAdapter = dropdownCssAdapter || _dropdownAdapter; if (dropdownCssClass.indexOf(':all:') !== -1) { - dropdownCssClass = dropdownCssClass.replace(':all:', ''); + dropdownCssClass = dropdownCssClass.replace(':all', ''); var _cssAdapter = dropdownCssAdapter; @@ -6177,4 +6111,4 @@ S2.define('jquery.select2',[ // Return the Select2 instance for anyone who is importing it. return select2; -})); \ No newline at end of file +}));