From d5297ccd6dcb94d088e6240a203662e217cc47d8 Mon Sep 17 00:00:00 2001 From: cmcnulty Date: Thu, 17 Oct 2013 15:09:02 -0500 Subject: [PATCH] #1807 add support for MutationObserver Better support mutation events in Firefox --- select2.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/select2.js b/select2.js index 7b4a2826..c0aa3875 100644 --- a/select2.js +++ b/select2.js @@ -999,7 +999,7 @@ the specific language governing permissions and limitations under the Apache Lic */ // abstract monitorSource: function () { - var el = this.opts.element, sync; + var el = this.opts.element, sync, observer; el.on("change.select2", this.bind(function (e) { if (this.opts.element.data("select2-change-triggered") !== true) { @@ -1026,9 +1026,8 @@ the specific language governing permissions and limitations under the Apache Lic }); - // mozilla and IE - el.on("propertychange.select2 DOMAttrModified.select2", sync); - + // IE8-10 + el.on("propertychange.select2", sync); // hold onto a reference of the callback to work around a chromium bug if (this.mutationCallback === undefined) { @@ -1037,10 +1036,11 @@ the specific language governing permissions and limitations under the Apache Lic } } - // safari and chrome - if (typeof WebKitMutationObserver !== "undefined") { + // safari, chrome, firefox, IE11 + observer = window.MutationObserver || window.WebKitMutationObserver|| window.MozMutationObserver; + if (observer !== undefined) { if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; } - this.propertyObserver = new WebKitMutationObserver(this.mutationCallback); + this.propertyObserver = new observer(this.mutationCallback); this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false }); } },