-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1481 lines (1304 loc) · 67.1 KB
/
script.js
File metadata and controls
1481 lines (1304 loc) · 67.1 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
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -------------------------
// Performance Optimizations and Utilities
// -------------------------
// Debounce utility for performance optimization
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Throttle utility for performance optimization
function throttle(func, limit) {
let inThrottle;
return function executedFunction(...args) {
if (!inThrottle) {
func(...args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
};
}
// RAF helper for smooth animations
function rafPromise() {
return new Promise(requestAnimationFrame);
}
// Intersection Observer for optimizing off-screen animations
const createIntersectionObserver = (callback, options = {}) => {
const defaultOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1,
...options
};
return new IntersectionObserver((entries) => {
entries.forEach(callback);
}, defaultOptions);
};
// Memory leak prevention - store cleanup functions
const cleanupFunctions = new Set();
// Register cleanup function
function registerCleanup(fn) {
cleanupFunctions.add(fn);
}
// Cleanup on page hide/unload
window.addEventListener('pagehide', () => {
cleanupFunctions.forEach(fn => fn());
cleanupFunctions.clear();
}, { once: true });
// -------------------------
// Animation Constants and Utilities
// -------------------------
const ANIMATION_TIMING = {
loaderMinDisplay: 1200, // Minimum time to show loader
loaderFadeOut: 600, // How long the loader takes to fade out
navStagger: 80, // Delay between nav items
heroDelay: 200, // Delay before hero animations start
heroStagger: 150, // Delay between hero elements
};
const EASINGS = {
outBack: 'cubic-bezier(0.34, 1.56, 0.64, 1)',
outCustom: 'cubic-bezier(0.22, 1, 0.36, 1)',
outSmooth: 'cubic-bezier(0.4, 0, 0.2, 1)'
};
// Helper to stagger animations
function staggerAnimate(elements, className, delayStart = 0, staggerDelay = 100) {
elements.forEach((el, i) => {
setTimeout(() => el.classList.add(className), delayStart + (i * staggerDelay));
});
}
// -------------------------
// Page Loader and Animations
// -------------------------
function startPageAnimations() {
// Get all animation elements
const navElements = [
document.querySelector('.logo'),
...document.querySelectorAll('.nav-link'),
document.querySelector('.settings-btn'),
document.querySelector('.hamburger')
].filter(Boolean); // Remove null elements
const heroElements = {
title: document.querySelector('.hero-title'),
dates: document.querySelector('.hero-dates'),
desc: document.querySelector('.hero-desc'),
image: document.querySelector('.hero-image-container')
};
// Start nav animations with stagger
staggerAnimate(navElements, 'animate', 0, ANIMATION_TIMING.navStagger);
// Prepare hero elements
Object.values(heroElements).forEach(el => {
if (el) {
el.style.opacity = '0';
el.style.willChange = 'transform, opacity';
}
});
// Define hero animations
const heroAnimations = [
{ el: heroElements.title, animation: `slideInLeft 1.2s ${EASINGS.outBack} forwards` },
{ el: heroElements.dates, animation: `slideInLeft 1s ${EASINGS.outCustom} forwards` },
{ el: heroElements.desc, animation: `slideInLeft 1s ${EASINGS.outCustom} forwards` },
{ el: heroElements.image, animation: `slideInRight 1.4s ${EASINGS.outCustom} forwards` }
];
// Start hero animations with stagger
heroAnimations.forEach(({ el, animation }, i) => {
if (el) {
setTimeout(() => {
el.style.animation = animation;
}, ANIMATION_TIMING.heroDelay + (i * ANIMATION_TIMING.heroStagger));
}
});
// Cleanup will-change after animations complete
setTimeout(() => {
Object.values(heroElements).forEach(el => {
if (el) el.style.willChange = 'auto';
});
}, ANIMATION_TIMING.heroDelay + (heroAnimations.length * ANIMATION_TIMING.heroStagger) + 1500);
}
// Handle loader timing and initial animations
document.addEventListener('DOMContentLoaded', () => {
// Initially hide the hamburger to prevent flash
const hamburger = document.querySelector('.hamburger');
if (hamburger) {
hamburger.style.opacity = '0';
hamburger.style.visibility = 'hidden';
}
const loader = document.querySelector('.loader');
if (!loader) return;
// Track when content is ready
const contentLoadTime = Date.now();
const minimumLoaderTime = ANIMATION_TIMING.loaderMinDisplay;
// Function to start animations
const startAnimationsSequence = () => {
// Ensure minimum loader display time
const timeElapsed = Date.now() - contentLoadTime;
const remainingLoaderTime = Math.max(0, minimumLoaderTime - timeElapsed);
setTimeout(() => {
// Add hidden class to start fade out
loader.classList.add('hidden');
// After loader starts fading, prepare hamburger
if (hamburger) {
hamburger.style.visibility = 'visible';
hamburger.style.opacity = '1';
hamburger.style.transition = 'opacity 0.3s ease-in-out';
}
// Start page animations after loader fade
setTimeout(() => {
startPageAnimations();
// Remove loader from DOM after all animations
setTimeout(() => {
loader.remove();
}, 1000);
}, ANIMATION_TIMING.loaderFadeOut);
}, remainingLoaderTime);
};
// Handle images loading
const preloadHeroImages = () => {
const heroImages = document.querySelectorAll('.hero-image');
let loadedImages = 0;
const totalImages = heroImages.length;
const checkAllLoaded = () => {
loadedImages++;
if (loadedImages === totalImages) {
startAnimationsSequence();
}
};
heroImages.forEach(img => {
if (img.complete) {
checkAllLoaded();
} else {
img.onload = checkAllLoaded;
img.onerror = checkAllLoaded; // Count errors as loaded to prevent hanging
}
});
// Fallback in case some images fail to load
setTimeout(startAnimationsSequence, 3000);
};
preloadHeroImages();
});
// -------------------------
// Image Gallery Viewer
// -------------------------
class ImageGalleryViewer {
constructor() {
this.createGalleryDOM();
this.currentIndex = 0;
this.images = [];
this.isOpen = false;
this.touchStartX = 0;
this.touchEndX = 0;
this.isDragging = false;
this.setupEventListeners();
}
createGalleryDOM() {
const gallery = document.createElement('div');
gallery.className = 'gallery-viewer';
gallery.innerHTML = `
<div class="gallery-content">
<button class="gallery-close" aria-label="Close gallery">×</button>
<button class="gallery-nav prev" aria-label="Previous image">‹</button>
<button class="gallery-nav next" aria-label="Next image">›</button>
<div class="gallery-title"></div>
<div class="gallery-image-container">
<img class="gallery-image" alt="" />
</div>
</div>
`;
document.body.appendChild(gallery);
this.element = gallery;
this.imageElement = gallery.querySelector('.gallery-image');
this.titleElement = gallery.querySelector('.gallery-title');
}
setupEventListeners() {
// Close button
this.element.querySelector('.gallery-close').addEventListener('click', () => this.close());
// Get the image container for both click and touch events
const imageContainer = this.element.querySelector('.gallery-image-container');
// Navigation buttons
const prevButton = this.element.querySelector('.gallery-nav.prev');
const nextButton = this.element.querySelector('.gallery-nav.next');
// Prevent clicks on navigation buttons from bubbling up
prevButton.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
if (!this.isOpen) return;
this.prev();
});
nextButton.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
if (!this.isOpen) return;
this.next();
});
// Touch event handling
imageContainer.addEventListener('touchstart', (e) => {
if (!this.isOpen) return;
this.touchStartX = e.touches[0].clientX;
this.isDragging = true;
}, { passive: true });
imageContainer.addEventListener('touchmove', (e) => {
if (!this.isDragging || !this.isOpen) return;
this.touchEndX = e.touches[0].clientX;
const diffX = this.touchEndX - this.touchStartX;
// Prevent scrolling while swiping
if (Math.abs(diffX) > 10) {
e.preventDefault();
}
}, { passive: false });
imageContainer.addEventListener('touchend', (e) => {
if (!this.isDragging || !this.isOpen) return;
const diffX = this.touchEndX - this.touchStartX;
const threshold = window.innerWidth * 0.15; // 15% of screen width
if (Math.abs(diffX) > threshold) {
if (diffX > 0) {
this.prev();
} else {
this.next();
}
}
this.isDragging = false;
this.touchStartX = 0;
this.touchEndX = 0;
}, { passive: true });
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (!this.isOpen) return;
switch(e.key) {
case 'ArrowLeft':
this.prev();
break;
case 'ArrowRight':
this.next();
break;
case 'Escape':
this.close();
break;
}
});
// Prevent any clicks on the image or image container from triggering navigation
imageContainer.addEventListener('click', (e) => {
e.stopPropagation();
});
// Close only when clicking the dark backdrop
this.element.addEventListener('click', (e) => {
if (e.target === this.element) {
this.close();
}
});
}
loadImage(src, title) {
return new Promise((resolve, reject) => {
this.imageElement.src = src;
this.imageElement.onload = () => {
this.imageElement.style.opacity = '1';
resolve();
};
this.imageElement.onerror = reject;
});
}
async show(images, startIndex = 0, section = null) {
if (section) {
// Get all images from the section
const cards = Array.from(document.querySelectorAll(`#${section} .content-card`));
this.images = cards.flatMap(card => {
const title = card.querySelector('.card-title')?.textContent.trim() || '';
const desc = card.querySelector('.card-text')?.textContent.trim() || '';
if (section === 'inventions' && multiImageMap[title]) {
// Map the descriptive names to the actual file names
const fileMap = {
'air_screw_prototype.jpg': 'air_screw_1.jpg',
'air_screw_sketch.jpg': 'air_screw_2.jpg',
'amored_tank_design.JPG': 'amored_tank_1.JPG',
'amored_tank_blueprint.jpg': 'amored_tank_2.jpg',
'hydraulic_systems_diagram.jpg': 'hydraulic_systems_1.jpg',
'hydraulic_systems_schematic.png': 'hydraulic_systems_2.png',
'multi-level_bridge_design.jpg': 'multi-level_bridge_1.jpg',
'multi-level_bridge_concept.jpg': 'multi-level_bridge_2.jpg'
};
// For cards with multiple images
return multiImageMap[title].map(displayName => ({
src: `./images/cards/inventions/${fileMap[displayName]}`,
title: `${title} - ${displayName.split('.')[0].split('_').pop().replace(/^\w/, c => c.toUpperCase())}`,
desc: desc
}));
} else {
// Single image (art or inventions)
const imageName = card.getAttribute('data-image');
return [{
src: `./images/cards/${section}/${imageName}.jpg`,
title: title,
desc: desc
}];
}
});
} else {
this.images = images;
}
this.currentIndex = startIndex;
this.isOpen = true;
// Save current scroll position
this.scrollY = window.scrollY;
// Prevent scrolling
document.body.style.overflow = 'hidden';
document.body.style.position = 'fixed';
document.body.style.width = '100%';
document.body.style.top = `-${this.scrollY}px`;
this.element.classList.add('active');
await this.updateImage();
}
async updateImage(direction = null) {
const current = this.images[this.currentIndex];
if (!current) return;
// Update title with fade
this.titleElement.style.opacity = '0';
setTimeout(() => {
this.titleElement.textContent = current.title;
this.titleElement.style.opacity = '1';
}, 150);
try {
// Optimize animations with will-change
this.imageElement.style.willChange = 'transform, opacity';
// Set initial position
const initialTransform = direction ?
`translateX(${direction === 'prev' ? '-50px' : '50px'}) scale(0.95)` :
'translateX(0) scale(1)';
// Apply initial state
Object.assign(this.imageElement.style, {
transform: initialTransform,
opacity: '0',
transition: 'none'
});
// Load image
await this.loadImage(current.src, current.title);
// Apply GPU-accelerated transition
requestAnimationFrame(() => {
Object.assign(this.imageElement.style, {
transition: 'transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1)',
transform: 'translateX(0) scale(1)',
opacity: '1'
});
});
// Update nav buttons with fade
const [prevButton, nextButton] = ['prev', 'next'].map(
dir => this.element.querySelector(`.gallery-nav.${dir}`)
);
[prevButton, nextButton].forEach(button => {
if (button) {
button.style.opacity = '1';
button.style.pointerEvents = 'auto';
}
});
// Cleanup will-change after animation
setTimeout(() => {
this.imageElement.style.willChange = 'auto';
}, 700);
} catch (error) {
console.error('Failed to load image:', error);
// Show error state to user
this.titleElement.textContent = 'Error loading image';
this.titleElement.style.color = 'var(--error-color, #ff5555)';
}
}
async next() {
if (!this.isOpen) return;
this.currentIndex = (this.currentIndex + 1) % this.images.length;
await this.updateImage('next');
}
async prev() {
if (!this.isOpen) return;
this.currentIndex = (this.currentIndex - 1 + this.images.length) % this.images.length;
await this.updateImage('prev');
}
close() {
if (!this.isOpen) return;
this.isOpen = false;
this.element.classList.remove('active');
// Restore scrolling and position smoothly
requestAnimationFrame(() => {
document.body.style.overflow = '';
document.body.style.position = '';
document.body.style.width = '';
document.body.style.top = '';
window.scrollTo({
top: this.scrollY,
behavior: 'instant'
});
});
}
}
// Helper function to gather image data from a container
function getImagesFromContainer(container) {
const images = [];
container.querySelectorAll('img').forEach(img => {
images.push({
src: img.src,
title: img.alt || img.getAttribute('data-title') || ''
});
});
return images;
}
// Create and initialize gallery viewer
const galleryViewer = new ImageGalleryViewer();
// Initialize cards with background images
function initializeCards() {
// Set up art card backgrounds
document.querySelectorAll('#art .content-card').forEach(card => {
const imageKey = card.dataset.image;
if (imageKey) {
card.style.backgroundImage = `url('./images/cards/art/${imageKey}.jpg')`;
}
});
// Set up invention card backgrounds
document.querySelectorAll('#inventions .content-card').forEach(card => {
const images = card.dataset.images ? JSON.parse(card.dataset.images) : [card.dataset.image];
if (images && images.length > 0) {
card.style.backgroundImage = `url('./images/cards/inventions/${images[0]}')`;
}
});
}
// Initialize cards when DOM is ready
document.addEventListener('DOMContentLoaded', initializeCards);
// Initialize click handlers for gallery
document.addEventListener('DOMContentLoaded', () => {
// Hero section images
const heroContainer = document.querySelector('.hero-image-container');
if (heroContainer) {
heroContainer.style.cursor = 'pointer';
const heroImages = getImagesFromContainer(heroContainer);
heroContainer.addEventListener('click', () => {
// Find the current active image index
const activeImg = heroContainer.querySelector('.hero-image.active');
const currentIndex = Array.from(heroContainer.children).indexOf(activeImg);
// Show gallery with current image
galleryViewer.show(heroImages, currentIndex);
});
}
// Initialize card previews and click handlers
const contentCards = document.querySelectorAll('#art .content-card, #inventions .content-card');
contentCards.forEach(card => {
const section = card.closest('section').id;
const preview = card.querySelector('.card-preview');
const title = card.querySelector('.card-title')?.textContent || '';
const desc = card.querySelector('.card-text')?.textContent || '';
const cardTitle = title.trim();
// Set up preview background
if (preview) {
if (section === 'art') {
const imageName = card.getAttribute('data-image');
preview.style.backgroundImage = `url('./images/cards/art/${imageName}.jpg')`;
} else {
const images = JSON.parse(card.getAttribute('data-images') || `["${card.getAttribute('data-image')}.jpg"]`);
preview.style.backgroundImage = `url('./images/cards/inventions/${images[0]}')`;
}
}
// Add click handler to the card
card.style.cursor = 'pointer';
card.addEventListener('click', (e) => {
// Don't trigger if clicking on reference icons
if (e.target.closest('.ref-icon-container')) return;
// Calculate start index based on cards before this one
const startIndex = Array.from(document.querySelectorAll(`#${section} .content-card`))
.slice(0, Array.from(card.parentNode.children).indexOf(card))
.reduce((count, prevCard) => {
const title = prevCard.querySelector('.card-title')?.textContent.trim() || '';
return count + (section === 'inventions' && multiImageMap[title] ? multiImageMap[title].length : 1);
}, 0);
// Show gallery for the entire section, starting from this card's position
galleryViewer.show(null, startIndex, section);
});
});
});
// -------------------------
// Reference Links
// -------------------------
const artWikiLinks = {
'Mona Lisa': 'https://en.wikipedia.org/wiki/Mona_Lisa',
'The Last Supper': 'https://en.wikipedia.org/wiki/The_Last_Supper_(Leonardo)',
'Vitruvian Man': 'https://en.wikipedia.org/wiki/Vitruvian_Man',
'Lady with an Ermine': 'https://en.wikipedia.org/wiki/Lady_with_an_Ermine'
};
const inventionWikiLinks = {
'Aerial Screw': 'https://en.wikipedia.org/wiki/Leonardo%27s_aerial_screw',
'Armored Tank': 'https://en.wikipedia.org/wiki/Leonardo%27s_tank',
'Parachute Design': 'https://en.wikipedia.org/wiki/Leonardo%27s_parachute',
'Robotic Knight': 'https://en.wikipedia.org/wiki/Leonardo%27s_robot',
'Hydraulic Systems': 'https://en.wikipedia.org/wiki/Science_and_inventions_of_Leonardo_da_Vinci#Engineering_and_hydraulics',
'Multi-Level Bridge': 'https://en.wikipedia.org/wiki/Science_and_inventions_of_Leonardo_da_Vinci#Civil_engineering'
};
const multiImageMap = {
'Aerial Screw': ['air_screw_prototype.jpg', 'air_screw_sketch.jpg'],
'Armored Tank': ['amored_tank_design.JPG', 'amored_tank_blueprint.jpg'],
'Hydraulic Systems': ['hydraulic_systems_diagram.jpg', 'hydraulic_systems_schematic.png'],
'Multi-Level Bridge': ['multi-level_bridge_design.jpg', 'multi-level_bridge_concept.jpg']
};function addReferenceIcon(card, link) {
const iconContainer = document.createElement('div');
iconContainer.className = 'ref-icon-container';
// Arrow SVG - Increased size for better touch target
const arrowSvg = `
<svg class="ref-icon arrow" viewBox="0 0 24 24" width="32" height="32">
<path d="M7 7h8.586L5.293 17.293l1.414 1.414L17 8.414V17h2V5H7v2z" fill="currentColor"/>
</svg>
`;
// World SVG - Increased size for better touch target
const worldSvg = `
<svg class="ref-icon world" viewBox="0 0 24 24" width="32" height="32">
<g fill="none" stroke="currentColor" stroke-width="1.5">
<circle cx="12" cy="12" r="9" />
<path d="M12 3a9 9 0 0 1 9 9M3 12a9 9 0 0 1 9-9" />
<path d="M12 21a9 9 0 0 1-9-9M21 12a9 9 0 0 1-9 9" />
<path d="M3.5 9h17M3.5 15h17" />
<path d="M12 3v18" stroke-opacity="0.5" />
<path d="M7 4.5C7 8.5 12 12 12 12s5-3.5 5-7.5" />
<path d="M7 19.5c0-4 5-7.5 5-7.5s5 3.5 5 7.5" />
</g>
</svg>
`;
iconContainer.innerHTML = arrowSvg + worldSvg;
card.appendChild(iconContainer);
// Add invisible touch target extender
const touchTarget = document.createElement('div');
touchTarget.className = 'ref-touch-target';
touchTarget.style.cssText = `
position: absolute;
top: -10px;
right: -10px;
width: 60px;
height: 60px;
cursor: pointer;
`;
iconContainer.appendChild(touchTarget);
// Improved touch/click handling
const handleInteraction = (e) => {
e.stopPropagation(); // Prevent triggering the card's click event
e.preventDefault();
// Add feedback for touch devices
iconContainer.style.transform = 'scale(0.95)';
setTimeout(() => {
iconContainer.style.transform = '';
window.open(link, '_blank', 'noopener');
}, 150);
};
// Handle both touch and click events
touchTarget.addEventListener('touchend', handleInteraction, { passive: false });
touchTarget.addEventListener('click', handleInteraction);
// Prevent card click when touching icon area
iconContainer.addEventListener('touchstart', e => e.stopPropagation(), { passive: true });
iconContainer.addEventListener('touchend', e => e.stopPropagation(), { passive: true });
}
// Add reference links to art and inventions cards
document.addEventListener('DOMContentLoaded', () => {
// Add reference links to art cards
document.querySelectorAll('#art .content-card').forEach(card => {
const title = card.querySelector('.card-title').textContent.trim();
if (artWikiLinks[title]) {
addReferenceIcon(card, artWikiLinks[title]);
}
});
// Add reference links to invention cards
document.querySelectorAll('#inventions .content-card').forEach(card => {
const title = card.querySelector('.card-title').textContent.trim();
if (inventionWikiLinks[title]) {
addReferenceIcon(card, inventionWikiLinks[title]);
}
});
});
// -------------------------
// Translations
// -------------------------
const translations = {
en: {
settings: "Settings",
theme: "Theme",
language: "Language",
light: "Light",
dark: "Dark",
biography: "Biography",
inventions: "Inventions",
art: "Art",
legacy: "Legacy",
heroTitle: "Leonardo<br>da Vinci",
heroDates: "1452 — 1519",
heroDesc: "Renaissance polymath who embodied the fusion of art, science, and innovation. A visionary whose notebooks contained designs for flying machines, anatomical studies, and masterpieces that continue to inspire humanity five centuries later.",
biographyTitle: "Biography",
birth1452: "Birth in Vinci",
birthDesc: "Born on April 15 in the hilltop town of Vinci, Republic of Florence. The illegitimate son of a successful notary and a local woman, marking the beginning of an extraordinary life.",
apprentice1466: "Apprenticeship Begins",
apprenticeDesc: "At age 14, became apprentice to the renowned artist Andrea del Verrocchio in Florence, learning painting, sculpture, metalwork, and mechanical arts in one of the city's most prestigious workshops.",
milan1482: "Milan Court",
milanDesc: "Moved to Milan under the patronage of Ludovico Sforza, where he served as court artist, engineer, and inventor, creating military designs, architectural plans, and court entertainments.",
mona1503: "The Mona Lisa",
monaDesc: "Began work on his most famous portrait, revolutionizing the art of painting with innovative techniques and psychological depth that continue to captivate viewers worldwide.",
death1519: "Final Chapter",
deathDesc: "Died on May 2 at Château du Clos Lucé in Amboise, France, under the patronage of King Francis I, leaving behind thousands of pages of notes and drawings that revealed his genius to the world.",
inventionsTitle: "Inventions",
aerialScrew: "Aerial Screw",
aerialDesc: "Designed a helicopter-like flying machine with a helical rotor, demonstrating his understanding of aerodynamics centuries before powered flight became reality.",
armoredTank: "Armored Tank",
tankDesc: "Conceptualized a mobile fortress powered by cranks, featuring armor plating and gun ports—essentially the first tank design in history.",
parachute: "Parachute Design",
parachuteDesc: "Created a pyramid-shaped parachute made of linen, which modern testing has proven to be remarkably effective and safe for descent.",
robotKnight: "Robotic Knight",
robotDesc: "Built a mechanical automaton that could sit, stand, and move its arms independently, representing pioneering work in robotics and automation.",
hydraulic: "Hydraulic Systems",
hydraulicDesc: "Designed complex water management systems including canals, locks, and irrigation networks that influenced civil engineering for generations.",
bridge: "Multi-Level Bridge",
bridgeDesc: "Proposed innovative bridge designs with multiple levels for different types of traffic, anticipating modern urban planning concepts.",
artTitle: "Masterworks",
monaLisa: "Mona Lisa",
monaArtDesc: "The world's most famous portrait, showcasing sfumato technique and enigmatic expression. Housed in the Louvre, it represents the pinnacle of Renaissance portraiture.",
lastSupper: "The Last Supper",
supperDesc: "Revolutionary fresco depicting Christ's final meal with mathematical precision in perspective and profound emotional narrative, despite its deteriorating condition.",
vitruvian: "Vitruvian Man",
vitruvianDesc: "Iconic drawing demonstrating ideal human proportions, perfectly embodying Renaissance fusion of art, mathematics, and scientific observation.",
ladyErmine: "Lady with an Ermine",
ermineDesc: "Portrait of Cecilia Gallerani showcasing innovative three-quarter pose and masterful rendering of light, texture, and psychological presence.",
legacyTitle: "Legacy",
scientific: "Scientific Method",
scientificDesc: "His approach of observation, hypothesis, and experimentation laid crucial groundwork for modern scientific methodology and empirical research practices.",
interdisciplinary: "Interdisciplinary Innovation",
interDesc: "Demonstrated how art and science could complement each other, inspiring today's approach to creative problem-solving across multiple fields.",
anatomical: "Anatomical Revolution",
anatomicalDesc: "His detailed dissections and drawings advanced medical understanding, establishing artistic documentation as a tool for scientific discovery.",
modern: "Modern Inspiration",
modernDesc: "Continues to inspire contemporary artists, engineers, and inventors worldwide, representing the ideal of lifelong learning and boundless curiosity."
},
es: {
settings: "Configuración",
theme: "Tema",
language: "Idioma",
light: "Claro",
dark: "Oscuro",
biography: "Biografía",
inventions: "Inventos",
art: "Arte",
legacy: "Legado",
heroTitle: "Leonardo<br>da Vinci",
heroDates: "1452 — 1519",
heroDesc: "Polímata renacentista que encarnó la fusión del arte, la ciencia y la innovación. Un visionario cuyos cuadernos contenían diseños de máquinas voladoras, estudios anatómicos y obras maestras que continúan inspirando a la humanidad cinco siglos después.",
biographyTitle: "Biografía",
birth1452: "Nacimiento en Vinci",
birthDesc: "Nació el 15 de abril en la ciudad montañosa de Vinci, República de Florencia. Hijo ilegítimo de un notario exitoso y una mujer local, marcando el comienzo de una vida extraordinaria.",
apprentice1466: "Comienza el Aprendizaje",
apprenticeDesc: "A los 14 años, se convirtió en aprendiz del renombrado artista Andrea del Verrocchio en Florencia, aprendiendo pintura, escultura, metalurgia y artes mecánicas en uno de los talleres más prestigiosos de la ciudad.",
milan1482: "Corte de Milán",
milanDesc: "Se trasladó a Milán bajo el patrocinio de Ludovico Sforza, donde sirvió como artista de la corte, ingeniero e inventor, creando diseños militares, planos arquitectónicos y entretenimientos cortesanos.",
mona1503: "La Mona Lisa",
monaDesc: "Comenzó a trabajar en su retrato más famoso, revolucionando el arte de la pintura con técnicas innovadoras y profundidad psicológica que continúan cautivando a espectadores de todo el mundo.",
death1519: "Capítulo Final",
deathDesc: "Murió el 2 de mayo en el Château du Clos Lucé en Amboise, Francia, bajo el patrocinio del Rey Francisco I, dejando atrás miles de páginas de notas y dibujos que revelaron su genio al mundo.",
inventionsTitle: "Inventos",
aerialScrew: "Tornillo Aéreo",
aerialDesc: "Diseñó una máquina voladora similar a un helicóptero con un rotor helicoidal, demostrando su comprensión de la aerodinámica siglos antes de que el vuelo motorizado se hiciera realidad.",
armoredTank: "Tanque Blindado",
tankDesc: "Conceptualizó una fortaleza móvil propulsada por manivelas, con blindaje y puertos de disparo: esencialmente el primer diseño de tanque en la historia.",
parachute: "Diseño de Paracaídas",
parachuteDesc: "Creó un paracaídas en forma de pirámide hecho de lino, que las pruebas modernas han demostrado que es notablemente efectivo y seguro para el descenso.",
robotKnight: "Caballero Robótico",
robotDesc: "Construyó un autómata mecánico que podía sentarse, pararse y mover sus brazos independientemente, representando un trabajo pionero en robótica y automatización.",
hydraulic: "Sistemas Hidráulicos",
hydraulicDesc: "Diseñó sistemas complejos de gestión del agua incluyendo canales, esclusas y redes de irrigación que influyeron en la ingeniería civil durante generaciones.",
bridge: "Puente Multinivel",
bridgeDesc: "Propuso diseños innovadores de puentes con múltiples niveles para diferentes tipos de tráfico, anticipando conceptos modernos de planificación urbana.",
artTitle: "Obras Maestras",
monaLisa: "La Mona Lisa",
monaArtDesc: "El retrato más famoso del mundo, mostrando la técnica del sfumato y una expresión enigmática. Alojada en el Louvre, representa la cúspide del retrato renacentista.",
lastSupper: "La Última Cena",
supperDesc: "Fresco revolucionario que representa la última comida de Cristo con precisión matemática en perspectiva y narrativa emocional profunda, a pesar de su condición deteriorada.",
vitruvian: "Hombre de Vitruvio",
vitruvianDesc: "Dibujo icónico que demuestra las proporciones humanas ideales, encarnando perfectamente la fusión renacentista del arte, las matemáticas y la observación científica.",
ladyErmine: "Dama con Armiño",
ermineDesc: "Retrato de Cecilia Gallerani mostrando una pose innovadora de tres cuartos y una representación magistral de la luz, textura y presencia psicológica.",
legacyTitle: "Legado",
scientific: "Método Científico",
scientificDesc: "Su enfoque de observación, hipótesis y experimentación sentó las bases cruciales para la metodología científica moderna y las prácticas de investigación empírica.",
interdisciplinary: "Innovación Interdisciplinaria",
interDesc: "Demostró cómo el arte y la ciencia podrían complementarse mutuamente, inspirando el enfoque actual para la resolución creativa de problemas en múltiples campos.",
anatomical: "Revolución Anatómica",
anatomicalDesc: "Sus disecciones detalladas y dibujos avanzaron la comprensión médica, estableciendo la documentación artística como una herramienta para el descubrimiento científico.",
modern: "Inspiración Moderna",
modernDesc: "Continúa inspirando a artistas, ingenieros e inventores contemporáneos en todo el mundo, representando el ideal del aprendizaje permanente y la curiosidad ilimitada."
},
fr: {
settings: "Paramètres",
theme: "Thème",
language: "Langue",
light: "Clair",
dark: "Sombre",
biography: "Biographie",
inventions: "Inventions",
art: "Art",
legacy: "Héritage",
heroTitle: "Léonard<br>de Vinci",
heroDates: "1452 — 1519",
heroDesc: "Polymathe de la Renaissance qui incarnait la fusion de l'art, de la science et de l'innovation. Un visionnaire dont les carnets contenaient des dessins de machines volantes, des études anatomiques et des chefs-d'œuvre qui continuent d'inspirer l'humanité cinq siècles plus tard.",
biographyTitle: "Biographie",
birth1452: "Naissance à Vinci",
birthDesc: "Né le 15 avril dans la ville perchée de Vinci, République de Florence. Fils illégitime d'un notaire prospère et d'une femme locale, marquant le début d'une vie extraordinaire.",
apprentice1466: "Début de l'Apprentissage",
apprenticeDesc: "À 14 ans, devient apprenti du célèbre artiste Andrea del Verrocchio à Florence, apprenant la peinture, la sculpture, la métallurgie et les arts mécaniques dans l'un des ateliers les plus prestigieux de la ville.",
milan1482: "Cour de Milan",
milanDesc: "S'installe à Milan sous le patronage de Ludovico Sforza, où il sert comme artiste de cour, ingénieur et inventeur, créant des dessins militaires, des plans architecturaux et des divertissements de cour.",
mona1503: "La Joconde",
monaDesc: "Commence le travail sur son portrait le plus célèbre, révolutionnant l'art de la peinture avec des techniques innovantes et une profondeur psychologique qui continue de captiver les spectateurs du monde entier.",
death1519: "Chapitre Final",
deathDesc: "Mort le 2 mai au Château du Clos Lucé à Amboise, France, sous le patronage du Roi François Ier, laissant derrière lui des milliers de pages de notes et de dessins qui ont révélé son génie au monde.",
inventionsTitle: "Inventions",
aerialScrew: "Vis Aérienne",
aerialDesc: "A conçu une machine volante semblable à un hélicoptère avec un rotor hélicoïdal, démontrant sa compréhension de l'aérodynamique des siècles avant que le vol motorisé ne devienne réalité.",
armoredTank: "Char Blindé",
tankDesc: "A conceptualisé une forteresse mobile propulsée par des manivelles, avec un blindage et des ports de tir—essentiellement le premier design de char de l'histoire.",
parachute: "Design de Parachute",
parachuteDesc: "A créé un parachute en forme de pyramide en lin, que les tests modernes ont prouvé être remarquablement efficace et sûr pour la descente.",
robotKnight: "Chevalier Robotique",
robotDesc: "A construit un automate mécanique qui pouvait s'asseoir, se lever et bouger ses bras indépendamment, représentant un travail pionnier en robotique et automatisation.",
hydraulic: "Systèmes Hydrauliques",
hydraulicDesc: "A conçu des systèmes complexes de gestion de l'eau incluant canaux, écluses et réseaux d'irrigation qui ont influencé l'ingénierie civile pendant des générations.",
bridge: "Pont Multi-Niveaux",
bridgeDesc: "A proposé des conceptions innovantes de ponts avec plusieurs niveaux pour différents types de trafic, anticipant les concepts modernes d'urbanisme.",
artTitle: "Chefs-d'œuvre",
monaLisa: "La Joconde",
monaArtDesc: "Le portrait le plus célèbre du monde, montrant la technique du sfumato et une expression énigmatique. Abritée au Louvre, elle représente l'apogée du portrait de la Renaissance.",
lastSupper: "La Cène",
supperDesc: "Fresque révolutionnaire dépeignant le dernier repas du Christ avec une précision mathématique en perspective et un récit émotionnel profond, malgré son état de détérioration.",
vitruvian: "Homme de Vitruve",
vitruvianDesc: "Dessin iconique démontrant les proportions humaines idéales, incarnant parfaitement la fusion Renaissance de l'art, les mathématiques et l'observation scientifique.",
ladyErmine: "Dame à l'Hermine",
ermineDesc: "Portrait de Cecilia Gallerani montrant une pose innovante de trois quarts et un rendu magistral de la lumière, de la texture et de la présence psychologique.",
legacyTitle: "Héritage",
scientific: "Méthode Scientifique",
scientificDesc: "Son approche d'observation, d'hypothèse et d'expérimentation a posé les bases cruciales de la méthodologie scientifique moderne et des pratiques de recherche empirique.",
interdisciplinary: "Innovation Interdisciplinaire",
interDesc: "A démontré comment l'art et la science pouvaient se compléter mutuellement, inspirant l'approche actuelle de résolution créative de problèmes dans plusieurs domaines.",
anatomical: "Révolution Anatomique",
anatomicalDesc: "Ses dissections détaillées et ses dessins ont fait progresser la compréhension médicale, établissant la documentation artistique comme un outil pour la découverte scientifique.",
modern: "Inspiration Moderne",
modernDesc: "Continue d'inspirer les artistes, ingénieurs et inventeurs contemporains du monde entier, représentant l'idéal d'apprentissage permanent et de curiosité sans limites."
},
de: {
settings: "Einstellungen",
theme: "Design",
language: "Sprache",
light: "Hell",
dark: "Dunkel",
biography: "Biografie",
inventions: "Erfindungen",
art: "Kunst",
legacy: "Vermächtnis",
heroTitle: "Leonardo<br>da Vinci",
heroDates: "1452 — 1519",
heroDesc: "Renaissance-Universalgelehrter, der die Verschmelzung von Kunst, Wissenschaft und Innovation verkörperte. Ein Visionär, dessen Notizbücher Entwürfe für Flugmaschinen, anatomische Studien und Meisterwerke enthielten, die die Menschheit fünf Jahrhunderte später weiterhin inspirieren.",
biographyTitle: "Biografie",
birth1452: "Geburt in Vinci",
birthDesc: "Geboren am 15. April in der Bergstadt Vinci, Republik Florenz. Der uneheliche Sohn eines erfolgreichen Notars und einer einheimischen Frau, was den Beginn eines außergewöhnlichen Lebens markierte.",
apprentice1466: "Lehre Beginnt",
apprenticeDesc: "Mit 14 Jahren wurde er Lehrling des renommierten Künstlers Andrea del Verrocchio in Florenz und lernte Malerei, Bildhauerei, Metallbearbeitung und mechanische Künste in einer der prestigeträchtigsten Werkstätten der Stadt.",
milan1482: "Mailänder Hof",
milanDesc: "Zog nach Mailand unter der Schirmherrschaft von Ludovico Sforza, wo er als Hofkünstler, Ingenieur und Erfinder diente und militärische Entwürfe, architektonische Pläne und Hofunterhaltung schuf.",
mona1503: "Die Mona Lisa",
monaDesc: "Begann die Arbeit an seinem berühmtesten Porträt und revolutionierte die Malkunst mit innovativen Techniken und psychologischer Tiefe, die Betrachter weltweit weiterhin fesseln.",
death1519: "Letztes Kapitel",
deathDesc: "Starb am 2. Mai im Château du Clos Lucé in Amboise, Frankreich, unter der Schirmherrschaft von König Franz I. und hinterließ Tausende von Seiten mit Notizen und Zeichnungen, die sein Genie der Welt offenbarten.",
inventionsTitle: "Erfindungen",
aerialScrew: "Luftschraube",
aerialDesc: "Entwarf eine hubschrauberartige Flugmaschine mit einem schraubenförmigen Rotor und demonstrierte sein Verständnis der Aerodynamik Jahrhunderte bevor der motorisierte Flug Realität wurde.",
armoredTank: "Gepanzerter Panzer",
tankDesc: "Konzipierte eine mobile Festung, die von Kurbeln angetrieben wurde, mit Panzerung und Schießscharten—im Wesentlichen das erste Panzerdesign der Geschichte.",
parachute: "Fallschirm-Design",
parachuteDesc: "Schuf einen pyramidenförmigen Fallschirm aus Leinen, der durch moderne Tests als bemerkenswert effektiv und sicher für den Abstieg erwiesen wurde.",
robotKnight: "Roboter-Ritter",
robotDesc: "Baute einen mechanischen Automaten, der sich setzen, stehen und seine Arme unabhängig bewegen konnte und damit Pionierarbeit in Robotik und Automatisierung leistete.",
hydraulic: "Hydraulische Systeme",
hydraulicDesc: "Entwarf komplexe Wassermanagementsysteme einschließlich Kanäle, Schleusen und Bewässerungsnetze, die den Tiefbau über Generationen beeinflussten.",
bridge: "Mehrstöckige Brücke",
bridgeDesc: "Schlug innovative Brückenentwürfe mit mehreren Ebenen für verschiedene Verkehrsarten vor und nahm moderne Stadtplanungskonzepte vorweg.",
artTitle: "Meisterwerke",
monaLisa: "Mona Lisa",
monaArtDesc: "Das berühmteste Porträt der Welt, das die Sfumato-Technik und einen rätselhaften Ausdruck zeigt. Im Louvre untergebracht, repräsentiert es den Höhepunkt der Renaissance-Porträtmalerei.",
lastSupper: "Das Abendmahl",
supperDesc: "Revolutionäres Fresko, das Christi letzte Mahlzeit mit mathematischer Präzision in der Perspektive und tiefgreifender emotionaler Erzählung darstellt, trotz ihres verschlechterten Zustands.",
vitruvian: "Vitruvianischer Mensch",
vitruvianDesc: "Ikonische Zeichnung, die ideale menschliche Proportionen demonstriert und die Renaissance-Verschmelzung von Kunst, Mathematik und wissenschaftlicher Beobachtung perfekt verkörpert.",
ladyErmine: "Dame mit Hermelin",
ermineDesc: "Porträt von Cecilia Gallerani, das eine innovative Dreiviertel-Pose und meisterhafte Darstellung von Licht, Textur und psychologischer Präsenz zeigt.",
legacyTitle: "Vermächtnis",
scientific: "Wissenschaftliche Methode",
scientificDesc: "Sein Ansatz von Beobachtung, Hypothese und Experimentation legte entscheidende Grundlagen für moderne wissenschaftliche Methodologie und empirische Forschungspraktiken.",
interdisciplinary: "Interdisziplinäre Innovation",
interDesc: "Demonstrierte, wie sich Kunst und Wissenschaft gegenseitig ergänzen können, und inspirierte den heutigen Ansatz zur kreativen Problemlösung in mehreren Bereichen.",
anatomical: "Anatomische Revolution",
anatomicalDesc: "Seine detaillierten Sektionen und Zeichnungen förderten das medizinische Verständnis und etablierten künstlerische Dokumentation als Werkzeug für wissenschaftliche Entdeckungen.",
modern: "Moderne Inspiration",
modernDesc: "Inspiriert weiterhin zeitgenössische Künstler, Ingenieure und Erfinder weltweit und repräsentiert das Ideal des lebenslangen Lernens und der grenzenlosen Neugier."
}
};
// -------------------------
// Language management
// -------------------------
function detectBrowserLanguage() {
const browserLang = navigator.language || navigator.userLanguage || 'en';
const langCode = browserLang.split('-')[0].toLowerCase();
return translations[langCode] ? langCode : 'en';
}
// initial detect
let currentLang = detectBrowserLanguage();
// -------------------------
// Image Carousel System
// -------------------------
function initImageCarousel() {
const images = document.querySelectorAll('.hero-image');
if (images.length <= 1) return;
let currentIndex = 0;
let isTransitioning = false;
let startX = 0;
let currentX = 0;
let isDragging = false;
function preloadImages() {
images.forEach(img => {
if (img.src) {
const preloadImg = new Image();
preloadImg.src = img.src;
}
});
}
function initCarousel() {
images.forEach((img, index) => {
img.style.zIndex = images.length - index;
img.classList.toggle('active', index === 0);
img.style.transform = 'translate(-50%, -50%) scale(1)';
img.style.transition = 'all 0.6s cubic-bezier(0.16, 1, 0.3, 1)';
});
}
function updateCarousel(direction) {
if (isTransitioning) return;
isTransitioning = true;
const currentImg = images[currentIndex];
currentImg.style.transition = 'all 0.6s cubic-bezier(0.16, 1, 0.3, 1)';
currentImg.classList.remove('active');
if (direction === 'next') {
currentIndex = (currentIndex + 1) % images.length;
} else {
currentIndex = (currentIndex - 1 + images.length) % images.length;
}
const nextImg = images[currentIndex];
currentImg.style.zIndex = 1;
nextImg.style.zIndex = 2;