diff --git a/themes/finna2/js/finna-common.js b/themes/finna2/js/finna-common.js index a344f3187ac..9d230dd08fc 100644 --- a/themes/finna2/js/finna-common.js +++ b/themes/finna2/js/finna-common.js @@ -64,14 +64,17 @@ finna.common = (function finnaCommon() { */ function initResultsEventHandler() { VuFind.listen('results-load', () => { - setTimeout( - function focusHeading() { - const heading = document.getElementById("results-heading"); - if (heading) { - heading.focus(); + setTimeout(() => { + var storagedEl = window.sessionStorage.getItem('clickedMenu'); + if (storagedEl) { + window.sessionStorage.removeItem('clickedMenu'); + var focusedEl = document.querySelector(storagedEl); + if (focusedEl) { + focusedEl.focus(); } - }, - 200 + } + }, + 200 ); }); VuFind.listen('results-loaded', () => { @@ -91,16 +94,30 @@ finna.common = (function finnaCommon() { }; link.addEventListener('click', function handleClick(event) { event.preventDefault(); + window.sessionStorage.setItem('clickedMenu', `${type}-dropdown a.dropdown-toggle`); // Update button text: const dropdownEl = link.closest('.dropdown'); + const dropdownLabel = type === 'sort' ? 'Sort' : 'Results per page'; if (dropdownEl) { const toggleEl = dropdownEl.querySelector('.dropdown-toggle'); if (toggleEl) { + toggleEl.ariaLabel = VuFind.translate(dropdownLabel) + ': ' + VuFind.translate(link.innerText) + ' ' + VuFind.translate('selected'); const spanEl = toggleEl.querySelector('span'); if (spanEl) { spanEl.innerText = link.innerText; } } + const menuEl = dropdownEl.querySelector('.dropdown-menu'); + if (menuEl) { + menuEl.querySelectorAll("li > a").forEach(element => { + if (element.ariaDescription) { + element.removeAttribute("aria-description"); + } + if (element.innerText.trim() === toggleEl.innerText.trim()) { + element.ariaDescription = VuFind.translate('selected'); + } + }); + } } // Get relevant data from the link and change the hidden field accordingly: const urlParts = link.getAttribute('href').split('?', 2); diff --git a/themes/finna2/templates/layout/finna-js-translations.phtml b/themes/finna2/templates/layout/finna-js-translations.phtml index ff454f50916..d822f060a8f 100644 --- a/themes/finna2/templates/layout/finna-js-translations.phtml +++ b/themes/finna2/templates/layout/finna-js-translations.phtml @@ -21,6 +21,16 @@ $this->jsTranslations()->addStrings( 'show_filters' => 'show_filters', 'hide_filters' => 'hide_filters', + 'Sort' => 'Sort', + 'Results per page' => 'Results per page', + 'sort_relevance' => 'sort_relevance', + 'sort_year' => 'sort_year', + 'sort_year asc' => 'sort_year asc', + 'sort_callnumber' => 'sort_callnumber', + 'sort_author' => 'sort_author', + 'sort_title' => 'sort_title', + 'sort_last_indexed' => 'sort_last_indexed', + 'radiusPrefix' => 'Radius', 'circleCaption' => 'Select Area', 'clearCaption' => 'Clear Selections', diff --git a/themes/finna2/templates/search/controls/limit.phtml b/themes/finna2/templates/search/controls/limit.phtml index b0c5dd552af..899ae7a5a36 100644 --- a/themes/finna2/templates/search/controls/limit.phtml +++ b/themes/finna2/templates/search/controls/limit.phtml @@ -8,7 +8,7 @@