-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.js
80 lines (68 loc) · 3.18 KB
/
select.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Get the labels by class
const touchLabel = document.querySelector('.vertical-label-touch');
const dontTouchLabel = document.querySelector('.vertical-label-dont-touch');
const objectLabel = document.querySelector('.vertical-label-object');
const subjectLabel = document.querySelector('.vertical-label-subject');
const liveLabel = document.querySelector('.vertical-label-live');
const stagedLabel = document.querySelector('.vertical-label-staged');
// Variable to keep track of the currently active label
let activeLabel = null;
// Function to reset the filters for all images
function resetFilters() {
const images = document.querySelectorAll('.image-container img');
images.forEach(img => {
img.style.filter = 'none'; // Reset filter for each image
console.log(`Filter reset for image: ${img.src}`);
});
// Reset all button colors by removing the active class
const allLabels = [touchLabel, dontTouchLabel, objectLabel, subjectLabel, liveLabel, stagedLabel];
allLabels.forEach(label => label.classList.remove('active'));
}
// Function to change the color of images with a specific class
function changeImageColorByClass(className, filterStyle) {
console.log(`Applying filter to images with class: ${className}`);
const targetedImages = document.querySelectorAll(`.image-container.${className}`);
targetedImages.forEach(image => {
const img = image.querySelector('img');
if (img) {
img.style.filter = filterStyle;
console.log(`Applied filter to image: ${img.src}`);
} else {
console.warn(`No <img> found in container with class: ${className}`);
}
});
}
// Function to toggle the filters and button styles based on the label
function toggleLabel(label, className, filterStyle) {
console.log(`Toggling label: ${label.className}`);
if (activeLabel === label) {
// If the same label is clicked, reset everything
resetFilters();
activeLabel = null;
} else {
// Switch to the new label
resetFilters(); // Reset all filters first
changeImageColorByClass(className, filterStyle); // Apply filter to relevant images
label.classList.add('active'); // Highlight the active label
activeLabel = label; // Set the active label
}
}
// Add event listeners for the labels
dontTouchLabel.addEventListener('click', function() {
toggleLabel(dontTouchLabel, 'dont-touch', 'sepia(3) saturate(1) hue-rotate(280deg)'); // Red
});
touchLabel.addEventListener('click', function() {
toggleLabel(touchLabel, 'touch', 'sepia(3) saturate(1) hue-rotate(190deg)'); // Blue
});
objectLabel.addEventListener('click', function() {
toggleLabel(objectLabel, 'object', 'sepia(3) saturate(1) hue-rotate(30deg)'); // Yellow
});
subjectLabel.addEventListener('click', function() {
toggleLabel(subjectLabel, 'subject', 'sepia(3) saturate(1) hue-rotate(300deg)'); // Purple
});
liveLabel.addEventListener('click', function() {
toggleLabel(liveLabel, 'live', 'sepia(3) saturate(1) hue-rotate(360deg)'); // Orange
});
stagedLabel.addEventListener('click', function() {
toggleLabel(stagedLabel, 'staged', 'sepia(3) saturate(1) hue-rotate(240deg)'); // Green
});