mirror of
https://github.com/webslides/WebSlides.git
synced 2025-08-21 04:12:01 +02:00
More JSDocs for the slides
This commit is contained in:
@@ -5,41 +5,77 @@ const CLASSES = {
|
|||||||
CURRENT: 'current'
|
CURRENT: 'current'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for the Slide section.
|
||||||
|
*/
|
||||||
export default class Slide {
|
export default class Slide {
|
||||||
|
/**
|
||||||
|
* Bootstraps the slide by saving some data, adding a class and hiding it.
|
||||||
|
* @param {Element} el Section element.
|
||||||
|
* @param {number} i Zero based index of the slide.
|
||||||
|
*/
|
||||||
constructor(el, i) {
|
constructor(el, i) {
|
||||||
|
/**
|
||||||
|
* @type {Element}
|
||||||
|
*/
|
||||||
this.el = el;
|
this.el = el;
|
||||||
|
/**
|
||||||
|
* The section's parent.
|
||||||
|
* @type {Node}
|
||||||
|
*/
|
||||||
this.parent = el.parentNode;
|
this.parent = el.parentNode;
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.i = i;
|
this.i = i;
|
||||||
this.el.id = 'section-' + (i + 1);
|
|
||||||
|
|
||||||
|
this.el.id = 'section-' + (i + 1);
|
||||||
this.el.classList.add(CLASSES.SLIDE);
|
this.el.classList.add(CLASSES.SLIDE);
|
||||||
|
|
||||||
// Hide slides by default
|
// Hide slides by default
|
||||||
this.hide();
|
this.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hides the node and removes the class that makes it "active".
|
||||||
|
*/
|
||||||
hide() {
|
hide() {
|
||||||
DOM.hide(this.el);
|
DOM.hide(this.el);
|
||||||
this.el.classList.remove(CLASSES.CURRENT);
|
this.el.classList.remove(CLASSES.CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the node and adds the class that makes it "active".
|
||||||
|
*/
|
||||||
show() {
|
show() {
|
||||||
DOM.show(this.el);
|
DOM.show(this.el);
|
||||||
this.el.classList.add(CLASSES.CURRENT);
|
this.el.classList.add(CLASSES.CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the section to the bottom of the section's list.
|
||||||
|
*/
|
||||||
moveAfterLast() {
|
moveAfterLast() {
|
||||||
const last = this.parent.childNodes[this.parent.childElementCount - 1];
|
const last = this.parent.childNodes[this.parent.childElementCount - 1];
|
||||||
|
|
||||||
this.parent.insertBefore(this.el, last.nextSibling);
|
this.parent.insertBefore(this.el, last.nextSibling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the section to the top of the section's list.
|
||||||
|
*/
|
||||||
moveBeforeFirst() {
|
moveBeforeFirst() {
|
||||||
const first = this.parent.childNodes[0];
|
const first = this.parent.childNodes[0];
|
||||||
|
|
||||||
this.parent.insertBefore(this.el, first);
|
this.parent.insertBefore(this.el, first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether an element is a valid candidate to be a slide by ensuring
|
||||||
|
* it's a "section" element.
|
||||||
|
* @param {Element} el Element to be checked.
|
||||||
|
* @return {boolean} Whether is candidate or not.
|
||||||
|
*/
|
||||||
static isCandidate(el) {
|
static isCandidate(el) {
|
||||||
return el.nodeType === 1 && el.tagName === 'SECTION';
|
return el.nodeType === 1 && el.tagName === 'SECTION';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user