mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-12 20:15:25 +00:00
fix: console error when clicking back_to_top button
Note: bug did not affect functionality, still scrolled to top. Fix #1352
This commit is contained in:
1 parent
b5a05867d8
commit
829995656e
4 files changed
+33
-19
No files matched your search
+14
-16
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
{{ with site.GetPage "terms.md" }}
|
||||
{{ if site.GetPage "privacy.md" }} · {{ end }}
|
||||
{{ printf "<a href=\"%s\">%s</a>" .RelPermalink .Title | safeHTML }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
{{ if ne .Type "docs" }}
|
||||
<span class="float-right" aria-hidden="true">
|
||||
<a href="#" id="back_to_top">
|
||||
<a href="#" class="back-to-top">
|
||||
<span class="button_icon">
|
||||
<i class="fas fa-chevron-up fa-2x"></i>
|
||||
</span>
|
||||
|
||||
@@ -16,3 +16,13 @@
|
||||
|
||||
[context.branch-deploy]
|
||||
command = "hugo --gc --minify -b $DEPLOY_PRIME_URL --themesDir ../../"
|
||||
|
||||
[[headers]]
|
||||
for = "*.webmanifest"
|
||||
[headers.values]
|
||||
Content-Type = "application/manifest+json; charset=UTF-8"
|
||||
|
||||
[[headers]]
|
||||
for = "index.xml"
|
||||
[headers.values]
|
||||
Content-Type = "application/rss+xml"
|
||||
Reference in new issue
Block a user