Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions js/oda_front.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
(function () {
'use strict';

// Wait for DOM to be ready
document.addEventListener('DOMContentLoaded', function () {
// Get all buttons that have nested ul elements
const menuButtons = document.querySelectorAll('ul > li > button');

menuButtons.forEach(function (button) {
const listItem = button.parentElement;
const nestedList = listItem.querySelector('ul');

// Only add click handlers if there's a nested list
if (nestedList) {
// Add the id to the nested list based on aria-labelledby
const ariaLabelledBy = button.getAttribute('aria-labelledby');
if (ariaLabelledBy) {
nestedList.setAttribute('id', ariaLabelledBy);
}

// Hide the nested list initially
nestedList.style.display = 'none';

// Add click handler to the button
button.addEventListener('click', function (e) {
e.stopPropagation();

// Check if this menu is currently open
const isOpen = nestedList.style.display === 'block';

// Close all menus and remove active class from all buttons
menuButtons.forEach(function (otherButton) {
const otherListItem = otherButton.parentElement;
const otherNestedList = otherListItem.querySelector('ul');
if (otherNestedList) {
otherNestedList.style.display = 'none';
}
otherButton.classList.remove('active');
});

// Toggle this menu - if it was closed, open it
if (!isOpen) {
nestedList.style.display = 'block';
button.classList.add('active');
}
});
}
});

// Close all menus when clicking anywhere else on the page
document.addEventListener('click', function (e) {
// Check if the click was outside all menu buttons and nested lists
const clickedInsideMenu = e.target.closest('ul > li > button') || e.target.closest('ul > li > ul');

if (!clickedInsideMenu) {
menuButtons.forEach(function (button) {
const listItem = button.parentElement;
const nestedList = listItem.querySelector('ul');
if (nestedList) {
nestedList.style.display = 'none';
}
button.classList.remove('active');
});
}
});

// Select '.oda-lock' elements and add "title='Login required'" if not present
const lockElements = document.querySelectorAll('.oda-lock');
lockElements.forEach(function (lockElement) {
if (!lockElement.hasAttribute('title')) {
lockElement.setAttribute('title', 'Login required');
}
});

});
})();
3 changes: 3 additions & 0 deletions oda.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ oit_data_report_page_form:
data_report_layout:
js:
js/data_report_layout.js: {}
oda_front:
js:
js/oda_front.js: {}
3 changes: 3 additions & 0 deletions oda.module
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ function oda_page_attachments(array &$attachments): void {
if ($node->getType() == 'data_report') {
$attachments['#attached']['library'][] = 'oda/node_page';
}
if ($node->id() == 32349) {
$attachments['#attached']['library'][] = 'oda/oda_front';
}
}
}

Expand Down
Loading