-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml.js
47 lines (43 loc) · 1.02 KB
/
html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { parseTemplate } from '../../parsers/template'
import {
createAnchor,
before,
replace,
remove,
_toString,
toArray
} from '../../util/index'
export default {
bind () {
// a comment node means this is a binding for
// {{{ inline unescaped html }}}
if (this.el.nodeType === 8) {
// hold nodes
this.nodes = []
// replace the placeholder with proper anchor
this.anchor = createAnchor('v-html')
replace(this.el, this.anchor)
}
},
update (value) {
value = _toString(value)
if (this.nodes) {
this.swap(value)
} else {
this.el.innerHTML = value
}
},
swap (value) {
// remove old nodes
var i = this.nodes.length
while (i--) {
remove(this.nodes[i])
}
// convert new value to a fragment
// do not attempt to retrieve from id selector
var frag = parseTemplate(value, true, true)
// save a reference to these nodes so we can remove later
this.nodes = toArray(frag.childNodes)
before(frag, this.anchor)
}
}