summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorKohei Yoshino <kohei.yoshino@gmail.com>2018-01-03 16:32:05 +0100
committerDylan William Hardison <dylan@hardison.net>2018-01-03 16:32:05 +0100
commitcf5aa47fadffcc555543ffb3d606008c8f733cde (patch)
tree1cfabc763ce3a050ab3aab1eafa8ae8b59b7a7c6 /js
parent1ece54f087f04778b21e94cc52084bec629fc012 (diff)
downloadbugzilla-cf5aa47fadffcc555543ffb3d606008c8f733cde.tar.gz
bugzilla-cf5aa47fadffcc555543ffb3d606008c8f733cde.tar.xz
Bug 1426685 - Fix regressions from fixed-positioning global header
Diffstat (limited to 'js')
-rw-r--r--js/global.js21
-rw-r--r--js/instant-search.js1
2 files changed, 15 insertions, 7 deletions
diff --git a/js/global.js b/js/global.js
index 2b353a69e..93f364c9e 100644
--- a/js/global.js
+++ b/js/global.js
@@ -192,6 +192,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 = {