From cd56d2083464007d418c190dd15ccec14737c981 Mon Sep 17 00:00:00 2001 From: daviddalbusco Date: Wed, 28 Nov 2018 10:19:35 +0100 Subject: [PATCH] feat: add an option to not trigger slideStart on slideNext and slidePrev --- doc/features/navigation.md | 12 ++++++++++ src/components.d.ts | 4 ++-- .../deck/deckdeckgo-deck/deckdeckgo-deck.tsx | 22 +++++++++++-------- src/index.html | 4 ++-- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/doc/features/navigation.md b/doc/features/navigation.md index 2b887e4bf..edcf1770e 100644 --- a/doc/features/navigation.md +++ b/doc/features/navigation.md @@ -32,12 +32,24 @@ const deck = document.getElementsByTagName('deckgo-deck'); await deck.slideNext(); ``` +*Optional parameter:* Optionally your could provide a boolean parameter to this method in case you would not like the event `slideNextStart` and `slidePrevStart` to be fired. + +``` +await deck.slideNext(false); +``` + ### Go to previous slide ``` await deck.slidePrev(); ``` +*Optional parameter:* Optionally your could provide a boolean parameter to this method in case you would not like the event `slideNextStart` and `slidePrevStart` to be fired. + +``` +await deck.slidePrev(false); +``` + ### Go to a specific slide ``` diff --git a/src/components.d.ts b/src/components.d.ts index 9aa28b0de..9ee72cf79 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -21,8 +21,8 @@ export namespace Components { 'keyboard': boolean; 'pager': boolean; 'pagerPercentage': boolean; - 'slideNext': () => Promise; - 'slidePrev': () => Promise; + 'slideNext': (emitEvent?: boolean) => Promise; + 'slidePrev': (emitEvent?: boolean) => Promise; 'slideTo': (index: number, speed?: number) => Promise; 'toggleFullScreen': () => Promise; } diff --git a/src/components/deck/deckdeckgo-deck/deckdeckgo-deck.tsx b/src/components/deck/deckdeckgo-deck/deckdeckgo-deck.tsx index 81a2a5ae5..c3683cc75 100644 --- a/src/components/deck/deckdeckgo-deck/deckdeckgo-deck.tsx +++ b/src/components/deck/deckdeckgo-deck/deckdeckgo-deck.tsx @@ -154,7 +154,7 @@ export class DeckdeckgoDeck { this.startX = null; } - private swipeSlide(deltaX: DeltaX): Promise { + private swipeSlide(deltaX: DeltaX, emitEvent: boolean = true): Promise { return new Promise(async (resolve) => { if (!deltaX || !window) { resolve(); @@ -173,11 +173,15 @@ export class DeckdeckgoDeck { if (deltaX.swipeLeft) { this.activeIndex++; - this.slideNextStart.emit(this.activeIndex); + if (emitEvent) { + this.slideNextStart.emit(this.activeIndex); + } } else { this.activeIndex--; - this.slidePrevStart.emit(this.activeIndex); + if (emitEvent) { + this.slidePrevStart.emit(this.activeIndex); + } } } } @@ -277,16 +281,16 @@ export class DeckdeckgoDeck { /* BEGIN: Manual sliding */ @Method() - async slideNext() { - await this.slideNextPrev(true); + async slideNext(emitEvent?: boolean) { + await this.slideNextPrev(true, emitEvent); } @Method() - async slidePrev() { - await this.slideNextPrev(false); + async slidePrev(emitEvent?: boolean) { + await this.slideNextPrev(false, emitEvent); } - private async slideNextPrev(swipeLeft: boolean) { + private async slideNextPrev(swipeLeft: boolean, emitEvent?: boolean) { const slider: HTMLElement = this.el.shadowRoot.querySelector('div.deckgo-deck'); if (!slider || !window) { @@ -303,7 +307,7 @@ export class DeckdeckgoDeck { deltaX: window.innerWidth }; - await this.swipeSlide(deltaX); + await this.swipeSlide(deltaX, emitEvent); } } diff --git a/src/index.html b/src/index.html index 157e80d71..389d8e1e8 100644 --- a/src/index.html +++ b/src/index.html @@ -127,14 +127,14 @@

Manual code

function slideNext() { const elem = document.getElementsByTagName('deckgo-deck'); if (elem && elem.length > 0) { - elem[0].slideNext(); + elem[0].slideNext(false); } } function slidePrev() { const elem = document.getElementsByTagName('deckgo-deck'); if (elem && elem.length > 0) { - elem[0].slidePrev(); + elem[0].slidePrev(false); } }