From e24b39d575941548a669a3c5d3e4286c2e332eb7 Mon Sep 17 00:00:00 2001 From: Austin Asbury Date: Thu, 29 Feb 2024 08:33:11 -0500 Subject: [PATCH] use id to map elements to steps --- index.html | 8 ++++---- main.js | 2 -- src/handhold.mjs | 26 ++++++-------------------- steps.json | 4 ++++ 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/index.html b/index.html index 499cc2b..7feb691 100644 --- a/index.html +++ b/index.html @@ -38,7 +38,7 @@

Dashboard

+ id="step-1">

Headline

Headline

+ id="step-2">
@@ -66,7 +66,7 @@

Your Daily Graph

+ id="step-3">
@@ -80,7 +80,7 @@

Your Daily Graph

+ id="step-4">
diff --git a/main.js b/main.js index ee656f7..5a69c56 100644 --- a/main.js +++ b/main.js @@ -2,8 +2,6 @@ import Handhold from './src/handhold'; import handholdData from './steps.json'; const startBtn = document.getElementById('start-button'); -console.log({ startBtn }); - const handhold = new Handhold(startBtn); handhold.setup(handholdData); handhold.init(); \ No newline at end of file diff --git a/src/handhold.mjs b/src/handhold.mjs index 45eeca4..b67b7c0 100644 --- a/src/handhold.mjs +++ b/src/handhold.mjs @@ -8,7 +8,6 @@ export default class Handhold { this._currentStepElement; this._mappedSteps; this._startBtn = startElement || document.querySelector('[data-start-handhold]'); - this._stepElements; this._steps; this._listeners; this._root; @@ -16,7 +15,6 @@ export default class Handhold { // Imports steps from JSON or JS Object setup(data) { - this.setStepElements(); if (data.steps) { this._steps = data.steps; @@ -27,13 +25,6 @@ export default class Handhold { return; } - setStepElements() { - const elements = Array.from(document.querySelectorAll('[data-step]')); - this._stepElements = elements.length ? elements : []; - - return; - } - // applies style configuration if available applyConfig() { if (this._config) { @@ -91,17 +82,12 @@ export default class Handhold { // Matches steps to the related element in the DOM, mapSteps() { - if (this._stepElements.length) { - this._mappedSteps = this._stepElements.map((el) => { - const matchingStep = this._steps.find((step) => { - return parseInt(step.number) === parseInt(el.dataset.step); - }); - return { - ...matchingStep, - element: el, - }; - }); - } + this._mappedSteps = this._steps.map(step => { + return { + ...step, + element: document.getElementById(step.elementId) + } + }) if (this._mappedSteps && this._mappedSteps.length) { this._currentStepElement = this._mappedSteps.find((step) => { diff --git a/steps.json b/steps.json index 890abbb..bc0200d 100644 --- a/steps.json +++ b/steps.json @@ -2,21 +2,25 @@ "steps": [ { "number": "1", + "elementId": "step-1", "title": "Your Daily Headlines", "content": "This is where all the latest news will appear." }, { "number": "2", + "elementId": "step-2", "title": "Daily Graph", "content": "The daily graph will display relevant information." }, { "number": "3", + "elementId": "step-3", "title": "Another Graph", "content": "This will show even more relevant information" }, { "number": "4", + "elementId": "step-4", "title": "Mmmm... Pie", "content": "This will show even more relevant information" }