-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
286 lines (232 loc) · 8.17 KB
/
main.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//OPEN CLOSE & TOGGLE BROWSER CONTAINER/TABS
const browserApp = document.querySelector('.browser-container');
const browserHeader = document.querySelector('.browser-header');
const browserTab = document.getElementById('browser');
const paintApp = document.querySelector('.paint-container');
const paintHeader = document.querySelector('.paint-header');
const paintTab = document.getElementById('paint');
const messengerApp = document.querySelector('.msngr-container');
const messengerHeader = document.querySelector('.msngr-header');
const messengerTab = document.getElementById('messenger');
function openBrowser() {
browserApp.classList.remove('hidden');
browserApp.style.zIndex = 1;
paintApp.style.zIndex = 0;
messengerApp.style.zIndex = 0;
}
function showBrowserTab() {
browserTab.classList.remove('hidden');
browserTab.classList.add('show');
}
function closeBrowser() {
browserApp.classList.add('hidden');
closeBrowserTab();
}
function closeBrowserTab() {
if (browserTab.classList.contains('show')) {
browserTab.classList.remove('show');
browserTab.classList.add('hidden');
}
}
function toggleBrowser() {
if (browserTab.classList.contains('show')) {
browserApp.classList.toggle('hidden');
if(paintApp.style.zIndex !== 0 || messengerApp.style.zIndex !== 0) {
paintApp.style.zIndex = 0;
messengerApp.style.zIndex = 0;
browserApp.style.zIndex = 1;
}
}
}
// OPEN CLOSE & TOGGLE PAINT APP CONTAINER/TAB
function openPaint() {
paintApp.classList.remove('hidden');
paintApp.style.zIndex = 1;
browserApp.style.zIndex = 0;
messengerApp.style.zIndex = 0;
}
function showPaintTab() {
paintTab.classList.remove('hidden');
paintTab.classList.add('show');
}
function closePaint() {
paintApp.classList.add('hidden');
closePaintTab();
}
function closePaintTab() {
if (paintTab.classList.contains('show')) {
paintTab.classList.remove('show');
paintTab.classList.add('hidden');
}
}
function togglePaint() {
if (paintTab.classList.contains('show')) {
paintApp.classList.toggle('hidden');
if(browserApp.style.zIndex !== 0 || messengerApp.style.zIndex !== 0) {
browserApp.style.zIndex = 0;
messengerApp.style.zIndex = 0;
paintApp.style.zIndex = 1;
}
}
}
// OPEN CLOSE & TOGGLE MESSENGER APP CONTAINER/TAB
function openMessenger() {
messengerApp.classList.remove('hidden');
messengerApp.style.zIndex = 1;
browserApp.style.zIndex = 0;
paintApp.style.zIndex = 0;
}
function showMsgTab() {
messengerTab.classList.remove('hidden');
messengerTab.classList.add('show');
}
function closeMessenger() {
messengerApp.classList.add('hidden');
closeMsgTab();
}
function closeMsgTab() {
if (messengerTab.classList.contains('show')) {
messengerTab.classList.remove('show');
messengerTab.classList.add('hidden');
}
}
function toggleMessenger() {
if (messengerTab.classList.contains('show')) {
messengerApp.classList.toggle('hidden');
if(browserApp.style.zIndex !== 0 || paintApp.style.zIndex !== 0) {
messengerApp.style.zIndex = 1;
browserApp.style.zIndex = 0;
paintApp.style.zIndex = 0;
}
}
}
// DRAG FUNCTION FOR BROWSER
// Set initial values for position tracking
let webDragging = false;
let dragStartX;
let dragStartY;
let initialX;
let initialY;
// When the user clicks or taps on the header, start dragging
browserHeader.addEventListener('mousedown', startBrowserDragging);
browserHeader.addEventListener('touchstart', startBrowserDragging);
function startBrowserDragging(e) {
// Use e.touches if it's a touch event
const touch = e.touches ? e.touches[0] : e;
webDragging = true;
browserApp.style.zIndex = 1;
paintApp.style.zIndex = 0;
messengerApp.style.zIndex = 0;
// Record the starting position
dragStartX = touch.clientX;
dragStartY = touch.clientY;
// Record the initial position of the appContainer
const computedStyle = window.getComputedStyle(browserApp);
initialX = parseInt(computedStyle.getPropertyValue('left'));
initialY = parseInt(computedStyle.getPropertyValue('top'));
// Prevent text selection during drag
e.preventDefault();
}
// When the user releases the mouse button or lifts their finger, stop dragging
document.addEventListener('mouseup', stopBrowserDragging);
document.addEventListener('touchend', stopBrowserDragging);
function stopBrowserDragging(e) {
webDragging = false;
}
//DRAG FUNCTION FOR PAINT | USES SAME INITIAL POS TRACKING VARIABLES
let paintDragging = false;
// When the user clicks or taps on the header, start dragging
paintHeader.addEventListener('mousedown', startPaintDragging);
paintHeader.addEventListener('touchstart', startPaintDragging);
function startPaintDragging(e) {
// Use e.touches if it's a touch event
const touch = e.touches ? e.touches[0] : e;
paintDragging = true;
paintApp.style.zIndex = 1;
browserApp.style.zIndex = 0;
messengerApp.style.zIndex = 0;
// Record the starting position
dragStartX = touch.clientX;
dragStartY = touch.clientY;
// Record the initial position of the appContainer
const computedStyle = window.getComputedStyle(paintApp);
initialX = parseInt(computedStyle.getPropertyValue('left'));
initialY = parseInt(computedStyle.getPropertyValue('top'));
// Prevent text selection during drag
e.preventDefault();
}
// When the user releases the mouse button or lifts their finger, stop dragging
document.addEventListener('mouseup', stopPaintDragging);
document.addEventListener('touchend', stopPaintDragging);
function stopPaintDragging(e) {
paintDragging = false;
}
//DRAG FUNCTION FOR MESSENGER | USES SAME INITIAL POS TRACKING VARIABLES
let messengerDragging = false;
// When the user clicks or taps on the header, start dragging
messengerHeader.addEventListener('mousedown', startMsgDragging);
messengerHeader.addEventListener('touchstart', startMsgDragging);
function startMsgDragging(e) {
// Use e.touches if it's a touch event
const touch = e.touches ? e.touches[0] : e;
messengerDragging = true;
messengerApp.style.zIndex = 1;
browserApp.style.zIndex = 0;
paintApp.style.zIndex = 0;
// Record the starting position
dragStartX = touch.clientX;
dragStartY = touch.clientY;
// Record the initial position of the appContainer
const computedStyle = window.getComputedStyle(messengerApp);
initialX = parseInt(computedStyle.getPropertyValue('left'));
initialY = parseInt(computedStyle.getPropertyValue('top'));
// Prevent text selection during drag
e.preventDefault();
}
// When the user releases the mouse button or lifts their finger, stop dragging
document.addEventListener('mouseup', stopMsgDragging);
document.addEventListener('touchend', stopMsgDragging);
function stopMsgDragging(e) {
messengerDragging = false;
}
// When the user moves their mouse or finger, update the position of the appContainer if we're currently dragging
document.addEventListener('mousemove', drag);
document.addEventListener('touchmove', drag);
function drag(e) {
if (webDragging) {
// Use e.touches if it's a touch event
const touch = e.touches ? e.touches[0] : e;
// Calculate the new position
const dragX = touch.clientX - dragStartX;
const dragY = touch.clientY - dragStartY;
const newX = initialX + dragX;
const newY = initialY + dragY;
// Set the new position of the appContainer
browserApp.style.left = newX + 'px';
browserApp.style.top = newY + 'px';
}
if (paintDragging) {
// Use e.touches if it's a touch event
const touch = e.touches ? e.touches[0] : e;
// Calculate the new position
const dragX = touch.clientX - dragStartX;
const dragY = touch.clientY - dragStartY;
const newX = initialX + dragX;
const newY = initialY + dragY;
// Set the new position of the appContainer
paintApp.style.left = newX + 'px';
paintApp.style.top = newY + 'px';
}
if (messengerDragging) {
// Use e.touches if it's a touch event
const touch = e.touches ? e.touches[0] : e;
// Calculate the new position
const dragX = touch.clientX - dragStartX;
const dragY = touch.clientY - dragStartY;
const newX = initialX + dragX;
const newY = initialY + dragY;
// Set the new position of the appContainer
messengerApp.style.left = newX + 'px';
messengerApp.style.top = newY + 'px';
}
}