1- const EVENT_NAME_MAP = {
1+ const START_EVENT_NAME_MAP = {
2+ transitionstart : {
3+ transition : 'transitionstart' ,
4+ WebkitTransition : 'webkitTransitionStart' ,
5+ MozTransition : 'mozTransitionStart' ,
6+ OTransition : 'oTransitionStart' ,
7+ msTransition : 'MSTransitionStart' ,
8+ } ,
9+
10+ animationstart : {
11+ animation : 'animationstart' ,
12+ WebkitAnimation : 'webkitAnimationStart' ,
13+ MozAnimation : 'mozAnimationStart' ,
14+ OAnimation : 'oAnimationStart' ,
15+ msAnimation : 'MSAnimationStart' ,
16+ } ,
17+ }
18+
19+ const END_EVENT_NAME_MAP = {
220 transitionend : {
321 transition : 'transitionend' ,
422 WebkitTransition : 'webkitTransitionEnd' ,
@@ -16,31 +34,39 @@ const EVENT_NAME_MAP = {
1634 } ,
1735}
1836
37+ const startEvents = [ ]
1938const endEvents = [ ]
2039
2140function detectEvents ( ) {
2241 const testEl = document . createElement ( 'div' )
2342 const style = testEl . style
2443
2544 if ( ! ( 'AnimationEvent' in window ) ) {
26- delete EVENT_NAME_MAP . animationend . animation
45+ delete START_EVENT_NAME_MAP . animationstart . animation
46+ delete END_EVENT_NAME_MAP . animationend . animation
2747 }
2848
2949 if ( ! ( 'TransitionEvent' in window ) ) {
30- delete EVENT_NAME_MAP . transitionend . transition
50+ delete START_EVENT_NAME_MAP . transitionstart . transition
51+ delete END_EVENT_NAME_MAP . transitionend . transition
3152 }
3253
33- for ( const baseEventName in EVENT_NAME_MAP ) {
34- if ( EVENT_NAME_MAP . hasOwnProperty ( baseEventName ) ) {
35- const baseEvents = EVENT_NAME_MAP [ baseEventName ]
36- for ( const styleName in baseEvents ) {
37- if ( styleName in style ) {
38- endEvents . push ( baseEvents [ styleName ] )
39- break
54+ function process ( EVENT_NAME_MAP , events ) {
55+ for ( const baseEventName in EVENT_NAME_MAP ) {
56+ if ( EVENT_NAME_MAP . hasOwnProperty ( baseEventName ) ) {
57+ const baseEvents = EVENT_NAME_MAP [ baseEventName ]
58+ for ( const styleName in baseEvents ) {
59+ if ( styleName in style ) {
60+ events . push ( baseEvents [ styleName ] )
61+ break
62+ }
4063 }
4164 }
4265 }
4366 }
67+
68+ process ( START_EVENT_NAME_MAP , startEvents )
69+ process ( END_EVENT_NAME_MAP , endEvents )
4470}
4571
4672if ( typeof window !== 'undefined' && typeof document !== 'undefined' ) {
@@ -56,6 +82,31 @@ function removeEventListener (node, eventName, eventListener) {
5682}
5783
5884const TransitionEvents = {
85+ // Start events
86+ startEvents,
87+
88+ addStartEventListener ( node , eventListener ) {
89+ if ( startEvents . length === 0 ) {
90+ window . setTimeout ( eventListener , 0 )
91+ return
92+ }
93+ startEvents . forEach ( ( startEvent ) => {
94+ addEventListener ( node , startEvent , eventListener )
95+ } )
96+ } ,
97+
98+ removeStartEventListener ( node , eventListener ) {
99+ if ( startEvents . length === 0 ) {
100+ return
101+ }
102+ startEvents . forEach ( ( startEvent ) => {
103+ removeEventListener ( node , startEvent , eventListener )
104+ } )
105+ } ,
106+
107+ // End events
108+ endEvents,
109+
59110 addEndEventListener ( node , eventListener ) {
60111 if ( endEvents . length === 0 ) {
61112 window . setTimeout ( eventListener , 0 )
@@ -66,8 +117,6 @@ const TransitionEvents = {
66117 } )
67118 } ,
68119
69- endEvents,
70-
71120 removeEndEventListener ( node , eventListener ) {
72121 if ( endEvents . length === 0 ) {
73122 return
@@ -79,4 +128,3 @@ const TransitionEvents = {
79128}
80129
81130export default TransitionEvents
82-
0 commit comments