@@ -11,6 +11,16 @@ var doc = typeof document === 'undefined' ? null : document
11
11
var TYPE_TRANSITION = 1
12
12
var TYPE_ANIMATION = 2
13
13
14
+ /**
15
+ * A Transition object that encapsulates the state and logic
16
+ * of the transition.
17
+ *
18
+ * @param {Element } el
19
+ * @param {String } id
20
+ * @param {Object } hooks
21
+ * @param {Vue } vm
22
+ */
23
+
14
24
function Transition ( el , id , hooks , vm ) {
15
25
this . el = el
16
26
this . enterClass = id + '-enter'
@@ -35,6 +45,13 @@ function Transition (el, id, hooks, vm) {
35
45
36
46
var p = Transition . prototype
37
47
48
+ /**
49
+ * Start an entering transition.
50
+ *
51
+ * @param {Function } op - insert/show the element
52
+ * @param {Function } [cb]
53
+ */
54
+
38
55
p . enter = function ( op , cb ) {
39
56
this . cancelPending ( )
40
57
this . callHook ( 'beforeEnter' )
@@ -44,6 +61,12 @@ p.enter = function (op, cb) {
44
61
queue . push ( this . nextEnter )
45
62
}
46
63
64
+ /**
65
+ * The "nextTick" phase of an entering transition, which is
66
+ * to be pushed into a queue and executed after a reflow so
67
+ * that removing the class can trigger a CSS transition.
68
+ */
69
+
47
70
p . nextEnter = function ( ) {
48
71
var enterHook = this . hooks && this . hooks . enter
49
72
var afterEnter = this . afterEnter
@@ -67,13 +90,24 @@ p.nextEnter = function () {
67
90
}
68
91
}
69
92
93
+ /**
94
+ * The "cleanup" phase of an entering transition.
95
+ */
96
+
70
97
p . afterEnter = function ( ) {
71
98
this . jsCancel = this . pendingJsCb = null
72
99
removeClass ( this . el , this . enterClass )
73
100
this . callHook ( 'afterEnter' )
74
101
if ( this . cb ) this . cb ( )
75
102
}
76
103
104
+ /**
105
+ * Start a leaving transition.
106
+ *
107
+ * @param {Function } op - remove/hide the element
108
+ * @param {Function } [cb]
109
+ */
110
+
77
111
p . leave = function ( op , cb ) {
78
112
this . cancelPending ( )
79
113
this . callHook ( 'beforeLeave' )
@@ -95,6 +129,10 @@ p.leave = function (op, cb) {
95
129
}
96
130
}
97
131
132
+ /**
133
+ * The "nextTick" phase of a leaving transition.
134
+ */
135
+
98
136
p . nextLeave = function ( ) {
99
137
var type = this . getCssTransitionType ( this . leaveClass )
100
138
if ( type ) {
@@ -107,13 +145,22 @@ p.nextLeave = function () {
107
145
}
108
146
}
109
147
148
+ /**
149
+ * The "cleanup" phase of a leaving transition.
150
+ */
151
+
110
152
p . afterLeave = function ( ) {
111
153
this . op ( )
112
154
removeClass ( this . el , this . leaveClass )
113
155
this . callHook ( 'afterLeave' )
114
156
if ( this . cb ) this . cb ( )
115
157
}
116
158
159
+ /**
160
+ * Cancel any pending callbacks from a previously running
161
+ * but not finished transition.
162
+ */
163
+
117
164
p . cancelPending = function ( ) {
118
165
this . op = this . cb = null
119
166
var hasPending = false
@@ -137,12 +184,26 @@ p.cancelPending = function () {
137
184
}
138
185
}
139
186
187
+ /**
188
+ * Call a user-provided hook function.
189
+ *
190
+ * @param {String } type
191
+ */
192
+
140
193
p . callHook = function ( type ) {
141
194
if ( this . hooks && this . hooks [ type ] ) {
142
195
this . hooks [ type ] . call ( this . vm , this . el )
143
196
}
144
197
}
145
198
199
+ /**
200
+ * Get an element's transition type based on the
201
+ * calculated styles.
202
+ *
203
+ * @param {String } className
204
+ * @return {Number }
205
+ */
206
+
146
207
p . getCssTransitionType = function ( className ) {
147
208
// skip CSS transitions if page is not visible -
148
209
// this solves the issue of transitionend events not
@@ -175,6 +236,13 @@ p.getCssTransitionType = function (className) {
175
236
return type
176
237
}
177
238
239
+ /**
240
+ * Setup a CSS transitionend/animationend callback.
241
+ *
242
+ * @param {String } event
243
+ * @param {Function } cb
244
+ */
245
+
178
246
p . setupCssCb = function ( event , cb ) {
179
247
this . pendingCssEvent = event
180
248
var self = this
0 commit comments