documentation/extensions/odoo_theme/static/js/switchers.js
Morgane (morm) b7bc34a197 [IMP] documentation: legal page design
Prior to this commit, the terms and conditions were displayed in a table
with all the languages and it was not practical for the futur, with many
more languages.

task-3073198

closes odoo/documentation#3058

Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
2022-12-07 10:45:41 +01:00

31 lines
1.2 KiB
JavaScript

(function ($) {
document.addEventListener('DOMContentLoaded', () => {
// Enable fallback URLs for broken redirects from the version or language switchers.
_prepareSwitchersFallbacks();
});
/**
* Add event listeners on links in the version and language switchers.
*
* If a link is clicked, the user is redirected to the closest fallback URL (including the
* original target URL) that is available.
*/
const _prepareSwitchersFallbacks = () => {
document.querySelectorAll('a[class="o_switcher_item"]').forEach(element => {
element.addEventListener('click', async event => {
if (element.hasAttribute('href')) {
const targetUrl = element.getAttribute('href');
if (!targetUrl.startsWith('/')) { // Don't test for valid URLs if in localhost.
event.preventDefault();
const fallbackUrls = await _generateFallbackUrls(targetUrl);
const fallbackUrl = await _getFirstValidUrl(fallbackUrls);
window.location.href = fallbackUrl;
}
}
});
});
};
})();