From 29d65bed78718640a7c9a965866e2587b5f30c96 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 7 Jan 2018 00:55:45 +0100 Subject: [PATCH] Added a tooltip on hovering version numbers. Will show details soon. --- assets/main.coffee | 54 ++++++++++++++++++++++++++++++++++++++++++++++ assets/style.css | 15 +++++++++++-- index_main.php | 20 +++++++++++------ 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/assets/main.coffee b/assets/main.coffee index 985b0e5..d2b9a5a 100644 --- a/assets/main.coffee +++ b/assets/main.coffee @@ -25,3 +25,57 @@ document.addEventListener 'DOMContentLoaded', (event) -> activatePanel 'family-' + hash.substring 1 else activatePanel 'family-keyone' + + window.showTooltip = (event) -> + tt = document.querySelector('#tooltip') + tt_title = document.querySelector('#tooltip-title') + tt_text = document.querySelector('#tooltip-text') + + ref = event.target.parentNode.dataset.ref + ver = event.target.innerText + + tt_title.innerHTML = ver + tt_text.innerHTML = "for #{ref}" + + + # Show tooltip + tt.style.visibility = 'hidden' + tt.style.display = 'block' + positionTooltip event.clientX + window.scrollX, event.clientY + window.scrollY + tt.style.visibility = 'visible' + + window.positionTooltip = (mouseX, mouseY) -> + tooltip = document.querySelector '#tooltip' + + #pageHeight = document.documentElement.getBoundingClientRect().height + viewportBottom = document.documentElement.clientHeight + document.documentElement.scrollTop + viewportRight = document.documentElement.clientWidth + document.documentElement.scrollLeft + cursorOffset = 20 + tooltipHeight = tooltip.clientHeight + tooltipWidth = tooltip.clientWidth + + #console.log('Cursor: %o, Planned bottom: %o, Viewport bottom: %o', mouseY, mouseY+cursorOffset+tooltipHeight, viewportBottom) + + # Check if tooltip is outside bottom of document + if mouseY + cursorOffset + tooltipHeight >= viewportBottom + # show tooltip ABOVE cursor + tooltip.style.top = (mouseY - cursorOffset - tooltipHeight) + 'px' + else + # show tooltip below cursor + tooltip.style.top = (mouseY + cursorOffset) + 'px' + + if mouseX + cursorOffset + tooltipWidth >= viewportRight + # show tooltip LEFT of cursor + tooltip.style.left = (mouseX - cursorOffset - tooltipWidth) + 'px' + else + # show tooltip right of cursor + tooltip.style.left = (mouseX + cursorOffset) + 'px' + + versionitems = document.querySelectorAll '.version' + for vi in versionitems + vi.addEventListener 'mousemove', (event) -> + positionTooltip event.clientX + window.scrollX, event.clientY + window.scrollY + vi.addEventListener 'mouseover', (event) -> + showTooltip event + vi.addEventListener 'mouseout', (event) -> + document.querySelector('#tooltip').style.display = 'none' diff --git a/assets/style.css b/assets/style.css index 742bfe5..771c757 100644 --- a/assets/style.css +++ b/assets/style.css @@ -15,17 +15,28 @@ body { margin-top: 70px; } +#tooltip { + background-color: white; + z-index: 200; + position: absolute; + display: none; +} + +#tooltip h1 { + font-weight: bold; +} + table td+td { border-left: 1px dashed silver; text-align: center; } -td { +th, td { font-family: monospace; white-space: nowrap; } -td.ref { +th.ref { font-weight: bold; } diff --git a/index_main.php b/index_main.php index 4ff1487..f6718eb 100644 --- a/index_main.php +++ b/index_main.php @@ -64,22 +64,22 @@ foreach ($allVars as $family => $models) { $allVersions = $db->getAllVersionsForModel($model); echo ''; foreach ($variants as $ref => $name) { - echo ''; $refVersions = $db->getAllVersionsForRef($ref); $allOta = $db->getAllVersionsForRef($ref, $db::OTA_ONLY); foreach ($allVersions as $v) { if (in_array($v, $refVersions, true)) { - if (in_array($v, $allOta)) { - echo ''; - } else { - echo ''; + $moreClasses = ''; + if (!in_array($v, $allOta)) { + $moreClasses = ' fullonly mdc-theme--secondary-dark'; } + echo ''; } else { echo ''; } @@ -91,6 +91,14 @@ foreach ($allVars as $family => $models) { echo ''; } ?> +
+
+

Title

+
+
+ Contents here. +
+
'; + echo '
'; if (mb_strlen($name) > 0) { echo '' . $ref . ''; } else { echo $ref; } - echo ''; + echo '' . $v . '' . $v . '' . $v . '- - -