From 78139a80bac29465d6c493a96a7f89c2394ee296 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sat, 27 Apr 2013 11:08:05 -0700 Subject: [PATCH] work around chrome and mutation observer bug. fixes #1099 --- select2.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/select2.js b/select2.js index e39c0a65..cda3bdfc 100644 --- a/select2.js +++ b/select2.js @@ -961,12 +961,19 @@ the specific language governing permissions and limitations under the Apache Lic // mozilla and IE el.bind("propertychange.select2 DOMAttrModified.select2", sync); + + + // hold onto a reference of the callback to work around a chromium bug + if (this.mutationCallback === undefined) { + this.mutationCallback = function (mutations) { + mutations.forEach(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 = new WebKitMutationObserver(this.mutationCallback); this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false }); } },