From 4c49a004808b0b02955b0b6eb4c984c4d1c8a8a7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 30 Dec 2014 10:35:40 -0500 Subject: [PATCH] - backport the latest version of scrolling (cherry picked from commit 69618c0d56882ac65594247c5f2d7189ccfa3077) --- doc/build/static/init.js | 63 ++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/doc/build/static/init.js b/doc/build/static/init.js index 70c6f46161..cb330bdc92 100644 --- a/doc/build/static/init.js +++ b/doc/build/static/init.js @@ -7,45 +7,58 @@ function initSQLPopups() { }); } -var automatedBreakpoint = -1; - function initFloatyThings() { - automatedBreakpoint = $("#docs-container").position().top + $("#docs-top-navigation-container").height(); - - left = $("#fixed-sidebar.withsidebar").offset() - if (left) { - left = left.left; - } // otherwise might be undefined - // we use a "fixed" positioning for the sidebar regardless // of whether or not we are moving with the page or not because // we want it to have an independently-moving scrollbar at all - // times. Otherwise, keeping it with plain positioning before the - // page has scrolled works more smoothly on safari, IE + // times. + // this unfortunately means we either have to keep it steady across + // page scrolls or deal with the fact that the text is flowing + // under it in some resize/side-scroll scenarios. + + var automatedBreakpoint = $("#docs-container").position().top + + $("#docs-top-navigation-container").height(); + + var docsBodyOffset = $("#docs-body").offset().top; + + // this turns on the whole thing, without this + // we are in graceful degradation assuming no JS $("#fixed-sidebar.withsidebar").addClass("preautomated"); - function setScroll(event) { + function setScroll() { var scrolltop = $(window).scrollTop(); - if (scrolltop < 0) { - // safari does this - $("#fixed-sidebar.withsidebar").css( - "top", $("#docs-body").offset().top - scrolltop); - } - else if (scrolltop >= automatedBreakpoint) { + var fix = scrolltop >= automatedBreakpoint; + + // when page is scrolled down past the top headers, + // sidebar stays fixed vertically + if (fix) { $("#fixed-sidebar.withsidebar").css("top", 5); } + else if (scrolltop < 0) { + // special trickery to deal with safari vs. chrome + // acting differently in this case, while avoiding using jquery's + // weird / slow? offset() setter + if ($("#fixed-sidebar.withsidebar").offset().top != docsBodyOffset) { + $("#fixed-sidebar.withsidebar").css( + "top", docsBodyOffset - scrolltop); + } + } else { - $("#fixed-sidebar.withsidebar").css( - "top", $("#docs-body").offset().top - Math.max(scrolltop, 0)); + $("#fixed-sidebar.withsidebar").css( + "top", docsBodyOffset - scrolltop); } - var scrollside = $(window).scrollLeft(); - // more safari crap, side scrolling - $("#fixed-sidebar.withsidebar").css("left", left - scrollside); + // adjusting left scroll is also an option, + // but doesn't seem to be worth it, safari is the only browser + // that shows much of a change, and overall the adjustment here + // is jerky and error-prone esp. on lesser browsers like safari ipad. + // looking at our "mentor" documentation, they don't do this; + // they just have the whole layout such that you don't really notice + // the horizontal squeezing as much (nav is on the right, they don't + // have a border around the text making it obvious). } - $(window).scroll(setScroll) - + $(window).scroll(setScroll); setScroll(); } -- 2.47.2