Skip to content

Commit

Permalink
fix(ToastMessage): switch to hosted ReactTransitionEvents
Browse files Browse the repository at this point in the history
* Original commit: 6aae839
* Original author: @KagamiChan
* Closes #108
* Closes #86
  • Loading branch information
KagamiChan authored and tomchentw committed Aug 21, 2017
1 parent 006736d commit b3423a9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/ToastMessage/animationMixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
default as ReactTransitionEvents,
} from "react/lib/ReactTransitionEvents";

import {
default as ReactDOM,
} from "react-dom";
Expand All @@ -10,6 +6,10 @@ import {
default as elementClass,
} from "element-class";

import {
default as ReactTransitionEvents,
} from "./transitionEvents";

const TICK = 17;
const { toString } = Object.prototype;

Expand Down
60 changes: 60 additions & 0 deletions src/lib/ToastMessage/transitionEvents.js
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;

0 comments on commit b3423a9

Please sign in to comment.