mapcomplete/UI/Image/SlideShow.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-10-14 12:15:09 +02:00
import {UIEventSource} from "../../Logic/UIEventSource";
import {UIElement} from "../UIElement";
2020-11-02 18:59:21 +01:00
import Combine from "../Base/Combine";
// @ts-ignore
import $ from "jquery"
2020-06-24 00:35:19 +02:00
export class SlideShow extends UIElement {
private readonly _embeddedElements: UIEventSource<UIElement[]>
constructor(
2020-09-13 00:53:24 +02:00
embeddedElements: UIEventSource<UIElement[]>) {
2020-06-24 00:35:19 +02:00
super(embeddedElements);
this._embeddedElements = embeddedElements;
this._embeddedElements.addCallbackAndRun(elements => {
for (const element of elements ?? []) {
element.SetClass("slick-carousel-content")
}
})
2020-07-06 13:47:22 +02:00
2020-06-24 00:35:19 +02:00
}
InnerRender(): string {
return new Combine(
this._embeddedElements.data,
).SetClass("block slick-carousel")
2020-11-06 04:02:53 +01:00
.Render();
2020-06-24 00:35:19 +02:00
}
Update() {
super.Update();
for (const uiElement of this._embeddedElements.data) {
uiElement.Update();
}
}
protected InnerUpdate(htmlElement: HTMLElement) {
require("slick-carousel")
if(this._embeddedElements.data.length == 0){
return;
}
2021-02-15 17:44:19 +01:00
// @ts-ignore
$('.slick-carousel').not('.slick-initialized').slick({
autoplay: true,
arrows: true,
dots: true,
lazyLoad: 'progressive',
variableWidth: true,
centerMode: true,
centerPadding: "60px",
adaptive: true
});
}
}