This is a variation of an earlier project:
In the current project, only one image is loaded, and CSS colour filters are applied to change the t-shirt's colour, corresponding to the checked 'Colour' radio button on the homepage form.
In the earlier project, multiple t-shirt images were loaded, corresponding to the checked 'Colour' radio button on the homepage form.
The main idea of this project is the use of URLSearchParams
to send information to another page to create a unique URL that can be saved and referenced later (or sent to a friend, etc.).
This project demonstrates how to collect and pass data between pages using URL parameters, focusing on client-side JavaScript techniques. The application is built with vanilla ES6 JavaScript.
- Order Form: The application allows users to select t-shirt quantity, size, and colour through a form.
- URL Construction: Upon form submission, the selected values are collected and appended as URL parameters to navigate to the checkout page. This allows for easy sharing or bookmarking of specific orders.
The application includes a dark mode and light mode toggle:
- The current theme state is stored in local storage and applied automatically on page reload.
- Accessible buttons with appropriate ARIA attributes are used to improve usability.
-
Built with vanilla ES6 JavaScript, focusing on modern syntax and browser APIs.
-
The project does not use any JavaScript frameworks like React or Angular, keeping dependencies minimal.
-
The order workflow and theme management have been split into separate modules, improving code modularity:
order-tshirt.js
: Manages the collection of order data from the form and appends it to the URL as parameters.switch-tshirt-colour.js
: Dynamically changes the t-shirt image colour filter according to which radio button is checked in the order form.checkout-tshirt.js
: Handles the retrieval of URL parameters (order details) on the checkout page and processes or displays them accordingly for the user.setMultipleAttributes.js
: This helper function is used in both theswitch-t-shirt-colour.js
andcheckout-t-shirt.js
modules to streamline the process of setting multiple attributes on HTML elements. It accepts an element and an object containing the attributes to set, and it dynamically applies each attribute to the target element.theme.js
: Handles theme toggling (light/dark mode) and local storage management.
- The
picture
element is used to displaywebp
andpng
versions of the t-shirt image:webp
version: These images offer smaller file sizes and are displayed on supported devices for better performance.png
version: Used as a fallback for browsers that do not supportwebp
.
The hue-rotate()
and drop-shadow()
filters are applied to the image.
The CSS filter
property is applied as follows:
filter: hue-rotate([n]deg) drop-shadow(
0.25rem 0.5625rem 0.25rem rgba(0, 0, 0, 0.5)
);
Where [n]
is the rotation angle of the hue-rotate
filter in degrees.
The angles used are:
45°
: Olive90°
: Green180°
: Blue270°
: Violet315°
: Red360°
: Brick
The angle is applied dynamically, using JavaScript (see switch-tshirt-colour.js
).
It's important to note that downloading or dragging the filtered image from the webpage to your desktop will only save the original, unfiltered version of the image. This is because the CSS filter
property only applies visual effects in the browser and does not alter the actual image file. To preserve the filtered appearance, you would need to use a screenshot tool or apply the desired filter in an image editing application.
- Local Storage:
- Saves the current theme preference (
dark mode
orlight mode
).
- Saves the current theme preference (
The site is fully navigable using tab keys and up/down arrows.
The application has been tested on the following platforms and browsers:
- Operating System: Windows 10
- Browsers:
- Google Chrome
- Mozilla Firefox
- Microsoft Edge
The layout and functionality have been verified in both browser and device simulation views to ensure responsiveness and usability.
- Clone or download the repository to your local machine.
- Open the project folder and start a simple HTTP server (e.g., using
Live Server
in VS Code or Python'shttp.server
module). - Open the project in a modern browser (e.g., Chrome, Firefox, or Edge).
- To view the order workflow in action, fill out the order form and navigate to the checkout page to see the data passed via the URL.
This project demonstrates the fundamentals of working with URL parameters to pass data between pages and how to implement a dynamic order form workflow using vanilla JavaScript.