Skip to content
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a7c1bde
Add instructions for running example locally
tyler-vs Dec 1, 2021
c9cd10b
Update HTML content
tyler-vs Dec 1, 2021
4690159
Update script
tyler-vs Dec 1, 2021
b2abea3
Update script comments
tyler-vs Dec 1, 2021
9e4973f
Move carousel initialization to index.html
tyler-vs Dec 1, 2021
ad3d35e
Add jsdocs to methods
tyler-vs Dec 1, 2021
2c492b6
Return if no value was passed for parameter
tyler-vs Dec 1, 2021
31c58c3
Update carousel empty element with more data- attributes for features
tyler-vs Dec 1, 2021
69da7ee
Add auto controls feature check
tyler-vs Dec 1, 2021
50facdf
Add renderAutoControls method
tyler-vs Dec 1, 2021
b9319d9
Remove commented out code
tyler-vs Dec 1, 2021
d0a0d41
Replace renderButtons with renderAutoControls
tyler-vs Dec 1, 2021
fff50f4
Uncomment fade related code in the JSON slider's constructor
tyler-vs Dec 1, 2021
052ed0c
Update styles with button and fade support
tyler-vs Dec 1, 2021
56d2377
Remove unnecessary code
tyler-vs Dec 1, 2021
fb61589
Update placeholder div element with data- attributes
tyler-vs Dec 1, 2021
d7e5203
Add support for captions
tyler-vs Dec 1, 2021
59fbb4f
Add support for pager
tyler-vs Dec 1, 2021
2f4c0d1
Add event listeners for "slide to" buttons
tyler-vs Dec 1, 2021
2efecd7
Fix left/prev button styles
tyler-vs Dec 1, 2021
d4b3ad1
Add inspiration section
tyler-vs Dec 10, 2021
c01cf75
Move slides variables
tyler-vs Dec 10, 2021
8440912
Add errors.js
tyler-vs Dec 10, 2021
e3852c3
Include errors.js to example
tyler-vs Dec 10, 2021
f5881f0
Throw custom error if no selector
tyler-vs Dec 10, 2021
5c7c356
Replace x with this.slides
tyler-vs Dec 10, 2021
007834c
Remove x variable
tyler-vs Dec 10, 2021
84837ea
Change new of showDivs method to showSlide
tyler-vs Dec 10, 2021
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
Prev Previous commit
Next Next commit
Update script comments
  • Loading branch information
tyler-vs committed Dec 1, 2021
commit b2abea3a8cfc3c821e5d3f039e734dbe34c7b371
49 changes: 38 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
console.clear();

class Carousel {
constructor(selector) {
// @TODO Feature detection
Expand All @@ -15,8 +13,16 @@ class Carousel {
this.init();
}

/**
* Initializes the carousel by:
* - setting up variables
* - Getting data- attribute values
* - Binding "this" to methods
* - Invoke addEventListeners() method
* - Show initial slide
* @return {[type]} [description]
*/
init() {
console.count("Original init");
// Set up variables
this.slideIndex = null;
this.sliderInterval = null;
Expand Down Expand Up @@ -44,8 +50,7 @@ class Carousel {
// Even private methods
this.showDivs = this.showDivs.bind(this);

// Add event listeners without bind() in the call.
// this.addEventListeners = this.addEventListeners.bind(this);
// Add event listeners
this.addEventListeners();

// Init
Expand Down Expand Up @@ -176,7 +181,14 @@ class SuperJSONCarousel extends Carousel {
].join("");
}

// Helper method to create HTML button elements from scratch
/**
* Helper method to create HTML button elements from scratch.
* @param {String} content HTML/string content
* @param {String} css String for CSS classes
* @param {String} title String title for title attribute
* @param {String} data String value for data- attribute
* @return {[type]} [description]
*/
renderButton(content, css, title, data) {
if (!content) {
console.log("Must provide content to the renderButton function.");
Expand All @@ -185,9 +197,6 @@ class SuperJSONCarousel extends Carousel {

return [
"<button ",
// @todo add checks
// "<button " +
// (css !== undefined ? this.renderClassAttribute(css) : "") +
this.renderClassAttribute(css),
this.renderDataAttribute("slide", data),
this.renderTitleAttribute(title),
Expand All @@ -198,15 +207,24 @@ class SuperJSONCarousel extends Carousel {
}

// @todo handle [...class] array of classes
/**
* Helper method to render class attribute.
* @param {String} name Class attribute value
* @return {[type]} [description]
*/
renderClassAttribute(name) {
if (!name) {
console.log("Error. Must provide a class name.");
return;
}
// return 'class="' + name + '" ';
return `class="${name}" `;
}

/**
* Helper method for rendering title attribute.
* @param {String} title Title attirbute value.
* @return {[type]} [description]
*/
renderTitleAttribute(title) {
if (!title) {
console.log("Error. Must provide a title for the title attribute.");
Expand All @@ -216,6 +234,12 @@ class SuperJSONCarousel extends Carousel {
return `title="${title}" `;
}

/**
* Helper method for rendering a data- attribute.
* @param {String} name Value that comes after data-
* @param {String} value String value
* @return {[type]} [description]
*/
renderDataAttribute(name = "slide", value) {
if (!value) {
console.log(
Expand All @@ -225,7 +249,10 @@ class SuperJSONCarousel extends Carousel {
return `data-${name}="${value}"`;
}

// Renders slideshow buttons
/**
* Helper method to render slideshow buttons.
* @return {[type]} [description]
*/
renderButtons() {
return [
// "<button class='button button--prev' data-slide='prev' title='Prev'>&#10094;</button>",
Expand Down