|
@@ -1,5 +1,5 @@
|
|
|
/*!
|
|
|
- * Select2 4.0.12
|
|
|
+ * Select2 4.0.13
|
|
|
* https://select2.github.io
|
|
|
*
|
|
|
* Released under the MIT license
|
|
@@ -1556,6 +1556,27 @@ S2.define('select2/selection/base',[
|
|
|
throw new Error('The `update` method must be defined in child classes.');
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Helper method to abstract the "enabled" (not "disabled") state of this
|
|
|
+ * object.
|
|
|
+ *
|
|
|
+ * @return {true} if the instance is not disabled.
|
|
|
+ * @return {false} if the instance is disabled.
|
|
|
+ */
|
|
|
+ BaseSelection.prototype.isEnabled = function () {
|
|
|
+ return !this.isDisabled();
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Helper method to abstract the "disabled" state of this object.
|
|
|
+ *
|
|
|
+ * @return {true} if the disabled option is true.
|
|
|
+ * @return {false} if the disabled option is false.
|
|
|
+ */
|
|
|
+ BaseSelection.prototype.isDisabled = function () {
|
|
|
+ return this.options.get('disabled');
|
|
|
+ };
|
|
|
+
|
|
|
return BaseSelection;
|
|
|
});
|
|
|
|
|
@@ -1706,7 +1727,7 @@ S2.define('select2/selection/multiple',[
|
|
|
'.select2-selection__choice__remove',
|
|
|
function (evt) {
|
|
|
// Ignore the event if it is disabled
|
|
|
- if (self.options.get('disabled')) {
|
|
|
+ if (self.isDisabled()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -1867,7 +1888,7 @@ S2.define('select2/selection/allowClear',[
|
|
|
|
|
|
AllowClear.prototype._handleClear = function (_, evt) {
|
|
|
// Ignore the event if it is disabled
|
|
|
- if (this.options.get('disabled')) {
|
|
|
+ if (this.isDisabled()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -1910,7 +1931,7 @@ S2.define('select2/selection/allowClear',[
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- this.$element.trigger('change');
|
|
|
+ this.$element.trigger('input').trigger('change');
|
|
|
|
|
|
this.trigger('toggle', {});
|
|
|
};
|
|
@@ -1933,7 +1954,7 @@ S2.define('select2/selection/allowClear',[
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var removeAll = this.options.get('translations').get('removeAllItems');
|
|
|
+ var removeAll = this.options.get('translations').get('removeAllItems');
|
|
|
|
|
|
var $remove = $(
|
|
|
'<span class="select2-selection__clear" title="' + removeAll() +'">' +
|
|
@@ -3201,7 +3222,7 @@ S2.define('select2/data/select',[
|
|
|
if ($(data.element).is('option')) {
|
|
|
data.element.selected = true;
|
|
|
|
|
|
- this.$element.trigger('change');
|
|
|
+ this.$element.trigger('input').trigger('change');
|
|
|
|
|
|
return;
|
|
|
}
|
|
@@ -3222,13 +3243,13 @@ S2.define('select2/data/select',[
|
|
|
}
|
|
|
|
|
|
self.$element.val(val);
|
|
|
- self.$element.trigger('change');
|
|
|
+ self.$element.trigger('input').trigger('change');
|
|
|
});
|
|
|
} else {
|
|
|
var val = data.id;
|
|
|
|
|
|
this.$element.val(val);
|
|
|
- this.$element.trigger('change');
|
|
|
+ this.$element.trigger('input').trigger('change');
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -3244,7 +3265,7 @@ S2.define('select2/data/select',[
|
|
|
if ($(data.element).is('option')) {
|
|
|
data.element.selected = false;
|
|
|
|
|
|
- this.$element.trigger('change');
|
|
|
+ this.$element.trigger('input').trigger('change');
|
|
|
|
|
|
return;
|
|
|
}
|
|
@@ -3262,7 +3283,7 @@ S2.define('select2/data/select',[
|
|
|
|
|
|
self.$element.val(val);
|
|
|
|
|
|
- self.$element.trigger('change');
|
|
|
+ self.$element.trigger('input').trigger('change');
|
|
|
});
|
|
|
};
|
|
|
|
|
@@ -5545,8 +5566,8 @@ S2.define('select2/core',[
|
|
|
|
|
|
if (observer != null) {
|
|
|
this._observer = new observer(function (mutations) {
|
|
|
- $.each(mutations, self._syncA);
|
|
|
- $.each(mutations, self._syncS);
|
|
|
+ self._syncA();
|
|
|
+ self._syncS(null, mutations);
|
|
|
});
|
|
|
this._observer.observe(this.$element[0], {
|
|
|
attributes: true,
|
|
@@ -5668,7 +5689,7 @@ S2.define('select2/core',[
|
|
|
if (self.isOpen()) {
|
|
|
if (key === KEYS.ESC || key === KEYS.TAB ||
|
|
|
(key === KEYS.UP && evt.altKey)) {
|
|
|
- self.close();
|
|
|
+ self.close(evt);
|
|
|
|
|
|
evt.preventDefault();
|
|
|
} else if (key === KEYS.ENTER) {
|
|
@@ -5702,7 +5723,7 @@ S2.define('select2/core',[
|
|
|
Select2.prototype._syncAttributes = function () {
|
|
|
this.options.set('disabled', this.$element.prop('disabled'));
|
|
|
|
|
|
- if (this.options.get('disabled')) {
|
|
|
+ if (this.isDisabled()) {
|
|
|
if (this.isOpen()) {
|
|
|
this.close();
|
|
|
}
|
|
@@ -5713,7 +5734,7 @@ S2.define('select2/core',[
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- Select2.prototype._syncSubtree = function (evt, mutations) {
|
|
|
+ Select2.prototype._isChangeMutation = function (evt, mutations) {
|
|
|
var changed = false;
|
|
|
var self = this;
|
|
|
|
|
@@ -5741,7 +5762,22 @@ S2.define('select2/core',[
|
|
|
}
|
|
|
} else if (mutations.removedNodes && mutations.removedNodes.length > 0) {
|
|
|
changed = true;
|
|
|
+ } else if ($.isArray(mutations)) {
|
|
|
+ $.each(mutations, function(evt, mutation) {
|
|
|
+ if (self._isChangeMutation(evt, mutation)) {
|
|
|
+ // We've found a change mutation.
|
|
|
+ // Let's escape from the loop and continue
|
|
|
+ changed = true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ return changed;
|
|
|
+ };
|
|
|
+
|
|
|
+ Select2.prototype._syncSubtree = function (evt, mutations) {
|
|
|
+ var changed = this._isChangeMutation(evt, mutations);
|
|
|
+ var self = this;
|
|
|
|
|
|
// Only re-pull the data if we think there is a change
|
|
|
if (changed) {
|
|
@@ -5792,7 +5828,7 @@ S2.define('select2/core',[
|
|
|
};
|
|
|
|
|
|
Select2.prototype.toggleDropdown = function () {
|
|
|
- if (this.options.get('disabled')) {
|
|
|
+ if (this.isDisabled()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -5808,15 +5844,40 @@ S2.define('select2/core',[
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ if (this.isDisabled()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
this.trigger('query', {});
|
|
|
};
|
|
|
|
|
|
- Select2.prototype.close = function () {
|
|
|
+ Select2.prototype.close = function (evt) {
|
|
|
if (!this.isOpen()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- this.trigger('close', {});
|
|
|
+ this.trigger('close', { originalEvent : evt });
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Helper method to abstract the "enabled" (not "disabled") state of this
|
|
|
+ * object.
|
|
|
+ *
|
|
|
+ * @return {true} if the instance is not disabled.
|
|
|
+ * @return {false} if the instance is disabled.
|
|
|
+ */
|
|
|
+ Select2.prototype.isEnabled = function () {
|
|
|
+ return !this.isDisabled();
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Helper method to abstract the "disabled" state of this object.
|
|
|
+ *
|
|
|
+ * @return {true} if the disabled option is true.
|
|
|
+ * @return {false} if the disabled option is false.
|
|
|
+ */
|
|
|
+ Select2.prototype.isDisabled = function () {
|
|
|
+ return this.options.get('disabled');
|
|
|
};
|
|
|
|
|
|
Select2.prototype.isOpen = function () {
|
|
@@ -5893,7 +5954,7 @@ S2.define('select2/core',[
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- this.$element.val(newVal).trigger('change');
|
|
|
+ this.$element.val(newVal).trigger('input').trigger('change');
|
|
|
};
|
|
|
|
|
|
Select2.prototype.destroy = function () {
|
|
@@ -6228,13 +6289,13 @@ S2.define('select2/compat/inputData',[
|
|
|
});
|
|
|
|
|
|
this.$element.val(data.id);
|
|
|
- this.$element.trigger('change');
|
|
|
+ this.$element.trigger('input').trigger('change');
|
|
|
} else {
|
|
|
var value = this.$element.val();
|
|
|
value += this._valueSeparator + data.id;
|
|
|
|
|
|
this.$element.val(value);
|
|
|
- this.$element.trigger('change');
|
|
|
+ this.$element.trigger('input').trigger('change');
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -6257,7 +6318,7 @@ S2.define('select2/compat/inputData',[
|
|
|
}
|
|
|
|
|
|
self.$element.val(values.join(self._valueSeparator));
|
|
|
- self.$element.trigger('change');
|
|
|
+ self.$element.trigger('input').trigger('change');
|
|
|
});
|
|
|
};
|
|
|
|