File "code021.php"
Full Path: /home/analogde/www/2024_PHP_02_11_2024/angular/code021.php
File size: 3.65 KB
MIME-type: text/html
Charset: utf-8
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tree Viewer avec menu contextuel</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
.context-menu {
display: none;
position: absolute;
background-color: #fff;
border: 1px solid #ccc;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
z-index: 1000;
}
.context-menu ul {
list-style: none;
padding: 0;
margin: 0;
}
.context-menu ul li {
padding: 10px;
cursor: pointer;
}
.context-menu ul li:hover {
background-color: #f0f0f0;
}
.list-item-span {
display: inline-block;
padding: 5px;
cursor: pointer;
}
.list-title {
font-weight: bold;
margin-bottom: 10px;
display: block;
cursor: pointer;
}
.list-content {
display: none;
margin-left: 20px;
padding-left: 15px;
border-left: 1px dashed #ccc;
list-style-type: none; /* Masquer les bullets */
}
.list-content li {
position: relative;
padding-left: 20px;
margin-bottom: 10px;
list-style-type: none; /* Masquer les bullets */
}
.list-content li::before {
content: '';
position: absolute;
left: -15px;
top: 10px;
width: 10px;
height: 1px;
background: #ccc;
}
.list-content li::after {
content: '';
position: absolute;
left: -15px;
top: 0;
width: 1px;
height: 100%;
background: #ccc;
}
.context-menu-link {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 200px; /* Ajustez cette valeur selon vos besoins */
}
.context-menu-link a {
text-decoration: none;
}
</style>
</head>
<body>
<h1>Tree Viewer avec menu contextuel</h1>
<div id="listContainer"></div>
<div id="contextMenu" class="context-menu">
<ul>
<li onclick="handleOption1()">Option 1</li>
<li onclick="handleOption2()">Option 2</li>
<li onclick="handleOption3()">Option 3</li>
<li id="contextMenuLink" class="context-menu-link"><a href="#">Lien vers une autre page</a></li>
</ul>
</div>
<script>
const contextMenu = document.getElementById('contextMenu');
const contextMenuLink = document.getElementById('contextMenuLink').querySelector('a');
// Fonction pour générer la liste à partir des données JSON
function generateList(data) {
const listContainer = document.getElementById('listContainer');
listContainer.innerHTML = '';
Object.keys(data).forEach(listName => {
const listDiv = document.createElement('div');
listDiv.className = 'list-container';
const listTitle = document.createElement('span');
listTitle.className = 'list-title';
listTitle.innerHTML = `<i class="fas fa-folder"></i> ${listName} (${data[listName].length} éléments)`;
listTitle.setAttribute('data-list', listName.replace(/\s+/g, ''));
listDiv.a