39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
Object.defineProperty(exports, "__esModule", {
|
||
|
|
value: true
|
||
|
|
});
|
||
|
|
exports.default = {
|
||
|
|
once: function once(el, type, callback) {
|
||
|
|
var typeArray = type ? type.split(' ') : [];
|
||
|
|
var recursiveFunction = function recursiveFunction(event) {
|
||
|
|
event.target.removeEventListener(event.type, recursiveFunction);
|
||
|
|
return callback(event);
|
||
|
|
};
|
||
|
|
|
||
|
|
for (var i = typeArray.length - 1; i >= 0; i--) {
|
||
|
|
this.on(el, typeArray[i], recursiveFunction);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
on: function on(el, type, callback) {
|
||
|
|
if (el.addEventListener) {
|
||
|
|
el.addEventListener(type, callback);
|
||
|
|
} else {
|
||
|
|
// IE8+ Support
|
||
|
|
el.attachEvent('on' + type, function () {
|
||
|
|
callback.call(el);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
off: function off(el, type, callback) {
|
||
|
|
if (el.removeEventListener) {
|
||
|
|
el.removeEventListener(type, callback);
|
||
|
|
} else {
|
||
|
|
// IE8+ Support
|
||
|
|
el.detachEvent('on' + type, callback);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
isKeyboard: function isKeyboard(event) {
|
||
|
|
return ['keydown', 'keypress', 'keyup'].indexOf(event.type) !== -1;
|
||
|
|
}
|
||
|
|
};
|