tiny-slider
Version:
Vanilla javascript slider for all purposes, inspired by Owl Carousel.
27 lines • 710 B
JavaScript
export function Events() {
return {
topics: {},
on: function (eventName, fn) {
this.topics[eventName] = this.topics[eventName] || [];
this.topics[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.topics[eventName]) {
for (var i = 0; i < this.topics[eventName].length; i++) {
if (this.topics[eventName][i] === fn) {
this.topics[eventName].splice(i, 1);
break;
}
}
}
},
emit: function (eventName, data) {
data.type = eventName;
if (this.topics[eventName]) {
this.topics[eventName].forEach(function(fn) {
fn(data, eventName);
});
}
}
};
};