78 lines
1.1 KiB
JavaScript
78 lines
1.1 KiB
JavaScript
/**
|
|
* Module Dependencies
|
|
*/
|
|
|
|
var events = require('event');
|
|
|
|
// CSS events
|
|
|
|
var watch = [
|
|
'transitionend'
|
|
, 'webkitTransitionEnd'
|
|
, 'oTransitionEnd'
|
|
, 'MSTransitionEnd'
|
|
, 'animationend'
|
|
, 'webkitAnimationEnd'
|
|
, 'oAnimationEnd'
|
|
, 'MSAnimationEnd'
|
|
];
|
|
|
|
/**
|
|
* Expose `CSSnext`
|
|
*/
|
|
|
|
module.exports = CssEmitter;
|
|
|
|
/**
|
|
* Initialize a new `CssEmitter`
|
|
*
|
|
*/
|
|
|
|
function CssEmitter(element){
|
|
if (!(this instanceof CssEmitter)) return new CssEmitter(element);
|
|
this.el = element;
|
|
}
|
|
|
|
/**
|
|
* Bind CSS events.
|
|
*
|
|
* @api public
|
|
*/
|
|
|
|
CssEmitter.prototype.bind = function(fn){
|
|
for (var i=0; i < watch.length; i++) {
|
|
events.bind(this.el, watch[i], fn);
|
|
}
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Unbind CSS events
|
|
*
|
|
* @api public
|
|
*/
|
|
|
|
CssEmitter.prototype.unbind = function(fn){
|
|
for (var i=0; i < watch.length; i++) {
|
|
events.unbind(this.el, watch[i], fn);
|
|
}
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Fire callback only once
|
|
*
|
|
* @api public
|
|
*/
|
|
|
|
CssEmitter.prototype.once = function(fn){
|
|
var self = this;
|
|
function on(){
|
|
self.unbind(on);
|
|
fn.apply(self.el, arguments);
|
|
}
|
|
self.bind(on);
|
|
return this;
|
|
};
|
|
|