Comparing version 1.2.0 to 1.2.1
@@ -1,2 +0,2 @@ | ||
/*! 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) { | ||
@@ -145,3 +145,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
if (this.enableLocationHash) { | ||
if (this.options.enableLocationHash) { | ||
this.debouncedHashFn(); | ||
@@ -166,3 +166,3 @@ } | ||
if (this$1.enableLocationHash) { | ||
if (this$1.options.enableLocationHash) { | ||
this$1.debouncedHashFn(); | ||
@@ -169,0 +169,0 @@ } |
@@ -1,2 +0,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<e});this.activateItem(t.pop())},t.prototype.activateItem=function(t){var s=this,n=this.options,i=n.activeClass,o=n.callback;if(!t)return this.scrollItems.forEach(function(t){return e.removeClass(t.elm.parentNode,i)}),this.lastInViewElm=null,void(this.enableLocationHash&&this.debouncedHashFn());this.lastInViewElm!==t.target&&(this.lastInViewElm=t.target,this.scrollItems.forEach(function(n){e.removeClass(n.elm.parentNode,i),n.target===t.target&&(e.addClass(n.elm.parentNode,i),"function"==typeof o&&o.call(s,n),s.enableLocationHash&&s.debouncedHashFn())}))},t.prototype.scrollFn=function(){var t=e.scrollTop();this.currScrollTop!==t&&(this.currScrollTop=t,this.tick()),this.raf=window.requestAnimationFrame(this.scrollFn.bind(this))},t.prototype.destroy=function(){this.raf&&window.cancelAnimationFrame(this.raf),window.removeEventListener("resize",this.debouncedAssignValuesFn)},t}); | ||
/*! MenuSpy v1.2.1 (Nov 15 2017) - http://leocs.me/menuspy/ - Copyright (c) 2017 Leonardo Santos; MIT License */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.MenuSpy=e()}(this,function(){"use strict";var t={extend:function(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t},offset:function(t){var e=t.getBoundingClientRect();return{top:e.top+window.pageYOffset,left:e.left+window.pageXOffset}},scrollTop:function(){return window.pageYOffset||document.documentElement.scrollTop},addClass:function(t,e){if(t.classList)t.classList.add(e);else{var s=t.className.split(" ");-1===s.indexOf(e)&&s.push(e),t.className=s.join(" ")}},removeClass:function(t,e){t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," ")},debounce:function(t,e){var s=null;return function(){var n=arguments,o=this;s||(s=setTimeout(function(){return s=0,t.apply(o,n)},e))}}},e=function(e,s){var n=this;if(e){var o={menuItemSelector:'a[href^="#"]',activeClass:"active",threshold:15,enableLocationHash:!0,hashTimeout:600,callback:null};this.element=e,this.options=t.extend(o,s),this.assignValues(),this.debouncedAssignValuesFn=t.debounce(function(){return n.assignValues()}),window.addEventListener("resize",this.debouncedAssignValuesFn),this.debouncedHashFn=t.debounce(function(){var e=n.lastInViewElm?"#"+n.lastInViewElm.id:"#";if(history.replaceState)history.replaceState(null,null,e);else{var s=t.scrollTop();window.location.hash=e,window.scrollTo(0,s)}},this.options.hashTimeout),this.cacheItems(),this.scrollFn()}};return e.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},e.prototype.cacheItems=function(){this.scrollItems=this.menuItems.map(function(e){var s=e.dataset.target?document.querySelector(e.dataset.target):document.getElementById(e.hash.slice(1));if(s){return{elm:e,target:s,offset:t.offset(s).top}}return!1}),this.scrollItems=this.scrollItems.filter(Boolean)},e.prototype.tick=function(){var t=this.currScrollTop+this.menuHeight,e=this.scrollItems.filter(function(e){return e.offset<t});this.activateItem(e.pop())},e.prototype.activateItem=function(e){var s=this,n=this.options,o=n.activeClass,i=n.callback;if(!e)return this.scrollItems.forEach(function(e){return t.removeClass(e.elm.parentNode,o)}),this.lastInViewElm=null,void(this.options.enableLocationHash&&this.debouncedHashFn());this.lastInViewElm!==e.target&&(this.lastInViewElm=e.target,this.scrollItems.forEach(function(n){t.removeClass(n.elm.parentNode,o),n.target===e.target&&(t.addClass(n.elm.parentNode,o),"function"==typeof i&&i.call(s,n),s.options.enableLocationHash&&s.debouncedHashFn())}))},e.prototype.scrollFn=function(){var e=t.scrollTop();this.currScrollTop!==e&&(this.currScrollTop=e,this.tick()),this.raf=window.requestAnimationFrame(this.scrollFn.bind(this))},e.prototype.destroy=function(){this.raf&&window.cancelAnimationFrame(this.raf),window.removeEventListener("resize",this.debouncedAssignValuesFn)},e}); |
{ | ||
"name": "menuspy", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"title": "MenuSpy", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -73,3 +73,3 @@ import utils from './utils.js'; | ||
if (this.enableLocationHash) { | ||
if (this.options.enableLocationHash) { | ||
this.debouncedHashFn(); | ||
@@ -94,3 +94,3 @@ } | ||
if (this.enableLocationHash) { | ||
if (this.options.enableLocationHash) { | ||
this.debouncedHashFn(); | ||
@@ -97,0 +97,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43187