tua-body-scroll-lock
Advanced tools
Comparing version 1.0.0-0 to 1.0.0
/** | ||
* tua-body-scroll-lock v1.0.0-0 | ||
* tua-body-scroll-lock v1.0.0 | ||
* (c) 2019 Evinma, BuptStEve | ||
@@ -93,14 +93,13 @@ * @license MIT | ||
const handleScroll = (event, targetElement) => { | ||
const clientY = event.targetTouches[0].clientY - initialClientY; | ||
const clientX = event.targetTouches[0].clientX - initialClientX; | ||
const absClientY = Math.abs(clientY); | ||
const absClientX = Math.abs(clientX); | ||
if (targetElement) { | ||
const { scrollLeft, scrollTop, scrollHeight, clientHeight, scrollWidth, clientWidth, } = targetElement; | ||
const { scrollTop, scrollLeft, scrollWidth, scrollHeight, clientWidth, clientHeight, } = targetElement; | ||
const clientX = event.targetTouches[0].clientX - initialClientX; | ||
const clientY = event.targetTouches[0].clientY - initialClientY; | ||
const isVertical = Math.abs(clientY) > Math.abs(clientX); | ||
const isOnTop = clientY > 0 && scrollTop === 0; | ||
const isOnLeft = clientX > 0 && scrollLeft === 0; | ||
const isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth; | ||
const isOnBottom = clientY < 0 && scrollTop + clientHeight + 1 >= scrollHeight; | ||
const isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth; | ||
if ((absClientY > absClientX && (isOnTop || isOnBottom)) || | ||
(absClientX > absClientY && (isOnLeft || isOnRight))) { | ||
if ((isVertical && (isOnTop || isOnBottom)) || | ||
(!isVertical && (isOnLeft || isOnRight))) { | ||
return preventDefault(event); | ||
@@ -107,0 +106,0 @@ } |
@@ -1,1 +0,1 @@ | ||
const t=()=>"undefined"==typeof window,e=t=>document.querySelector(t),o=t=>{t=t||navigator.userAgent;const e=/(iPad).*OS\s([\d_]+)/.test(t);return{ios:!e&&/(iPhone\sOS)\s([\d_]+)/.test(t)||e,android:/(Android);?[\s\/]+([\d.]+)?/.test(t)}};let n=0,i=0,s=0,l=null,r=!1;const c=[],d=function(e){if(t())return!1;if(!e)throw new Error("options must be provided");let o=!1;const n={get passive(){o=!0}},i=()=>{};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);const{capture:s}=e;return o?e:void 0!==s&&s}({passive:!1}),h=t=>{t.cancelable&&t.preventDefault()},a=a=>{t()||(o().ios?(a&&-1===c.indexOf(a)&&(a.ontouchstart=t=>{i=t.targetTouches[0].clientY,s=t.targetTouches[0].clientX},a.ontouchmove=t=>{1===t.targetTouches.length&&((t,e)=>{const o=t.targetTouches[0].clientY-i,n=t.targetTouches[0].clientX-s,l=Math.abs(o),r=Math.abs(n);if(e){const{scrollLeft:i,scrollTop:s,scrollHeight:c,clientHeight:d,scrollWidth:a,clientWidth:u}=e,f=o>0&&0===s,g=n>0&&0===i,p=o<0&&s+d+1>=c,v=n<0&&i+u+1>=a;if(l>r&&(f||p)||r>l&&(g||v))return h(t)}t.stopPropagation()})(t,a)},c.push(a)),r||(document.addEventListener("touchmove",h,d),r=!0)):n<=0&&(l=o().android?(()=>{const t=e("html"),o=e("body"),n=t.scrollTop||o.scrollTop,i=Object.assign({},t.style),s=Object.assign({},o.style);return t.style.height="100%",t.style.overflow="hidden",o.style.top=`-${n}px`,o.style.width="100%",o.style.height="auto",o.style.position="fixed",o.style.overflow="hidden",()=>{t.style.height=i.height||"",t.style.overflow=i.overflow||"",["top","width","height","overflow","position"].forEach(t=>{o.style[t]=s[t]||""}),window.scrollTo(0,n)}})():(()=>{const t=e("body"),o=Object.assign({},t.style),n=window.innerWidth-document.body.clientWidth;return t.style.overflow="hidden",t.style.boxSizing="border-box",t.style.paddingRight=`${n}px`,()=>{["overflow","boxSizing","paddingRight"].forEach(e=>{t.style[e]=o[e]||""})}})()),n+=1)},u=e=>{if(!(t()||(n-=1)>0))if(o().ios||"function"!=typeof l){if(e){const t=c.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,c.splice(t,1))}r&&(document.removeEventListener("touchmove",h,d),r=!1)}else l()};export{a as lock,u as unlock}; | ||
const t=()=>"undefined"==typeof window,e=t=>document.querySelector(t),o=t=>{t=t||navigator.userAgent;const e=/(iPad).*OS\s([\d_]+)/.test(t);return{ios:!e&&/(iPhone\sOS)\s([\d_]+)/.test(t)||e,android:/(Android);?[\s\/]+([\d.]+)?/.test(t)}};let n=0,i=0,s=0,l=null,r=!1;const d=[],c=function(e){if(t())return!1;if(!e)throw new Error("options must be provided");let o=!1;const n={get passive(){o=!0}},i=()=>{};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);const{capture:s}=e;return o?e:void 0!==s&&s}({passive:!1}),h=t=>{t.cancelable&&t.preventDefault()},a=a=>{t()||(o().ios?(a&&-1===d.indexOf(a)&&(a.ontouchstart=t=>{i=t.targetTouches[0].clientY,s=t.targetTouches[0].clientX},a.ontouchmove=t=>{1===t.targetTouches.length&&((t,e)=>{if(e){const{scrollTop:o,scrollLeft:n,scrollWidth:l,scrollHeight:r,clientWidth:d,clientHeight:c}=e,a=t.targetTouches[0].clientX-s,u=t.targetTouches[0].clientY-i,f=Math.abs(u)>Math.abs(a),g=u>0&&0===o,p=a>0&&0===n,v=a<0&&n+d+1>=l,y=u<0&&o+c+1>=r;if(f&&(g||y)||!f&&(p||v))return h(t)}t.stopPropagation()})(t,a)},d.push(a)),r||(document.addEventListener("touchmove",h,c),r=!0)):n<=0&&(l=o().android?(()=>{const t=e("html"),o=e("body"),n=t.scrollTop||o.scrollTop,i=Object.assign({},t.style),s=Object.assign({},o.style);return t.style.height="100%",t.style.overflow="hidden",o.style.top=`-${n}px`,o.style.width="100%",o.style.height="auto",o.style.position="fixed",o.style.overflow="hidden",()=>{t.style.height=i.height||"",t.style.overflow=i.overflow||"",["top","width","height","overflow","position"].forEach(t=>{o.style[t]=s[t]||""}),window.scrollTo(0,n)}})():(()=>{const t=e("body"),o=Object.assign({},t.style),n=window.innerWidth-document.body.clientWidth;return t.style.overflow="hidden",t.style.boxSizing="border-box",t.style.paddingRight=`${n}px`,()=>{["overflow","boxSizing","paddingRight"].forEach(e=>{t.style[e]=o[e]||""})}})()),n+=1)},u=e=>{if(!(t()||(n-=1)>0))if(o().ios||"function"!=typeof l){if(e){const t=d.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,d.splice(t,1))}r&&(document.removeEventListener("touchmove",h,c),r=!1)}else l()};export{a as lock,u as unlock}; |
/** | ||
* tua-body-scroll-lock v1.0.0-0 | ||
* tua-body-scroll-lock v1.0.0 | ||
* (c) 2019 Evinma, BuptStEve | ||
@@ -106,20 +106,18 @@ * @license MIT | ||
var handleScroll = function handleScroll(event, targetElement) { | ||
var clientY = event.targetTouches[0].clientY - initialClientY; | ||
var clientX = event.targetTouches[0].clientX - initialClientX; | ||
var absClientY = Math.abs(clientY); | ||
var absClientX = Math.abs(clientX); | ||
if (targetElement) { | ||
var scrollLeft = targetElement.scrollLeft, | ||
scrollTop = targetElement.scrollTop, | ||
var scrollTop = targetElement.scrollTop, | ||
scrollLeft = targetElement.scrollLeft, | ||
scrollWidth = targetElement.scrollWidth, | ||
scrollHeight = targetElement.scrollHeight, | ||
clientHeight = targetElement.clientHeight, | ||
scrollWidth = targetElement.scrollWidth, | ||
clientWidth = targetElement.clientWidth; | ||
clientWidth = targetElement.clientWidth, | ||
clientHeight = targetElement.clientHeight; | ||
var clientX = event.targetTouches[0].clientX - initialClientX; | ||
var clientY = event.targetTouches[0].clientY - initialClientY; | ||
var isVertical = Math.abs(clientY) > Math.abs(clientX); | ||
var isOnTop = clientY > 0 && scrollTop === 0; | ||
var isOnLeft = clientX > 0 && scrollLeft === 0; | ||
var isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth; | ||
var isOnBottom = clientY < 0 && scrollTop + clientHeight + 1 >= scrollHeight; | ||
var isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth; | ||
if (absClientY > absClientX && (isOnTop || isOnBottom) || absClientX > absClientY && (isOnLeft || isOnRight)) { | ||
if (isVertical && (isOnTop || isOnBottom) || !isVertical && (isOnLeft || isOnRight)) { | ||
return preventDefault(event); | ||
@@ -126,0 +124,0 @@ } |
/** | ||
* tua-body-scroll-lock v1.0.0-0 | ||
* tua-body-scroll-lock v1.0.0 | ||
* (c) 2019 Evinma, BuptStEve | ||
@@ -112,20 +112,18 @@ * @license MIT | ||
var handleScroll = function handleScroll(event, targetElement) { | ||
var clientY = event.targetTouches[0].clientY - initialClientY; | ||
var clientX = event.targetTouches[0].clientX - initialClientX; | ||
var absClientY = Math.abs(clientY); | ||
var absClientX = Math.abs(clientX); | ||
if (targetElement) { | ||
var scrollLeft = targetElement.scrollLeft, | ||
scrollTop = targetElement.scrollTop, | ||
var scrollTop = targetElement.scrollTop, | ||
scrollLeft = targetElement.scrollLeft, | ||
scrollWidth = targetElement.scrollWidth, | ||
scrollHeight = targetElement.scrollHeight, | ||
clientHeight = targetElement.clientHeight, | ||
scrollWidth = targetElement.scrollWidth, | ||
clientWidth = targetElement.clientWidth; | ||
clientWidth = targetElement.clientWidth, | ||
clientHeight = targetElement.clientHeight; | ||
var clientX = event.targetTouches[0].clientX - initialClientX; | ||
var clientY = event.targetTouches[0].clientY - initialClientY; | ||
var isVertical = Math.abs(clientY) > Math.abs(clientX); | ||
var isOnTop = clientY > 0 && scrollTop === 0; | ||
var isOnLeft = clientX > 0 && scrollLeft === 0; | ||
var isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth; | ||
var isOnBottom = clientY < 0 && scrollTop + clientHeight + 1 >= scrollHeight; | ||
var isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth; | ||
if (absClientY > absClientX && (isOnTop || isOnBottom) || absClientX > absClientY && (isOnLeft || isOnRight)) { | ||
if (isVertical && (isOnTop || isOnBottom) || !isVertical && (isOnLeft || isOnRight)) { | ||
return preventDefault(event); | ||
@@ -132,0 +130,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).bodyScrollLock={})}(this,function(e){"use strict";var t=function(){return"undefined"==typeof window},o=function(e){return document.querySelector(e)},n=function(e){e=e||navigator.userAgent;var t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s\/]+([\d.]+)?/.test(e)}};var i=0,r=0,s=0,c=null,l=!1,d=[],u=function(e){if(t())return!1;if(!e)throw new Error("options must be provided");var o=!1,n={get passive(){o=!0}},i=function(){};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);var r=e.capture;return o?e:void 0!==r&&r}({passive:!1}),f=function(e){e.cancelable&&e.preventDefault()};e.lock=function(e){var a,h,v,p,y;t()||(n().ios?(e&&-1===d.indexOf(e)&&(e.ontouchstart=function(e){r=e.targetTouches[0].clientY,s=e.targetTouches[0].clientX},e.ontouchmove=function(t){1===t.targetTouches.length&&function(e,t){var o=e.targetTouches[0].clientY-r,n=e.targetTouches[0].clientX-s,i=Math.abs(o),c=Math.abs(n);if(t){var l=t.scrollLeft,d=t.scrollTop,u=t.scrollHeight,a=t.clientHeight,h=t.scrollWidth,v=t.clientWidth;if(i>c&&(o>0&&0===d||o<0&&d+a+1>=u)||c>i&&(n>0&&0===l||n<0&&l+v+1>=h))return f(e)}e.stopPropagation()}(t,e)},d.push(e)),l||(document.addEventListener("touchmove",f,u),l=!0)):i<=0&&(c=n().android?(a=o("html"),h=o("body"),v=a.scrollTop||h.scrollTop,p=Object.assign({},a.style),y=Object.assign({},h.style),a.style.height="100%",a.style.overflow="hidden",h.style.top="-".concat(v,"px"),h.style.width="100%",h.style.height="auto",h.style.position="fixed",h.style.overflow="hidden",function(){a.style.height=p.height||"",a.style.overflow=p.overflow||"",["top","width","height","overflow","position"].forEach(function(e){h.style[e]=y[e]||""}),window.scrollTo(0,v)}):function(){var e=o("body"),t=Object.assign({},e.style),n=window.innerWidth-document.body.clientWidth;return e.style.overflow="hidden",e.style.boxSizing="border-box",e.style.paddingRight="".concat(n,"px"),function(){["overflow","boxSizing","paddingRight"].forEach(function(o){e.style[o]=t[o]||""})}}()),i+=1)},e.unlock=function(e){if(!(t()||(i-=1)>0))if(n().ios||"function"!=typeof c){if(e){var o=d.indexOf(e);-1!==o&&(e.ontouchmove=null,e.ontouchstart=null,d.splice(o,1))}l&&(document.removeEventListener("touchmove",f,u),l=!1)}else c()},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).bodyScrollLock={})}(this,function(e){"use strict";var t=function(){return"undefined"==typeof window},o=function(e){return document.querySelector(e)},n=function(e){e=e||navigator.userAgent;var t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s\/]+([\d.]+)?/.test(e)}};var i=0,r=0,s=0,c=null,l=!1,d=[],u=function(e){if(t())return!1;if(!e)throw new Error("options must be provided");var o=!1,n={get passive(){o=!0}},i=function(){};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);var r=e.capture;return o?e:void 0!==r&&r}({passive:!1}),f=function(e){e.cancelable&&e.preventDefault()};e.lock=function(e){var a,h,v,p,y;t()||(n().ios?(e&&-1===d.indexOf(e)&&(e.ontouchstart=function(e){r=e.targetTouches[0].clientY,s=e.targetTouches[0].clientX},e.ontouchmove=function(t){1===t.targetTouches.length&&function(e,t){if(t){var o=t.scrollTop,n=t.scrollLeft,i=t.scrollWidth,c=t.scrollHeight,l=t.clientWidth,d=t.clientHeight,u=e.targetTouches[0].clientX-s,a=e.targetTouches[0].clientY-r,h=Math.abs(a)>Math.abs(u);if(h&&(a>0&&0===o||a<0&&o+d+1>=c)||!h&&(u>0&&0===n||u<0&&n+l+1>=i))return f(e)}e.stopPropagation()}(t,e)},d.push(e)),l||(document.addEventListener("touchmove",f,u),l=!0)):i<=0&&(c=n().android?(a=o("html"),h=o("body"),v=a.scrollTop||h.scrollTop,p=Object.assign({},a.style),y=Object.assign({},h.style),a.style.height="100%",a.style.overflow="hidden",h.style.top="-".concat(v,"px"),h.style.width="100%",h.style.height="auto",h.style.position="fixed",h.style.overflow="hidden",function(){a.style.height=p.height||"",a.style.overflow=p.overflow||"",["top","width","height","overflow","position"].forEach(function(e){h.style[e]=y[e]||""}),window.scrollTo(0,v)}):function(){var e=o("body"),t=Object.assign({},e.style),n=window.innerWidth-document.body.clientWidth;return e.style.overflow="hidden",e.style.boxSizing="border-box",e.style.paddingRight="".concat(n,"px"),function(){["overflow","boxSizing","paddingRight"].forEach(function(o){e.style[o]=t[o]||""})}}()),i+=1)},e.unlock=function(e){if(!(t()||(i-=1)>0))if(n().ios||"function"!=typeof c){if(e){var o=d.indexOf(e);-1!==o&&(e.ontouchmove=null,e.ontouchstart=null,d.splice(o,1))}l&&(document.removeEventListener("touchmove",f,u),l=!1)}else c()},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "tua-body-scroll-lock", | ||
"version": "1.0.0-0", | ||
"version": "1.0.0", | ||
"description": "🔐Body scroll locking that just works with everything", | ||
@@ -5,0 +5,0 @@ "main": "dist/tua-bsl.umd.js", |
@@ -71,24 +71,23 @@ import { | ||
const handleScroll = (event: TouchEvent, targetElement: HTMLElement) => { | ||
const clientY = event.targetTouches[0].clientY - initialClientY | ||
const clientX = event.targetTouches[0].clientX - initialClientX | ||
const absClientY = Math.abs(clientY) | ||
const absClientX = Math.abs(clientX) | ||
if (targetElement) { | ||
const { | ||
scrollTop, | ||
scrollLeft, | ||
scrollTop, | ||
scrollWidth, | ||
scrollHeight, | ||
clientWidth, | ||
clientHeight, | ||
scrollWidth, | ||
clientWidth, | ||
} = targetElement | ||
const clientX = event.targetTouches[0].clientX - initialClientX | ||
const clientY = event.targetTouches[0].clientY - initialClientY | ||
const isVertical = Math.abs(clientY) > Math.abs(clientX) | ||
const isOnTop = clientY > 0 && scrollTop === 0 | ||
const isOnLeft = clientX > 0 && scrollLeft === 0 | ||
const isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth | ||
const isOnBottom = clientY < 0 && scrollTop + clientHeight + 1 >= scrollHeight | ||
const isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth | ||
if ( | ||
(absClientY > absClientX && (isOnTop || isOnBottom)) || | ||
(absClientX > absClientY && (isOnLeft || isOnRight)) | ||
(isVertical && (isOnTop || isOnBottom)) || | ||
(!isVertical && (isOnLeft || isOnRight)) | ||
) { | ||
@@ -95,0 +94,0 @@ return preventDefault(event) |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
46470
726