36 lines
708 B
JavaScript
36 lines
708 B
JavaScript
/**
|
|
* Skip to content functionality with modern ES syntax
|
|
*/
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// Wait for jQuery to be defined
|
|
const checkJQuery = () => {
|
|
if (window.jQuery) {
|
|
initSkipToContent(jQuery);
|
|
} else {
|
|
setTimeout(checkJQuery, 50);
|
|
}
|
|
};
|
|
|
|
checkJQuery();
|
|
});
|
|
|
|
function initSkipToContent($) {
|
|
$('.skip-to-content').click(e => {
|
|
skipTo();
|
|
e.preventDefault();
|
|
});
|
|
|
|
$('.skip-to-content').keyup(e => {
|
|
if (e.which === 13) {
|
|
skipTo();
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
|
|
function skipTo() {
|
|
$('main').attr('tabindex', 0).focus();
|
|
$('html,body').animate({
|
|
scrollTop: $('main').offset().top
|
|
});
|
|
}
|
|
}
|