@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
62 lines (61 loc) • 2.51 kB
JavaScript
import { ESLCarouselActionEvent } from './esl-carousel.events.base';
/** {@link ESLCarousel} event that represents slide change event */
export class ESLCarouselSlideEvent extends ESLCarouselActionEvent {
constructor(type, init) {
super(type, {
bubbles: true,
cancelable: ESLCarouselSlideEvent.BEFORE === type,
composed: true
});
Object.assign(this, init, type === ESLCarouselSlideEvent.AFTER ? { final: true } : {});
}
static create(type, init) {
return new ESLCarouselSlideEvent(ESLCarouselSlideEvent[type], init);
}
}
/** {@link ESLCarouselSlideEvent} cancelable event type dispatched before slide change (pre-event) */
ESLCarouselSlideEvent.BEFORE = 'esl:before:slide-change';
/** {@link ESLCarouselSlideEvent} event type dispatched before carousel is going to change active slide (post-event) */
ESLCarouselSlideEvent.CHANGE = 'esl:slide-change';
/** {@link ESLCarouselSlideEvent} event type dispatched after slide change (post-event) */
ESLCarouselSlideEvent.AFTER = 'esl:after:slide-change';
/** {@link ESLCarousel} event that represents slide move event */
export class ESLCarouselMoveEvent extends ESLCarouselActionEvent {
constructor(type, init) {
super(type, {
bubbles: false, // Do not bubble, to improve performance
cancelable: false,
composed: true
});
const delta = init.offset - init.offsetBefore;
Object.assign(this, init, {
final: true, // Move itself is always final
delta,
direction: Math.sign(delta)
});
}
static create(init) {
return new ESLCarouselMoveEvent(ESLCarouselMoveEvent.TYPE, init);
}
}
/** {@link ESLCarouselMoveEvent} event type dispatched on carousel move */
ESLCarouselMoveEvent.TYPE = 'esl:carousel:move';
/** {@link ESLCarousel} event that represents slide configuration change */
export class ESLCarouselChangeEvent extends Event {
constructor(type, init) {
super(type, {
bubbles: true,
cancelable: false,
composed: true
});
this.initial = false;
this.added = [];
this.removed = [];
Object.assign(this, init);
}
static create(init) {
return new ESLCarouselChangeEvent(ESLCarouselChangeEvent.TYPE, init);
}
}
/** {@link ESLCarouselSlideEvent} event type dispatched on carousel config changes */
ESLCarouselChangeEvent.TYPE = 'esl:carousel:change';