From 03af075a6453881f036a8960fedd790535dd65ca Mon Sep 17 00:00:00 2001 From: Deathamns Date: Tue, 11 Nov 2014 17:14:54 +0100 Subject: [PATCH] Move MutationObserver shim Since it will be used only for older Safari versions, move it to Safari related code, so it doesn't pollute the content scripts. --- src/js/vapi-client.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/js/vapi-client.js b/src/js/vapi-client.js index b406713..69bd09c 100644 --- a/src/js/vapi-client.js +++ b/src/js/vapi-client.js @@ -197,6 +197,20 @@ if (self.chrome) { return; } + window.MutationObserver = window.MutationObserver || window.WebKitMutationObserver; + + if (!window.MutationObserver) { + // dummy, minimalistic shim for older versions (<6) + // only supports node insertions, but currently we don't use it for anything else + window.MutationObserver = function(handler) { + this.observe = function(target) { + target.addEventListener('DOMNodeInserted', function(e) { + handler([{addedNodes: [e.target]}]); + }, true); + }; + } + } + var beforeLoadEvent = document.createEvent('Event'); beforeLoadEvent.initEvent('beforeload');