| 123456789101112131415161718192021222324252627282930313233343536373839 |
- var toText = require('../utils').toText,
- slice = [].slice
- module.exports = {
- bind: function () {
- // a comment node means this is a binding for
- // {{{ inline unescaped html }}}
- if (this.el.nodeType === 8) {
- // hold nodes
- this.holder = document.createElement('div')
- this.nodes = []
- }
- },
- update: function (value) {
- value = toText(value)
- if (this.holder) {
- this.swap(value)
- } else {
- this.el.innerHTML = value
- }
- },
- swap: function (value) {
- var parent = this.el.parentNode,
- holder = this.holder,
- nodes = this.nodes,
- i = nodes.length, l
- while (i--) {
- parent.removeChild(nodes[i])
- }
- holder.innerHTML = value
- nodes = this.nodes = slice.call(holder.childNodes)
- for (i = 0, l = nodes.length; i < l; i++) {
- parent.insertBefore(nodes[i], this.el)
- }
- }
- }
|