1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-21 04:12:01 +02:00

Finishing navigation

This commit is contained in:
Antonio Laguna
2017-01-28 16:26:55 +01:00
parent 6e7ce46ebc
commit ae36e15588

View File

@@ -27,23 +27,55 @@ export default class Navigation {
constructor(wsInstance) { constructor(wsInstance) {
const arrowLabels = wsInstance.isVertical ? const arrowLabels = wsInstance.isVertical ?
LABELS.VERTICAL : LABELS.HORIZONTAL; LABELS.VERTICAL : LABELS.HORIZONTAL;
/**
* Navigation element.
* @type {Element}
*/
this.el = DOM.createNode('div', 'navigation'); this.el = DOM.createNode('div', 'navigation');
/**
* Next button.
* @type {Element}
*/
this.next = Navigation.createArrow(ELEMENT_ID.NEXT, arrowLabels.NEXT); this.next = Navigation.createArrow(ELEMENT_ID.NEXT, arrowLabels.NEXT);
/**
* Prev button.
* @type {Element}
*/
this.prev = Navigation.createArrow(ELEMENT_ID.PREV, arrowLabels.PREV); this.prev = Navigation.createArrow(ELEMENT_ID.PREV, arrowLabels.PREV);
/**
* Counter Element.
* @type {Element}
*/
this.counter = DOM.createNode('span', ELEMENT_ID.COUNTER); this.counter = DOM.createNode('span', ELEMENT_ID.COUNTER);
/**
* @type {WebSlides}
* @private
*/
this.ws_ = wsInstance;
this.el.appendChild(this.next); this.el.appendChild(this.next);
this.el.appendChild(this.prev); this.el.appendChild(this.prev);
this.el.appendChild(this.counter); this.el.appendChild(this.counter);
wsInstance.el.appendChild(this.el); this.ws_.el.appendChild(this.el);
this.bindEvents_();
} }
/** /**
* * Bind all events for the navigation.
* @param current * @private
* @param max */
bindEvents_() {
this.ws_.el.addEventListener(
'ws:slide-change', this.onSlideChanged_.bind(this));
this.next.addEventListener('click', this.onButtonClicked_.bind(this));
this.prev.addEventListener('click', this.onButtonClicked_.bind(this));
}
/**
* Updates the counter inside the navigation.
* @param {string|number} current Current slide number.
* @param {string|number} max Max slide number.
*/ */
updateCounter(current, max) { updateCounter(current, max) {
this.counter.textContent = `${current} / ${max}`; this.counter.textContent = `${current} / ${max}`;
@@ -62,4 +94,27 @@ export default class Navigation {
return arrow; return arrow;
} }
/**
* Slide Change event handler. Will update the text on the navigation.
* @param {CustomEvent} event
* @private
*/
onSlideChanged_(event) {
this.updateCounter(event.detail.currentSlide, event.detail.slides);
}
/**
* Handles clicks on the next/prev buttons.
* @param {MouseEvent} event
* @private
*/
onButtonClicked_(event) {
event.preventDefault();
if (event.target === this.next) {
this.ws_.goNext();
} else {
this.ws_.goPrev();
}
}
} }