diff --git a/components/Dropdown/Dropdown.js b/components/Dropdown/Dropdown.js index c6cad4454..ad8a27dd9 100644 --- a/components/Dropdown/Dropdown.js +++ b/components/Dropdown/Dropdown.js @@ -1,28 +1,27 @@ class Dropdown { constructor(element) { - // Assign this.element to the dropdown element - this.element; - + this.element = element; + // Get the element with the ".dropdown-button" class found in the dropdown element (look at the HTML for context) - this.button = this.element.querySelector(); - + this.button = this.element.querySelector(".dropdown-button"); + // assign the reference to the ".dropdown-content" class found in the dropdown element - this.content; - - // Add a click handler to the button reference and call the toggleContent method. - this.button.addEventListener('click', () => { + this.content = this.element.querySelector(".dropdown-content"); - }) + // Add a click handler to the button reference and call the toggleContent method. + this.button.addEventListener("click", () => { + this.toggleContent(); + }); } toggleContent() { - // Toggle the ".dropdown-hidden" class off and on - this.content; + this.content.classList.toggle("dropdown-hidden"); } } - // Nothing to do here, just study what the code is doing and move on to the Dropdown class -let dropdowns = document.querySelectorAll('.dropdown').forEach( dropdown => new Dropdown(dropdown)); \ No newline at end of file +let dropdowns = document + .querySelectorAll(".dropdown") + .forEach(dropdown => new Dropdown(dropdown)); diff --git a/components/Tabs/Tabs.js b/components/Tabs/Tabs.js index 4163d47aa..cb8aed69f 100644 --- a/components/Tabs/Tabs.js +++ b/components/Tabs/Tabs.js @@ -1,51 +1,55 @@ - class TabLink { constructor(element) { + //console.log("i see you", element); // Assign this.element to the passed in DOM element - // this.element; - + this.element = element; + // Get the custom data attribute on the Link - // this.data; - + this.data = this.element.dataset.tab; + // // Using the custom data attribute get the associated Item element - // this.itemElement; - + this.itemElement = document.querySelector( + `.tabs-item[data-tab="${this.data}"]` + ); + console.log(this.itemElement); // Using the Item element, create a new instance of the TabItem class - // this.tabItem; - - // Add a click event listener on this instance, calling the select method on click + this.tabItem = new TabItem(this.itemElement); - }; + // Add a click event listener on this instance, calling the select method on click + this.element.addEventListener("click", () => this.select()); + } select() { // Get all of the elements with the tabs-link class - // const links; - + const links = document.querySelectorAll(".tabs-link"); + console.log(links); // Using a loop or the forEach method remove the 'tabs-link-selected' class from all of the links - // Array.from(links).forEach(); - + Array.from(links).forEach(link => { + link.classList.remove("tabs-link-selected"); + }); // Add a class named "tabs-link-selected" to this link - // this.element; - + this.element.classList.add("tabs-link-selected"); // Call the select method on the item associated with this link - + this.tabItem.select(); + console.log("chosen"); } } class TabItem { constructor(element) { // Assign this.element to the passed in element - // this.element; + this.element = element; } select() { // Select all ".tabs-item" elements from the DOM - // const items; - + const items = document.querySelectorAll(".tabs-item"); // Remove the class "tabs-item-selected" from each element - + Array.from(items).forEach(element => { + element.classList.remove("tabs-item-selected"); + }); // Add a class named "tabs-item-selected" to this element - //this.element; + this.element.classList.add("tabs-item-selected"); } } @@ -58,5 +62,9 @@ class TabItem { - In your .forEach() method's callback function, return a new instance of TabLink and pass in each link as a parameter */ - -links = document.querySelectorAll(); \ No newline at end of file +// nodelist +const links = document.querySelectorAll(".tabs-link"); +// iterate over nodelist, create new object +links.forEach(function(link) { + return new TabLink(link); +});