/*! * Scroll Lock v2.2.0 * https://github.com/MohammadYounes/jquery-scrollLock * * Copyright (c) 2016 Mohammad Younes * Licensed under the MIT license. */ (function(n){typeof define=="function"&&define.amd?define(["jquery"],n):n(jQuery)})(function(n){"use strict";var t=function(i,r){this.$element=i;this.options=n.extend({},t.DEFAULTS,this.$element.data(),r);this.enabled=!0;this.startClientY=0;this.$element.on(t.CORE.wheelEventName+t.NAMESPACE,this.options.selector,n.proxy(t.CORE.handler,this));if(this.options.touch){this.$element.on("touchstart"+t.NAMESPACE,this.options.selector,n.proxy(t.CORE.touchHandler,this));this.$element.on("touchmove"+t.NAMESPACE,this.options.selector,n.proxy(t.CORE.handler,this))}},i;t.NAME="ScrollLock";t.VERSION="2.1.0";t.NAMESPACE=".scrollLock";t.ANIMATION_NAMESPACE=t.NAMESPACE+".effect";t.DEFAULTS={strict:!1,strictFn:function(n){return n.prop("scrollHeight")>n.prop("clientHeight")},selector:!1,animation:!1,touch:"ontouchstart"in window};t.CORE={wheelEventName:"onmousewheel"in window?"ActiveXObject"in window?"wheel":"mousewheel":"DOMMouseScroll",animationEventName:["webkitAnimationEnd","mozAnimationEnd","MSAnimationEnd","oanimationend","animationend"].join(t.ANIMATION_NAMESPACE+" ")+t.ANIMATION_NAMESPACE,handler:function(i){var r,s,h,o;if(this.enabled&&!i.ctrlKey&&(r=n(i.currentTarget),this.options.strict!==!0||this.options.strictFn(r))){i.stopPropagation();var f=r.scrollTop(),c=r.prop("scrollHeight"),l=r.prop("clientHeight"),e=i.originalEvent.wheelDelta||-1*i.originalEvent.detail||-1*i.originalEvent.deltaY,u=0;i.type==="wheel"?(s=r.height()/n(window).height(),u=i.originalEvent.deltaY*s):this.options.touch&&i.type==="touchmove"&&(e=i.originalEvent.changedTouches[0].clientY-this.startClientY);((h=e>0&&f+u<=0)||e<0&&f+u>=c-l)&&(i.preventDefault(),u&&r.scrollTop(f+u),o=h?"top":"bottom",this.options.animation&&setTimeout(t.CORE.animationHandler.bind(this,r,o),0),r.trigger(n.Event(o+t.NAMESPACE)))}},touchHandler:function(n){this.startClientY=n.originalEvent.touches[0].clientY},animationHandler:function(n,i){var r=this.options.animation[i],u=this.options.animation.top+" "+this.options.animation.bottom;n.off(t.ANIMATION_NAMESPACE).removeClass(u).addClass(r).one(t.CORE.animationEventName,function(){n.removeClass(r)})}};t.prototype.toggleStrict=function(){this.options.strict=!this.options.strict};t.prototype.enable=function(){this.enabled=!0};t.prototype.disable=function(){this.enabled=!1};t.prototype.destroy=function(){this.disable();this.$element.off(t.NAMESPACE);this.$element=null;this.options=null};i=n.fn.scrollLock;n.fn.scrollLock=function(i){return this.each(function(){var u=n(this),f=typeof i=="object"&&i,r=u.data(t.NAME);(r||"destroy"!==i)&&(r||u.data(t.NAME,r=new t(u,f)),typeof i=="string"&&r[i]())})};n.fn.scrollLock.defaults=t.DEFAULTS;n.fn.scrollLock.noConflict=function(){return n.fn.scrollLock=i,this}});