litmus/mkdocs/docs/graphql/v2.9.0/javascripts/spectacle.min.js

1 line
2.9 KiB
JavaScript

function Traverse(t,e){this.$element=t,this.options=$.extend({},Traverse.defaults,this.$element.data(),e),this._init()}$(function(){var i,s,a,n,t=$("#sidebar");t.length&&($("#docs"),new Traverse(i=t.find("nav"),{threshold:10,barOffset:t.position().top}),i.on("update.traverse",function(t,e){i.find("section").removeClass("expand");e=e.parents("section:first");e.length&&e.addClass("expand")}),s=$(".drawer-layout"),a=s.find(".drawer"),n=function(){return a.removeClass("slide-right slide-left"),a.find(".drawer-overlay").remove(),s.removeClass("drawer-open drawer-slide-left-large drawer-slide-right-large"),!1},s.find("[data-drawer-slide]").click(function(t){var e=$(this).data("drawer-slide"),e=(s.addClass("drawer-open"),a.addClass("slide-"+e),$('<a href="#" class="drawer-overlay"></a>'));return a.append(e),e.click(n),!1}),s.find("[data-drawer-close]").click(n))}),Traverse.defaults={animationDuration:500,animationEasing:"linear",threshold:50,activeClass:"active",deepLinking:!1,barOffset:0},Traverse.prototype._init=function(){var t=this.$element[0].id;this.$targets=$("[data-traverse-target]"),this.$links=this.$element.find("a"),this.$element.attr({"data-resize":t,"data-scroll":t,id:t}),this.$active=$(),this.scrollPos=parseInt(window.pageYOffset,10),this._events()},Traverse.prototype.calcPoints=function(){var i=this,t=document.body,e=document.documentElement;this.points=[],this.winHeight=Math.round(Math.max(window.innerHeight,e.clientHeight)),this.docHeight=Math.round(Math.max(t.scrollHeight,t.offsetHeight,e.clientHeight,e.scrollHeight,e.offsetHeight)),this.$targets.each(function(){var t=$(this),e=t.offset().top;t.targetPoint=e,i.points.push(e)})},Traverse.prototype._events=function(){var e=this,i=$("html, body"),s={duration:e.options.animationDuration,easing:e.options.animationEasing};$(window).one("load",function(){e.calcPoints(),e._updateActive(),$(this).resize(function(t){e.reflow()}).scroll(function(t){e._updateActive()})}),this.$element.on("click",'a[href^="#"]',function(t){t.preventDefault();t=this.getAttribute("href").replace(".","\\."),t=$(t).offset().top-e.options.barOffset;i.stop(!0).animate({scrollTop:t},s)})},Traverse.prototype.reflow=function(){this.calcPoints(),this._updateActive()},Traverse.prototype._updateActive=function(){var i,s,t,a=parseInt(window.pageYOffset,10),e=(n=a+this.winHeight===this.docHeight?this.points.length-1:a<this.points[0]?0:(i=this.scrollPos<a,(n=(s=this).points.filter(function(t,e){return i?t<=a+s.options.barOffset+s.options.threshold:t-(s.options.barOffset+s.options.threshold)<=a})).length?n.length-1:0),this.$active),n=this.$links.eq(n);this.$active.removeClass(this.options.activeClass),this.$active=n.addClass(this.options.activeClass),this.options.deepLinking&&(t=this.$active[0].getAttribute("href"),window.history.pushState?window.history.pushState(null,null,t):window.location.hash=t),this.scrollPos=a,e[0]!==n[0]&&this.$element.trigger("update.traverse",[this.$active])};