From 1f583ce96024c1c33cf9635ad0cca85637f33571 Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Thu, 27 Dec 2018 10:21:25 +0300 Subject: [PATCH] fixes abpframework/abp#678 . Added JQuery scroll for hashed URL. Locating to a lazy loading html element invalidates to hash scrolling from the URL. Added cross-browser JQuery solution that animates to the given element with ID or Name. --- .../Pages/Documents/Shared/Scripts/vs.js | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js index 473326d3b8..dcf9916619 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js @@ -34,11 +34,34 @@ return false; }); + var scrollToHashLink = function () { + var hash = window.location.hash; + + if (!hash || hash === "#") { + return; + } + + var $targetElement = $(hash); + + $targetElement = $targetElement.length ? $targetElement : $('[name=' + this.hash.slice(1) + ']'); + + if (!$targetElement.length) { + return; + } + + $('html,body').stop().animate({ + scrollTop: $targetElement.offset().top + }, 200); + + return; + }; + $(document).ready(function () { handleCustomScrolls(); var $myNav = $("#docs-sticky-index"); Toc.init($myNav); + $("body").scrollspy({ target: $myNav }); @@ -59,6 +82,7 @@ $(".toggle-row").slideToggle(400); $(this).toggleClass("less"); }); + $(".close-mmenu").on("click", function () { $(".navbar-collapse").removeClass("show"); }); @@ -66,7 +90,10 @@ $(".open-dmenu").on("click", function () { $(".docs-tree-list").slideToggle(); }); + + scrollToHashLink(); }); + $(window).resize(function () { handleCustomScrolls(); }); @@ -74,7 +101,7 @@ function handleCustomScrolls() { var wWidth = $(window).width(); - if (wWidth > 766) { + if (wWidth > 766) { $("#sidebar-scroll").mCustomScrollbar({ theme: "minimal" }); @@ -82,13 +109,9 @@ $("#scroll-index").mCustomScrollbar({ theme: "minimal-dark" }); - - //$(".docs-text-field").mCustomScrollbar({ - // axis: "xy", - // theme: "minimal" - //}); } } + window.Toc.helpers.createNavList = function () { return $(''); }; @@ -107,4 +130,5 @@ $li.append($a); return $li; }; + })(jQuery); \ No newline at end of file