aurelia-materialize-bridge
Version:
Aurelia interface to http://materializecss.com/
84 lines (66 loc) • 1.95 kB
text/typescript
import * as au from "../aurelia";
.customElement("md-carousel")
.autoinject
export class MdCarousel {
constructor(private element: Element, private taskQueue: au.TaskQueue) { }
.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime })
indicators: boolean = true;
.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime })
fullWidth: boolean = false;
.ato.bindable.numberMd({ defaultBindingMode: au.bindingMode.oneTime })
duration: number;
.ato.bindable.numberMd({ defaultBindingMode: au.bindingMode.oneTime })
dist: number;
.ato.bindable.numberMd({ defaultBindingMode: au.bindingMode.oneTime })
shift: number;
.ato.bindable.numberMd({ defaultBindingMode: au.bindingMode.oneTime })
padding: number;
.ato.bindable.numberMd({ defaultBindingMode: au.bindingMode.oneTime })
numVisible: number;
.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.oneTime })
noWrap: boolean;
.children("md-carousel-item")
items: Element[] = [];
itemsChanged() {
this.refresh();
}
instance: M.Carousel;
attached() {
if (this.fullWidth) {
this.element.classList.add("carousel-slider");
}
this.refresh();
}
detached() {
this.instance.destroy();
}
refresh() {
if (!this.items.length) {
return;
}
const options: Partial<M.CarouselOptions> = {
fullWidth: this.fullWidth,
indicators: this.indicators,
dist: this.dist,
duration: this.duration,
noWrap: this.noWrap,
numVisible: this.numVisible,
padding: this.padding,
shift: this.shift,
onCycleTo: (current, dragged) => au.fireMaterializeEvent(this.element, "cycle-to", { current, dragged })
};
au.cleanOptions(options);
this.taskQueue.queueTask(() => {
this.instance = new M.Carousel(this.element, options);
});
}
next(n?: number) {
this.instance.next(n);
}
prev(n?: number) {
this.instance.prev(n);
}
set(n?: number) {
this.instance.set(n);
}
}