From cf5aa47fadffcc555543ffb3d606008c8f733cde Mon Sep 17 00:00:00 2001 From: Kohei Yoshino Date: Wed, 3 Jan 2018 10:32:05 -0500 Subject: Bug 1426685 - Fix regressions from fixed-positioning global header --- js/global.js | 21 +++++++++++++++------ js/instant-search.js | 1 - 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'js') diff --git a/js/global.js b/js/global.js index 2b353a69e..93f364c9e 100644 --- a/js/global.js +++ b/js/global.js @@ -191,6 +191,16 @@ $().ready(function() { }); }); +/** + * Focus the main content when the page is loaded and there is no autofocus + * element, so the user can immediately scroll down the page using keyboard. + */ +const focus_main_content = () => { + if (!document.querySelector('[autofocus]')) { + document.querySelector('main').focus(); + } +} + /** * Check if Gravatar images on the page are successfully loaded, and if blocked * (by any content blocker), replace them with the default/fallback image. @@ -210,17 +220,16 @@ const detect_blocked_gravatars = () => { */ const scroll_element_into_view = () => { if (location.hash) { - const $header = document.querySelector('#header'); - const $comment = document.querySelector(location.hash); + const $main = document.querySelector('main'); + const $target = document.querySelector(location.hash); - if ($comment) { - window.setTimeout(() => { - window.scrollTo(0, $comment.offsetTop - $header.offsetHeight - 20); - }, 250); + if ($target) { + window.setTimeout(() => $main.scrollTop = $target.offsetTop - 20, 50); } } } +window.addEventListener('DOMContentLoaded', focus_main_content, { once: true }); window.addEventListener('load', detect_blocked_gravatars, { once: true }); window.addEventListener('load', scroll_element_into_view, { once: true }); window.addEventListener('hashchange', scroll_element_into_view); diff --git a/js/instant-search.js b/js/instant-search.js index 8277b97a9..946f8ccfc 100644 --- a/js/instant-search.js +++ b/js/instant-search.js @@ -15,7 +15,6 @@ Event.onDOMReady(function() { } else { YAHOO.bugzilla.instantSearch.reset(); } - Dom.get('content').focus(); }); YAHOO.bugzilla.instantSearch = { -- cgit v1.2.3-24-g4f1b