|
@@ -1497,6 +1497,12 @@ S2.define('select2/selection/single',[
|
|
|
// User exits the container
|
|
|
});
|
|
|
|
|
|
+ container.on('focus', function (evt) {
|
|
|
+ if (!container.isOpen()) {
|
|
|
+ self.$selection.focus();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
container.on('selection:update', function (params) {
|
|
|
self.update(params.data);
|
|
|
});
|
|
@@ -3436,6 +3442,12 @@ S2.define('select2/data/ajax',[
|
|
|
|
|
|
callback(results);
|
|
|
}, function () {
|
|
|
+ // Attempt to detect if a request was aborted
|
|
|
+ // Only works if the transport exposes a status property
|
|
|
+ if ($request.status && $request.status === '0') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
self.trigger('results:message', {
|
|
|
message: 'errorLoading'
|
|
|
});
|
|
@@ -3607,6 +3619,29 @@ S2.define('select2/data/tokenizer',[
|
|
|
Tokenizer.prototype.query = function (decorated, params, callback) {
|
|
|
var self = this;
|
|
|
|
|
|
+ function createAndSelect (data) {
|
|
|
+ // Normalize the data object so we can use it for checks
|
|
|
+ var item = self._normalizeItem(data);
|
|
|
+
|
|
|
+ // Check if the data object already exists as a tag
|
|
|
+ // Select it if it doesn't
|
|
|
+ var $existingOptions = self.$element.find('option').filter(function () {
|
|
|
+ return $(this).val() === item.id;
|
|
|
+ });
|
|
|
+
|
|
|
+ // If an existing option wasn't found for it, create the option
|
|
|
+ if (!$existingOptions.length) {
|
|
|
+ var $option = self.option(item);
|
|
|
+ $option.attr('data-select2-tag', true);
|
|
|
+
|
|
|
+ self._removeOldTags();
|
|
|
+ self.addOptions([$option]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Select the item, now that we know there is an option for it
|
|
|
+ select(item);
|
|
|
+ }
|
|
|
+
|
|
|
function select (data) {
|
|
|
self.trigger('select', {
|
|
|
data: data
|
|
@@ -3615,7 +3650,7 @@ S2.define('select2/data/tokenizer',[
|
|
|
|
|
|
params.term = params.term || '';
|
|
|
|
|
|
- var tokenData = this.tokenizer(params, this.options, select);
|
|
|
+ var tokenData = this.tokenizer(params, this.options, createAndSelect);
|
|
|
|
|
|
if (tokenData.term !== params.term) {
|
|
|
// Replace the search term if we have the search box
|
|
@@ -3880,6 +3915,12 @@ S2.define('select2/dropdown/search',[
|
|
|
self.$search.val('');
|
|
|
});
|
|
|
|
|
|
+ container.on('focus', function () {
|
|
|
+ if (container.isOpen()) {
|
|
|
+ self.$search.focus();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
container.on('results:all', function (params) {
|
|
|
if (params.query.term == null || params.query.term === '') {
|
|
|
var showSearch = self.showSearch(params);
|
|
@@ -4229,7 +4270,7 @@ S2.define('select2/dropdown/attachBody',[
|
|
|
|
|
|
if (newDirection == 'above' ||
|
|
|
(isCurrentlyAbove && newDirection !== 'below')) {
|
|
|
- css.top = container.top - dropdown.height;
|
|
|
+ css.top = container.top - parentOffset.top - dropdown.height;
|
|
|
}
|
|
|
|
|
|
if (newDirection != null) {
|
|
@@ -4251,6 +4292,7 @@ S2.define('select2/dropdown/attachBody',[
|
|
|
|
|
|
if (this.options.get('dropdownAutoWidth')) {
|
|
|
css.minWidth = css.width;
|
|
|
+ css.position = 'relative';
|
|
|
css.width = 'auto';
|
|
|
}
|
|
|
|
|
@@ -5129,6 +5171,10 @@ S2.define('select2/core',[
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ this.$element.on('focus.select2', function (evt) {
|
|
|
+ self.trigger('focus', evt);
|
|
|
+ });
|
|
|
+
|
|
|
this._sync = Utils.bind(this._syncAttributes, this);
|
|
|
|
|
|
if (this.$element[0].attachEvent) {
|
|
@@ -6235,6 +6281,7 @@ S2.define('jquery.select2',[
|
|
|
return this;
|
|
|
} else if (typeof options === 'string') {
|
|
|
var ret;
|
|
|
+ var args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
|
|
this.each(function () {
|
|
|
var instance = $(this).data('select2');
|
|
@@ -6246,8 +6293,6 @@ S2.define('jquery.select2',[
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- var args = Array.prototype.slice.call(arguments, 1);
|
|
|
-
|
|
|
ret = instance[options].apply(instance, args);
|
|
|
});
|
|
|
|