Skip to content

Instantly share code, notes, and snippets.

@sjmiles
Created January 17, 2014 18:28
Show Gist options
  • Save sjmiles/8478807 to your computer and use it in GitHub Desktop.
Save sjmiles/8478807 to your computer and use it in GitHub Desktop.
Dynamic loading imports in Polymer circa 1/17/2014. Will be very much streamlined shortly.
loadLinks: function(urls, callback) {
var doc = document.createDocumentFragment();
urls.forEach(function(url) {
var link = doc.appendChild(document.createElement('link'));
link.rel = "import";
link.href = url;
});
// load-all-links in document method should be factored somewhere
// very similar method used in x-meta
HTMLImports.importer.load(doc, function() {
doc.querySelectorAll('link').array().forEach(
function(link) {
HTMLImports.parser.parse(link.content);
CustomElements.parser.parse(link.content);
}
);
callback && callback();
}.bind(this));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment