This is a step-by-step guide to completing the Dynamic UI with jQuery part of the Dynamic Project. It also covers Setup
[0] Setup
- Create GitHub Repo from Template
- Go to the Github Template
- Click the green Use this Template button.
- Go through the steps to finish creating your version of the repository.
- Clone Repo to Your Local Computer
- In the GitHub Repo: Click the green Code button.
- Copy the link
- Open VS Code
- Open a New Window
- Click the Clone Git Repository link
- paste in the link
- Click Open to open the cloned Repository
- Install and test node
- Open Terminal
- Type: npm install
- it should run through installing and make node-modules folder
- Type: npm start
- The site should build and you should get a link to see it in the browser
- Use the link from the terminal to open it in a browser
- Remember the link is something like: http://localhost:8080/
[1] Get JavaScript Ready
- Add jQuery
- Go to jQuery CDN: https://code.jquery.com/
- Click on the minified link under jQuery 3.x
- Copy the script tag by clicking the blue file icon
- Paste the copied code into the base.njk file just before the closing </body> tag (around line 38).
- Add a link to main.js
- Add a new blank line right after the code you just pasted
- add a script element with the src attribute of: src=”/js/main.js”
[2] Get Accordion Working
- Go to my Accordion example Codepen
- Copy the code in the JavaScript part
- Paste this into the main.js file in the js folder
- Test the Accordion
- If you stopped the server type npm start in the terminal again and open the browser
- click the accordion to see if its working
[3] Get the Filter Buttons Working
- Go to my Filter Buttons Example Codepen
- Copy the JavaScript inside of the $(document).ready(). Lines 3–33. You already have a document ready from the accordion.
- Paste this into main.js making sure it is doesn’t go inside of the Accordion code but is inside of the $(document).ready() in main.js.
- There should be two lines that look the same at the end:
- one is to end the filer code and one to end the document.ready
- edit the code to change the data- attribute
- There are two places in the code that refer to data-type. In our buttons we use data-borough.
- You can either manually or use find and replace to change the data-type to data-borough.
- Add a data attribute to the cards
- open image-card.njk in the includes folder
- in the opening div element, add a data-borough attribute and make the value {{img.borough}} to read in the borough from the yaml file. It should look like this:
- Test out the buttons.
Everything should be working now.
1 comment