Skip to content

Commit

Permalink
Apply BS3 data attribute mappings to added child elements too.
Browse files Browse the repository at this point in the history
Improved Bootstrap 3 compatibility layer to handle dynamically added content better by converting data attributes for child nodes of the added nodes as well.
  • Loading branch information
EreMaijala committed Jan 3, 2025
1 parent 8fb19dc commit c128ff4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions themes/bootstrap5/js/bs3-compat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*global VuFind*/
VuFind.register('bootstrap3CompatibilityLayer', function bootstrap3CompatibilityLayer() {
const data_attribute_selector = '[data-dismiss],[data-target],[data-toggle],[data-ride],[data-slide],[data-slide-to]';

function initNavbar() {
document.querySelectorAll('.navbar').forEach((el) => {
Expand Down Expand Up @@ -114,13 +115,14 @@ VuFind.register('bootstrap3CompatibilityLayer', function bootstrap3Compatibility
}

function initDataAttributeMappings() {
document.querySelectorAll('[data-dismiss],[data-target],[data-toggle],[data-ride],[data-slide],[data-slide-to]').forEach((el) => {
convertDataAttributes(el);
});
document.querySelectorAll(data_attribute_selector).forEach((el) => convertDataAttributes(el));
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((el) => {
convertDataAttributes(el);
if (typeof el.querySelectorAll !== 'undefined') {
el.querySelectorAll(data_attribute_selector).forEach((subEl) => convertDataAttributes(subEl));
}
});
});
});
Expand Down

0 comments on commit c128ff4

Please sign in to comment.