Skip to content

Commit

Permalink
Merge 45f9624 into 23f5fd3
Browse files Browse the repository at this point in the history
  • Loading branch information
AStaroverov committed Sep 1, 2016
2 parents 23f5fd3 + 45f9624 commit c14f259
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/NotificationItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,33 @@ var Helpers = require('./helpers');
var merge = require('object-assign');

/* From Modernizr */
var whichTransitionEvent = function() {
var whichEvent = function (props) {
var t;
var el = document.createElement('fakeelement');

for (p in props) {
if (el.style[p] !== undefined) {
return props[p];
}
}
}
var whichTransitionEvent = function() {
var transitions = {
'transition': 'transitionend',
'OTransition': 'oTransitionEnd',
'MozTransition': 'transitionend',
'WebkitTransition': 'webkitTransitionEnd'
};

return whichEvent(transitions)
};
var whichAnimationEvent = function() {
var animations = {
'animation': 'animationend',
'webkitAnimation': 'webkitAnimationEnd'
};

for (t in transitions) {
if (el.style[t] !== undefined) {
return transitions[t];
}
}
return whichEvent(animations)
};

var NotificationItem = React.createClass({
Expand Down Expand Up @@ -185,6 +197,7 @@ var NotificationItem = React.createClass({
componentDidMount: function() {
var self = this;
var transitionEvent = whichTransitionEvent();
var animationEvent = whichAnimationEvent();
var notification = this.props.notification;
var element = ReactDOM.findDOMNode(this);

Expand All @@ -195,13 +208,17 @@ var NotificationItem = React.createClass({
// Watch for transition end
if (!this._noAnimation) {
if (transitionEvent) {
element.addEventListener(transitionEvent, this._onTransitionEnd);
} else {
transitionEvent && element.addEventListener(transitionEvent, this._onTransitionEnd);
}
if (animationEvent) {
animationEvent && element.addEventListener(animationEvent, this._onTransitionEnd);
}

if (!(transitionEvent || animationEvent)) {
this._noAnimation = true;
}
}


if (notification.autoDismiss) {
this._notificationTimer = new Helpers.Timer(function() {
self._hideNotification();
Expand All @@ -228,7 +245,15 @@ var NotificationItem = React.createClass({
componentWillUnmount: function() {
var element = ReactDOM.findDOMNode(this);
var transitionEvent = whichTransitionEvent();
element.removeEventListener(transitionEvent, this._onTransitionEnd);
var animationEvent = whichAnimationEvent();

if (transitionEvent) {
element.removeEventListener(transitionEvent, this._onTransitionEnd);
}
if (animationEvent) {
element.removeEventListener(animationEvent, this._onTransitionEnd);
}

this._isMounted = false;
},

Expand Down

0 comments on commit c14f259

Please sign in to comment.