-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
778 lines (670 loc) · 28.5 KB
/
index.html
File metadata and controls
778 lines (670 loc) · 28.5 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EasySorting — Free Sorting Algorithm Visualizer | Bubble, Quick, Merge Sort & More</title>
<meta name="description"
content="Understand sorting algorithms visually — step by step, pass by pass. Explore Bubble Sort, Quick Sort, Merge Sort, Heap Sort, Radix Sort and more with interactive animations and code examples." />
<meta name="keywords"
content="sorting algorithm visualizer, bubble sort, quick sort, merge sort, heap sort, insertion sort, selection sort, radix sort, shell sort, sorting in c, sorting in python, learn sorting, data structures" />
<link rel="canonical" href="https://easysorting.netlify.app/" />
<meta name="author" content="Arun Neupane" />
<meta name="robots" content="index, follow" />
<link rel="icon" href="./images/sort.png" type="image/x-icon">
<meta name="google-adsense-account" content="ca-pub-1708134460872611">
<!-- Open Graph / Social Media -->
<meta property="og:type" content="website" />
<meta property="og:title" content="EasySorting — Free Sorting Algorithm Visualizer" />
<meta property="og:description"
content="Understand sorting algorithms visually — step by step. Explore Bubble Sort, Quick Sort, Merge Sort and more with interactive animations." />
<meta property="og:url" content="https://easysorting.netlify.app/" />
<meta property="og:image" content="https://easysorting.netlify.app/images/sort.png" />
<meta property="og:site_name" content="EasySorting" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="EasySorting — Sorting Algorithm Visualizer" />
<meta name="twitter:description"
content="Understand sorting algorithms step by step with interactive visualizations." />
<meta name="twitter:image" content="https://easysorting.netlify.app/images/sort.png" />
<!-- Google AdSense -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1708134460872611"
crossorigin="anonymous"></script>
<!-- JSON-LD Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "EasySorting",
"url": "https://easysorting.netlify.app",
"description": "Free interactive sorting algorithm visualizer covering Bubble Sort, Quick Sort, Merge Sort, Heap Sort, Radix Sort, Shell Sort and more.",
"author": {
"@type": "Person",
"name": "Arun Neupane",
"url": "https://arunneupane.netlify.app/"
},
"potentialAction": {
"@type": "SearchAction",
"target": "https://easysorting.netlify.app"
}
}
</script>
<link rel="manifest" href="./manifest.json">
<!-- For ios -->
<link rel="apple-touch-icon" href="./images/sort.png">
<meta name="apple-mobile-web-app-status-bar" content="1338BE">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#installButton {
display: none;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #141414 0%, #000000 100%);
color: #ecf0f1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
cursor: none;
}
.home-about-section {
max-width: 1000px;
width: 100%;
margin: 3rem auto 0;
padding: 2rem;
background: rgba(44, 62, 80, 0.4);
border-radius: 12px;
border-top: 2px solid #3498db;
}
.home-about-section h2 {
font-size: 1.5rem;
color: #4a9eff;
margin: 1.5rem 0 0.75rem;
border-bottom: 1px solid #2c3e50;
padding-bottom: 0.4rem;
}
.home-about-section h2:first-child {
margin-top: 0;
}
.home-about-section p {
font-size: 1rem;
color: #bdc3c7;
line-height: 1.8;
text-align: justify;
margin-bottom: 0.75rem;
}
.home-features-list {
padding-left: 1.5rem;
margin: 0.75rem 0 1rem;
color: #bdc3c7;
}
.home-features-list li {
margin-bottom: 0.5rem;
line-height: 1.7;
}
*:not(input):not(textarea) {
caret-color: transparent;
}
.icon-container {
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
.icon-container img {
width: 50px;
height: 50px;
}
h1 {
font-size: 2.5rem;
color: #ecf0f1;
margin-bottom: 20px;
text-align: center;
}
p {
font-size: 1.2rem;
color: #bdc3c7;
margin-bottom: 40px;
text-align: center;
}
.container {
max-width: 1000px;
width: 100%;
text-align: center;
}
.algorithm-list {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
gap: 20px;
padding: 0 20px;
}
.algorithm-list a {
text-decoration: none;
color: inherit;
}
.algorithm-list a:focus,
.algorithm-list a:active {
text-decoration: none;
outline: none;
}
.algorithm-item {
background-color: #2c3e50;
padding: 30px;
border-radius: 10px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
transition: transform 0.3s ease, background-color 0.3s ease, box-shadow 0.5s ease;
text-align: center;
}
.algorithm-item:hover {
transform: translate(-10px);
background-color: #34495e;
box-shadow: 0 0 3px 2px#007bff;
}
.algorithm-item img {
width: 50px;
margin-bottom: 15px;
}
.algorithm-item h2 {
font-size: 1.4rem;
color: #f0f6f8;
margin-bottom: 10px;
}
.algorithm-item p {
font-size: 1rem;
color: #f7feff;
}
footer {
margin-top: 50px;
font-size: 0.9rem;
color: #7f8c8d;
}
footer a {
color: #3498db;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
::-webkit-scrollbar {
width: 0px;
height: 0px;
}
.progress-bar-container {
display: none;
position: fixed;
top: 0;
right: 0;
width: 10px;
height: 100vh;
background-color: #f1f1f1;
}
.progress-bar {
width: 100%;
height: 0;
background-color: #007bff;
transition: height 0.2s ease;
}
.cursor {
position: absolute;
z-index: 99;
transform: translate(-50%, -50%);
pointer-events: none;
transition: height 0.15s ease, width 0.15s ease, opacity 0.25s ease;
}
.big {
width: 30px;
height: 30px;
border-radius: 50%;
background: linear-gradient(250deg, #f8bd0e, #40fc06);
}
.small {
width: 15px;
height: 15px;
background-color: transparent;
border: 1px solid white;
border-radius: 50%;
}
.big.mouse-down {
width: 45px;
height: 45px;
background: transparent;
border: 1px solid white;
}
.small.mouse-down {
width: 0;
height: 0;
}
/* Custom Context Menu */
#context-menu {
width: 220px;
position: absolute;
z-index: 10;
display: none;
background-color: #333;
border: 1px solid #666;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
color: #f0f0f0;
border-radius: 8px;
}
#context-menu ul {
list-style: none;
padding: 0;
margin: 0;
}
/* Top-level menu items */
#context-menu li {
padding: 12px 20px;
border-bottom: 1px solid #555;
cursor: pointer;
transition: background-color 0.2s ease;
}
#context-menu li:hover {
background-color: #555;
}
.submenu {
display: none;
position: absolute;
height: inherit;
width: 200px;
left: 100%;
top: 0;
background-color: #444;
border: 1px solid #777;
box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.4);
color: #f0f0f0;
border-radius: 6px;
}
.submenu li {
width: 50px;
display: flex;
align-items: center;
justify-content: center;
}
/* Icon styling */
#context-menu .icon {
width: 30px;
height: 30px;
filter: brightness(0.9);
transition: transform 0.4s ease, filter 0.3s ease;
}
.icon:hover {
transform: rotate(360deg) scale(1.1);
filter: brightness(1.2) hue-rotate(30deg);
}
@media (max-width:768px) {
.progress-bar-container {
display: block;
}
}
.scroll-animate {
opacity: 0;
transform: translateY(20px) scale(0.5);
transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}
.scroll-animate.show {
opacity: 1;
transform: translateY(0) scale(1);
}
@media (pointer: coarse) {
body {
cursor: auto;
}
.cursor {
display: none;
}
}
#install-button-mobile {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
background-color: #1DB954;
color: white;
border: none;
padding: 12px 20px;
border-radius: 25px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
font-size: 16px;
cursor: pointer;
z-index: 1;
}
</style>
</head>
<body>
<div class="progress-bar-container">
<div class="progress-bar"></div>
</div>
<div id="context-menu" class="hidden">
<ul>
<li onclick="window.location.reload(true);">Refresh</li>
<li onclick="window.open('./contact.html','_self')">
Contact
</li>
<li>
Share
<ul class="submenu">
<li class="submenu-item">
<a href="https://www.facebook.com/sharer/sharer.php?u=https://easysorting.netlify.app"e=Hey%20check%20out%20this%20sorting%20algorithm%20visualizer"
target="_blank" rel="noopener">
<img src="./images/svg-icons/facebook.svg" alt="Facebook" class="icon">
</a>
</li>
<li class="submenu-item">
<a href="https://www.instagram.com" target="_blank" rel="noopener">
<img src="./images/svg-icons/instagram.svg" alt="Instagram" class="icon">
</a>
</li>
<li class="submenu-item">
<a href="https://wa.me/?text=Hey%20check%20out%20this%20sorting%20algorithm%20visualizer%20-%20https://easysorting.netlify.app"
target="_blank" rel="noopener">
<img src="./images/svg-icons/whatsapp.svg" alt="Whatsapp" class="icon">
</a>
</li>
<li class="submenu-item">
<a href="https://t.me/share/url?url=https://easysorting.netlify.app&text=Hey%20check%20out%20this%20sorting%20algorithm%20visualizer"
target="_blank" rel="noopener">
<img src="./images/svg-icons/telegram.svg" alt="Telegram" class="icon">
</a>
</li>
</ul>
</li>
<li>
Follow me
<ul class="submenu">
<li class="submenu-item">
<a href="https://www.facebook.com/arunneupane9000/" target="_blank" rel="noopener">
<img src="./images/svg-icons/facebook.svg" alt="Facebook" class="icon">
</a>
</li>
<li class="submenu-item">
<a href="https://www.instagram.com/arundada9000" target="_blank" rel="noopener">
<img src="./images/svg-icons/instagram.svg" alt="Instagram" class="icon">
</a>
</li>
<li class="submenu-item">
<a href="https://www.github.com/arundada9000" target="_blank" rel="noopener">
<img src="./images/svg-icons/github.svg" alt="Telegram" class="icon">
</a>
</li>
<li class="submenu-item">
<a href="https://www.youtube.com/@code_with_ease" target="_blank" rel="noopener">
<img src="./images/svg-icons/youtube.svg" alt="Youtube" class="icon">
</a>
</li>
</ul>
</li>
<li onclick="window.open('./feedback.html','_self')">
Feedback
</li>
<li id="installButton">Install</li>
</ul>
</div>
<div class="cursor big"></div>
<div class="cursor small"></div>
<div class="container">
<div class="icon-container">
<img src="./images/reorder.gif" alt="Sorting">
<h1>Sorting Algorithms Visualizer</h1>
</div>
<p>Explore different sorting algorithms and understand how they work, step-by-step. Click
on any algorithm below
to start the visualization!</p>
<div class="algorithm-list">
<a href="./bubbleSort.html" class="algorithm-item scroll-animate">
<!-- <img src="images/bubble_sort_icon.png" alt="Bubble Sort Icon"> -->
<div class="icon-container">
<img src="./images/bubble.webp" alt="Bubble sort">
<h2>Bubble Sort</h2>
</div>
<p>Compares adjacent elements and swaps them if they're in the wrong order.</p>
</a>
<a href="./selectionSort.html" class="algorithm-item scroll-animate">
<div class="icon-container">
<img src="./images/selection.webp" alt="Selection sort">
<h2>Selection Sort</h2>
</div>
<p>Finds the smallest element in the array and places it at the front.</p>
</a>
<a href="./insertionSort.html" class="algorithm-item scroll-animate">
<!-- <img src="images/insertion_sort_icon.png" alt="Insertion Sort Icon"> -->
<div class="icon-container">
<img src="./images/insertion.webp" alt="Insertion sort">
<h2>Insertion Sort</h2>
</div>
<p>Builds the sorted array by inserting elements in their correct position.</p>
</a>
<a href="./mergeSort.html" class="algorithm-item scroll-animate">
<!-- <img src="images/merge_sort_icon.png" alt="Merge Sort Icon"> -->
<div class="icon-container">
<img src="./images/merge.webp" alt="Merge sort">
<h2>Merge Sort</h2>
</div>
<p>Divides the array, sorts them, and merges them back together.</p>
</a>
<a href="./quickSort.html" class="algorithm-item scroll-animate">
<!-- <img src="images/quick_sort_icon.png" alt="Quick Sort Icon"> -->
<div class="icon-container">
<img src="./images/quick.webp" alt="Quick sort">
<h2>Quick Sort</h2>
</div>
<p>Uses a pivot to partition the array and sorts each partition.</p>
</a>
<a href="./heapSort.html" class="algorithm-item scroll-animate">
<!-- <img src="images/heap_sort_icon.png" alt="Heap Sort Icon"> -->
<div class="icon-container">
<img src="./images/heap.webp" alt="Heap sort">
<h2>Heap Sort</h2>
</div>
<p>Transforms the array into a heap structure and sorts it.</p>
</a>
<a href="./radixSort.html" class="algorithm-item scroll-animate">
<!-- <img src="images/radix_sort_icon.png" alt="Radix Sort Icon"> -->
<div class="icon-container">
<img src="./images/radix.webp" alt="Radix sort">
<h2>Radix Sort</h2>
</div>
<p>Sorts numbers by processing individual digits from least to most significant.</p>
</a>
<a href="./shellSort.html" class="algorithm-item scroll-animate">
<!-- <img src="images/shell_sort_icon.png" alt="Shell Sort Icon"> -->
<div class="icon-container">
<img src="./images/shell.webp" alt="Shell sort">
<h2>Shell Sort</h2>
</div>
<p>Sorts elements by comparing elements at a gap and reducing the gap over time.</p>
</a>
<a href="./summary.html" class="algorithm-item scroll-animate">
<!-- <img src="images/shell_sort_icon.png" alt="Shell Sort Icon"> -->
<div class="icon-container">
<img src="./images/summary.png" alt="Summary">
<h2>Summary</h2>
</div>
<p>Summary of all the sorting algorithms their worst, average and best case complexities in one table.
</p>
</a>
</div>
<!-- Educational Content Section for SEO -->
<section class="home-about-section" aria-label="About sorting algorithms">
<h2>What Are Sorting Algorithms?</h2>
<p>A <strong>sorting algorithm</strong> is a method for reorganizing a collection of items such as numbers,
letters, or records into a specific order, typically ascending or descending. Sorting is one of the most
fundamental operations in computer science, forming the backbone of efficient data retrieval, search
operations, and data processing pipelines.</p>
<p>Whether you are a student learning data structures for the first time, a developer preparing for
technical interviews, or a professional brushing up on algorithm fundamentals, understanding sorting
algorithms is essential. Each algorithm has unique properties in terms of <strong>time
complexity</strong>, <strong>space complexity</strong>, and real-world applicability.</p>
<h2>Why Learn Sorting Algorithms Visually?</h2>
<p>Sorting algorithms can be difficult to grasp from text or pseudocode alone. That's exactly why
<strong>EasySorting</strong> was created to let you <em>see</em> each algorithm in action, pass by pass,
comparison by comparison. You can:</p>
<ul class="home-features-list">
<li>Enter your own array of numbers and watch it get sorted in real time</li>
<li>Generate a random array with one click and observe the algorithm's behavior</li>
<li>Track every comparison and swap with color-coded visual indicators</li>
<li>Review every pass in full detail below the visualization</li>
<li>Copy ready-to-run code in C, C++, Java, Python, and JavaScript</li>
</ul>
<h2>Sorting Algorithms Covered</h2>
<p>EasySorting covers <strong>8 major sorting algorithms</strong>, each explained with history, time and
space complexity, pseudocode, and step-by-step visualization:</p>
<ul class="home-features-list">
<li><strong>Bubble Sort:</strong> The classic beginner algorithm — compares adjacent elements and swaps
them repeatedly. O(n²) worst case.</li>
<li><strong>Selection Sort:</strong> Finds the smallest element and places it at the front in each pass.
O(n²) in all cases.</li>
<li><strong>Insertion Sort:</strong> Builds the sorted list one item at a time, ideal for nearly sorted
data. O(n) best case.</li>
<li><strong>Merge Sort:</strong> Divide and conquer approach splits the array and merges sorted halves.
O(n log n) guaranteed.</li>
<li><strong>Quick Sort:</strong> Uses a pivot element to partition the array. Average O(n log n), very
fast in practice.</li>
<li><strong>Heap Sort:</strong> Builds a max-heap structure and extracts elements in order. O(n log n)
always.</li>
<li><strong>Radix Sort:</strong> A non-comparison sort that processes digits. Extremely fast for integer
data with O(nk) complexity.</li>
<li><strong>Shell Sort:</strong> An improved insertion sort that compares elements at a gap. O(n log n)
to O(n²) depending on the gap sequence.</li>
</ul>
<p>Click on any algorithm above to begin the interactive visualization. Happy Learning! 🎉</p>
</section>
</div>
<button id="install-button-mobile" aria-label="Install app">Install</button>
<footer class="scroll-animate" role="contentinfo">
<p class="scroll-animate">Created by <a href="https://arunneupane.netlify.app/" target="_blank"
rel="noopener noreferrer">Arun Neupane</a></p>
<p class="scroll-animate">
<a href="./about.html">About</a> |
<a href="./feedback.html">Feedback</a> |
<a href="./contact.html">Contact</a> |
<a href="./privacy-policy.html">Privacy Policy</a>
</p>
<p class="scroll-animate" style="font-size:0.8rem;color:#7f8c8d;">© <span id="copy-year"></span>
EasySorting. All rights reserved.</p>
</footer>
<script src="./app.js"></script>
<script>
window.addEventListener("scroll", function () {
const scrollTop = window.scrollY;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollPercent = (scrollTop / docHeight) * 100;
document.querySelector(".progress-bar").style.height = scrollPercent + "%";
});
// scroll animate
const animatedElements = document.querySelectorAll('.scroll-animate');
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('show');
} else {
entry.target.classList.remove('show');
}
});
}, {
threshold: 0.25
});
animatedElements.forEach(element => observer.observe(element));
// Custom cursor
const cursor = document.querySelectorAll(".cursor");
let big_cursor = document.querySelector(".big");
let small_cursor = document.querySelector(".small");
const isTouchDevice = "ontouchstart" in window || navigator.maxTouchPoints > 0;
if (!isTouchDevice) {
document.documentElement.addEventListener("mousemove", (event) => {
if (hasPointerCursor(event.target)) {
big_cursor.classList.add("mouse-down");
small_cursor.classList.add("mouse-down");
} else {
if (big_cursor.classList.contains("mouse-down")) {
big_cursor.classList.remove("mouse-down");
small_cursor.classList.remove("mouse-down");
}
}
// cursor.forEach((item) => (item.style.opacity = hasPointerCursor(event.target)?0:1));
big_cursor.style.top = event.clientY + window.scrollY + "px";
big_cursor.style.left = event.clientX + window.scrollX + "px";
setTimeout(() => {
small_cursor.style.top = event.clientY + window.scrollY + "px";
small_cursor.style.left = event.clientX + window.scrollX + "px";
}, 150);
});
document.documentElement.addEventListener("mouseleave", () => {
cursor.forEach((item) => (item.style.opacity = 0));
});
document.documentElement.addEventListener("mouseenter", () => {
cursor.forEach((item) => (item.style.opacity = 1));
});
} else {
document.body.style.cursor = "auto";
}
document.body.addEventListener("mousedown", () => {
big_cursor.classList.add("mouse-down");
});
document.body.addEventListener("mouseup", () => {
big_cursor.classList.remove("mouse-down");
});
function hasPointerCursor(element) {
while (element) {
if (getComputedStyle(element).cursor === "pointer") {
return true;
}
element = element.parentElement;
}
return false;
}
const contextMenu = document.getElementById('context-menu');
document.addEventListener('contextmenu', (event) => {
event.preventDefault();
contextMenu.style.display = 'block';
const x = event.clientX;
const y = event.clientY;
const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight;
const scrollY = window.scrollY;
const scrollX = window.scrollX;
const menuWidth = contextMenu.offsetWidth;
const menuHeight = contextMenu.offsetHeight;
let left = x + scrollX;
let top = y + scrollY;
if (left + menuWidth > windowWidth + scrollX) {
left = windowWidth + scrollX - menuWidth;
}
if (top + menuHeight > windowHeight + scrollY) {
top = windowHeight + scrollY - menuHeight;
}
contextMenu.style.left = left + 'px';
contextMenu.style.top = top + 'px';
const submenus = contextMenu.querySelectorAll('.submenu');
submenus.forEach(submenu => {
const parentLi = submenu.parentElement;
parentLeft = parentLi.getBoundingClientRect();
submenu.style.top = parentLi.offsetTop + 'px';
parentLi.addEventListener('mouseenter', () => {
submenu.style.display = 'flex';
const submenuWidth = submenu.offsetWidth;
if (parentLeft.right + submenuWidth > windowWidth + scrollX) {
submenu.style.left = menuWidth - (2 * submenuWidth) - 20 + 'px';
} else {
submenu.style.left = menuWidth - 2 + 'px';
}
});
parentLi.addEventListener('mouseleave', () => {
submenu.style.display = 'none';
});
});
});
document.addEventListener('click', () => {
contextMenu.style.display = 'none';
});
// Dynamic copyright year
const copyYearEl = document.getElementById('copy-year');
if (copyYearEl) copyYearEl.textContent = new Date().getFullYear();
</script>
</body>
</html>