0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00
Bootstrap/js/dist/util.js.map
Mark Otto b68ea572da dist
2018-09-17 12:34:34 -07:00

1 line
8.4 KiB
Plaintext

{"version":3,"file":"util.js","sources":["../src/util.js"],"sourcesContent":["import $ from 'jquery'\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.1.3): util.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst Util = (($) => {\n /**\n * ------------------------------------------------------------------------\n * Private TransitionEnd Helpers\n * ------------------------------------------------------------------------\n */\n\n const TRANSITION_END = 'transitionend'\n const MAX_UID = 1000000\n const MILLISECONDS_MULTIPLIER = 1000\n\n // Shoutout AngusCroll (https://goo.gl/pxwQGp)\n function toType(obj) {\n return {}.toString.call(obj).match(/\\s([a-z]+)/i)[1].toLowerCase()\n }\n\n function getSpecialTransitionEndEvent() {\n return {\n bindType: TRANSITION_END,\n delegateType: TRANSITION_END,\n handle(event) {\n if ($(event.target).is(this)) {\n return event.handleObj.handler.apply(this, arguments) // eslint-disable-line prefer-rest-params\n }\n return undefined // eslint-disable-line no-undefined\n }\n }\n }\n\n function transitionEndEmulator(duration) {\n let called = false\n\n $(this).one(Util.TRANSITION_END, () => {\n called = true\n })\n\n setTimeout(() => {\n if (!called) {\n Util.triggerTransitionEnd(this)\n }\n }, duration)\n\n return this\n }\n\n function setTransitionEndSupport() {\n $.fn.emulateTransitionEnd = transitionEndEmulator\n $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent()\n }\n\n /**\n * --------------------------------------------------------------------------\n * Public Util Api\n * --------------------------------------------------------------------------\n */\n\n const Util = {\n\n TRANSITION_END: 'bsTransitionEnd',\n\n getUID(prefix) {\n do {\n // eslint-disable-next-line no-bitwise\n prefix += ~~(Math.random() * MAX_UID) // \"~~\" acts like a faster Math.floor() here\n } while (document.getElementById(prefix))\n return prefix\n },\n\n getSelectorFromElement(element) {\n let selector = element.getAttribute('data-target')\n\n if (!selector || selector === '#') {\n const hrefAttr = element.getAttribute('href')\n selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : ''\n }\n\n return selector && document.querySelector(selector) ? selector : null\n },\n\n getTransitionDurationFromElement(element) {\n if (!element) {\n return 0\n }\n\n // Get transition-duration of the element\n let transitionDuration = $(element).css('transition-duration')\n const floatTransitionDuration = parseFloat(transitionDuration)\n\n // Return 0 if element or transition duration is not found\n if (!floatTransitionDuration) {\n return 0\n }\n\n // If multiple durations are defined, take the first\n transitionDuration = transitionDuration.split(',')[0]\n\n return parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER\n },\n\n reflow(element) {\n return element.offsetHeight\n },\n\n triggerTransitionEnd(element) {\n $(element).trigger(TRANSITION_END)\n },\n\n // TODO: Remove in v5\n supportsTransitionEnd() {\n return Boolean(TRANSITION_END)\n },\n\n isElement(obj) {\n return (obj[0] || obj).nodeType\n },\n\n typeCheckConfig(componentName, config, configTypes) {\n for (const property in configTypes) {\n if (Object.prototype.hasOwnProperty.call(configTypes, property)) {\n const expectedTypes = configTypes[property]\n const value = config[property]\n const valueType = value && Util.isElement(value)\n ? 'element' : toType(value)\n\n if (!new RegExp(expectedTypes).test(valueType)) {\n throw new Error(\n `${componentName.toUpperCase()}: ` +\n `Option \"${property}\" provided type \"${valueType}\" ` +\n `but expected type \"${expectedTypes}\".`)\n }\n }\n }\n }\n }\n\n setTransitionEndSupport()\n\n return Util\n})($)\n\nexport default Util\n"],"names":["Util","$","TRANSITION_END","MAX_UID","MILLISECONDS_MULTIPLIER","toType","obj","toString","call","match","toLowerCase","getSpecialTransitionEndEvent","bindType","delegateType","handle","event","target","is","handleObj","handler","apply","arguments","undefined","transitionEndEmulator","duration","called","one","setTimeout","triggerTransitionEnd","setTransitionEndSupport","fn","emulateTransitionEnd","special","getUID","prefix","Math","random","document","getElementById","getSelectorFromElement","element","selector","getAttribute","hrefAttr","trim","querySelector","getTransitionDurationFromElement","transitionDuration","css","floatTransitionDuration","parseFloat","split","reflow","offsetHeight","trigger","supportsTransitionEnd","Boolean","isElement","nodeType","typeCheckConfig","componentName","config","configTypes","property","Object","prototype","hasOwnProperty","expectedTypes","value","valueType","RegExp","test","Error","toUpperCase"],"mappings":";;;;;;;;EAEA;;;;;;;EAOA,IAAMA,IAAI,GAAI,UAACC,IAAD,EAAO;EACnB;;;;;EAMA,MAAMC,cAAc,GAAG,eAAvB;EACA,MAAMC,OAAO,GAAG,OAAhB;EACA,MAAMC,uBAAuB,GAAG,IAAhC,CATmB;;EAYnB,WAASC,MAAT,CAAgBC,GAAhB,EAAqB;EACnB,WAAO,GAAGC,QAAH,CAAYC,IAAZ,CAAiBF,GAAjB,EAAsBG,KAAtB,CAA4B,aAA5B,EAA2C,CAA3C,EAA8CC,WAA9C,EAAP;EACD;;EAED,WAASC,4BAAT,GAAwC;EACtC,WAAO;EACLC,MAAAA,QAAQ,EAAEV,cADL;EAELW,MAAAA,YAAY,EAAEX,cAFT;EAGLY,MAAAA,MAHK,kBAGEC,KAHF,EAGS;EACZ,YAAId,IAAC,CAACc,KAAK,CAACC,MAAP,CAAD,CAAgBC,EAAhB,CAAmB,IAAnB,CAAJ,EAA8B;EAC5B,iBAAOF,KAAK,CAACG,SAAN,CAAgBC,OAAhB,CAAwBC,KAAxB,CAA8B,IAA9B,EAAoCC,SAApC,CAAP,CAD4B;EAE7B;;EACD,eAAOC,SAAP,CAJY;EAKb;EARI,KAAP;EAUD;;EAED,WAASC,qBAAT,CAA+BC,QAA/B,EAAyC;EAAA;;EACvC,QAAIC,MAAM,GAAG,KAAb;EAEAxB,IAAAA,IAAC,CAAC,IAAD,CAAD,CAAQyB,GAAR,CAAY1B,IAAI,CAACE,cAAjB,EAAiC,YAAM;EACrCuB,MAAAA,MAAM,GAAG,IAAT;EACD,KAFD;EAIAE,IAAAA,UAAU,CAAC,YAAM;EACf,UAAI,CAACF,MAAL,EAAa;EACXzB,QAAAA,IAAI,CAAC4B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