Browse Source

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.
pull/696/head
Alper Ebicoglu 8 years ago
parent
commit
1f583ce960
  1. 36
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js

36
modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js

@ -34,11 +34,34 @@
return false; 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 () { $(document).ready(function () {
handleCustomScrolls(); handleCustomScrolls();
var $myNav = $("#docs-sticky-index"); var $myNav = $("#docs-sticky-index");
Toc.init($myNav); Toc.init($myNav);
$("body").scrollspy({ $("body").scrollspy({
target: $myNav target: $myNav
}); });
@ -59,6 +82,7 @@
$(".toggle-row").slideToggle(400); $(".toggle-row").slideToggle(400);
$(this).toggleClass("less"); $(this).toggleClass("less");
}); });
$(".close-mmenu").on("click", function () { $(".close-mmenu").on("click", function () {
$(".navbar-collapse").removeClass("show"); $(".navbar-collapse").removeClass("show");
}); });
@ -66,7 +90,10 @@
$(".open-dmenu").on("click", function () { $(".open-dmenu").on("click", function () {
$(".docs-tree-list").slideToggle(); $(".docs-tree-list").slideToggle();
}); });
scrollToHashLink();
}); });
$(window).resize(function () { $(window).resize(function () {
handleCustomScrolls(); handleCustomScrolls();
}); });
@ -74,7 +101,7 @@
function handleCustomScrolls() { function handleCustomScrolls() {
var wWidth = $(window).width(); var wWidth = $(window).width();
if (wWidth > 766) { if (wWidth > 766) {
$("#sidebar-scroll").mCustomScrollbar({ $("#sidebar-scroll").mCustomScrollbar({
theme: "minimal" theme: "minimal"
}); });
@ -82,13 +109,9 @@
$("#scroll-index").mCustomScrollbar({ $("#scroll-index").mCustomScrollbar({
theme: "minimal-dark" theme: "minimal-dark"
}); });
//$(".docs-text-field").mCustomScrollbar({
// axis: "xy",
// theme: "minimal"
//});
} }
} }
window.Toc.helpers.createNavList = function () { window.Toc.helpers.createNavList = function () {
return $('<ul class="nav nav-pills flex-column"></ul>'); return $('<ul class="nav nav-pills flex-column"></ul>');
}; };
@ -107,4 +130,5 @@
$li.append($a); $li.append($a);
return $li; return $li;
}; };
})(jQuery); })(jQuery);
Loading…
Cancel
Save