-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
151 lines (137 loc) · 2.87 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var _ = require('../util')
var applyCSSTransition = require('./css')
var applyJSTransition = require('./js')
/**
* Append with transition.
*
* @oaram {Element} el
* @param {Element} target
* @param {Vue} vm
* @param {Function} [cb]
*/
exports.append = function (el, target, vm, cb) {
apply(el, 1, function () {
target.appendChild(el)
}, vm, cb)
}
/**
* InsertBefore with transition.
*
* @oaram {Element} el
* @param {Element} target
* @param {Vue} vm
* @param {Function} [cb]
*/
exports.before = function (el, target, vm, cb) {
apply(el, 1, function () {
_.before(el, target)
}, vm, cb)
}
/**
* Remove with transition.
*
* @oaram {Element} el
* @param {Vue} vm
* @param {Function} [cb]
*/
exports.remove = function (el, vm, cb) {
apply(el, -1, function () {
_.remove(el)
}, vm, cb)
}
/**
* Remove by appending to another parent with transition.
* This is only used in block operations.
*
* @oaram {Element} el
* @param {Element} target
* @param {Vue} vm
* @param {Function} [cb]
*/
exports.removeThenAppend = function (el, target, vm, cb) {
apply(el, -1, function () {
target.appendChild(el)
}, vm, cb)
}
/**
* Append the childNodes of a fragment to target.
*
* @param {DocumentFragment} block
* @param {Node} target
* @param {Vue} vm
*/
exports.blockAppend = function (block, target, vm) {
var nodes = _.toArray(block.childNodes)
for (var i = 0, l = nodes.length; i < l; i++) {
exports.before(nodes[i], target, vm)
}
}
/**
* Remove a block of nodes between two edge nodes.
*
* @param {Node} start
* @param {Node} end
* @param {Vue} vm
*/
exports.blockRemove = function (start, end, vm) {
var node = start.nextSibling
var next
while (node !== end) {
next = node.nextSibling
exports.remove(node, vm)
node = next
}
}
/**
* Apply transitions with an operation callback.
*
* @oaram {Element} el
* @param {Number} direction
* 1: enter
* -1: leave
* @param {Function} op - the actual DOM operation
* @param {Vue} vm
* @param {Function} [cb]
*/
var apply = exports.apply = function (el, direction, op, vm, cb) {
var transData = el.__v_trans
if (
!transData ||
!vm._isCompiled ||
// if the vm is being manipulated by a parent directive
// during the parent's compilation phase, skip the
// animation.
(vm.$parent && !vm.$parent._isCompiled)
) {
op()
if (cb) cb()
return
}
// determine the transition type on the element
var jsTransition = vm.$options.transitions[transData.id]
if (jsTransition) {
// js
applyJSTransition(
el,
direction,
op,
transData,
jsTransition,
vm,
cb
)
} else if (_.transitionEndEvent) {
// css
applyCSSTransition(
el,
direction,
op,
transData,
cb
)
} else {
// not applicable
op()
if (cb) cb()
}
}