movable.min.js 3.0 KB

1
  1. !function(o,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(o="undefined"!=typeof globalThis?globalThis:o||self).Movable=t()}(this,function(){"use strict";var n="undefined"!=typeof window,t=n&&navigator.userAgent.toLowerCase();t&&/wechatdevtools/.test(t),t&&t.indexOf("android"),function(){if("string"==typeof t){var o=/os (\d\d?_\d(_\d)?)/.exec(t);if(!o)return;o=o[1].split("_").map(function(o){return parseInt(o,10)});13===o[0]&&o[1]}}();if(n)try{var o={};Object.defineProperty(o,"passive",{get:function(){}}),window.addEventListener("test-passive",function(){},o)}catch(o){}var r=n&&document.createElement("div").style,e=function(){if(!n)return!1;for(var o=0,t=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];o<t.length;o++){var e=t[o];if(void 0!==r[e.value])return e.key}return!1}();function s(o){return!1===e?o:"standard"===e?"transitionEnd"===o?"transitionend":o:e+o.charAt(0).toUpperCase()+o.substr(1)}e&&"standard"!==e&&e.toLowerCase();s("transform"),s("transition");n&&s("perspective")in r,s("transitionTimingFunction"),s("transitionDuration"),s("transitionDelay"),s("transformOrigin"),s("transitionEnd"),s("transitionProperty");var i={style:"cubic-bezier(0.165, 0.84, 0.44, 1)",fn:function(o){return 1- --o*o*o*o}},l=[{key:"putAt",name:"putAt"}].map(function(o){return{key:o.key,sourceKey:"plugins.movable."+o.name}});function a(o){this.scroll=o,this.handleBScroll(),this.handleHooks()}return a.prototype.handleBScroll=function(){this.scroll.proxy(l)},a.prototype.handleHooks=function(){var o=this;this.hooksFn=[];function t(o,t){0<o.maxScrollPos&&(o.minScrollPos=t.wrapperSize-t.contentSize,o.maxScrollPos=0)}var e=this.scroll.scroller,n=e.scrollBehaviorX,r=e.scrollBehaviorY;this.registerHooks(n.hooks,n.hooks.eventTypes.ignoreHasScroll,function(){return!0}),this.registerHooks(n.hooks,n.hooks.eventTypes.computeBoundary,function(o){t(o,n)}),this.registerHooks(r.hooks,r.hooks.eventTypes.ignoreHasScroll,function(){return!0}),this.registerHooks(r.hooks,r.hooks.eventTypes.computeBoundary,function(o){t(o,r)}),this.registerHooks(this.scroll.hooks,this.scroll.hooks.eventTypes.destroy,function(){o.destroy()})},a.prototype.putAt=function(o,t,e,n){void 0===e&&(e=this.scroll.options.bounceTime),void 0===n&&(n=i);t=this.resolvePostion(o,t);this.scroll.scrollTo(t.x,t.y,e,n)},a.prototype.resolvePostion=function(o,t){var e=this.scroll.scroller,n=e.scrollBehaviorX,r=e.scrollBehaviorY,e={left:function(){return 0},top:function(){return 0},right:function(){return n.minScrollPos},bottom:function(){return r.minScrollPos},center:function(o){return(0===o?n:r).minScrollPos/2}};return{x:"number"==typeof o?o:e[o](0),y:"number"==typeof t?t:e[t](1)}},a.prototype.destroy=function(){this.hooksFn.forEach(function(o){var t=o[0],e=o[1],o=o[2];t.off(e,o)}),this.hooksFn.length=0},a.prototype.registerHooks=function(o,t,e){o.on(t,e,this),this.hooksFn.push([o,t,e])},a.pluginName="movable",a.applyOrder="pre",a});