react-bootstrap
Version:
Bootstrap 3 components build with React
53 lines (45 loc) • 1.42 kB
JavaScript
import React from './react-es6';
// TODO: listen for onTransitionEnd to remove el
export default = {
_fadeIn: function () {
var els;
if (this.isMounted()) {
els = this.getDOMNode().querySelectorAll('.fade');
if (els.length) {
Array.prototype.forEach.call(els, function (el) {
el.className += ' in';
});
}
}
},
_fadeOut: function () {
var els = this._fadeOutEl.querySelectorAll('.fade.in');
if (els.length) {
Array.prototype.forEach.call(els, function (el) {
el.className = el.className.replace(/\bin\b/, '');
});
}
setTimeout(this._handleFadeOutEnd, 300);
},
_handleFadeOutEnd: function () {
if (this._fadeOutEl && this._fadeOutEl.parentNode) {
this._fadeOutEl.parentNode.removeChild(this._fadeOutEl);
}
},
componentDidMount: function () {
if (document.querySelectorAll) {
// Firefox needs delay for transition to be triggered
setTimeout(this._fadeIn, 20);
}
},
componentWillUnmount: function () {
var els = this.getDOMNode().querySelectorAll('.fade');
if (els.length) {
this._fadeOutEl = document.createElement('div');
document.body.appendChild(this._fadeOutEl);
this._fadeOutEl.innerHTML = this.getDOMNode().innerHTML;
// Firefox needs delay for transition to be triggered
setTimeout(this._fadeOut, 20);
}
}
};