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 44fc045
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/descriptions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Descriptions', () => {
cy.visit('/informationobject/add')
cy.contains('Identity area').click()
cy.get('input#identifier').type('123')
cy.get('input#title').type('Test description A')
cy.get('input#title').type('Test description A', {force: true});
cy.get('#main-column form').submit()

cy.get('#main-column > h1').contains('123 - Test description A')
Expand Down
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');
}
}
}
}
22 changes: 17 additions & 5 deletions plugins/arDominionB5Plugin/js/tooltip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
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("title", idElement.textContent.trim());
var tooltip = new bootstrap.Tooltip(parentElement);
}
});
}
});

0 comments on commit 44fc045

Please sign in to comment.