1
|
(function(a){if(typeof module!=="undefined"&&typeof exports=="object"){if(typeof window!="undefined"){module.exports=a()}else{module.exports=a}}else{window.ScrollSpy=a()}})(function(){var h=function(i,j,n){n=n||{};this.element=typeof i==="object"?i:document.querySelector(i);this.options={};this.isIE=(new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent)!=null)?parseFloat(RegExp.$1):false;this.options.target=n.target?(typeof n.target==="object"?n.target:document.querySelector(n.target)):null;this.items=this.options.target&&this.options.target.getElementsByTagName("A");this.item=j;this.parent=this.item.parentNode;this.parentParent=this.parent.parentNode.parentNode;this.tg=this.item.href&&document.getElementById(this.item.getAttribute("href").replace("#",""));this.active=false;this.topEdge=0;this.bottomEdge=0;if(this.element.offsetHeight<this.element.scrollHeight){this.scrollTarget=this.element}else{this.scrollTarget=window}if(this.options.target){this.init()}};h.prototype={init:function(){if(this.item.getAttribute("href")&&this.item.getAttribute("href").indexOf("#")>-1){this.checkEdges();this.refresh();this.scrollEvent();if(!(this.isIE&&this.isIE<9)){this.resizeEvent()}}},topLimit:function(){if(this.scrollTarget===window){return this.tg.getBoundingClientRect().top+this.scrollOffset()-5}else{return this.tg.offsetTop}},bottomLimit:function(){return this.topLimit()+this.tg.clientHeight},checkEdges:function(){this.topEdge=this.topLimit();this.bottomEdge=this.bottomLimit()},scrollOffset:function(){if(this.scrollTarget===window){return window.pageYOffset||document.documentElement.scrollTop}else{return this.element.scrollTop}},activate:function(){if(this.parent&&this.parent.tagName==="LI"&&!/active/.test(this.parent.className)){this.addClass(this.parent,"active");if(this.parentParent&&this.parentParent.tagName==="LI"&&/dropdown/.test(this.parentParent.className)&&!/active/.test(this.parentParent.className)){this.addClass(this.parentParent,"active")}this.active=true}},deactivate:function(){if(this.parent&&this.parent.tagName==="LI"&&/active/.test(this.parent.className)){this.removeClass(this.parent,"active");if(this.parentParent&&this.parentParent.tagName==="LI"&&/dropdown/.test(this.parentParent.className)&&/active/.test(this.parentParent.className)){this.removeClass(this.parentParent,"active")}this.active=false}},toggle:function(){if(this.active===false&&(this.bottomEdge>this.scrollOffset()&&this.scrollOffset()>=this.topEdge)){this.activate()}else{if(this.active===true&&(this.bottomEdge<=this.scrollOffset()&&this.scrollOffset()<this.topEdge)){this.deactivate()}}},refresh:function(){this.deactivate();this.checkEdges();this.toggle()},scrollEvent:function(){var j=this;this.scrollTarget.addEventListener("scroll",i,false);function i(){j.refresh()}},resizeEvent:function(){var j=this;window.addEventListener("resize",i,false);function i(){j.refresh()}},scrollHeight:function(){if(this.scrollTarget===window){return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)}else{return this.element.scrollHeight}},addClass:function(j,i){if(j.classList){j.classList.add(i)}else{j.className+=" "+i}},removeClass:function(j,i){if(j.classList){j.classList.remove(i)}else{j.className=j.className.replace(i,"").replace(/^\s+|\s+$/g,"")}}};var k=document.querySelectorAll('[data-spy="scroll"]'),a=0,m=k.length;for(a;a<m;a++){var l=k[a],g={};g.target=l.getAttribute("data-target")||null;if(g.target!==null){var f=g.target==="object"?g.target:document.querySelector(g.target),d=f.querySelectorAll("a"),e=0,b=d.length;for(e;e<b;e++){var c=d[e];if(c.href&&c.getAttribute("href")!=="#"){new h(l,c,g)}}}}return h});
|