machines/systems/flexibot/docs/marlin/assets/javascript/test/toc.min.js
2025-03-11 23:32:39 +01:00

9 lines
2.5 KiB
JavaScript

/*!
* toc - jQuery Table of Contents Plugin
* v0.3.2
* http://projects.jga.me/toc/
* copyright Greg Allen 2014
* MIT License
*/
!function(t){t.fn.smoothScroller=function(e){e=t.extend({},t.fn.smoothScroller.defaults,e);var o=t(this);return t(e.scrollEl).animate({scrollTop:o.offset().top-t(e.scrollEl).offset().top-e.offset},e.speed,e.ease,function(){var t=o.attr("id");t.length&&(history.pushState?history.pushState(null,null,"#"+t):document.location.hash=t),o.trigger("smoothScrollerComplete")}),this},t.fn.smoothScroller.defaults={speed:400,ease:"swing",scrollEl:"body,html",offset:0},t("body").on("click","[data-smoothscroller]",function(e){e.preventDefault();var o=t(this).attr("href");0===o.indexOf("#")&&t(o).smoothScroller()})}(jQuery),function(t){var e={};t.fn.toc=function(e){var o,r=this,l=t.extend({},jQuery.fn.toc.defaults,e),n=t(l.container),i=t(l.selectors,n),s=[],a=l.activeClass,c=function(e,o){if(l.smoothScrolling&&"function"==typeof l.smoothScrolling){e.preventDefault();var n=t(e.target).attr("href");l.smoothScrolling(n,l,o)}t("li",r).removeClass(a),t(e.target).parent().addClass(a)},f=function(e){o&&clearTimeout(o),o=setTimeout(function(){for(var e,o=t(window).scrollTop(),n=Number.MAX_VALUE,i=0,c=0,f=s.length;f>c;c++){var h=Math.abs(s[c]-o);n>h&&(i=c,n=h)}t("li",r).removeClass(a),e=t("li:eq("+i+")",r).addClass(a),l.onHighlight(e)},50)};return l.highlightOnScroll&&(t(window).bind("scroll",f),f()),this.each(function(){var e=t(this),o=t(l.listType);i.each(function(r,n){var i=t(n);s.push(i.offset().top-l.highlightOffset);var a=l.anchorName(r,n,l.prefix);if(n.id!==a){t("<span/>").attr("id",a).insertBefore(i)}var h=t("<a/>").text(l.headerText(r,n,i)).attr("href","#"+a).bind("click",function(o){t(window).unbind("scroll"),c(o,function(){t(window).bind("scroll",f)}),e.trigger("selected",t(this).attr("href"))}),u=t("<li/>").addClass(l.itemClass(r,n,i,l.prefix)).append(h);o.append(u)}),e.html(o)})},jQuery.fn.toc.defaults={container:"body",listType:'<ul class="nav nav-sidebar"/>',selectors:"h1,h2,h3",smoothScrolling:function(e,o,r){t(e).smoothScroller({offset:o.scrollToOffset}).on("smoothScrollerComplete",function(){r()})},scrollToOffset:0,prefix:"toc",activeClass:"toc-active",onHighlight:function(){},highlightOnScroll:!0,highlightOffset:100,anchorName:function(o,r,l){if(r.id.length)return r.id;var n=t(r).text().replace(/[^a-z0-9]/gi," ").replace(/\s+/g,"-").toLowerCase();if(e[n]){for(var i=2;e[n+i];)i++;n=n+"-"+i}return e[n]=!0,l+"-"+n},headerText:function(t,e,o){return o.text()},itemClass:function(t,e,o,r){return r+"-"+o[0].tagName.toLowerCase()}}}(jQuery);