diff --git a/dist/simple-scrollspy.min.js b/dist/simple-scrollspy.min.js index 1ee6f92..a0b4c93 100644 --- a/dist/simple-scrollspy.min.js +++ b/dist/simple-scrollspy.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.scrollSpy=e():t.scrollSpy=e()}(window,function(){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,o),s.l=!0,s.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},o.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e,o){"use strict";o.r(e),o.d(e,"ScrollSpy",function(){return n});class n{constructor(t,e={}){if(!t)throw new Error("First argument is query selector to your navigation.");if("object"!=typeof e)throw new Error("Second argument must be instance of Object.");this.menuList=t instanceof HTMLElement?t:document.querySelector(t),this.options=Object.assign({},{sectionClass:".scrollspy",menuActiveTarget:"li > a",offset:0,hrefAttribute:"href",activeClass:"active"},e),this.sections=document.querySelectorAll(this.options.sectionClass)}onScroll(){const t=this.getSectionInView(),e=this.getMenuItemBySection(t);this.removeCurrentActive({ignore:e}),this.setActive(e)}getMenuItemBySection(t){const e=t.getAttribute("id");return this.menuList.querySelector(`[${this.options.hrefAttribute}="#${e}"]`)}getSectionInView(){for(let t=0;te&&n<=o)return this.sections[t]}}setActive(t){t.classList.contains(this.options.activeClass)||t.classList.add(this.options.activeClass)}removeCurrentActive({ignore:t}){const{hrefAttribute:e,menuActiveTarget:o}=this.options,n=`${o}.active:not([${e}="${t.getAttribute(e)}"])`;this.menuList.querySelectorAll(n).forEach(t=>t.classList.remove(this.options.activeClass))}}},function(t,e,o){t.exports=((t,e={})=>{const{ScrollSpy:n}=o(0),s=new n(t,e);return window.onload=s.onScroll(),window.addEventListener("scroll",()=>s.onScroll()),s})}])}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.scrollSpy=e():t.scrollSpy=e()}(window,function(){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,o),s.l=!0,s.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},o.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e,o){"use strict";o.r(e),o.d(e,"ScrollSpy",function(){return n});class n{constructor(t,e={}){if(!t)throw new Error("First argument is query selector to your navigation.");if("object"!=typeof e)throw new Error("Second argument must be instance of Object.");this.menuList=t instanceof HTMLElement?t:document.querySelector(t),this.options=Object.assign({},{sectionClass:".scrollspy",menuActiveTarget:"li > a",offset:0,hrefAttribute:"href",activeClass:"active"},e),this.sections=document.querySelectorAll(this.options.sectionClass)}onScroll(){const t=this.getSectionInView(),e=this.getMenuItemBySection(t);e&&(this.removeCurrentActive({ignore:e}),this.setActive(e))}getMenuItemBySection(t){if(!t)return;const e=t.getAttribute("id");return this.menuList.querySelector(`[${this.options.hrefAttribute}="#${e}"]`)}getSectionInView(){for(let t=0;te&&n<=o)return this.sections[t]}}setActive(t){t.classList.contains(this.options.activeClass)||t.classList.add(this.options.activeClass)}removeCurrentActive({ignore:t}){const{hrefAttribute:e,menuActiveTarget:o}=this.options,n=`${o}.active:not([${e}="${t.getAttribute(e)}"])`;this.menuList.querySelectorAll(n).forEach(t=>t.classList.remove(this.options.activeClass))}}},function(t,e,o){t.exports=((t,e={})=>{const{ScrollSpy:n}=o(0),s=new n(t,e);return window.onload=s.onScroll(),window.addEventListener("scroll",()=>s.onScroll()),s})}])}); \ No newline at end of file diff --git a/package.json b/package.json index 98c8438..f9c3d44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-scrollspy", - "version": "2.0.0", + "version": "2.0.1", "description": "Simple scrollspy javascript without jQuery, no dependencies.", "main": "src/index.js", "scripts": {