client/components/yields/after-transition/0.0.1/index.js
/**
* dependencies
*/
var has = require('../../has-transitions/1.0.0')
, emitter = require('css-emitter-component')
, once = require('once-component');
/**
* Transition support.
*/
var supported = has();
/**
* Export `after`
*/
module.exports = after;
/**
* Invoke the given `fn` after transitions
*
* It will be invoked only if the browser
* supports transitions __and__
* the element has transitions
* set in `.style` or css.
*
* @param {Element} el
* @param {Function} fn
* @return {Function} fn
* @api public
*/
function after(el, fn){
if (!supported || !has(el)) return fn();
emitter(el).bind(fn);
return fn;
};
/**
* Same as `after()` only the function is invoked once.
*
* @param {Element} el
* @param {Function} fn
* @return {Function}
* @api public
*/
after.once = function(el, fn){
var callback = once(fn);
after(el, fn = function(){
emitter(el).unbind(fn);
callback();
});
};