Last version
by velo_ninja
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Menu with Submenus</title>
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">-->
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
<style>
</style>
<script>
let menuData = [
{
id: 'item1',
title: 'Project-1',
submenu: [
{
id: 'subitem1',
title: 'Sub-Project',
submenu: [
{ id: 'subsubitem1', title: 'Document PDF', url: 'https://example.com/file1.pdf' },
{ id: 'subsubitem2', title: 'Document PDF', url: 'https://example.com/file2.pdf' },
{ id: 'subsubitem3', title: 'Document PDF', url: 'https://example.com/file3.pdf' },
{ id: 'subsubitem4', title: 'Document PDF', url: 'https://example.com/file4.pdf' },
{ id: 'subsubitem5', title: 'Word Document DOCX', url: 'https://example.com/file5.docx' },
]
},
{
id: 'subitem2',
title: 'Sub-Project2',
submenu: [
{ id: 'subsubitem6', title: 'Spreadsheet XLS', url: 'https://example.com/file6.xls' },
{ id: 'subsubitem7', title: 'Spreadsheet XLSM', url: 'https://example.com/file7.xlsm' },
{ id: 'subsubitem8', title: 'Spreadsheet XLSB', url: 'https://example.com/file8.xlsb' },
{ id: 'subsubitem9', title: 'Spreadsheet XLTX', url: 'https://example.com/file9.xltx' },
...
CSS
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: white;
}
.circle-menu {
display: flex;
justify-content: center;
align-items: center;
background-color: rgb(83, 82, 80);
}
.menu-item {
position: relative;
padding: 15px;
margin: 5px;
border-radius: 50%;
cursor: pointer;
color: #ffffff;
text-align: center;
font-size: 14px;
background-color: rgb(41, 40, 40);
transition: background-color 0.3s ease, transform 0.3s ease;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.menu-item:hover {background-color: black;}
.submenu-container li {
margin: 5px 0;
padding: 10px;
background-color: #858484;
color: #ffffff;
border-radius: 15%;
cursor: pointer;
transition: background-color 0.3s ease;
}
.submenu-container {
position: absolute;
background-color: transparent;
padding: 3px;
border-radius: 25px;
min-width: 150px;
min-width: 175px;
margin-left: 10px;
z-index: 1000;
white-space: nowrap;
}
.submenu-container li:hover {background-color: black;}
.icon-and-text {
display: flex;
align-items: center;
gap: 5px; /* Space between icon and text */
}
.degree-mark {
position: absolute;
width: 1px;
height: 1px;
background-color: white;
}
.degree-label {
position: absolute;
font-size: 10px;
color: white;
text-align: center;
}
.hamburger-button {
cursor: pointer;
font-size: 24px;
color: #333;
margin: 10px;
}
.hamburger-menu ul {
list-style-type: none;
padding: 0;
margin: 0;
}
.hamburger-menu li {
margin: 5px...
JavaScript
function insertIcon(iconClassOrUrl, size, color, styleClass, targetElement) {
// Define size and style class mappings
const sizeMapping = {small: 'fa-1x', standard: 'fa-2x', medium: 'fa-3x', big: 'fa-4x'};
const styleClassMapping = {
brand: 'fab', solid: 'fas', regular: 'far', light: 'fal', thin: 'fat', duotone: 'fad',
sharpSolid: 'fass fa-sharp fa-solid', sharpRegular: 'fasr fa-sharp fa-regular',
sharpLight: 'fasl fa-sharp fa-light', sharpThin: 'fast fa-sharp fa-thin',
sharpDuotoneSolid: 'fasds fa-sharp-duotone fa-solid'
};
const iconMapping = {
pdf: 'file-pdf', png: 'file-image', jpg: 'file-image', jpeg: 'file-image', pptx: 'file-powerpoint',
gif: 'file-image', txt: 'file-alt', xls: 'file-excel', xla: 'file-excel', csv: 'file-csv',
xlam: 'file-excel', xltm: 'file-excel', xltx: 'file-excel', xlsb: 'file-excel', zip: 'file-archive',
xlsm: 'file-excel', xlsx: 'file-excel', csv: 'file-csv', docx: 'file-word', mp3: 'file-audio',
mp4: 'file-video', default: 'folder' // Default icon if no URL is detected
};
const colorMapping = {
pdf: 'red', png: 'white', jpg: 'white', jpeg: 'white', gif: 'white', txt: 'gray', pptx: 'orange',
xlsx: 'green', docx: 'lightblue', zip: 'purple', csv: 'lightgreen', mp3: 'darkblue', mp4: 'darkred',
folder: 'orange', default: color // Default color if no URL is detected
};
// Extract the file extension from the URL
function extractFileExtension(url) {
const match = url.match(/\.(\w+)(?:\?.*)?$/);
return match ? match[1].toLowerCase() : null;
}
// Get the icon class based on the file extension
function...