-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ToastMessage): switch to hosted ReactTransitionEvents
* Original commit: 6aae839 * Original author: @KagamiChan * Closes #108 * Closes #86
- Loading branch information
1 parent
006736d
commit b3423a9
Showing
2 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const endEvents = []; | ||
|
||
const EVENTS = { | ||
transitionend: { | ||
transition: `transitionend`, | ||
WebkitTransition: `webkitTransitionEnd`, | ||
MozTransition: `mozTransitionEnd`, | ||
msTransition: `MSTransitionEnd`, | ||
OTransition: `oTransitionEnd`, | ||
}, | ||
|
||
animationend: { | ||
animation: `animationend`, | ||
WebkitAnimation: `webkitAnimationEnd`, | ||
MozAnimation: `mozAnimationEnd`, | ||
msAnimation: `MSAnimationEnd`, | ||
OAnimation: `oAnimationEnd`, | ||
}, | ||
}; | ||
|
||
if (typeof window !== `undefined`) { | ||
const style = document.createElement(`div`).style; | ||
for (let eventType in EVENTS) { | ||
if (!EVENTS.hasOwnProperty(eventType)) { | ||
continue | ||
} | ||
const prefixes = EVENTS[eventType]; | ||
for (let styleProp in prefixes) { | ||
if (prefixes.hasOwnProperty(styleProp) && styleProp in style) { | ||
endEvents.push(prefixes[styleProp]); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
const TransitionEvents = { | ||
addEndEventListener: function(node, eventListener) { | ||
if (endEvents.length === 0) { | ||
setTimeout(eventListener, 0); | ||
return; | ||
} | ||
endEvents.forEach(function(event) { | ||
node.addEventListener(event, eventListener, false); | ||
}); | ||
}, | ||
|
||
removeEndEventListener: function(node, eventListener) { | ||
if (endEvents.length === 0) { | ||
return; | ||
} | ||
endEvents.forEach(function(event) { | ||
node.removeEventListener(event, eventListener, false); | ||
}); | ||
}, | ||
}; | ||
|
||
|
||
export default TransitionEvents; |