Skip to content

Instantly share code, notes, and snippets.

@beriberikix
Forked from sjmiles/gist:5763113
Last active December 18, 2015 10:10
Show Gist options
  • Save beriberikix/5766487 to your computer and use it in GitHub Desktop.
Save beriberikix/5766487 to your computer and use it in GitHub Desktop.
Polymer/web components with async loading.
<element name="plus-plusone">
<script>
Polymer.register(this, {
ready: function() {
addInstance(this);
},
plusOneReady: function() {
// do stuff
console.log('plusone.js is ready');
}
});
var instances = [];
function addInstance(instance) {
instances.push(instance)
}
function notify(instance) {
instance.plusOneReady();
}
window.google_plusone_loaded = function() {
window.google_plusone_loaded = undefined;
instances.forEach(notify);
instances = undefined;
addInstance = notify;
};
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?onload=google_plusone_loaded';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
</script>
</element>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment