diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-02-18 00:31:36 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-02-18 00:31:36 -0500 |
commit | 7f63e065917f8879f42dbac92748702bfb6d044d (patch) | |
tree | 02f9c58e26bd7229972b0e3ba37d2a16398df724 /src/SMAPI.Web/wwwroot | |
parent | 4ce27475675ddeb9a5fcdec0e460553f0f608be7 (diff) | |
download | SMAPI-7f63e065917f8879f42dbac92748702bfb6d044d.tar.gz SMAPI-7f63e065917f8879f42dbac92748702bfb6d044d.tar.bz2 SMAPI-7f63e065917f8879f42dbac92748702bfb6d044d.zip |
fix anchor position for new sticky header
Diffstat (limited to 'src/SMAPI.Web/wwwroot')
-rw-r--r-- | src/SMAPI.Web/wwwroot/Content/js/mods.js | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/SMAPI.Web/wwwroot/Content/js/mods.js b/src/SMAPI.Web/wwwroot/Content/js/mods.js index 0394ac4f..35098b60 100644 --- a/src/SMAPI.Web/wwwroot/Content/js/mods.js +++ b/src/SMAPI.Web/wwwroot/Content/js/mods.js @@ -102,7 +102,7 @@ smapi.modList = function (mods, enableBeta) { app = new Vue({ el: "#app", data: data, - mounted: function() { + mounted: function () { // enable table sorting $("#mod-list").tablesorter({ cssHeader: "header", @@ -115,11 +115,7 @@ smapi.modList = function (mods, enableBeta) { $("#search-box").focus(); // jump to anchor (since table is added after page load) - if (location.hash) { - var row = $(location.hash).get(0); - if (row) - row.scrollIntoView(); - } + this.fixHashPosition(); }, methods: { /** @@ -144,6 +140,18 @@ smapi.modList = function (mods, enableBeta) { } }, + /** + * Fix the window position for the current hash. + */ + fixHashPosition: function () { + if (!location.hash) + return; + + var row = $(location.hash); + var target = row.prev().get(0) || row.get(0); + if (target) + target.scrollIntoView(); + }, /** * Get whether a mod matches the current filters. @@ -151,7 +159,7 @@ smapi.modList = function (mods, enableBeta) { * @param {string[]} searchWords The search words to match. * @returns {bool} Whether the mod matches the filters. */ - matchesFilters: function(mod, searchWords) { + matchesFilters: function (mod, searchWords) { var filters = data.filters; // check hash @@ -249,7 +257,9 @@ smapi.modList = function (mods, enableBeta) { } }); app.applyFilters(); + app.fixHashPosition(); window.addEventListener("hashchange", function () { app.applyFilters(); + app.fixHashPosition(); }); }; |