|
|
@@ -1,4 +1,4 @@
|
|
|
-var utils = require('../utils'),
|
|
|
+var utils = require('../utils'),
|
|
|
transition = require('../transition')
|
|
|
|
|
|
module.exports = {
|
|
|
@@ -6,6 +6,7 @@ module.exports = {
|
|
|
on : require('./on'),
|
|
|
repeat : require('./repeat'),
|
|
|
model : require('./model'),
|
|
|
+ 'if' : require('./if'),
|
|
|
|
|
|
attr: function (value) {
|
|
|
this.el.setAttribute(this.arg, value)
|
|
|
@@ -50,58 +51,6 @@ module.exports = {
|
|
|
this.el.classList.add(value)
|
|
|
this.lastVal = value
|
|
|
}
|
|
|
- },
|
|
|
-
|
|
|
- 'if': {
|
|
|
- bind: function () {
|
|
|
- this.parent = this.el.parentNode
|
|
|
- this.ref = document.createComment('sd-if-' + this.key)
|
|
|
- this.el.sd_ref = this.ref
|
|
|
- },
|
|
|
- update: function (value, init) {
|
|
|
-
|
|
|
- var el = this.el,
|
|
|
- attached = !!el.parentNode
|
|
|
-
|
|
|
- if (!this.parent) { // the node was detached when bound
|
|
|
- if (!attached) {
|
|
|
- return
|
|
|
- } else {
|
|
|
- this.parent = el.parentNode
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // should always have this.parent if we reach here
|
|
|
- var parent = this.parent,
|
|
|
- ref = this.ref
|
|
|
-
|
|
|
- if (!value) {
|
|
|
- if (attached) {
|
|
|
- // insert the reference node
|
|
|
- var next = el.nextSibling
|
|
|
- if (next) {
|
|
|
- parent.insertBefore(ref, next)
|
|
|
- } else {
|
|
|
- parent.appendChild(ref)
|
|
|
- }
|
|
|
- transition(el, -1, remove, init)
|
|
|
- }
|
|
|
- } else if (!attached) {
|
|
|
- transition(el, 1, insert, init)
|
|
|
- }
|
|
|
-
|
|
|
- function remove () {
|
|
|
- parent.removeChild(el)
|
|
|
- }
|
|
|
-
|
|
|
- function insert () {
|
|
|
- parent.insertBefore(el, ref)
|
|
|
- parent.removeChild(ref)
|
|
|
- }
|
|
|
- },
|
|
|
- unbind: function () {
|
|
|
- this.el.sd_ref = null
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|