Created
January 17, 2014 18:28
-
-
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.
This file contains hidden or 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
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