mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 11:17:41 +00:00
directory adjust: delete entry index.js
This commit is contained in:
77
packages/swipe/utils.js
Executable file
77
packages/swipe/utils.js
Executable file
@@ -0,0 +1,77 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
var extend = Object.assign.bind(Object);
|
||||
|
||||
function EventEmitter() {
|
||||
this.__events = {};
|
||||
}
|
||||
EventEmitter.prototype = {
|
||||
on: function(name, cb) {
|
||||
this.__events[name] || (this.__events[name] = []);
|
||||
this.__events[name].push(cb);
|
||||
return this;
|
||||
},
|
||||
emit: function(name) {
|
||||
var arr = this.__events[name];
|
||||
var argus = Array.prototype.slice.call(arguments, 1);
|
||||
var self = this;
|
||||
if (arr) {
|
||||
arr.forEach(function(cb) {
|
||||
cb.apply(self, argus);
|
||||
});
|
||||
}
|
||||
},
|
||||
removeListener: function(name, fn) {
|
||||
if (!this.__events[name]) {
|
||||
return;
|
||||
}
|
||||
let index;
|
||||
if (fn) {
|
||||
index = this.__events[name].indexOf(fn);
|
||||
if (index > 0) {
|
||||
this.__events[name].splice(index, 1);
|
||||
}
|
||||
} else {
|
||||
delete this.__events[name];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const isSupportRequestAnimationFrame = !Vue.prototype.$isServer &&
|
||||
(window.requestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame);
|
||||
const isSupportCancelAnimationFrame = !Vue.prototype.$isServer &&
|
||||
(window.cancelAnimationFrame ||
|
||||
window.mozCancelAnimationFrame ||
|
||||
window.webkitCancelAnimationFrame ||
|
||||
window.msCancelAnimationFrame);
|
||||
|
||||
const requestAnimationFrame = isSupportRequestAnimationFrame || function(callback, element) {
|
||||
return window.setTimeout(callback, 1000 / 60);
|
||||
};
|
||||
|
||||
const cancelAnimationFrame = isSupportCancelAnimationFrame || function(id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
|
||||
const bindEvents = (elem, eventNames, fn) => {
|
||||
eventNames = eventNames.split(/\s+/);
|
||||
eventNames.forEach(eventName => elem.addEventListener(eventName, fn));
|
||||
};
|
||||
|
||||
const removeEvents = (elem, eventNames, fn) => {
|
||||
eventNames = eventNames.split(/\s+/);
|
||||
eventNames.forEach(eventName => elem.removeEventListener(eventName, fn));
|
||||
};
|
||||
|
||||
export {
|
||||
extend,
|
||||
EventEmitter,
|
||||
requestAnimationFrame,
|
||||
cancelAnimationFrame,
|
||||
bindEvents,
|
||||
removeEvents
|
||||
};
|
||||
|
Reference in New Issue
Block a user