1
0
mirror of synced 2025-02-10 17:19:23 +03:00

#1807 add support for MutationObserver

Better support mutation events in Firefox
This commit is contained in:
cmcnulty 2013-10-17 15:09:02 -05:00
parent 92c6cef6cb
commit d5297ccd6d

View File

@ -999,7 +999,7 @@ the specific language governing permissions and limitations under the Apache Lic
*/ */
// abstract // abstract
monitorSource: function () { monitorSource: function () {
var el = this.opts.element, sync; var el = this.opts.element, sync, observer;
el.on("change.select2", this.bind(function (e) { el.on("change.select2", this.bind(function (e) {
if (this.opts.element.data("select2-change-triggered") !== true) { 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 // IE8-10
el.on("propertychange.select2 DOMAttrModified.select2", sync); el.on("propertychange.select2", sync);
// hold onto a reference of the callback to work around a chromium bug // hold onto a reference of the callback to work around a chromium bug
if (this.mutationCallback === undefined) { if (this.mutationCallback === undefined) {
@ -1037,10 +1036,11 @@ the specific language governing permissions and limitations under the Apache Lic
} }
} }
// safari and chrome // safari, chrome, firefox, IE11
if (typeof WebKitMutationObserver !== "undefined") { observer = window.MutationObserver || window.WebKitMutationObserver|| window.MozMutationObserver;
if (observer !== undefined) {
if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; } 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 }); this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false });
} }
}, },