Sha256: 1679169b31c2a50ca2f2e4bb6334134559ac5a74aebd73f357ed161d901de7b8

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

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: '<div><span>my template</span></div>'
 * 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);
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fluentd-ui-0.3.8 vendor/assets/javascripts/bower/vue/src/template-parser.js
fluentd-ui-0.3.7 vendor/assets/javascripts/bower/vue/src/template-parser.js
fluentd-ui-0.3.6 vendor/assets/javascripts/bower/vue/src/template-parser.js
fluentd-ui-0.3.5 vendor/assets/javascripts/bower/vue/src/template-parser.js
fluentd-ui-0.3.3 vendor/assets/javascripts/bower/vue/src/template-parser.js
fluentd-ui-0.3.2 vendor/assets/javascripts/bower/vue/src/template-parser.js
fluentd-ui-0.3.1 vendor/assets/javascripts/bower/vue/src/template-parser.js