Sha256: f9ab17cd6e758f31ff6c6bd6b22ac3e18f14f7605bab965c0111fd9526d0c8d5

Contents?: true

Size: 1021 Bytes

Versions: 14

Compression:

Stored size: 1021 Bytes

Contents

var utils = require('../utils'),
    slice = [].slice

/**
 *  Binding for innerHTML
 */
module.exports = {

    bind: function () {
        // a comment node means this is a binding for
        // {{{ inline unescaped html }}}
        if (this.el.nodeType === 8) {
            // hold nodes
            this.nodes = []
        }
    },

    update: function (value) {
        value = utils.guard(value)
        if (this.nodes) {
            this.swap(value)
        } else {
            this.el.innerHTML = value
        }
    },

    swap: function (value) {
        var parent = this.el.parentNode,
            nodes  = this.nodes,
            i      = nodes.length
        // remove old nodes
        while (i--) {
            parent.removeChild(nodes[i])
        }
        // convert new value to a fragment
        var frag = utils.toFragment(value)
        // save a reference to these nodes so we can remove later
        this.nodes = slice.call(frag.childNodes)
        parent.insertBefore(frag, this.el)
    }
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fluentd-ui-0.3.8 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.3.7 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.3.6 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.3.5 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.3.3 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.3.2 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.3.1 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.3.0 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.2.0 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.1.4 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.1.3 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.1.2 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.1.1 vendor/assets/javascripts/bower/vue/src/directives/html.js
fluentd-ui-0.1.0 vendor/assets/javascripts/bower/vue/src/directives/html.js