-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex3.html
More file actions
943 lines (800 loc) · 33 KB
/
index3.html
File metadata and controls
943 lines (800 loc) · 33 KB
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Desktop Dashboard with Floating Windows</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100%;
overflow: hidden;
font-family: Arial, sans-serif;
}
.dashboard-container {
position: relative;
width: 100%;
height: 100vh;
background-color: #2a2a2a; /* Dark grey background */
background-image:
linear-gradient(rgba(0, 128, 128, 0.5) 1px, transparent 1px), /* Horizontal teal lines */
linear-gradient(90deg, rgba(0, 128, 128, 0.5) 1px, transparent 1px); /* Vertical teal lines */
background-size: 20px 20px;
overflow: hidden;
}
.window {
position: absolute;
background-color: white;
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
display: flex;
flex-direction: column;
overflow: hidden;
border-radius: 5px;
min-width: 250px;
min-height: 200px;
transition: box-shadow 0.2s;
}
.window.active {
box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}
.window-header {
padding: 10px;
background-color: #2c3e50;
color: white;
display: flex;
justify-content: space-between;
align-items: center;
cursor: move;
user-select: none;
}
.window-content {
flex: 1;
overflow: hidden;
position: relative;
}
.window-content iframe {
width: 100%;
height: 100%;
border: none;
}
.window-controls {
display: flex;
gap: 8px;
}
.window-button {
width: 12px;
height: 12px;
border-radius: 50%;
cursor: pointer;
}
.minimize-button {
background-color: #f1c40f;
}
.maximize-button {
background-color: #27ae60;
}
.close-button {
background-color: #e74c3c;
}
.resize-handle {
position: absolute;
background-color: transparent;
z-index: 10;
}
.resize-handle.n {
top: 0;
left: 0;
right: 0;
height: 5px;
cursor: ns-resize;
}
.resize-handle.s {
bottom: 0;
left: 0;
right: 0;
height: 5px;
cursor: ns-resize;
}
.resize-handle.e {
top: 0;
right: 0;
bottom: 0;
width: 5px;
cursor: ew-resize;
}
.resize-handle.w {
top: 0;
left: 0;
bottom: 0;
width: 5px;
cursor: ew-resize;
}
.resize-handle.ne {
top: 0;
right: 0;
width: 10px;
height: 10px;
cursor: nesw-resize;
}
.resize-handle.nw {
top: 0;
left: 0;
width: 10px;
height: 10px;
cursor: nwse-resize;
}
.resize-handle.se {
bottom: 0;
right: 0;
width: 10px;
height: 10px;
cursor: nwse-resize;
}
.resize-handle.sw {
bottom: 0;
left: 0;
width: 10px;
height: 10px;
cursor: nesw-resize;
}
.controls {
position: fixed;
bottom: 20px;
right: 20px;
padding: 15px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
z-index: 1000;
display: flex;
gap: 10px;
align-items: center;
transition: transform 0.3s;
}
.controls.collapsed {
transform: translateY(calc(100% - 40px));
}
.controls-toggle {
position: absolute;
top: -15px;
left: 50%;
transform: translateX(-50%);
width: 30px;
height: 15px;
background-color: white;
border-radius: 5px 5px 0 0;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
}
.controls input, .controls select, .controls button {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
.controls button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
transition: background-color 0.2s;
}
.controls button:hover {
background-color: #3e8e41;
}
.add-window-modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 5px 20px rgba(0,0,0,0.2);
z-index: 1001;
width: 400px;
max-width: 90%;
display: none;
}
.add-window-modal.visible {
display: block;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.modal-form {
display: flex;
flex-direction: column;
gap: 15px;
}
.dragging {
opacity: 0.8;
pointer-events: none;
}
.resizing {
opacity: 0.8;
}
</style>
</head>
<body>
<div class="dashboard-container" id="dashboard">
<!-- Windows will be added here dynamically -->
</div>
<!-- Controls -->
<div class="controls" id="controls">
<div class="controls-toggle" id="controls-toggle">▲</div>
<button id="add-window-btn">Add Window</button>
<select id="template-selector">
<option value="">Quick Add</option>
<option value="https://www.google.com">Google</option>
<option value="widgets/weather/weather.html">Weather</option>
<option value="widgets/clock/clock.html">Clock</option>
<option value="widgets/calendar-events/calendar-events.html">Current Events</option>
<option value="widgets/mbta-bus/mbta-bus.html">MBTA Bus Tracker</option>
<option value="widgets/countdown/countdown.html">Reality Hack Countdown</option>
<option value="https://www.bbc.com">News</option>
<option value="https://calendar.google.com/calendar/embed">Calendar</option>
</select>
</div>
<!-- Add Window Modal -->
<div class="add-window-modal" id="add-window-modal">
<div class="modal-header">
<h3>Add New Window</h3>
<span class="close-button" id="modal-close">✕</span>
</div>
<div class="modal-form">
<input type="text" id="window-url" placeholder="Enter website URL (e.g., https://example.com)" value="https://example.com">
<input type="text" id="window-title" placeholder="Title (optional)">
<button id="add-window-confirm">Add Window</button>
</div>
</div>
<script>
// Dashboard state
const state = {
windows: [],
nextWindowId: 1,
zIndex: 1,
draggingWindow: null,
resizingWindow: null,
resizeDirection: '',
dragOffset: { x: 0, y: 0 },
resizeStartDimensions: null
};
// Save dashboard state to localStorage
function saveDashboardState() {
const windowsState = state.windows.map(window => ({
id: window.id,
url: window.url,
title: window.title,
position: window.position,
isMinimized: window.isMinimized,
isMaximized: window.isMaximized,
previousPosition: window.previousPosition,
zIndex: window.zIndex
}));
localStorage.setItem('dashboardState_index3', JSON.stringify({
windows: windowsState,
nextWindowId: state.nextWindowId,
zIndex: state.zIndex
}));
}
// Load dashboard state from localStorage
function loadDashboardState() {
const savedState = localStorage.getItem('dashboardState_index3');
if (!savedState) return false;
try {
const parsedState = JSON.parse(savedState);
state.nextWindowId = parsedState.nextWindowId || 1;
state.zIndex = parsedState.zIndex || 1;
// Clear existing windows
state.windows = [];
dashboardEl.innerHTML = '';
// Recreate windows from saved state
if (parsedState.windows && parsedState.windows.length) {
parsedState.windows.forEach(windowState => {
addWindow(
windowState.url,
windowState.title,
windowState.position,
windowState.id,
windowState.zIndex,
windowState.isMinimized,
windowState.isMaximized,
windowState.previousPosition
);
});
}
return true;
} catch (e) {
console.error('Error loading dashboard state:', e);
return false;
}
}
// DOM references
const dashboardEl = document.getElementById('dashboard');
const controlsEl = document.getElementById('controls');
const controlsToggleEl = document.getElementById('controls-toggle');
const addWindowBtnEl = document.getElementById('add-window-btn');
const templateSelectorEl = document.getElementById('template-selector');
const addWindowModalEl = document.getElementById('add-window-modal');
const modalCloseEl = document.getElementById('modal-close');
const windowUrlEl = document.getElementById('window-url');
const windowTitleEl = document.getElementById('window-title');
const addWindowConfirmEl = document.getElementById('add-window-confirm');
// Add a new window
function addWindow(url, title, position = null, id = null, zIndex = null, isMinimized = false, isMaximized = false, previousPosition = null) {
// Generate default position if not provided
if (!position) {
position = {
x: 50 + (state.windows.length * 30) % 200,
y: 50 + (state.windows.length * 30) % 150,
width: 400,
height: 300
};
}
const windowId = id || `window-${state.nextWindowId++}`;
const windowZIndex = zIndex || ++state.zIndex;
// Create window element
const windowEl = document.createElement('div');
windowEl.className = 'window';
windowEl.id = windowId;
windowEl.style.left = `${position.x}px`;
windowEl.style.top = `${position.y}px`;
windowEl.style.width = `${position.width}px`;
windowEl.style.height = `${position.height}px`;
windowEl.style.zIndex = windowZIndex;
// Create window content
windowEl.innerHTML = `
<div class="window-header">
<div class="window-controls">
<div class="window-button close-button" title="Close"></div>
<div class="window-button maximize-button" title="Maximize"></div>
<div class="window-button minimize-button" title="Minimize"></div>
</div>
<span>${title || `Window ${windowId.split('-')[1]}`}</span>
</div>
<div class="window-content">
<iframe src="${url}" title="${title}" allowfullscreen></iframe>
</div>
<div class="resize-handle n"></div>
<div class="resize-handle s"></div>
<div class="resize-handle e"></div>
<div class="resize-handle w"></div>
<div class="resize-handle ne"></div>
<div class="resize-handle nw"></div>
<div class="resize-handle se"></div>
<div class="resize-handle sw"></div>
`;
// Add to DOM
dashboardEl.appendChild(windowEl);
// Create window object
const window = {
id: windowId,
url,
title: title || `Window ${windowId.split('-')[1]}`,
element: windowEl,
position: { ...position },
zIndex: windowZIndex,
isMinimized: isMinimized,
isMaximized: isMaximized,
previousPosition: previousPosition
};
// Add to windows array
state.windows.push(window);
// Apply minimized/maximized state if needed
if (isMinimized) {
windowEl.style.display = 'none';
} else if (isMaximized) {
windowEl.style.left = '0';
windowEl.style.top = '0';
windowEl.style.width = '100%';
windowEl.style.height = '100%';
}
// Setup window events
setupWindowEvents(window);
// Activate new window
activateWindow(window);
// Save dashboard state
saveDashboardState();
return window;
}
// Setup window events
function setupWindowEvents(window) {
const windowEl = window.element;
const headerEl = windowEl.querySelector('.window-header');
const closeButtonEl = windowEl.querySelector('.close-button');
const maximizeButtonEl = windowEl.querySelector('.maximize-button');
const minimizeButtonEl = windowEl.querySelector('.minimize-button');
const resizeHandles = windowEl.querySelectorAll('.resize-handle');
// Make window active when clicked anywhere
windowEl.addEventListener('mousedown', () => {
activateWindow(window);
});
// Close button handler
closeButtonEl.addEventListener('click', (e) => {
e.stopPropagation();
removeWindow(window.id);
});
// Maximize button handler
maximizeButtonEl.addEventListener('click', (e) => {
e.stopPropagation();
toggleMaximize(window);
});
// Minimize button handler
minimizeButtonEl.addEventListener('click', (e) => {
e.stopPropagation();
toggleMinimize(window);
});
// Drag handler
headerEl.addEventListener('mousedown', (e) => {
if (window.isMaximized) return;
e.preventDefault();
const rect = windowEl.getBoundingClientRect();
state.draggingWindow = window;
state.dragOffset = {
x: e.clientX - rect.left,
y: e.clientY - rect.top
};
windowEl.classList.add('dragging');
// Add document listeners
document.addEventListener('mousemove', handleDragMove);
document.addEventListener('mouseup', handleDragEnd);
});
// Resize handlers
resizeHandles.forEach(handle => {
handle.addEventListener('mousedown', (e) => {
if (window.isMaximized) return;
e.preventDefault();
e.stopPropagation();
const rect = windowEl.getBoundingClientRect();
state.resizingWindow = window;
state.resizeDirection = handle.classList[1]; // n, s, e, w, ne, nw, se, sw
state.resizeStartDimensions = {
x: rect.left,
y: rect.top,
width: rect.width,
height: rect.height,
mouseX: e.clientX,
mouseY: e.clientY
};
windowEl.classList.add('resizing');
// Add document listeners
document.addEventListener('mousemove', handleResizeMove);
document.addEventListener('mouseup', handleResizeEnd);
});
});
}
// Handle drag move
function handleDragMove(e) {
if (!state.draggingWindow) return;
const windowEl = state.draggingWindow.element;
const newLeft = e.clientX - state.dragOffset.x;
const newTop = e.clientY - state.dragOffset.y;
// Update element position
windowEl.style.left = `${newLeft}px`;
windowEl.style.top = `${newTop}px`;
// Update window object
state.draggingWindow.position.x = newLeft;
state.draggingWindow.position.y = newTop;
}
// Handle drag end
function handleDragEnd() {
if (!state.draggingWindow) return;
const windowEl = state.draggingWindow.element;
windowEl.classList.remove('dragging');
// Clean up
state.draggingWindow = null;
state.dragOffset = { x: 0, y: 0 };
// Remove document listeners
document.removeEventListener('mousemove', handleDragMove);
document.removeEventListener('mouseup', handleDragEnd);
// Save dashboard state
saveDashboardState();
}
// Handle resize move
function handleResizeMove(e) {
if (!state.resizingWindow) return;
const windowEl = state.resizingWindow.element;
const minWidth = 250;
const minHeight = 200;
// Calculate mouse movement delta
const deltaX = e.clientX - state.resizeStartDimensions.mouseX;
const deltaY = e.clientY - state.resizeStartDimensions.mouseY;
// Initial dimensions
let newLeft = state.resizeStartDimensions.x;
let newTop = state.resizeStartDimensions.y;
let newWidth = state.resizeStartDimensions.width;
let newHeight = state.resizeStartDimensions.height;
// Apply changes based on resize direction
if (state.resizeDirection.includes('n')) {
newTop = state.resizeStartDimensions.y + deltaY;
newHeight = Math.max(minHeight, state.resizeStartDimensions.height - deltaY);
if (newHeight === minHeight && deltaY > 0) {
newTop = state.resizeStartDimensions.y + state.resizeStartDimensions.height - minHeight;
}
}
if (state.resizeDirection.includes('s')) {
newHeight = Math.max(minHeight, state.resizeStartDimensions.height + deltaY);
}
if (state.resizeDirection.includes('w')) {
newLeft = state.resizeStartDimensions.x + deltaX;
newWidth = Math.max(minWidth, state.resizeStartDimensions.width - deltaX);
if (newWidth === minWidth && deltaX > 0) {
newLeft = state.resizeStartDimensions.x + state.resizeStartDimensions.width - minWidth;
}
}
if (state.resizeDirection.includes('e')) {
newWidth = Math.max(minWidth, state.resizeStartDimensions.width + deltaX);
}
// Update element dimensions
windowEl.style.left = `${newLeft}px`;
windowEl.style.top = `${newTop}px`;
windowEl.style.width = `${newWidth}px`;
windowEl.style.height = `${newHeight}px`;
// Update window object
state.resizingWindow.position = {
x: newLeft,
y: newTop,
width: newWidth,
height: newHeight
};
}
// Handle resize end
function handleResizeEnd() {
if (!state.resizingWindow) return;
const windowEl = state.resizingWindow.element;
windowEl.classList.remove('resizing');
// Clean up
state.resizingWindow = null;
state.resizeDirection = '';
state.resizeStartDimensions = null;
// Remove document listeners
document.removeEventListener('mousemove', handleResizeMove);
document.removeEventListener('mouseup', handleResizeEnd);
// Save dashboard state
saveDashboardState();
}
// Activate (bring to front) window
function activateWindow(window) {
// Update z-index for all windows
state.windows.forEach(w => {
if (w.id === window.id) {
w.zIndex = ++state.zIndex;
w.element.style.zIndex = w.zIndex;
w.element.classList.add('active');
} else {
w.element.classList.remove('active');
}
});
// Save dashboard state
saveDashboardState();
}
// Toggle maximize window
function toggleMaximize(window) {
const windowEl = window.element;
if (!window.isMaximized) {
// Save current position
window.previousPosition = { ...window.position };
// Maximize
windowEl.style.left = '0';
windowEl.style.top = '0';
windowEl.style.width = '100%';
windowEl.style.height = '100%';
window.position = {
x: 0,
y: 0,
width: window.innerWidth,
height: window.innerHeight
};
window.isMaximized = true;
} else {
// Restore position
if (window.previousPosition) {
windowEl.style.left = `${window.previousPosition.x}px`;
windowEl.style.top = `${window.previousPosition.y}px`;
windowEl.style.width = `${window.previousPosition.width}px`;
windowEl.style.height = `${window.previousPosition.height}px`;
window.position = { ...window.previousPosition };
window.previousPosition = null;
}
window.isMaximized = false;
}
// Save dashboard state
saveDashboardState();
}
// Toggle minimize window
function toggleMinimize(window) {
const windowEl = window.element;
if (!window.isMinimized) {
// Save current position if not already saved
if (!window.previousPosition) {
window.previousPosition = { ...window.position };
}
// Minimize (just hide for now)
windowEl.style.display = 'none';
window.isMinimized = true;
// In a real implementation, you might create a taskbar
// and add a button there to represent the minimized window
} else {
// Restore
windowEl.style.display = 'flex';
window.isMinimized = false;
// Bring to front
activateWindow(window);
}
// Save dashboard state
saveDashboardState();
}
// Remove window
function removeWindow(windowId) {
const windowIndex = state.windows.findIndex(w => w.id === windowId);
if (windowIndex !== -1) {
const window = state.windows[windowIndex];
// Remove from DOM
window.element.remove();
// Remove from windows array
state.windows.splice(windowIndex, 1);
// Save dashboard state
saveDashboardState();
}
}
// Controls toggle
controlsToggleEl.addEventListener('click', () => {
controlsEl.classList.toggle('collapsed');
controlsToggleEl.textContent = controlsEl.classList.contains('collapsed') ? '▼' : '▲';
});
// Add window button
addWindowBtnEl.addEventListener('click', () => {
showAddWindowModal();
});
// Template selector
templateSelectorEl.addEventListener('change', () => {
const selectedUrl = templateSelectorEl.value;
if (selectedUrl) {
// Use the option text as the title
const selectedTitle = templateSelectorEl.options[templateSelectorEl.selectedIndex].text;
addWindow(selectedUrl, selectedTitle);
templateSelectorEl.value = '';
}
});
// Modal close
modalCloseEl.addEventListener('click', () => {
hideAddWindowModal();
});
// Add window confirm
addWindowConfirmEl.addEventListener('click', () => {
const url = validateUrl(windowUrlEl.value);
if (url) {
const title = windowTitleEl.value || `Window ${state.nextWindowId}`;
addWindow(url, title);
hideAddWindowModal();
} else {
alert("Please enter a valid URL (including https:// or http://)");
}
});
// Show add window modal
function showAddWindowModal() {
addWindowModalEl.classList.add('visible');
}
// Hide add window modal
function hideAddWindowModal() {
addWindowModalEl.classList.remove('visible');
// Reset inputs
windowUrlEl.value = "https://example.com";
windowTitleEl.value = "";
}
// Validate URL
function validateUrl(url) {
try {
const newUrl = new URL(url);
return newUrl.toString();
} catch(e) {
return false;
}
}
// Handle keyboard events (Escape to cancel modals/dragging)
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
// Close modal if open
if (addWindowModalEl.classList.contains('visible')) {
hideAddWindowModal();
}
// Cancel dragging
if (state.draggingWindow) {
state.draggingWindow.element.classList.remove('dragging');
state.draggingWindow = null;
state.dragOffset = { x: 0, y: 0 };
document.removeEventListener('mousemove', handleDragMove);
document.removeEventListener('mouseup', handleDragEnd);
}
// Cancel resizing
if (state.resizingWindow) {
state.resizingWindow.element.classList.remove('resizing');
state.resizingWindow = null;
state.resizeDirection = '';
state.resizeStartDimensions = null;
document.removeEventListener('mousemove', handleResizeMove);
document.removeEventListener('mouseup', handleResizeEnd);
}
}
});
// Initialize dashboard with default windows
function initDashboard() {
// Try to load saved state first
if (!loadDashboardState()) {
// Add initial windows if no saved state
addWindow('https://www.google.com', 'Google', { x: 50, y: 50, width: 600, height: 400 });
addWindow('widgets/clock/clock.html', 'Clock', { x: 100, y: 100, width: 400, height: 300 });
addWindow('https://www.openweathermap.org/widgets', 'Weather', { x: 150, y: 150, width: 500, height: 350 });
addWindow('https://calendar.google.com/calendar/embed', 'Calendar', { x: 200, y: 200, width: 550, height: 450 });
}
// Collapse controls by default
controlsEl.classList.add('collapsed');
controlsToggleEl.textContent = '▼';
}
// Initialize on page load
window.addEventListener('load', initDashboard);
// Function to inject selective dark mode CSS into an iframe
function injectSelectiveDarkModeCSS(iframe) {
const darkCSS = `
html, body {
background-color: #1e1e1e !important;
color: #ffffff !important;
}
/* Apply background and text color only to elements that explicitly define defaults */
body, div, p, span, header, footer, section, article, aside, main {
background-color: transparent !important;
color: inherit !important;
}
/* Preserve original colors for elements explicitly styled by widget authors */
a, button, input, select, textarea, svg, img, canvas, .colored, [style*="color"] {
background-color: initial !important;
color: initial !important;
}
/* Optionally, ensure input fields and buttons are still readable */
input, select, textarea, button {
background-color: #333 !important;
color: #fff !important;
border-color: #555 !important;
}
`;
try {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
const style = iframeDoc.createElement('style');
style.textContent = darkCSS;
iframeDoc.head.appendChild(style);
} catch (e) {
console.warn('Could not inject CSS into iframe:', e);
}
}
// Observe newly added windows and inject CSS selectively
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.classList && node.classList.contains('window')) {
const iframe = node.querySelector('iframe');
iframe.onload = () => injectSelectiveDarkModeCSS(iframe);
}
});
});
});
// Observe dashboard container for new windows
observer.observe(document.getElementById('dashboard'), { childList: true });
// Initial injection for existing windows
document.querySelectorAll('.window-content iframe').forEach(iframe => {
iframe.onload = () => injectSelectiveDarkModeCSS(iframe);
});
</script>
</body>
</html>