1
0
mirror of synced 2024-11-26 23:06:02 +03:00

sync disabled and readonly statuses off original element even post creation

This commit is contained in:
Igor Vaynberg 2013-02-01 12:21:28 -08:00
parent 22dba24881
commit 5374b8799b

View File

@ -634,7 +634,11 @@ the specific language governing permissions and limitations under the Apache Lic
// abstract // abstract
destroy: function () { destroy: function () {
var select2 = this.opts.element.data("select2"); var select2 = this.opts.element.data("select2");
if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; }
if (select2 !== undefined) { if (select2 !== undefined) {
select2.container.remove(); select2.container.remove();
select2.dropdown.remove(); select2.dropdown.remove();
select2.opts.element select2.opts.element
@ -810,11 +814,39 @@ the specific language governing permissions and limitations under the Apache Lic
*/ */
// abstract // abstract
monitorSource: function () { monitorSource: function () {
this.opts.element.bind("change.select2", this.bind(function (e) { var el = this.opts.element, sync;
el.bind("change.select2", this.bind(function (e) {
if (this.opts.element.data("select2-change-triggered") !== true) { if (this.opts.element.data("select2-change-triggered") !== true) {
this.initSelection(); this.initSelection();
} }
})); }));
sync = this.bind(function () {
var enabled = this.opts.element.attr("disabled") !== "disabled";
var readonly = this.opts.element.attr("readonly") === "readonly";
enabled = enabled && !readonly;
if (this.enabled !== enabled) {
if (enabled) {
this.enable();
} else {
this.disable();
}
}
});
// mozilla and IE
el.bind("propertychange.select2 DOMAttrModified.select2", sync);
// safari and chrome
if (typeof WebKitMutationObserver !== "undefined") {
if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; }
this.propertyObserver = new WebKitMutationObserver(function (mutations) {
mutations.forEach(sync);
});
this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false });
}
}, },
/** /**