Skip to content

Commit

Permalink
Fix tooltips for BS5 (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Apr 2, 2024
1 parent 83f4277 commit 59e45ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
19 changes: 18 additions & 1 deletion lib/QubitDescription.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,24 @@ public static function addAssets(sfWebResponse $response)
if (sfConfig::get('app_show_tooltips')) {
$response->addJavaScript('description', 'last');
} else {
$response->addStylesheet('hide_tooltips', 'last');
if (sfConfig::get('app_b5_theme')) { ?>
<script <?php echo sfConfig::get('csp_nonce', ''); ?>>
document.addEventListener('DOMContentLoaded', function() {
var accordionElements = document.querySelectorAll('.accordion-button');
accordionElements.forEach(function(element) {
element.addEventListener('click', function() {
const tooltipElements = document.querySelectorAll('[data-bs-toggle="tooltip"]');
tooltipElements.forEach(function (tooltip) {
tooltip.removeAttribute('data-bs-toggle');
tooltip.removeAttribute('data-bs-original-title');
});
});
});
});
</script>
<?php } else {
$response->addStylesheet('hide_tooltips', 'last');
}
}
}
}
23 changes: 18 additions & 5 deletions plugins/arDominionB5Plugin/js/tooltip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import Tooltip from "bootstrap/js/dist/tooltip";

document
.querySelectorAll("[data-bs-toggle=tooltip]")
.forEach((element) => new Tooltip(element));
document.addEventListener("DOMContentLoaded", function () {
if (
window.location.pathname.endsWith("/add") ||
window.location.pathname.endsWith("/edit")
) {
var elements = document.querySelectorAll('[id$="-help"]');
elements.forEach(function (idElement) {
idElement.style.display = "none";
parentElement = idElement.previousElementSibling;
if (parentElement != null) {
parentElement.setAttribute("data-bs-toggle", "tooltip");
parentElement.setAttribute("data-bs-placement", "left");
parentElement.setAttribute("title", idElement.textContent.trim());
var tooltip = new bootstrap.Tooltip(parentElement);
}
});
}
});

0 comments on commit 59e45ec

Please sign in to comment.