silk-gui
Version:
GUI for developers and Node OS
46 lines (45 loc) • 1.14 kB
JavaScript
/**
* Apply JavaScript enter/leave functions.
*
* @param {Element} el
* @param {Number} direction - 1: enter, -1: leave
* @param {Function} op - the actual DOM operation
* @param {Object} data - target element's transition data
* @param {Object} def - transition definition object
* @param {Vue} vm - the owner vm of the element
* @param {Function} [cb]
*/
module.exports = function (el, direction, op, data, def, vm, cb) {
// if the element is the root of an instance,
// use that instance as the transition function context
vm = el.__vue__ || vm
if (data.cancel) {
data.cancel()
data.cancel = null
}
if (direction > 0) { // enter
if (def.beforeEnter) {
def.beforeEnter.call(vm, el)
}
op()
if (def.enter) {
data.cancel = def.enter.call(vm, el, function () {
data.cancel = null
if (cb) cb()
})
} else if (cb) {
cb()
}
} else { // leave
if (def.leave) {
data.cancel = def.leave.call(vm, el, function () {
data.cancel = null
op()
if (cb) cb()
})
} else {
op()
if (cb) cb()
}
}
}