From 484025fe0ac49e9225127d74636e9aaebdc8d670 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 16 Dec 2020 23:54:06 +0100 Subject: [PATCH] force scroll to the blog once it's loaded --- actaddmanual/index.html | 2 +- actaddmanual/index.js | 10 +--------- index.html | 2 +- scripts/blog.js | 1 + scripts/{cookies.js => util.js} | 12 ++++++++++++ 5 files changed, 16 insertions(+), 11 deletions(-) rename scripts/{cookies.js => util.js} (59%) diff --git a/actaddmanual/index.html b/actaddmanual/index.html index 7bd6478..bd0f921 100644 --- a/actaddmanual/index.html +++ b/actaddmanual/index.html @@ -13,6 +13,7 @@ + @@ -41,7 +42,6 @@
-
diff --git a/actaddmanual/index.js b/actaddmanual/index.js index 763539e..641bf7f 100644 --- a/actaddmanual/index.js +++ b/actaddmanual/index.js @@ -53,15 +53,7 @@ function populateManual(lang) { sidebar.append(`© Ellpeck`); sidebar.append("
"); - // Move to anchor now that it's loaded - if (window.location.hash.startsWith("#")) { - var anchor = $(window.location.hash); - if (anchor.length) { - $('html, body').animate({ - scrollTop: anchor.offset().top - }, 0); - } - } + forceToAnchor(); } function replaceFormatting(text) { diff --git a/index.html b/index.html index 9acc5ab..d6b22ba 100644 --- a/index.html +++ b/index.html @@ -28,7 +28,7 @@ - + diff --git a/scripts/blog.js b/scripts/blog.js index 2c55889..920f15e 100644 --- a/scripts/blog.js +++ b/scripts/blog.js @@ -28,5 +28,6 @@ $.ajax({ list.append(p); } } + forceToAnchor(); } }); \ No newline at end of file diff --git a/scripts/cookies.js b/scripts/util.js similarity index 59% rename from scripts/cookies.js rename to scripts/util.js index de73e51..b3100e0 100644 --- a/scripts/cookies.js +++ b/scripts/util.js @@ -11,4 +11,16 @@ function setCookie(key, value, days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); document.cookie = key + "=" + value + "; expires=" + date.toUTCString(); +} + +function forceToAnchor() { + // this is probably a terrible hack + if (window.location.hash.startsWith("#")) { + var anchor = $(window.location.hash); + if (anchor.length) { + $('html, body').animate({ + scrollTop: anchor.offset().top + }, 0); + } + } } \ No newline at end of file