mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-04 16:24:22 +01:00
1 line
8.9 KiB
Plaintext
1 line
8.9 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 let method = 'querySelector'\n\n if (!selector || selector === '#') {\n selector = (element.getAttribute('href') || '').trim()\n }\n\n const validSelector = selector\n if (selector.charAt(0) === '#' && selector.indexOf(',') === -1) {\n selector = selector.substr(1)\n method = 'getElementById'\n }\n\n try {\n return document[method](selector) ? validSelector : null\n } catch (err) {\n return null\n }\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","method","trim","validSelector","charAt","indexOf","substr","err","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,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