Fix slider behavior when using navigate back button (#8496)

Closes https://github.com/FreshRSS/FreshRSS/issues/8488

* Ensure leave confirmation is shown by preventing navigation using the [Navigation API](https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API)
* Prevent scroll lock by removing it on `hashchange` instead of `onclick` on the close buttons
This commit is contained in:
Inverle
2026-02-08 20:42:20 +01:00
committed by GitHub
parent d7848e9fd6
commit 6b5304b825
2 changed files with 27 additions and 4 deletions

View File

@@ -1125,8 +1125,8 @@ function init_column_categories() {
// Wait for dropdown to be closed so it can be removed
// Dropdown visibility is based on CSS :target
window.addEventListener('hashchange', () => {
dropdownMenu.nextElementSibling.remove(); // dropdown close
dropdownMenu.remove();
dropdownMenu?.nextElementSibling?.remove(); // dropdown close
dropdownMenu?.remove();
}, { once: true });
}, { once: true });
@@ -2359,12 +2359,25 @@ function init_main_beforeDOM() {
}
}
function init_navigation_handler() {
navigation.addEventListener('navigate', (e) => {
if (!(e.canIntercept && e.hashChange && e.navigationType === 'traverse')) {
return;
}
if (location.hash.substr(1) === 'slider' && !close_slider_listener()) {
e.preventDefault();
}
});
}
function init_main_afterDOM() {
removeFirstLoadSpinner();
init_notifications();
init_csp_alert();
init_confirm_action();
init_nav_menu();
init_navigation_handler();
const stream = document.getElementById('stream');
if (stream) {
init_load_more(stream);