Last active
August 29, 2015 14:24
-
-
Save naderio/7a6c7fc6c2852564c101 to your computer and use it in GitHub Desktop.
Conditionally load WebComponents polyfill for use with Polymer, fire `WebComponentsReady` anyway
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
<script> | |
if ('registerElement' in document | |
&& 'createShadowRoot' in HTMLElement.prototype | |
&& 'import' in document.createElement('link') | |
&& 'content' in document.createElement('template')) { | |
(function () { | |
function ready() { | |
setTimeout(function () { | |
document.dispatchEvent(new CustomEvent('WebComponentsReady', { | |
bubbles: true | |
})); | |
}); | |
} | |
if (document.readyState === 'complete' || document.readyState === 'interactive') { | |
ready(); | |
} else { | |
window.addEventListener('DOMContentLoaded', ready); | |
} | |
})(); | |
} else { | |
document.write('<script src="bower_components\/webcomponentsjs\/webcomponents.min.js"><\/script>'); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment