Created
September 16, 2013 16:58
-
-
Save sorvell/6583385 to your computer and use it in GitHub Desktop.
ShadowDOM + MutationObserver polyfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="../../../ShadowDOM/shadowdom.js"></script> | |
<script src="../../../MutationObservers/MutationObserver.js"></script> | |
</head> | |
<body> | |
<x-host></x-host> | |
<script> | |
function makeSR(scope, selector, html) { | |
var node = scope.querySelector(selector); | |
if (node) { | |
node.createShadowRoot().innerHTML = html; | |
return node.shadowRoot; | |
} | |
} | |
var root = makeSR(document, 'x-host', '<x-inner-host>inner</x-inner-host>'); | |
requestAnimationFrame(function() { | |
window.MutationObserver = window.MutationObserver || JsMutationObserver; | |
var o = new MutationObserver(function(mutations) { | |
console.log('mutation!'); | |
}); | |
o.observe(document, {childList: true, subtree: true}); | |
// | |
makeSR(root, 'x-inner-host', '<x-inner-inner-host>inner inner</x-inner-inner-host>'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment