1
- var endEvent = sniffTransitionEndEvent ( ) ,
1
+ var endEvents = sniffEndEvents ( ) ,
2
2
config = require ( './config' ) ,
3
3
// exit codes for testing
4
4
codes = {
@@ -31,7 +31,8 @@ var transition = module.exports = function (el, stage, cb, compiler) {
31
31
return codes . INIT
32
32
}
33
33
34
- var transitionId = el . vue_trans
34
+ var transitionId = el . vue_trans ,
35
+ animation = el . vue_anim
35
36
36
37
if ( transitionId ) {
37
38
return applyTransitionFunctions (
@@ -41,11 +42,12 @@ var transition = module.exports = function (el, stage, cb, compiler) {
41
42
transitionId ,
42
43
compiler
43
44
)
44
- } else if ( transitionId === '' ) {
45
+ } else if ( transitionId === '' || animation === '' ) {
45
46
return applyTransitionClass (
46
47
el ,
47
48
stage ,
48
- changeState
49
+ changeState ,
50
+ animation
49
51
)
50
52
} else {
51
53
changeState ( )
@@ -59,50 +61,73 @@ transition.codes = codes
59
61
/**
60
62
* Togggle a CSS class to trigger transition
61
63
*/
62
- function applyTransitionClass ( el , stage , changeState ) {
64
+ function applyTransitionClass ( el , stage , changeState , animation ) {
63
65
64
- if ( ! endEvent ) {
66
+ if ( ! endEvents . trans ) {
65
67
changeState ( )
66
68
return codes . CSS_SKIP
67
69
}
68
70
69
71
// if the browser supports transition,
70
72
// it must have classList...
71
- var classList = el . classList ,
72
- lastLeaveCallback = el . vue_trans_cb
73
+ var onEnd ,
74
+ classList = el . classList ,
75
+ lastLeaveCallback = el . vue_trans_cb ,
76
+ enterClass = config . enterClass ,
77
+ leaveClass = config . leaveClass ,
78
+ isAnimation = animation === '' ,
79
+ endEvent = isAnimation
80
+ ? endEvents . anim
81
+ : endEvents . trans
82
+
83
+ // cancel unfinished leave transition
84
+ if ( lastLeaveCallback ) {
85
+ el . removeEventListener ( endEvent , lastLeaveCallback )
86
+ classList . remove ( enterClass )
87
+ classList . remove ( leaveClass )
88
+ el . vue_trans_cb = null
89
+ }
73
90
74
91
if ( stage > 0 ) { // enter
75
92
76
- // cancel unfinished leave transition
77
- if ( lastLeaveCallback ) {
78
- el . removeEventListener ( endEvent , lastLeaveCallback )
79
- classList . remove ( config . leaveClass )
80
- el . vue_trans_cb = null
81
- }
82
-
83
93
// set to hidden state before appending
84
- classList . add ( config . enterClass )
94
+ if ( ! isAnimation ) {
95
+ classList . add ( enterClass )
96
+ }
85
97
// append
86
98
changeState ( )
87
99
// force a layout so transition can be triggered
88
100
/* jshint unused: false */
89
101
var forceLayout = el . clientHeight
90
102
// trigger transition
91
- classList . remove ( config . enterClass )
103
+ if ( ! isAnimation ) {
104
+ classList . remove ( enterClass )
105
+ } else {
106
+ classList . add ( enterClass )
107
+ onEnd = function ( e ) {
108
+ if ( e . target === el ) {
109
+ el . removeEventListener ( endEvent , onEnd )
110
+ el . vue_trans_cb = null
111
+ classList . remove ( enterClass )
112
+ }
113
+ }
114
+ el . addEventListener ( endEvent , onEnd )
115
+ el . vue_trans_cb = onEnd
116
+ }
92
117
return codes . CSS_E
93
118
94
119
} else { // leave
95
120
96
121
if ( el . offsetWidth || el . offsetHeight ) {
97
122
// trigger hide transition
98
- classList . add ( config . leaveClass )
99
- var onEnd = function ( e ) {
123
+ classList . add ( leaveClass )
124
+ onEnd = function ( e ) {
100
125
if ( e . target === el ) {
101
126
el . removeEventListener ( endEvent , onEnd )
102
127
el . vue_trans_cb = null
103
128
// actually remove node here
104
129
changeState ( )
105
- classList . remove ( config . leaveClass )
130
+ classList . remove ( leaveClass )
106
131
}
107
132
}
108
133
// attach transition end listener
@@ -150,17 +175,23 @@ function applyTransitionFunctions (el, stage, changeState, functionId, compiler)
150
175
/**
151
176
* Sniff proper transition end event name
152
177
*/
153
- function sniffTransitionEndEvent ( ) {
178
+ function sniffEndEvents ( ) {
154
179
var el = document . createElement ( 'vue' ) ,
155
180
defaultEvent = 'transitionend' ,
156
181
events = {
157
182
'transition' : defaultEvent ,
158
183
'mozTransition' : defaultEvent ,
159
184
'webkitTransition' : 'webkitTransitionEnd'
160
- }
185
+ } ,
186
+ ret = { }
161
187
for ( var name in events ) {
162
188
if ( el . style [ name ] !== undefined ) {
163
- return events [ name ]
189
+ ret . trans = events [ name ]
190
+ break
164
191
}
165
192
}
193
+ ret . anim = el . style . animation === ''
194
+ ? 'animationend'
195
+ : 'webkitAnimationEnd'
196
+ return ret
166
197
}
0 commit comments