diff --git a/dist/menuspy.js b/dist/menuspy.js index 889b11f..23564db 100644 --- a/dist/menuspy.js +++ b/dist/menuspy.js @@ -1,4 +1,4 @@ -/*! MenuSpy v1.2.0 (Nov 14 2017) - http://leocs.me/menuspy/ - Copyright (c) 2017 Leonardo Santos; MIT License */ +/*! MenuSpy v1.2.1 (Nov 15 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) : @@ -142,7 +142,7 @@ MenuSpy.prototype.activateItem = function activateItem (inViewElm) { this.scrollItems.forEach(function (item) { return utils.removeClass(item.elm.parentNode, activeClass); }); this.lastInViewElm = null; - if (this.enableLocationHash) { + if (this.options.enableLocationHash) { this.debouncedHashFn(); } @@ -162,7 +162,7 @@ MenuSpy.prototype.activateItem = function activateItem (inViewElm) { callback.call(this$1, item); } - if (this$1.enableLocationHash) { + if (this$1.options.enableLocationHash) { this$1.debouncedHashFn(); } } diff --git a/dist/menuspy.min.js b/dist/menuspy.min.js index ed36457..08c88be 100644 --- a/dist/menuspy.min.js +++ b/dist/menuspy.min.js @@ -1,2 +1,2 @@ -/*! 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 utils.removeClass(item.elm.parentNode, activeClass)); this.lastInViewElm = null; - if (this.enableLocationHash) { + if (this.options.enableLocationHash) { this.debouncedHashFn(); } @@ -90,7 +90,7 @@ class MenuSpy { callback.call(this, item); } - if (this.enableLocationHash) { + if (this.options.enableLocationHash) { this.debouncedHashFn(); } }