Skip to content

Commit 988eccb

Browse files
committed
Merge pull request select2#2332 from FallSe7en/master
Unbind onpropertychange event handler on destroy for IE8-10
2 parents 0db21bb + 0313630 commit 988eccb

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

select2.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,16 @@ the specific language governing permissions and limitations under the Apache Lic
828828

829829
this.close();
830830

831+
if (element.length && element[0].detachEvent) {
832+
element.each(function () {
833+
this.detachEvent("onpropertychange", this._sync);
834+
});
835+
}
831836
if (this.propertyObserver) {
832837
this.propertyObserver.disconnect();
833838
this.propertyObserver = null;
834839
}
840+
this._sync = null;
835841

836842
if (select2 !== undefined) {
837843
select2.container.remove();
@@ -1062,15 +1068,15 @@ the specific language governing permissions and limitations under the Apache Lic
10621068
*/
10631069
// abstract
10641070
monitorSource: function () {
1065-
var el = this.opts.element, sync, observer;
1071+
var el = this.opts.element, observer;
10661072

10671073
el.on("change.select2", this.bind(function (e) {
10681074
if (this.opts.element.data("select2-change-triggered") !== true) {
10691075
this.initSelection();
10701076
}
10711077
}));
10721078

1073-
sync = this.bind(function () {
1079+
this._sync = this.bind(function () {
10741080

10751081
// sync enabled state
10761082
var disabled = el.prop("disabled");
@@ -1092,7 +1098,7 @@ the specific language governing permissions and limitations under the Apache Lic
10921098
// IE8-10 (IE9/10 won't fire propertyChange via attachEventListener)
10931099
if (el.length && el[0].attachEvent) {
10941100
el.each(function() {
1095-
this.attachEvent("onpropertychange", sync);
1101+
this.attachEvent("onpropertychange", this._sync);
10961102
});
10971103
}
10981104

@@ -1101,7 +1107,7 @@ the specific language governing permissions and limitations under the Apache Lic
11011107
if (observer !== undefined) {
11021108
if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; }
11031109
this.propertyObserver = new observer(function (mutations) {
1104-
mutations.forEach(sync);
1110+
mutations.forEach(this._sync);
11051111
});
11061112
this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false });
11071113
}

0 commit comments

Comments
 (0)