Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: first and last slides of carousel component are no longer centred by default #1719

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="carousel-wrapper">
Config: {{ config | json }}
<swiper (swiper)="handleSwiperInitialised($event)" [config]="config">
<ng-template
swiperSlide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export class TmplCarouselComponent extends TemplateBaseComponent implements OnIn
}

async ngOnInit() {
await this.getParams();
this.getParams();
await this.hackSetHighlightedTask();
}

async getParams() {
getParams() {
this.config.slidesPerView =
getNumberParamFromTemplateRow(this._row, "slides_per_view", null) || "auto";
this.config.spaceBetween = getNumberParamFromTemplateRow(this._row, "space_between", 10);
Expand All @@ -37,14 +37,30 @@ export class TmplCarouselComponent extends TemplateBaseComponent implements OnIn
if (this.config.loop) {
this.config.loopedSlides = this._row.rows.length;
}
this.config.centeredSlides = getBooleanParamFromTemplateRow(this._row, "centered_slides", true);
this.initialSlide = getNumberParamFromTemplateRow(this._row, "initial_slide_index", 0);
this.config.centeredSlides = getBooleanParamFromTemplateRow(this._row, "centred_slides", true);
this.config.centeredSlidesBounds = !getBooleanParamFromTemplateRow(
this._row,
"centre_first_and_last",
false
);
this.config.initialSlide = getNumberParamFromTemplateRow(this._row, "initial_slide_index", 0);
}

/** Event emitter called when swiper initialised */
public handleSwiperInitialised(swiper: Swiper) {
// setInterval(() => console.log("initial slide:", this.swiper.params.initialSlide), 10)
console.log("swiper initialised");
this.swiper = swiper;
this.swiper.slideTo(this.initialSlide, 0, false);
this.swiper.slideTo(this.config.initialSlide, 0, false);
console.log("swiper params:", this.swiper.params);
console.log("active index:", this.swiper.activeIndex);
this.swiper.params.centeredSlidesBounds = true;
this.swiper.update();

setTimeout(() => {
console.log("hi");
this.swiper.slideTo(this.config.initialSlide, 0, false);
}, 1000);
}

/** When using carousel within task_group context set additional highlighted slide from task data */
Expand All @@ -53,10 +69,12 @@ export class TmplCarouselComponent extends TemplateBaseComponent implements OnIn
if (taskGroupsList) {
const highlightedTaskGroup = this.taskService.getHighlightedTaskGroup();
if (highlightedTaskGroup) {
this.initialSlide = await this.taskService.getHighlightedTaskGroupIndex(
this.config.initialSlide = await this.taskService.getHighlightedTaskGroupIndex(
highlightedTaskGroup,
taskGroupsList
);
// If the Swiper instance has already been intialised, update it
if (this.swiper) this.swiper.update();
}
}
}
Expand Down