mirror of
https://github.com/mdbootstrap/mdb-ui-kit.git
synced 2025-02-19 13:10:41 +03:00
2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.Popper=b()}(this,function(){"use strict";function a(a,b,c){var d=a.find(function(a){return a[b]===c});return a.indexOf(d)}function b(a){var b=a.offsetParent;return b!==window.document.body&&b?b:window.document.documentElement}function c(a,b){var c=window.getComputedStyle(a,null);return c[b]}function d(a){return a===window.document?window.document.body.scrollTop?window.document.body:window.document.documentElement:["scroll","auto"].indexOf(c(a,"overflow"))!==-1||["scroll","auto"].indexOf(c(a,"overflow-x"))!==-1||["scroll","auto"].indexOf(c(a,"overflow-y"))!==-1?a===window.document.body?d(a.parentNode):a:a.parentNode?d(a.parentNode):a}function e(a){var b={width:a.offsetWidth,height:a.offsetHeight,left:a.offsetLeft,top:a.offsetTop};return b.right=b.left+b.width,b.bottom=b.top+b.height,b}function f(a,c,f,g){var h={};if("window"===g){var i=window.document.body,j=window.document.documentElement,k=Math.max(i.scrollHeight,i.offsetHeight,j.clientHeight,j.scrollHeight,j.offsetHeight),l=Math.max(i.scrollWidth,i.offsetWidth,j.clientWidth,j.scrollWidth,j.offsetWidth);h={top:0,right:l,bottom:k,left:0}}else if("viewport"===g){var m=b(a),n=d(a),o=e(m),p="fixed"===c.offsets.popper.position?0:n.scrollTop,q="fixed"===c.offsets.popper.position?0:n.scrollLeft;h={top:0-(o.top-p),right:window.document.documentElement.clientWidth-(o.left-q),bottom:window.document.documentElement.clientHeight-(o.top-p),left:0-(o.left-q)}}else h=b(a)===g?{top:0,left:0,right:g.clientWidth,bottom:g.clientHeight}:e(g);return h.left+=f,h.right-=f,h.top=h.top+f,h.bottom=h.bottom-f,h}function g(a){var b=a.getBoundingClientRect();return{left:b.left,top:b.top,right:b.right,bottom:b.bottom,width:b.right-b.left,height:b.bottom-b.top}}function h(a,b,c,e){var f=g(a),h=g(b);if(c&&!e){var i=d(b);h.top+=i.scrollTop,h.bottom+=i.scrollTop,h.left+=i.scrollLeft,h.right+=i.scrollLeft}var j={top:f.top-h.top,left:f.left-h.left,bottom:f.top-h.top+f.height,right:f.left-h.left+f.width,width:f.width,height:f.height};return j}function i(a){var b=a.style.display,c=a.style.visibility;a.style.display="block",a.style.visibility="hidden";var d=(a.offsetWidth,window.getComputedStyle(a)),e=parseFloat(d.marginTop)+parseFloat(d.marginBottom),f=parseFloat(d.marginLeft)+parseFloat(d.marginRight),g={width:a.offsetWidth+f,height:a.offsetHeight+e};return a.style.display=b,a.style.visibility=c,g}function j(a){return Object.assign({},a,{right:a.left+a.width,bottom:a.top+a.height})}function k(a){return a!==window.document.body&&("fixed"===c(a,"position")||(a.parentNode?k(a.parentNode):a))}function l(a,c){var d=b(c),e=k(c,d);return e?"fixed":"absolute"}function m(a){for(var b=["","ms","webkit","moz","o"],c=0;c<b.length;c++){var d=b[c]?b[c]+a.charAt(0).toUpperCase()+a.slice(1):a;if("undefined"!=typeof window.document.body.style[d])return d}return null}function n(a){var b={};return a&&"[object Function]"===b.toString.call(a)}function o(a,b,c){return!!a.filter(function(a){return a.name===c||(a.name===b,!1)}).length}function p(a){return""!==a&&!isNaN(parseFloat(a))&&isFinite(a)}function q(a){return a!==window.document.body&&("none"!==c(a,"transform")||(a.parentNode?q(a.parentNode):a))}function r(b,c,d,e){var f=void 0===e?b:b.slice(0,a(b,"name",e));return f.forEach(function(a){a.enabled&&n(a["function"])&&(d=a["function"](d,a))}),d}function s(a,b){Object.keys(b).forEach(function(c){var d="";["width","height","top","right","bottom","left"].indexOf(c)!==-1&&p(b[c])&&(d="px"),a.style[c]=b[c]+d})}function t(a,c,d,e){e=e.split("-")[0];var f={};f.position=a.position;var g="fixed"===f.position,j=a.isParentTransformed,k=b(g&&j?d:c),l=h(d,k,g,j),m=i(c);return["right","left"].indexOf(e)!==-1?(f.top=l.top+l.height/2-m.height/2,"left"===e?f.left=l.left-m.width:f.left=l.right):(f.left=l.left+l.width/2-m.width/2,"top"===e?f.top=l.top-m.height:f.top=l.bottom),f.width=m.width,f.height=m.height,{popper:f,reference:l}}function u(a,b,c,e){if(c.updateBound=e,window.addEventListener("resize",c.updateBound),"window"!==b.boundariesElement){var f=d(a);f!==window.document.body&&f!==window.document.documentElement||(f=window),f.addEventListener("scroll",c.updateBound)}}function v(a,b,c){if(window.removeEventListener("resize",b.updateBound),"window"!==c.boundariesElement){var e=d(a);e!==window.document.body&&e!==window.document.documentElement||(e=window),e.removeEventListener("scroll",b.updateBound)}return b.updateBound=null,b}function w(a,b){return a.order<b.order?-1:a.order>b.order?1:0}function x(a){var b={position:a.offsets.popper.position},c=Math.round(a.offsets.popper.left),d=Math.round(a.offsets.popper.top),e=m("transform");return a.instance.options.gpuAcceleration&&e?(b[e]="translate3d("+c+"px, "+d+"px, 0)",b.top=0,b.left=0):(b.left=c,b.top=d),Object.assign(b,a.styles),s(a.instance.popper,b),a.instance.popper.setAttribute("x-placement",a.placement),o(a.instance.modifiers,"applyStyle","arrow")&&a.offsets.arrow&&s(a.arrowElement,a.offsets.arrow),a}function y(a,b,c){b.setAttribute("x-placement",c.placement)}function z(a,b){var c=b.element;if("string"==typeof c&&(c=a.instance.popper.querySelector(c)),!c)return a;if(!a.instance.popper.contains(c))return console.warn("WARNING: `arrowElement` must be child of its popper element!"),a;if(!o(a.instance.modifiers,"arrow","keepTogether"))return console.warn("WARNING: keepTogether modifier is required by arrow modifier in order to work, be sure to include it before arrow!"),a;var d={},e=a.placement.split("-")[0],f=j(a.offsets.popper),g=a.offsets.reference,h=["left","right"].indexOf(e)!==-1,k=h?"height":"width",l=h?"top":"left",m=h?"left":"top",n=h?"bottom":"right",p=i(c)[k];g[n]-p<f[l]&&(a.offsets.popper[l]-=f[l]-(g[n]-p)),g[l]+p>f[n]&&(a.offsets.popper[l]+=g[l]+p-f[n]);var q=g[l]+g[k]/2-p/2,r=q-j(a.offsets.popper)[l];return r=Math.max(Math.min(f[k]-p,r),0),d[l]=r,d[m]="",a.offsets.arrow=d,a.arrowElement=c,a}function A(a){var b={left:"right",right:"left",bottom:"top",top:"bottom"};return a.replace(/left|right|bottom|top/g,function(a){return b[a]})}function B(a,b){if(!o(a.instance.modifiers,"flip","preventOverflow"))return console.warn("WARNING: preventOverflow modifier is required by flip modifier in order to work, be sure to include it before flip!"),a;if(a.flipped&&a.placement===a.originalPlacement)return a;var c=a.placement.split("-")[0],d=A(c),e=a.placement.split("-")[1]||"",f=[];return f="flip"===b.behavior?[c,d]:b.behavior,f.forEach(function(b,g){if(c!==b||f.length===g+1)return a;c=a.placement.split("-")[0],d=A(c);var h=j(a.offsets.popper),i=["right","bottom"].indexOf(c)!==-1;(i&&Math.floor(a.offsets.reference[c])>Math.floor(h[d])||!i&&Math.floor(a.offsets.reference[c])<Math.floor(h[d]))&&(a.flipped=!0,a.placement=f[g+1],e&&(a.placement+="-"+e),a.offsets.popper=t(a.instance.state,a.instance.popper,a.instance.reference,a.placement).popper,a=r(a.instance.modifiers,a.instance.options,a,"flip"))}),a}function C(a){var b=j(a.offsets.popper),c=a.offsets.reference,d=Math.floor;return b.right<d(c.left)&&(a.offsets.popper.left=d(c.left)-b.width),b.left>d(c.right)&&(a.offsets.popper.left=d(c.right)),b.bottom<d(c.top)&&(a.offsets.popper.top=d(c.top)-b.height),b.top>d(c.bottom)&&(a.offsets.popper.top=d(c.bottom)),a}function D(a,b){var c=b.offset,d=a.offsets.popper;return a.placement.indexOf("left")!==-1?d.top-=c:a.placement.indexOf("right")!==-1?d.top+=c:a.placement.indexOf("top")!==-1?d.left-=c:a.placement.indexOf("bottom")!==-1&&(d.left+=c),a}function E(a,b){var c=b.priority,d=j(a.offsets.popper),e={left:function(){var b=d.left;return d.left<a.boundaries.left&&(b=Math.max(d.left,a.boundaries.left)),{left:b}},right:function(){var b=d.left;return d.right>a.boundaries.right&&(b=Math.min(d.left,a.boundaries.right-d.width)),{left:b}},top:function(){var b=d.top;return d.top<a.boundaries.top&&(b=Math.max(d.top,a.boundaries.top)),{top:b}},bottom:function(){var b=d.top;return d.bottom>a.boundaries.bottom&&(b=Math.min(d.top,a.boundaries.bottom-d.height)),{top:b}}};return c.forEach(function(b){a.offsets.popper=Object.assign(d,e[b]())}),a}function F(a){var b=a.placement,c=b.split("-")[0],d=b.split("-")[1];if(d){var e=a.offsets.reference,f=j(a.offsets.popper),g={y:{start:{top:e.top},end:{top:e.top+e.height-f.height}},x:{start:{left:e.left},end:{left:e.left+e.width-f.width}}},h=["bottom","top"].indexOf(c)!==-1?"x":"y";a.offsets.popper=Object.assign(f,g[h][d])}return a}if(Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:function(a){if(void 0===a||null===a)throw new TypeError("Cannot convert first argument to object");for(var b=Object(a),c=1;c<arguments.length;c++){var d=arguments[c];if(void 0!==d&&null!==d){d=Object(d);for(var e=Object.keys(d),f=0,g=e.length;f<g;f++){var h=e[f],i=Object.getOwnPropertyDescriptor(d,h);void 0!==i&&i.enumerable&&(b[h]=d[h])}}}return b}}),!window.requestAnimationFrame){for(var G=0,H=["ms","moz","webkit","o"],I=0;I<H.length&&!window.requestAnimationFrame;++I)window.requestAnimationFrame=window[H[I]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[H[I]+"CancelAnimationFrame"]||window[H[I]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(a){var b=(new Date).getTime(),c=Math.max(0,16-(b-G)),d=window.setTimeout(function(){a(b+c)},c);return G=b+c,d}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(a){clearTimeout(a)})}var J={findIndex:a,getBoundaries:f,getBoundingClientRect:g,getOffsetParent:b,getOffsetRectRelativeToCustomParent:h,getOuterSizes:i,getPopperClientRect:j,getPosition:l,getScrollParent:d,getStyleComputedProperty:c,getSupportedPropertyName:m,isFixed:k,isFunction:n,isModifierRequired:o,isNumeric:p,isTransformed:q,runModifiers:r,setStyle:s},K={applyStyle:x,arrow:z,flip:B,keepTogether:C,offset:D,preventOverflow:E,shift:F},L={applyStyleOnLoad:y},M=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")},N={placement:"bottom",gpuAcceleration:!0,boundariesElement:"viewport",boundariesPadding:5,modifiers:{shift:{order:100,enabled:!0,"function":K.shift},offset:{order:200,enabled:!0,"function":K.offset,offset:0},preventOverflow:{order:300,enabled:!0,"function":K.preventOverflow,priority:["left","right","top","bottom"]},keepTogether:{order:400,enabled:!0,"function":K.keepTogether},arrow:{order:500,enabled:!0,"function":K.arrow,element:"[x-arrow]"},flip:{order:600,enabled:!0,"function":K.flip,behavior:"flip"},applyStyle:{order:700,enabled:!0,"function":K.applyStyle,onLoad:L.applyStyleOnLoad}}},O=function(){function a(b,c){var d=this,e=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return M(this,a),this.reference=b.jquery?b[0]:b,this.state={},this.popper=c.jquery?c[0]:c,this.options=Object.assign({},N,e),this.options.modifiers=Object.assign({},N.modifiers,e.modifiers),this.modifiers=Object.keys(this.options.modifiers).map(function(a){return Object.assign({name:a},d.options.modifiers[a])}).sort(w),this.modifiers.forEach(function(a){a.enabled&&n(a.onLoad)&&a.onLoad(d.reference,d.popper,d.options)}),this.state.position=l(this.popper,this.reference),this.state.isParentTransformed=q(this.popper.parentNode),this.update(!0),u(this.reference,this.options,this.state,function(){return d.update}),this}return a.prototype.update=function(a){var b=this,c={instance:this,styles:{}};this.state.position=l(this.popper,this.reference),s(this.popper,{position:this.state.position}),window.requestAnimationFrame(function(){var d=window.performance.now();d-b.state.lastFrame<=16||(b.state.lastFrame=d,c.placement=b.options.placement,c.originalPlacement=b.options.placement,c.offsets=t(b.state,b.popper,b.reference,c.placement),c.boundaries=f(b.popper,c,b.options.boundariesPadding,b.options.boundariesElement),c=r(b.modifiers,b.options,c),a&&n(b.state.createCalback)?b.state.createCalback(c.instance):!a&&n(b.state.updateCallback)&&b.state.updateCallback(c))})},a.prototype.onCreate=function(a){return this.state.createCalback=a,this},a.prototype.onUpdate=function(a){return this.state.updateCallback=a,this},a.prototype.destroy=function(){return this.popper.removeAttribute("x-placement"),this.popper.style.left="",this.popper.style.position="",this.popper.style.top="",this.popper.style[m("transform")]="",this.state=v(this.reference,this.state,this.options),this.options.removeOnDestroy&&this.popper.parentNode.removeChild(this.popper),this},a}();return O.Utils=J,O});
|