diff --git a/dist/menuspy.js b/dist/menuspy.js index 1162012..889b11f 100644 --- a/dist/menuspy.js +++ b/dist/menuspy.js @@ -1,4 +1,4 @@ -/*! MenuSpy v1.1.3 (Nov 14 2017) - http://leocs.me/menuspy/ - Copyright (c) 2017 Leonardo Santos; MIT License */ +/*! MenuSpy v1.2.0 (Nov 14 2017) - http://leocs.me/menuspy/ - Copyright (c) 2017 Leonardo Santos; MIT License */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : diff --git a/dist/menuspy.min.js b/dist/menuspy.min.js index 6bed665..ed36457 100644 --- a/dist/menuspy.min.js +++ b/dist/menuspy.min.js @@ -1,2 +1,2 @@ -/*! MenuSpy v1.1.3 (Nov 14 2017) - http://leocs.me/menuspy/ - Copyright (c) 2017 Leonardo Santos; MIT License */ +/*! MenuSpy v1.2.0 (Nov 14 2017) - http://leocs.me/menuspy/ - Copyright (c) 2017 Leonardo Santos; MIT License */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.MenuSpy=t()}(this,function(){"use strict";var e={extend:function(e,t){for(var s in t)t.hasOwnProperty(s)&&(e[s]=t[s]);return e},offset:function(e){var t=e.getBoundingClientRect();return{top:t.top+window.pageYOffset,left:t.left+window.pageXOffset}},scrollTop:function(){return window.pageYOffset||document.documentElement.scrollTop},addClass:function(e,t){if(e.classList)e.classList.add(t);else{var s=e.className.split(" ");-1===s.indexOf(t)&&s.push(t),e.className=s.join(" ")}},removeClass:function(e,t){e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp("(^|\\b)"+t.split(" ").join("|")+"(\\b|$)","gi")," ")},debounce:function(e,t){var s=null;return function(){var n=arguments,i=this;s||(s=setTimeout(function(){return s=0,e.apply(i,n)},t))}}},t=function(t,s){var n=this;if(t){var i={menuItemSelector:'a[href^="#"]',activeClass:"active",threshold:15,enableLocationHash:!0,hashTimeout:600,callback:null};this.element=t,this.options=e.extend(i,s),this.assignValues(),this.debouncedAssignValuesFn=e.debounce(function(){return n.assignValues()}),window.addEventListener("resize",this.debouncedAssignValuesFn),this.debouncedHashFn=e.debounce(function(){var t=n.lastInViewElm?"#"+n.lastInViewElm.id:"#";if(history.replaceState)history.replaceState(null,null,t);else{var s=e.scrollTop();window.location.hash=t,window.scrollTo(0,s)}},this.options.hashTimeout),this.cacheItems(),this.scrollFn()}};return t.prototype.assignValues=function(){this.currScrollTop=0,this.lastInViewElm=null,this.menuHeight=this.element.offsetHeight+this.options.threshold,this.menuItems=[].slice.call(this.element.querySelectorAll(this.options.menuItemSelector)),this.raf=null},t.prototype.cacheItems=function(){this.scrollItems=this.menuItems.map(function(t){var s=t.dataset.target?document.querySelector(t.dataset.target):document.getElementById(t.hash.slice(1));if(s){return{elm:t,target:s,offset:e.offset(s).top}}return!1}),this.scrollItems=this.scrollItems.filter(Boolean)},t.prototype.tick=function(){var e=this.currScrollTop+this.menuHeight,t=this.scrollItems.filter(function(t){return t.offset