-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaderOverlays.js
151 lines (130 loc) · 5.13 KB
/
headerOverlays.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
(function() {
var playlistBtn = document.getElementById('playlistBtn');
var mobileHeaderBtn = document.getElementById('mobileHeaderBtn');
var desktopHeaderBtn = document.getElementById('desktopHeaderBtn');
var imageContainer = document.getElementById('imageContainer');
var currentOverlayType = null;
var overlay = null;
// Variables to store overlay window dimensions
window.overlayWindowWidth = 0;
window.overlayWindowHeight = 0;
function createOverlay(type) {
// Remove existing overlay if any
if (overlay) {
imageContainer.removeChild(overlay);
overlay = null;
}
// Create overlay div
overlay = document.createElement('div');
overlay.className = 'overlay';
// Define fixed window sizes based on type and screen size
var windowWidth, windowHeight, aspectRatio;
if (type === 'playlist') {
aspectRatio = 1; // 1:1
if (window.innerWidth < 500) {
windowWidth = 350;
} else {
windowWidth = 700;
}
windowHeight = windowWidth / aspectRatio;
} else if (type === 'mobileHeader') {
aspectRatio = 750 / 760; // 750:760
if (window.innerWidth < 500) {
windowWidth = 300;
} else {
windowWidth = 600;
}
windowHeight = windowWidth / aspectRatio;
} else if (type === 'desktopHeader') {
aspectRatio = 2660 / 1496; // 2660:1496
windowWidth = Math.min(946, window.innerWidth * 0.8);
windowHeight = windowWidth / aspectRatio;
}
// Store overlay window dimensions for size warning calculations
window.overlayWindowWidth = windowWidth;
window.overlayWindowHeight = windowHeight;
// Calculate wall dimensions
var leftWallWidth = (window.innerWidth - windowWidth) / 2;
var rightWallWidth = leftWallWidth;
var topWallHeight = (window.innerHeight - windowHeight) / 3; // More wall at the bottom
var bottomWallHeight = window.innerHeight - windowHeight - topWallHeight;
// Create the four walls
var topWall = document.createElement('div');
topWall.className = 'wall';
topWall.style.top = '0';
topWall.style.left = '0';
topWall.style.width = '100%';
topWall.style.height = topWallHeight + 'px';
var bottomWall = document.createElement('div');
bottomWall.className = 'wall';
bottomWall.style.bottom = '0';
bottomWall.style.left = '0';
bottomWall.style.width = '100%';
bottomWall.style.height = bottomWallHeight + 'px';
var leftWall = document.createElement('div');
leftWall.className = 'wall';
leftWall.style.top = topWallHeight + 'px';
leftWall.style.left = '0';
leftWall.style.width = leftWallWidth + 'px';
leftWall.style.height = windowHeight + 'px';
var rightWall = document.createElement('div');
rightWall.className = 'wall';
rightWall.style.top = topWallHeight + 'px';
rightWall.style.right = '0';
rightWall.style.width = rightWallWidth + 'px';
rightWall.style.height = windowHeight + 'px';
// Append walls to overlay
overlay.appendChild(topWall);
overlay.appendChild(bottomWall);
overlay.appendChild(leftWall);
overlay.appendChild(rightWall);
// Append overlay to imageContainer
imageContainer.appendChild(overlay);
// Update size warning
if (typeof updateInfo === 'function') {
updateInfo();
}
}
function toggleOverlay(type, button) {
if (currentOverlayType === type) {
// If the same overlay is active, remove it
if (overlay) {
imageContainer.removeChild(overlay);
overlay = null;
currentOverlayType = null;
// Reset button styles
button.classList.remove('active');
window.overlayWindowWidth = 0;
window.overlayWindowHeight = 0;
if (typeof updateInfo === 'function') {
updateInfo();
}
}
} else {
currentOverlayType = type;
// Reset all buttons
var buttons = document.querySelectorAll('.btn');
buttons.forEach(function(btn) {
btn.classList.remove('active');
});
// Activate current button
button.classList.add('active');
createOverlay(type);
}
}
playlistBtn.addEventListener('click', function() {
toggleOverlay('playlist', this);
});
mobileHeaderBtn.addEventListener('click', function() {
toggleOverlay('mobileHeader', this);
});
desktopHeaderBtn.addEventListener('click', function() {
toggleOverlay('desktopHeader', this);
});
// Adjust overlay on window resize
window.addEventListener('resize', function() {
if (currentOverlayType) {
createOverlay(currentOverlayType);
}
});
})();