parent
84da7f3698
commit
e9ed9d14c8
|
|
@ -106,9 +106,21 @@
|
|||
return this
|
||||
}
|
||||
|
||||
// LIST WIDGET HELPERS
|
||||
// =================
|
||||
|
||||
if ($.oc === undefined)
|
||||
$.oc = {}
|
||||
|
||||
$.oc.listToggleChecked = function(el) {
|
||||
$(el)
|
||||
.closest('[data-control="listwidget"]')
|
||||
.listWidget('toggleChecked', el)
|
||||
}
|
||||
|
||||
// LIST WIDGET DATA-API
|
||||
// ==============
|
||||
|
||||
|
||||
$(document).render(function(){
|
||||
$('[data-control="listwidget"]').listWidget();
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1319,7 +1319,7 @@ S2.define('select2/selection/base',[
|
|||
});
|
||||
|
||||
this.$selection.on('blur', function (evt) {
|
||||
self.trigger('blur', evt);
|
||||
self._handleBlur(evt);
|
||||
});
|
||||
|
||||
this.$selection.on('keydown', function (evt) {
|
||||
|
|
@ -1366,6 +1366,24 @@ 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;
|
||||
|
||||
|
|
@ -1475,11 +1493,11 @@ S2.define('select2/selection/single',[
|
|||
this.$selection.find('.select2-selection__rendered').empty();
|
||||
};
|
||||
|
||||
SingleSelection.prototype.display = function (data) {
|
||||
SingleSelection.prototype.display = function (data, container) {
|
||||
var template = this.options.get('templateSelection');
|
||||
var escapeMarkup = this.options.get('escapeMarkup');
|
||||
|
||||
return escapeMarkup(template(data));
|
||||
return escapeMarkup(template(data, container));
|
||||
};
|
||||
|
||||
SingleSelection.prototype.selectionContainer = function () {
|
||||
|
|
@ -1494,9 +1512,9 @@ S2.define('select2/selection/single',[
|
|||
|
||||
var selection = data[0];
|
||||
|
||||
var formatted = this.display(selection);
|
||||
|
||||
var $rendered = this.$selection.find('.select2-selection__rendered');
|
||||
var formatted = this.display(selection, $rendered);
|
||||
|
||||
$rendered.empty().append(formatted);
|
||||
$rendered.prop('title', selection.title || selection.text);
|
||||
};
|
||||
|
|
@ -1556,11 +1574,11 @@ S2.define('select2/selection/multiple',[
|
|||
this.$selection.find('.select2-selection__rendered').empty();
|
||||
};
|
||||
|
||||
MultipleSelection.prototype.display = function (data) {
|
||||
MultipleSelection.prototype.display = function (data, container) {
|
||||
var template = this.options.get('templateSelection');
|
||||
var escapeMarkup = this.options.get('escapeMarkup');
|
||||
|
||||
return escapeMarkup(template(data));
|
||||
return escapeMarkup(template(data, container));
|
||||
};
|
||||
|
||||
MultipleSelection.prototype.selectionContainer = function () {
|
||||
|
|
@ -1587,8 +1605,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);
|
||||
|
|
@ -1777,6 +1795,8 @@ S2.define('select2/selection/search',[
|
|||
|
||||
var $rendered = decorated.call(this);
|
||||
|
||||
this._transferTabIndex();
|
||||
|
||||
return $rendered;
|
||||
};
|
||||
|
||||
|
|
@ -1786,32 +1806,34 @@ S2.define('select2/selection/search',[
|
|||
decorated.call(this, container, $container);
|
||||
|
||||
container.on('open', function () {
|
||||
self.$search.attr('tabindex', 0);
|
||||
|
||||
self.$search.focus();
|
||||
self.$search.trigger('focus');
|
||||
});
|
||||
|
||||
container.on('close', function () {
|
||||
self.$search.attr('tabindex', -1);
|
||||
|
||||
self.$search.val('');
|
||||
self.$search.focus();
|
||||
self.$search.trigger('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.trigger('blur', evt);
|
||||
self._handleBlur(evt);
|
||||
});
|
||||
|
||||
this.$selection.on('keydown', '.select2-search--inline', function (evt) {
|
||||
|
|
@ -1819,7 +1841,7 @@ S2.define('select2/selection/search',[
|
|||
|
||||
self.trigger('keypress', evt);
|
||||
|
||||
self._keyUpPrevented = evt.isDefaultPrevented();
|
||||
self._keyUpPrevented = false; //evt.isDefaultPrevented();
|
||||
|
||||
var key = evt.which;
|
||||
|
||||
|
|
@ -1847,15 +1869,41 @@ 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);
|
||||
|
|
@ -1864,6 +1912,9 @@ S2.define('select2/selection/search',[
|
|||
.append(this.$searchContainer);
|
||||
|
||||
this.resizeSearch();
|
||||
if (searchHadFocus) {
|
||||
this.$search.focus();
|
||||
}
|
||||
};
|
||||
|
||||
Search.prototype.handleSearch = function () {
|
||||
|
|
@ -1948,7 +1999,7 @@ S2.define('select2/selection/eventRelay',[
|
|||
return;
|
||||
}
|
||||
|
||||
params.prevented = evt.isDefaultPrevented();
|
||||
params.prevented = false; //evt.isDefaultPrevented();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -3259,7 +3310,7 @@ S2.define('select2/data/ajax',[
|
|||
this.processResults = this.ajaxOptions.processResults;
|
||||
}
|
||||
|
||||
ArrayAdapter.__super__.constructor.call(this, $element, options);
|
||||
AjaxAdapter.__super__.constructor.call(this, $element, options);
|
||||
}
|
||||
|
||||
Utils.Extend(AjaxAdapter, ArrayAdapter);
|
||||
|
|
@ -3723,7 +3774,7 @@ S2.define('select2/dropdown/search',[
|
|||
this.$search.on('keydown', function (evt) {
|
||||
self.trigger('keypress', evt);
|
||||
|
||||
self._keyUpPrevented = evt.isDefaultPrevented();
|
||||
self._keyUpPrevented = false; //evt.isDefaultPrevented();
|
||||
});
|
||||
|
||||
// Workaround for browsers which do not support the `input` event
|
||||
|
|
@ -4868,8 +4919,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();
|
||||
|
||||
|
|
@ -5004,12 +5055,16 @@ S2.define('select2/core',[
|
|||
|
||||
Select2.prototype._registerSelectionEvents = function () {
|
||||
var self = this;
|
||||
var nonRelayEvents = ['toggle'];
|
||||
var nonRelayEvents = ['toggle', 'focus'];
|
||||
|
||||
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;
|
||||
|
|
@ -5054,10 +5109,6 @@ 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');
|
||||
});
|
||||
|
|
@ -5088,7 +5139,12 @@ S2.define('select2/core',[
|
|||
var key = evt.which;
|
||||
|
||||
if (self.isOpen()) {
|
||||
if (key === KEYS.ENTER) {
|
||||
if (key === KEYS.ESC || key === KEYS.TAB ||
|
||||
(key === KEYS.UP && evt.altKey)) {
|
||||
self.close();
|
||||
|
||||
evt.preventDefault();
|
||||
} else if (key === KEYS.ENTER) {
|
||||
self.trigger('results:select');
|
||||
|
||||
evt.preventDefault();
|
||||
|
|
@ -5103,15 +5159,11 @@ 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 || key === KEYS.UP) && evt.altKey)) {
|
||||
(key === KEYS.DOWN && evt.altKey)) {
|
||||
self.open();
|
||||
|
||||
evt.preventDefault();
|
||||
|
|
@ -5201,6 +5253,20 @@ 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(
|
||||
|
|
@ -5281,7 +5347,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();
|
||||
|
|
@ -5385,7 +5451,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;
|
||||
|
||||
|
|
@ -5442,7 +5508,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;
|
||||
|
||||
|
|
@ -6111,4 +6177,4 @@ S2.define('jquery.select2',[
|
|||
|
||||
// Return the Select2 instance for anyone who is importing it.
|
||||
return select2;
|
||||
}));
|
||||
}));
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -12,4 +12,3 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue