-
Notifications
You must be signed in to change notification settings - Fork 0
/
WellScroller.min.js
1 lines (1 loc) · 6.65 KB
/
WellScroller.min.js
1
!function(a){"use strict";function b(){var a,b;for(a=1;a<arguments.length;a++)for(b in arguments[a])arguments[a].hasOwnProperty(b)&&(arguments[0][b]=arguments[a][b]);return arguments[0]}function f(e,f){function s(){h.update(),w()}function t(){if(k.getBoundingClientRect().bottom<j.getBoundingClientRect().bottom){var a=j.getBoundingClientRect().bottom-k.getBoundingClientRect().bottom;k.style.transition="all 0s",h.contentPosition=h.contentPosition-a}else h.contentPosition=parseInt(scrollTo,10)||h.contentPosition}function u(){var a=$(h.catShowMore.parentNode).position().top,b=a-h.contentPosition;0>b&&(h.contentPosition+=b)}function v(){m.style[q]=h.thumbPosition+"px",k.style[q]=-h.contentPosition+"px",l.style[r]=h.trackSize+"px",m.style[r]=h.thumbSize+"px"}function w(){j.ontouchstart=function(a){1===a.touches.length&&(h.touch=!0,B(a.touches[0]),a.stopPropagation())},m.ontouchstart=function(a){a.stopPropagation(),B(a.touches[0])},l.ontouchstart=function(a){h.touchScrollbar=!0,B(a,!0)},m.onmousedown=function(a){a.stopPropagation(),B(a)},l.onmousedown=function(a){B(a,!0)},a.addEventListener("resize",function(){h.update("relative")},!0),e.addEventListener("wheel",C,!1)}function x(){return h.contentPosition>0}function y(){return h.contentPosition<=h.contentSize-h.viewportSize-5}function z(){k.style.transition=n}function A(){var a=k.scrollHeight;h.contentSize!==a&&h.update()}function B(a,b){if(A(),z(),h.hasContentToSroll){var c;("margin-top"===q||"top"===q)&&(c="top"),("margin-left"===q||"left"===q)&&(c="left"),o=b?m.getBoundingClientRect()[c]:p?a.clientX:a.clientY,i.classList.contains("wellNoSelect")||i.classList.add("wellNoSelect"),document.ontouchmove=function(a){(h.options.touchLock||x()&&y())&&a.preventDefault(),D(a.touches[0])},m.ontouchmove=function(a){(h.options.touchLock||x()&&y())&&a.preventDefault(),D(a.touches[0])},a.target.classList.contains("scrollbar")?D(a,!0):document.onmousemove=D,document.onmouseup=m.onmouseup=m.ontouchend=document.ontouchend=G}}function C(b){if(A(),z(),b.stopPropagation(),h.hasContentToSroll){var c=b||a.event,d=-(c.deltaY||c.detail||-1/3*c.wheelDelta)/40;navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&(d*=20),h.contentPosition-=d*h.options.wheelSpeed,h.contentPosition=F(),h.thumbPosition=h.contentPosition/h.trackRatio,0===h.trackDistance&&(h.trackDistance=l.clientHeight-m.clientHeight),h.thumbPosition>h.trackDistance&&(h.thumbPosition=h.trackDistance),m.style[q]=h.thumbPosition+"px",k.style[q]=-h.contentPosition+"px",(h.options.wheelLock||x()&&y())&&c.preventDefault()}}function D(a){if(h.hasContentToSroll){var b=p?a.clientX:a.clientY,c=h.touch?o-b:b-o,d=Math.min(h.trackSize-h.thumbSize,Math.max(0,h.thumbPosition+c));0===h.trackDistance&&(h.trackDistance=l.clientHeight-m.clientHeight),d>h.trackDistance&&(d=h.trackDistance),h.contentPosition=d*h.trackRatio,m.style[q]=d+"px",k.style[q]=-h.contentPosition+"px"}}function E(a){var b=h.options.scrollDownBtn,c=h.options.scrollDownBtnStep,d=a/c;b&&b.addEventListener("click",function(){h.contentPosition+=d,h.contentPosition=F(),h.thumbPosition=h.contentPosition/h.trackRatio,k.style[q]=-h.contentPosition+"px",m.style[q]=h.thumbPosition+"px"})}function F(){return Math.min(h.contentSize-h.viewportSize,Math.max(0,h.contentPosition))}function G(){h.thumbPosition=parseInt(m.style[q],10)||0,i.className=i.className.replace(" welNoSelect",""),document.onmousemove=document.onmouseup=null,m.onmouseup=null,l.onmouseup=null,document.ontouchmove=document.ontouchend=null,h.touch=!1,i.classList.contains("wellNoSelect")&&i.classList.remove("wellNoSelect"),0===i.getAttribute("class").trim().length&&i.removeAttribute("class")}this.options=b({},d,f),this._defaults=d,this._name=c;var q,h=this,i=document.querySelector("body"),j=g(e,"viewport"),k=g(j,"overview"),l=g(e,"scrollbar"),m=g(l,"thumb"),n=getComputedStyle(k).transition,o=0,p="x"===this.options.axis,r=p?"width":"height";return q=p?"left":this.options.marginTop?"margin-top":"top",this.touch=!1,this.contentPosition=0,this.viewportSize=0,this.contentSize=0,this.contentRatio=0,this.trackSize=0,this.trackRatio=0,this.thumbSize=0,this.thumbPosition=0,this.hasContentToSroll=!1,this.typeScrollUpdate=null,this.catShowMore=null,this.update=function(a){var b=getComputedStyle(e,null),c=r.charAt(0).toUpperCase()+r.slice(1).toLowerCase(),d=l.className,f=getComputedStyle(l),g=+f.borderTopWidth.substring(0,f.borderTopWidth.indexOf("px"))+ +f.borderBottomWidth.substring(0,f.borderBottomWidth.indexOf("px")),i="x"===this.options.axis?+b.width.replace(/px/,""):+b.height.replace(/px/,""),m=getComputedStyle(l),n=+m.borderTopWidth.replace(/px/,"")+ +m.borderBottomWidth.replace(/px/,"");switch(("100%"===i||"auto"===b||0===i)&&(i="x"===this.options.axis?b.maxWidth.replace(/px/,""):b.maxHeight.replace(/px/,"")),j.dataset.initSize=i,this.viewportSize=i,this.contentSize=k["scroll"+c],this.contentRatio=this.viewportSize/this.contentSize,this.trackSize=this.options.trackSize||this.viewportSize,this.trackSize-=n,this.thumbSize=Math.min(this.trackSize,Math.max(this.options.thumbSizeMin,this.options.thumbSize||this.trackSize*this.contentRatio)),this.trackRatio=(this.contentSize-this.viewportSize)/(this.trackSize-this.thumbSize),this.trackDistance=this.viewportSize-g-this.thumbSize,this.hasContentToSroll=this.contentRatio<1,d=d.replace(/\s?disable\s?/g,""),this.hasContentToSroll||(d+=" disable"),l.className=d,E(this.contentSize),a){case"bottom":this.contentPosition=Math.max(this.contentSize-this.viewportSize,0);break;case"relative":this.contentPosition=Math.min(Math.max(this.contentSize-this.viewportSize,0),Math.max(0,this.contentPosition));break;default:switch(this.typeScrollUpdate){case"simpleUpdate":t();break;case"oppositeCat":u();break;default:this.contentPosition=parseInt(a,10)||0}}this.thumbPosition=h.contentPosition/h.trackRatio,v(),e.dataset.scroller="enable"},this.updateAndfixScrollBar=function(){"simpleUpdate"!==this.typeScrollUpdate&&(this.typeScrollUpdate="simpleUpdate"),this.update()},this.updateCategoryScroll=function(a){"oppositeCat"!==this.typeScrollUpdate&&(this.typeScrollUpdate="oppositeCat"),a&&(this.catShowMore=a),this.update()},s()}function g(a,b){var c;return a&&a.childNodes&&(Array.prototype.slice.call(a.childNodes).forEach(function(a){3!==a.nodeType&&a.classList.contains(b)&&(c=a)}),void 0!==c)?c:void 0}var e,c="wellScroller",d={axis:"y",wheel:!0,wheelSpeed:40,wheelLock:!0,touchLock:!0,trackSize:!1,thumbSize:!1,thumbSizeMin:20,marginTop:!1,marginLeft:!1,scrollDownBtn:null,scrollDownBtnStep:4};e=function(a,b){if(!a)throw console.trace(),new Error("\u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 Container");return a.hasOwnProperty("WScroller")||(a.WScroller=new f(a,b)),a.WScroller},a.wellScroller=e}(window);