From 829995656ee943be8500f548ec73328fae2cdc24 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 22 Sep 2019 14:34:24 +0100 Subject: [PATCH] fix: console error when clicking back_to_top button Note: bug did not affect functionality, still scrolled to top. Fix #1352 --- assets/js/academic.js | 30 ++++++++++++++---------------- assets/sass/academic/_root.scss | 8 +++++++- layouts/partials/site_footer.html | 4 ++-- netlify.toml | 10 ++++++++++ 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/assets/js/academic.js b/assets/js/academic.js index 6f17f929..89efc20a 100644 --- a/assets/js/academic.js +++ b/assets/js/academic.js @@ -29,11 +29,12 @@ // If `target` is undefined or HashChangeEvent object, set it to window's hash. // Decode the hash as browsers can encode non-ASCII characters (e.g. Chinese symbols). target = (typeof target === 'undefined' || typeof target === 'object') ? decodeURIComponent(window.location.hash) : target; - // Escape special chars from IDs, such as colons found in Markdown footnote links. - target = '#' + $.escapeSelector(target.substring(1)); // Previously, `target = target.replace(/:/g, '\\:');` // If target element exists, scroll to it taking into account fixed navigation bar offset. if($(target).length) { + // Escape special chars from IDs, such as colons found in Markdown footnote links. + target = '#' + $.escapeSelector(target.substring(1)); // Previously, `target = target.replace(/:/g, '\\:');` + let elementOffset = Math.ceil($(target).offset().top - getNavBarHeight()); // Round up to highlight right ID! $('body').addClass('scrolling'); $('html, body').animate({ @@ -42,7 +43,7 @@ $('body').removeClass('scrolling'); }); }else{ - console.warn('Cannot scroll to '+target+'. ID not found!'); + console.debug('Cannot scroll to target `#'+target+'`. ID not found!'); } } @@ -95,19 +96,6 @@ } }); - /* --------------------------------------------------------------------------- - * Smooth scrolling for Back To Top link. - * --------------------------------------------------------------------------- */ - - $('#back_to_top').on('click', function(event) { - event.preventDefault(); - $('html, body').animate({ - 'scrollTop': 0 - }, 800, function() { - window.location.hash = ""; - }); - }); - /* --------------------------------------------------------------------------- * Hide mobile collapsable menu on clicking a link. * --------------------------------------------------------------------------- */ @@ -543,6 +531,16 @@ // window.addEventListener('hashchange', filter_publications, false); } + // Scroll to top of page. + $('.back-to-top').click( function(event) { + event.preventDefault(); + $('html, body').animate({ + 'scrollTop': 0 + }, 800, function() { + window.location.hash = ""; + }); + }); + // Load citation modal on 'Cite' click. $('.js-cite-modal').click(function(e) { e.preventDefault(); diff --git a/assets/sass/academic/_root.scss b/assets/sass/academic/_root.scss index 23e62ba2..534e62c1 100644 --- a/assets/sass/academic/_root.scss +++ b/assets/sass/academic/_root.scss @@ -135,6 +135,12 @@ video { margin: 0 auto; } +// Center all figure images by default. +figure img { + @extend .margin-auto; +} + +// Center all figure captions by default. figcaption { display: block; margin-top: 0.75em; @@ -343,7 +349,7 @@ footer p { } site-footer, -footer a#back_to_top i { +footer a.back-to-top i { color: rgba(0,0,0,0.54); } diff --git a/layouts/partials/site_footer.html b/layouts/partials/site_footer.html index 82f15f0f..8da3d664 100644 --- a/layouts/partials/site_footer.html +++ b/layouts/partials/site_footer.html @@ -7,7 +7,7 @@ {{ with site.GetPage "terms.md" }} {{ if site.GetPage "privacy.md" }} · {{ end }} {{ printf "%s" .RelPermalink .Title | safeHTML }} - {{ end }} + {{ end }}

{{ end }} @@ -20,7 +20,7 @@ {{ if ne .Type "docs" }}