Skip to content

Commit 4914e3b

Browse files
committed
Add tooltip system
Signed-off-by: tdruez <[email protected]>
1 parent 9864acd commit 4914e3b

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

scancodeio/static/main.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,47 @@ a[target="_blank"] .fa-up-right-from-square {
242242
.is-wider-x2 .dropdown-menu {
243243
min-width: 24rem;
244244
}
245+
.tooltip {
246+
position: absolute;
247+
background-color: rgb(var(--custom-tooltip-bg-rgb));
248+
color: var(--bulma-white);
249+
padding: var(--custom-tooltip-padding);
250+
border-radius: var(--bulma-radius-small);
251+
font-size: var(--bulma-size-small);
252+
width: max-content;
253+
opacity: 0;
254+
transition: opacity 0.3s ease;
255+
pointer-events: none;
256+
text-align: center;
257+
word-wrap: break-word;
258+
z-index: 9999;
259+
}
260+
.tooltip.visible {
261+
opacity: 1;
262+
}
263+
.tooltip.top {
264+
bottom: 100%;
265+
}
266+
.tooltip.bottom {
267+
top: 100%;
268+
}
269+
.tooltip.left {
270+
right: 0;
271+
}
272+
.tooltip.right {
273+
left: 0;
274+
}
275+
.tooltip.center {
276+
left: 50%;
277+
transform: translateX(-50%);
278+
}
279+
.tooltip:not(.top):not(.bottom) {
280+
bottom: 100%;
281+
}
282+
.tooltip:not(.left):not(.right):not(.center) {
283+
left: 50%;
284+
transform: translateX(-50%);
285+
}
245286
.copy-to-clipboard {
246287
position: relative;
247288
}

scancodeio/static/main.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,42 @@ class PaginationNavigator {
356356
}
357357
}
358358

359+
// Tooltips
360+
361+
function enableTooltips() {
362+
// Enable tooltips on elements with 'has-tooltip' class
363+
const elements = document.querySelectorAll('.has-tooltip');
364+
365+
elements.forEach(element => {
366+
let tooltip = null;
367+
368+
element.addEventListener('mouseenter', () => {
369+
// Get tooltip text from data-title or title attribute
370+
const tooltipText = element.getAttribute('data-title') || element.getAttribute('title');
371+
if (!tooltipText) return;
372+
373+
// Get position classes from data attribute
374+
const positionClasses = element.getAttribute('data-tooltip-position') || '';
375+
376+
// Create tooltip
377+
tooltip = document.createElement('span');
378+
tooltip.classList.add('tooltip', 'visible');
379+
if (positionClasses) {
380+
tooltip.classList.add(...positionClasses.split(' '));
381+
}
382+
tooltip.textContent = tooltipText;
383+
element.appendChild(tooltip);
384+
});
385+
386+
element.addEventListener('mouseleave', () => {
387+
if (tooltip && element.contains(tooltip)) {
388+
element.removeChild(tooltip);
389+
tooltip = null;
390+
}
391+
});
392+
});
393+
}
394+
359395
// Copy to Clipboard (using `navigator.clipboard`)
360396

361397
function enableCopyToClipboard(selector) {
@@ -413,6 +449,7 @@ document.addEventListener('DOMContentLoaded', function () {
413449
setupTextarea();
414450
setupHighlightControls();
415451
setupSelectCheckbox();
452+
enableTooltips();
416453
enableCopyToClipboard(".copy-to-clipboard");
417454

418455
const paginationContainer = document.querySelector("#pagination-header");
@@ -468,6 +505,7 @@ document.addEventListener('DOMContentLoaded', function () {
468505
document.body.addEventListener("htmx:afterSwap", function(evt) {
469506
// Call the following functions after a HTMX swap is done.
470507
setupTabs();
508+
enableTooltips();
471509
enableCopyToClipboard(".copy-to-clipboard");
472510
});
473511

scanpipe/templates/scanpipe/tree/resource_left_pane_header.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<div class="is-flex is-align-items-center mb-2">
2-
<button id="hide-left-pane" class="button is-light px-2">
2+
<button
3+
id="hide-left-pane"
4+
class="button is-light px-2 has-tooltip"
5+
data-title="Hide resource tree"
6+
data-tooltip-position="bottom right">
37
<i class="fa-solid fa-square-caret-left"></i>
48
</button>
59
<div class="is-size-5 has-text-weight-semibold ml-2">

scanpipe/templates/scanpipe/tree/resource_path_breadcrumb.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<nav class="breadcrumb is-flex is-align-items-center" aria-label="breadcrumbs">
2-
<button id="expand-left-pane" class="button is-light px-2 mr-2 is-hidden">
2+
<button
3+
id="expand-left-pane"
4+
class="button is-light px-2 mr-2 has-tooltip is-hidden"
5+
data-title="Show resource tree"
6+
data-tooltip-position="bottom right">
37
<i class="fa-solid fa-square-caret-right"></i>
48
</button>
59
<ul>

0 commit comments

Comments
 (0)