-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstepped-scroll.min.js
More file actions
1 lines (1 loc) · 4.98 KB
/
stepped-scroll.min.js
File metadata and controls
1 lines (1 loc) · 4.98 KB
1
'use strict';function SteppedScroll(){function a(){var _ref2=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},_ref2$container=_ref2.container,H=void 0===_ref2$container?H:_ref2$container,G=_ref2.current;H.scrollTop=G.offsetTop-H.offsetTop}function b(){var G=l.querySelector(n+q);return!!G}function d(G){var H={up:[38,33],down:[40,34],start:[36],end:[35]},I=G.keyCode||G.which;-1<H.up.indexOf(I)?D.toPrev():-1<H.down.indexOf(I)?D.toNext():-1<H.start.indexOf(I)?D.toStart():-1<H.end.indexOf(I)&&D.toEnd()}function f(G){function H(J,K){K.stopPropagation(),J.classList.add('animated')}G.preventDefault(),G.returnValue=!1;var I=(G.deltaY||-G.wheelDelta||G.detail)>>10||1;return!l.classList.contains('animated')&&void(-1>=I?(H(l,G),D.toPrev()):1<=I&&(H(l,G),D.toNext()),setTimeout(function(){l.classList.remove('animated')},t))}function g(G){for(var H=G.target;H&&!H.isSameNode(l.querySelector(n+o));)H=H.parentNode;H&&h({current:H,state:!0})}function h(_ref3){var _ref3$current=_ref3.current,G=void 0===_ref3$current?null:_ref3$current,_ref3$state=_ref3.state;if(G&&!G.classList.contains(s))if(void 0!==_ref3$state&&_ref3$state&&!G.classList.contains(A)){var I=document.createElement('button');I.type='button',I.classList.add(B),I.innerHTML='×',G.insertBefore(I,G.childNodes[0]),I.addEventListener('click',function(J){J.preventDefault(),J.stopPropagation(),h({current:J.target.parentNode,state:!1}),J.target.parentNode.removeChild(J.target)},!1),G.classList.add(A),G.removeEventListener('click',g),window.removeEventListener('keydown',d),window.removeEventListener('DOMMouseScroll',f),window.removeEventListener('wheel',f),window.removeEventListener('mousewheel',f)}else G.classList.remove(A),G.addEventListener('click',g),window.addEventListener('keydown',d),window.addEventListener('DOMMouseScroll',f),window.addEventListener('wheel',f),window.addEventListener('mousewheel',f)}function k(){var G=l.querySelector(o);return G?(C=0,h({current:G}),G):0<E.length?function(H){for(var I=0;I<H.length;I++)if(H[I].classList.contains(y)){for(var J=I-1;0<=J;J--)H[J].classList.add(z);return C=I,h({current:H[I]}),scrollToElem(H[I]),H[I]}return null}(E)||function(H){return H.classList.add(y),C=0,h({current:H}),H}(E[0]):null}var _ref=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},_ref$container=_ref.container,l=void 0===_ref$container?'.scrollable':_ref$container,_ref$itemSelector=_ref.itemSelector,n=void 0===_ref$itemSelector?'.scroll':_ref$itemSelector,_ref$currentSelector=_ref.currentSelector,o=void 0===_ref$currentSelector?'.current':_ref$currentSelector,_ref$prevSelector=_ref.prevSelector,p=void 0===_ref$prevSelector?'.prev':_ref$prevSelector,_ref$activeSelector=_ref.activeSelector,q=void 0===_ref$activeSelector?'.active':_ref$activeSelector,_ref$closeButtonSelec=_ref.closeButtonSelector,r=void 0===_ref$closeButtonSelec?'.close-active-post':_ref$closeButtonSelec,_ref$unactivableClass=_ref.unactivableClass,s=void 0===_ref$unactivableClass?'unactivable':_ref$unactivableClass,_ref$animationLockDel=_ref.animationLockDelay,t=void 0===_ref$animationLockDel?2500:_ref$animationLockDel,x=null,y=o.substr(1),z=p.substr(1),A=q.substr(1),B=r.substr(1),C=null;if('string'==typeof l&&(l=document.querySelector(l)),!l||!(l instanceof HTMLElement))throw new Error('Container element not found.');if('string'!=typeof n)throw new Error('Item selector must be a string.');if('string'!=typeof p)throw new Error('Item selector must be a string.');var D=this;attachSwipeEvent({element:l,itemSelector:n,currentSelector:o,closeButtonSelector:r,activeSelector:q}),l.addEventListener('swipe',function(G){'up'===G.detail.direction?D.toNext():'down'===G.detail.direction&&D.toPrev()});var E=l.querySelectorAll(n)||[],F=k();!1!==x&&('MutationObserver'in window?(window.MutationObserver=window.MutationObserver||window.WebkitMutationObserver,x=new MutationObserver(function(G){G.forEach(function(I){'childList'===I.type&&(E=l.querySelectorAll(n),F=k())})}),x.observe(l,{childList:!0})):(x=!1,l.addEventListener('DOMNodeInserted DOMNodeRemoved',function(){E=l.querySelectorAll(n),F=k()}))),window.addEventListener('keydown',d),window.addEventListener('DOMMouseScroll',f),window.addEventListener('wheel',f),window.addEventListener('mousewheel',f),this.toStart=function(){if(!b()){F.classList.remove(y);for(var G=E.length-1;0<=G;G--)E[G].classList.remove(z),F=E[G];F.classList.add(y),C=0,h({container:l,current:F}),a({container:l,current:F})}},this.toEnd=function(){if(!b()){F.classList.remove(y);for(var G=C;G<E.length;G++)E[G].classList.add(z),F=E[G];F.classList.add(y),C=E.length-1,h({current:F}),a({container:l,current:F})}},this.toPrev=function(){if(!b()){for(var G=F.previousElementSibling;G&&!G.classList.contains('scroll');)G=F.previousElementSibling;G&&(F.classList.remove(y),G.classList.remove(z),G.classList.add(y),F=G,--C,h({current:F}),a({container:l,current:F}))}},this.toNext=function(){if(!b()){for(var H=0;H<E.length-1;H++){if(E[H].isSameNode(F)){break}}-1<G&&(F.classList.remove(y),F.classList.add(z),F=E[G+1],++C,h({current:F}),F.classList.add(y),a({container:l,current:F}))}}}