@@ -11,6 +11,16 @@ var doc = typeof document === 'undefined' ? null : document
1111var TYPE_TRANSITION = 1
1212var TYPE_ANIMATION = 2
1313
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+
1424function Transition ( el , id , hooks , vm ) {
1525 this . el = el
1626 this . enterClass = id + '-enter'
@@ -35,6 +45,13 @@ function Transition (el, id, hooks, vm) {
3545
3646var p = Transition . prototype
3747
48+ /**
49+ * Start an entering transition.
50+ *
51+ * @param {Function } op - insert/show the element
52+ * @param {Function } [cb]
53+ */
54+
3855p . enter = function ( op , cb ) {
3956 this . cancelPending ( )
4057 this . callHook ( 'beforeEnter' )
@@ -44,6 +61,12 @@ p.enter = function (op, cb) {
4461 queue . push ( this . nextEnter )
4562}
4663
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+
4770p . nextEnter = function ( ) {
4871 var enterHook = this . hooks && this . hooks . enter
4972 var afterEnter = this . afterEnter
@@ -67,13 +90,24 @@ p.nextEnter = function () {
6790 }
6891}
6992
93+ /**
94+ * The "cleanup" phase of an entering transition.
95+ */
96+
7097p . afterEnter = function ( ) {
7198 this . jsCancel = this . pendingJsCb = null
7299 removeClass ( this . el , this . enterClass )
73100 this . callHook ( 'afterEnter' )
74101 if ( this . cb ) this . cb ( )
75102}
76103
104+ /**
105+ * Start a leaving transition.
106+ *
107+ * @param {Function } op - remove/hide the element
108+ * @param {Function } [cb]
109+ */
110+
77111p . leave = function ( op , cb ) {
78112 this . cancelPending ( )
79113 this . callHook ( 'beforeLeave' )
@@ -95,6 +129,10 @@ p.leave = function (op, cb) {
95129 }
96130}
97131
132+ /**
133+ * The "nextTick" phase of a leaving transition.
134+ */
135+
98136p . nextLeave = function ( ) {
99137 var type = this . getCssTransitionType ( this . leaveClass )
100138 if ( type ) {
@@ -107,13 +145,22 @@ p.nextLeave = function () {
107145 }
108146}
109147
148+ /**
149+ * The "cleanup" phase of a leaving transition.
150+ */
151+
110152p . afterLeave = function ( ) {
111153 this . op ( )
112154 removeClass ( this . el , this . leaveClass )
113155 this . callHook ( 'afterLeave' )
114156 if ( this . cb ) this . cb ( )
115157}
116158
159+ /**
160+ * Cancel any pending callbacks from a previously running
161+ * but not finished transition.
162+ */
163+
117164p . cancelPending = function ( ) {
118165 this . op = this . cb = null
119166 var hasPending = false
@@ -137,12 +184,26 @@ p.cancelPending = function () {
137184 }
138185}
139186
187+ /**
188+ * Call a user-provided hook function.
189+ *
190+ * @param {String } type
191+ */
192+
140193p . callHook = function ( type ) {
141194 if ( this . hooks && this . hooks [ type ] ) {
142195 this . hooks [ type ] . call ( this . vm , this . el )
143196 }
144197}
145198
199+ /**
200+ * Get an element's transition type based on the
201+ * calculated styles.
202+ *
203+ * @param {String } className
204+ * @return {Number }
205+ */
206+
146207p . getCssTransitionType = function ( className ) {
147208 // skip CSS transitions if page is not visible -
148209 // this solves the issue of transitionend events not
@@ -175,6 +236,13 @@ p.getCssTransitionType = function (className) {
175236 return type
176237}
177238
239+ /**
240+ * Setup a CSS transitionend/animationend callback.
241+ *
242+ * @param {String } event
243+ * @param {Function } cb
244+ */
245+
178246p . setupCssCb = function ( event , cb ) {
179247 this . pendingCssEvent = event
180248 var self = this
0 commit comments