var toFragment = require('./fragment'); /** * Parses a template string or node and normalizes it into a * a node that can be used as a partial of a template option * * Possible values include * id selector: '#some-template-id' * template string: '
my template
' * DocumentFragment object * Node object of type Template */ module.exports = function(template) { var templateNode; if (template instanceof window.DocumentFragment) { // if the template is already a document fragment -- do nothing return template } if (typeof template === 'string') { // template by ID if (template.charAt(0) === '#') { templateNode = document.getElementById(template.slice(1)) if (!templateNode) return } else { return toFragment(template) } } else if (template.nodeType) { templateNode = template } else { return } // if its a template tag and the browser supports it, // its content is already a document fragment! if (templateNode.tagName === 'TEMPLATE' && templateNode.content) { return templateNode.content } if (templateNode.tagName === 'SCRIPT') { return toFragment(templateNode.innerHTML) } return toFragment(templateNode.outerHTML); }