mobile-drag-drop
Version:
Polyfill for making HTML5 drag and drop possible in all browsers.
2 lines • 2.39 kB
JavaScript
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.MobileDragDrop=n.MobileDragDrop||{})}(this,function(n){"use strict";function u(n){return n===document.body||n===document.documentElement}function r(n,t){return u(n)?0===t?n.clientLeft:n.clientTop:(n=n.getBoundingClientRect(),0===t?n.left:n.top)}function i(n,t){return u(n)?0===t?window.innerWidth:window.innerHeight:0===t?n.clientWidth:n.clientHeight}function c(n,t,o){var e=0===t?"scrollLeft":"scrollTop",t=u(n);if(2===arguments.length)return t?document.body[e]||document.documentElement[e]:n[e];t?(document.documentElement[e]+=o,document.body[e]+=o):n[e]+=o}function l(n,t,o){return n<o?-1:t-n<o?1:0}function f(n,t,o,e){return-1===n?Math.abs(t-e):1===n?Math.abs(o-t-e):0}function d(n,t,o){var e=0===n?o.scrollX:o.scrollY;return 1===t?(0===n?o.scrollWidth-o.width:o.scrollHeight-o.height)<=e:-1!==t||e<=0}var s,a,h,w,m,p={threshold:75,velocityFn:function(n,t){n/=t;return n*n*n*t}},v={horizontal:0,vertical:0},y={x:0,y:0};function x(){s=s||window.requestAnimationFrame(t)}function t(){var n=0,t=0,o=u(w);0!==v.horizontal&&(n=Math.round(p.velocityFn(y.x,p.threshold)*v.horizontal),c(w,0,n)),0!==v.vertical&&(t=Math.round(p.velocityFn(y.y,p.threshold)*v.vertical),c(w,1,t)),o?m(n,t):m(0,0),s=null,M(a,w,p.threshold,v,y)&&x()}function M(n,t,o,e,u){if(n&&t){t={x:r(t,0),y:r(t,1),width:i(t,0),height:i(t,1),scrollX:c(t,0),scrollY:c(t,1),scrollWidth:t.scrollWidth,scrollHeight:t.scrollHeight},n={x:n.x-t.x,y:n.y-t.y};return e.horizontal=l(n.x,t.width,o),e.vertical=l(n.y,t.height,o),e.horizontal&&d(0,e.horizontal,t)?e.horizontal=0:e.horizontal&&(u.x=f(e.horizontal,n.x,t.width,o)),e.vertical&&d(1,e.vertical,t)?e.vertical=0:e.vertical&&(u.y=f(e.vertical,n.y,t.height,o)),e.horizontal||e.vertical}}n.scrollBehaviourDragImageTranslateOverride=function(n,t,o,e){a=t,m=e,h!==o&&(w=function(n){do{if(!n)return;if(t=n,o=getComputedStyle(t),t.scrollHeight>t.clientHeight&&("scroll"===o.overflowY||"auto"===o.overflowY)||t.scrollWidth>t.clientWidth&&("scroll"===o.overflowX||"auto"===o.overflowX))return n;if(n===document.documentElement)return null}while(n=n.parentNode);var t,o;return null}(h=o)),M(a,w,p.threshold,v,y)?x():s&&(window.cancelAnimationFrame(s),s=null)},Object.defineProperty(n,"t",{value:!0})});
//# sourceMappingURL=scroll-behaviour.min.js.map