quarkd
Version:
Mobile UI Components built on Web Components.
2 lines (1 loc) • 2.43 kB
JavaScript
var e=!1;if("undefined"!=typeof window){var t={get passive(){e=!0}};window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}var o="undefined"!=typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),n=[],r=!1,i=-1,l=void 0,a=void 0,d=function(e){return n.some((function(t){return!(!t.options.allowTouchMove||!t.options.allowTouchMove(e))}))},c=function(e){var t=e||window.event;return!!d(t.target)||(t.touches.length>1||(t.preventDefault&&t.preventDefault(),!1))},u=function(){void 0!==a&&(document.body.style.paddingRight=a,a=void 0),void 0!==l&&(document.body.style.overflow=l,l=void 0)},s=function(t,u){if(t){if(!n.some((function(e){return e.targetElement===t}))){var s={targetElement:t,options:u||{}};n=[].concat(function(e){if(Array.isArray(e)){for(var t=0,o=Array(e.length);t<e.length;t++)o[t]=e[t];return o}return Array.from(e)}(n),[s]),o?(t.ontouchstart=function(e){1===e.targetTouches.length&&(i=e.targetTouches[0].clientY)},t.ontouchmove=function(e){1===e.targetTouches.length&&function(e,t){var o=e.targetTouches[0].clientY-i;!d(e.target)&&(t&&0===t.scrollTop&&o>0||function(e){return!!e&&e.scrollHeight-e.scrollTop<=e.clientHeight}(t)&&o<0?c(e):e.stopPropagation())}(e,t)},r||(document.addEventListener("touchmove",c,e?{passive:!1}:void 0),r=!0)):function(e){if(void 0===a){var t=!!e&&!0===e.reserveScrollBarGap,o=window.innerWidth-document.documentElement.clientWidth;t&&o>0&&(a=document.body.style.paddingRight,document.body.style.paddingRight=o+"px")}void 0===l&&(l=document.body.style.overflow,document.body.style.overflow="hidden")}(u)}}else console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.")},v=function(){o?(n.forEach((function(e){e.targetElement.ontouchstart=null,e.targetElement.ontouchmove=null})),r&&(document.removeEventListener("touchmove",c,e?{passive:!1}:void 0),r=!1),i=-1):u(),n=[]},f=function(t){t?(n=n.filter((function(e){return e.targetElement!==t})),o?(t.ontouchstart=null,t.ontouchmove=null,r&&0===n.length&&(document.removeEventListener("touchmove",c,e?{passive:!1}:void 0),r=!1)):n.length||u()):console.error("enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.")};export{v as c,s as d,f as e};