popper.js 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532
  1. /**!
  2. * @fileOverview Kickass library to create and place poppers near their reference elements.
  3. * @version 1.14.4
  4. * @license
  5. * Copyright (c) 2016 Federico Zivolo and contributors
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
  26. var longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
  27. var timeoutDuration = 0;
  28. for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
  29. if (isBrowser && navigator.userAgent.indexOf(longerTimeoutBrowsers[i]) >= 0) {
  30. timeoutDuration = 1;
  31. break;
  32. }
  33. }
  34. function microtaskDebounce(fn) {
  35. var called = false;
  36. return function () {
  37. if (called) {
  38. return;
  39. }
  40. called = true;
  41. window.Promise.resolve().then(function () {
  42. called = false;
  43. fn();
  44. });
  45. };
  46. }
  47. function taskDebounce(fn) {
  48. var scheduled = false;
  49. return function () {
  50. if (!scheduled) {
  51. scheduled = true;
  52. setTimeout(function () {
  53. scheduled = false;
  54. fn();
  55. }, timeoutDuration);
  56. }
  57. };
  58. }
  59. var supportsMicroTasks = isBrowser && window.Promise;
  60. /**
  61. * Create a debounced version of a method, that's asynchronously deferred
  62. * but called in the minimum time possible.
  63. *
  64. * @method
  65. * @memberof Popper.Utils
  66. * @argument {Function} fn
  67. * @returns {Function}
  68. */
  69. var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
  70. /**
  71. * Check if the given variable is a function
  72. * @method
  73. * @memberof Popper.Utils
  74. * @argument {Any} functionToCheck - variable to check
  75. * @returns {Boolean} answer to: is a function?
  76. */
  77. function isFunction(functionToCheck) {
  78. var getType = {};
  79. return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
  80. }
  81. /**
  82. * Get CSS computed property of the given element
  83. * @method
  84. * @memberof Popper.Utils
  85. * @argument {Eement} element
  86. * @argument {String} property
  87. */
  88. function getStyleComputedProperty(element, property) {
  89. if (element.nodeType !== 1) {
  90. return [];
  91. }
  92. // NOTE: 1 DOM access here
  93. var css = getComputedStyle(element, null);
  94. return property ? css[property] : css;
  95. }
  96. /**
  97. * Returns the parentNode or the host of the element
  98. * @method
  99. * @memberof Popper.Utils
  100. * @argument {Element} element
  101. * @returns {Element} parent
  102. */
  103. function getParentNode(element) {
  104. if (element.nodeName === 'HTML') {
  105. return element;
  106. }
  107. return element.parentNode || element.host;
  108. }
  109. /**
  110. * Returns the scrolling parent of the given element
  111. * @method
  112. * @memberof Popper.Utils
  113. * @argument {Element} element
  114. * @returns {Element} scroll parent
  115. */
  116. function getScrollParent(element) {
  117. // Return body, `getScroll` will take care to get the correct `scrollTop` from it
  118. if (!element) {
  119. return document.body;
  120. }
  121. switch (element.nodeName) {
  122. case 'HTML':
  123. case 'BODY':
  124. return element.ownerDocument.body;
  125. case '#document':
  126. return element.body;
  127. }
  128. // Firefox want us to check `-x` and `-y` variations as well
  129. var _getStyleComputedProp = getStyleComputedProperty(element),
  130. overflow = _getStyleComputedProp.overflow,
  131. overflowX = _getStyleComputedProp.overflowX,
  132. overflowY = _getStyleComputedProp.overflowY;
  133. if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
  134. return element;
  135. }
  136. return getScrollParent(getParentNode(element));
  137. }
  138. var isIE11 = isBrowser && !!(window.MSInputMethodContext && document.documentMode);
  139. var isIE10 = isBrowser && /MSIE 10/.test(navigator.userAgent);
  140. /**
  141. * Determines if the browser is Internet Explorer
  142. * @method
  143. * @memberof Popper.Utils
  144. * @param {Number} version to check
  145. * @returns {Boolean} isIE
  146. */
  147. function isIE(version) {
  148. if (version === 11) {
  149. return isIE11;
  150. }
  151. if (version === 10) {
  152. return isIE10;
  153. }
  154. return isIE11 || isIE10;
  155. }
  156. /**
  157. * Returns the offset parent of the given element
  158. * @method
  159. * @memberof Popper.Utils
  160. * @argument {Element} element
  161. * @returns {Element} offset parent
  162. */
  163. function getOffsetParent(element) {
  164. if (!element) {
  165. return document.documentElement;
  166. }
  167. var noOffsetParent = isIE(10) ? document.body : null;
  168. // NOTE: 1 DOM access here
  169. var offsetParent = element.offsetParent;
  170. // Skip hidden elements which don't have an offsetParent
  171. while (offsetParent === noOffsetParent && element.nextElementSibling) {
  172. offsetParent = (element = element.nextElementSibling).offsetParent;
  173. }
  174. var nodeName = offsetParent && offsetParent.nodeName;
  175. if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
  176. return element ? element.ownerDocument.documentElement : document.documentElement;
  177. }
  178. // .offsetParent will return the closest TD or TABLE in case
  179. // no offsetParent is present, I hate this job...
  180. if (['TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') {
  181. return getOffsetParent(offsetParent);
  182. }
  183. return offsetParent;
  184. }
  185. function isOffsetContainer(element) {
  186. var nodeName = element.nodeName;
  187. if (nodeName === 'BODY') {
  188. return false;
  189. }
  190. return nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element;
  191. }
  192. /**
  193. * Finds the root node (document, shadowDOM root) of the given element
  194. * @method
  195. * @memberof Popper.Utils
  196. * @argument {Element} node
  197. * @returns {Element} root node
  198. */
  199. function getRoot(node) {
  200. if (node.parentNode !== null) {
  201. return getRoot(node.parentNode);
  202. }
  203. return node;
  204. }
  205. /**
  206. * Finds the offset parent common to the two provided nodes
  207. * @method
  208. * @memberof Popper.Utils
  209. * @argument {Element} element1
  210. * @argument {Element} element2
  211. * @returns {Element} common offset parent
  212. */
  213. function findCommonOffsetParent(element1, element2) {
  214. // This check is needed to avoid errors in case one of the elements isn't defined for any reason
  215. if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
  216. return document.documentElement;
  217. }
  218. // Here we make sure to give as "start" the element that comes first in the DOM
  219. var order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
  220. var start = order ? element1 : element2;
  221. var end = order ? element2 : element1;
  222. // Get common ancestor container
  223. var range = document.createRange();
  224. range.setStart(start, 0);
  225. range.setEnd(end, 0);
  226. var commonAncestorContainer = range.commonAncestorContainer;
  227. // Both nodes are inside #document
  228. if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
  229. if (isOffsetContainer(commonAncestorContainer)) {
  230. return commonAncestorContainer;
  231. }
  232. return getOffsetParent(commonAncestorContainer);
  233. }
  234. // one of the nodes is inside shadowDOM, find which one
  235. var element1root = getRoot(element1);
  236. if (element1root.host) {
  237. return findCommonOffsetParent(element1root.host, element2);
  238. } else {
  239. return findCommonOffsetParent(element1, getRoot(element2).host);
  240. }
  241. }
  242. /**
  243. * Gets the scroll value of the given element in the given side (top and left)
  244. * @method
  245. * @memberof Popper.Utils
  246. * @argument {Element} element
  247. * @argument {String} side `top` or `left`
  248. * @returns {number} amount of scrolled pixels
  249. */
  250. function getScroll(element) {
  251. var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top';
  252. var upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft';
  253. var nodeName = element.nodeName;
  254. if (nodeName === 'BODY' || nodeName === 'HTML') {
  255. var html = element.ownerDocument.documentElement;
  256. var scrollingElement = element.ownerDocument.scrollingElement || html;
  257. return scrollingElement[upperSide];
  258. }
  259. return element[upperSide];
  260. }
  261. /*
  262. * Sum or subtract the element scroll values (left and top) from a given rect object
  263. * @method
  264. * @memberof Popper.Utils
  265. * @param {Object} rect - Rect object you want to change
  266. * @param {HTMLElement} element - The element from the function reads the scroll values
  267. * @param {Boolean} subtract - set to true if you want to subtract the scroll values
  268. * @return {Object} rect - The modifier rect object
  269. */
  270. function includeScroll(rect, element) {
  271. var subtract = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  272. var scrollTop = getScroll(element, 'top');
  273. var scrollLeft = getScroll(element, 'left');
  274. var modifier = subtract ? -1 : 1;
  275. rect.top += scrollTop * modifier;
  276. rect.bottom += scrollTop * modifier;
  277. rect.left += scrollLeft * modifier;
  278. rect.right += scrollLeft * modifier;
  279. return rect;
  280. }
  281. /*
  282. * Helper to detect borders of a given element
  283. * @method
  284. * @memberof Popper.Utils
  285. * @param {CSSStyleDeclaration} styles
  286. * Result of `getStyleComputedProperty` on the given element
  287. * @param {String} axis - `x` or `y`
  288. * @return {number} borders - The borders size of the given axis
  289. */
  290. function getBordersSize(styles, axis) {
  291. var sideA = axis === 'x' ? 'Left' : 'Top';
  292. var sideB = sideA === 'Left' ? 'Right' : 'Bottom';
  293. return parseFloat(styles['border' + sideA + 'Width'], 10) + parseFloat(styles['border' + sideB + 'Width'], 10);
  294. }
  295. function getSize(axis, body, html, computedStyle) {
  296. return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE(10) ? parseInt(html['offset' + axis]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')]) : 0);
  297. }
  298. function getWindowSizes(document) {
  299. var body = document.body;
  300. var html = document.documentElement;
  301. var computedStyle = isIE(10) && getComputedStyle(html);
  302. return {
  303. height: getSize('Height', body, html, computedStyle),
  304. width: getSize('Width', body, html, computedStyle)
  305. };
  306. }
  307. var classCallCheck = function (instance, Constructor) {
  308. if (!(instance instanceof Constructor)) {
  309. throw new TypeError("Cannot call a class as a function");
  310. }
  311. };
  312. var createClass = function () {
  313. function defineProperties(target, props) {
  314. for (var i = 0; i < props.length; i++) {
  315. var descriptor = props[i];
  316. descriptor.enumerable = descriptor.enumerable || false;
  317. descriptor.configurable = true;
  318. if ("value" in descriptor) descriptor.writable = true;
  319. Object.defineProperty(target, descriptor.key, descriptor);
  320. }
  321. }
  322. return function (Constructor, protoProps, staticProps) {
  323. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  324. if (staticProps) defineProperties(Constructor, staticProps);
  325. return Constructor;
  326. };
  327. }();
  328. var defineProperty = function (obj, key, value) {
  329. if (key in obj) {
  330. Object.defineProperty(obj, key, {
  331. value: value,
  332. enumerable: true,
  333. configurable: true,
  334. writable: true
  335. });
  336. } else {
  337. obj[key] = value;
  338. }
  339. return obj;
  340. };
  341. var _extends = Object.assign || function (target) {
  342. for (var i = 1; i < arguments.length; i++) {
  343. var source = arguments[i];
  344. for (var key in source) {
  345. if (Object.prototype.hasOwnProperty.call(source, key)) {
  346. target[key] = source[key];
  347. }
  348. }
  349. }
  350. return target;
  351. };
  352. /**
  353. * Given element offsets, generate an output similar to getBoundingClientRect
  354. * @method
  355. * @memberof Popper.Utils
  356. * @argument {Object} offsets
  357. * @returns {Object} ClientRect like output
  358. */
  359. function getClientRect(offsets) {
  360. return _extends({}, offsets, {
  361. right: offsets.left + offsets.width,
  362. bottom: offsets.top + offsets.height
  363. });
  364. }
  365. /**
  366. * Get bounding client rect of given element
  367. * @method
  368. * @memberof Popper.Utils
  369. * @param {HTMLElement} element
  370. * @return {Object} client rect
  371. */
  372. function getBoundingClientRect(element) {
  373. var rect = {};
  374. // IE10 10 FIX: Please, don't ask, the element isn't
  375. // considered in DOM in some circumstances...
  376. // This isn't reproducible in IE10 compatibility mode of IE11
  377. try {
  378. if (isIE(10)) {
  379. rect = element.getBoundingClientRect();
  380. var scrollTop = getScroll(element, 'top');
  381. var scrollLeft = getScroll(element, 'left');
  382. rect.top += scrollTop;
  383. rect.left += scrollLeft;
  384. rect.bottom += scrollTop;
  385. rect.right += scrollLeft;
  386. } else {
  387. rect = element.getBoundingClientRect();
  388. }
  389. } catch (e) {}
  390. var result = {
  391. left: rect.left,
  392. top: rect.top,
  393. width: rect.right - rect.left,
  394. height: rect.bottom - rect.top
  395. };
  396. // subtract scrollbar size from sizes
  397. var sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {};
  398. var width = sizes.width || element.clientWidth || result.right - result.left;
  399. var height = sizes.height || element.clientHeight || result.bottom - result.top;
  400. var horizScrollbar = element.offsetWidth - width;
  401. var vertScrollbar = element.offsetHeight - height;
  402. // if an hypothetical scrollbar is detected, we must be sure it's not a `border`
  403. // we make this check conditional for performance reasons
  404. if (horizScrollbar || vertScrollbar) {
  405. var styles = getStyleComputedProperty(element);
  406. horizScrollbar -= getBordersSize(styles, 'x');
  407. vertScrollbar -= getBordersSize(styles, 'y');
  408. result.width -= horizScrollbar;
  409. result.height -= vertScrollbar;
  410. }
  411. return getClientRect(result);
  412. }
  413. function getOffsetRectRelativeToArbitraryNode(children, parent) {
  414. var fixedPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  415. var isIE10 = isIE(10);
  416. var isHTML = parent.nodeName === 'HTML';
  417. var childrenRect = getBoundingClientRect(children);
  418. var parentRect = getBoundingClientRect(parent);
  419. var scrollParent = getScrollParent(children);
  420. var styles = getStyleComputedProperty(parent);
  421. var borderTopWidth = parseFloat(styles.borderTopWidth, 10);
  422. var borderLeftWidth = parseFloat(styles.borderLeftWidth, 10);
  423. // In cases where the parent is fixed, we must ignore negative scroll in offset calc
  424. if (fixedPosition && isHTML) {
  425. parentRect.top = Math.max(parentRect.top, 0);
  426. parentRect.left = Math.max(parentRect.left, 0);
  427. }
  428. var offsets = getClientRect({
  429. top: childrenRect.top - parentRect.top - borderTopWidth,
  430. left: childrenRect.left - parentRect.left - borderLeftWidth,
  431. width: childrenRect.width,
  432. height: childrenRect.height
  433. });
  434. offsets.marginTop = 0;
  435. offsets.marginLeft = 0;
  436. // Subtract margins of documentElement in case it's being used as parent
  437. // we do this only on HTML because it's the only element that behaves
  438. // differently when margins are applied to it. The margins are included in
  439. // the box of the documentElement, in the other cases not.
  440. if (!isIE10 && isHTML) {
  441. var marginTop = parseFloat(styles.marginTop, 10);
  442. var marginLeft = parseFloat(styles.marginLeft, 10);
  443. offsets.top -= borderTopWidth - marginTop;
  444. offsets.bottom -= borderTopWidth - marginTop;
  445. offsets.left -= borderLeftWidth - marginLeft;
  446. offsets.right -= borderLeftWidth - marginLeft;
  447. // Attach marginTop and marginLeft because in some circumstances we may need them
  448. offsets.marginTop = marginTop;
  449. offsets.marginLeft = marginLeft;
  450. }
  451. if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
  452. offsets = includeScroll(offsets, parent);
  453. }
  454. return offsets;
  455. }
  456. function getViewportOffsetRectRelativeToArtbitraryNode(element) {
  457. var excludeScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  458. var html = element.ownerDocument.documentElement;
  459. var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
  460. var width = Math.max(html.clientWidth, window.innerWidth || 0);
  461. var height = Math.max(html.clientHeight, window.innerHeight || 0);
  462. var scrollTop = !excludeScroll ? getScroll(html) : 0;
  463. var scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0;
  464. var offset = {
  465. top: scrollTop - relativeOffset.top + relativeOffset.marginTop,
  466. left: scrollLeft - relativeOffset.left + relativeOffset.marginLeft,
  467. width: width,
  468. height: height
  469. };
  470. return getClientRect(offset);
  471. }
  472. /**
  473. * Check if the given element is fixed or is inside a fixed parent
  474. * @method
  475. * @memberof Popper.Utils
  476. * @argument {Element} element
  477. * @argument {Element} customContainer
  478. * @returns {Boolean} answer to "isFixed?"
  479. */
  480. function isFixed(element) {
  481. var nodeName = element.nodeName;
  482. if (nodeName === 'BODY' || nodeName === 'HTML') {
  483. return false;
  484. }
  485. if (getStyleComputedProperty(element, 'position') === 'fixed') {
  486. return true;
  487. }
  488. return isFixed(getParentNode(element));
  489. }
  490. /**
  491. * Finds the first parent of an element that has a transformed property defined
  492. * @method
  493. * @memberof Popper.Utils
  494. * @argument {Element} element
  495. * @returns {Element} first transformed parent or documentElement
  496. */
  497. function getFixedPositionOffsetParent(element) {
  498. // This check is needed to avoid errors in case one of the elements isn't defined for any reason
  499. if (!element || !element.parentElement || isIE()) {
  500. return document.documentElement;
  501. }
  502. var el = element.parentElement;
  503. while (el && getStyleComputedProperty(el, 'transform') === 'none') {
  504. el = el.parentElement;
  505. }
  506. return el || document.documentElement;
  507. }
  508. /**
  509. * Computed the boundaries limits and return them
  510. * @method
  511. * @memberof Popper.Utils
  512. * @param {HTMLElement} popper
  513. * @param {HTMLElement} reference
  514. * @param {number} padding
  515. * @param {HTMLElement} boundariesElement - Element used to define the boundaries
  516. * @param {Boolean} fixedPosition - Is in fixed position mode
  517. * @returns {Object} Coordinates of the boundaries
  518. */
  519. function getBoundaries(popper, reference, padding, boundariesElement) {
  520. var fixedPosition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  521. // NOTE: 1 DOM access here
  522. var boundaries = { top: 0, left: 0 };
  523. var offsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
  524. // Handle viewport case
  525. if (boundariesElement === 'viewport') {
  526. boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition);
  527. } else {
  528. // Handle other cases based on DOM element used as boundaries
  529. var boundariesNode = void 0;
  530. if (boundariesElement === 'scrollParent') {
  531. boundariesNode = getScrollParent(getParentNode(reference));
  532. if (boundariesNode.nodeName === 'BODY') {
  533. boundariesNode = popper.ownerDocument.documentElement;
  534. }
  535. } else if (boundariesElement === 'window') {
  536. boundariesNode = popper.ownerDocument.documentElement;
  537. } else {
  538. boundariesNode = boundariesElement;
  539. }
  540. var offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition);
  541. // In case of HTML, we need a different computation
  542. if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) {
  543. var _getWindowSizes = getWindowSizes(popper.ownerDocument),
  544. height = _getWindowSizes.height,
  545. width = _getWindowSizes.width;
  546. boundaries.top += offsets.top - offsets.marginTop;
  547. boundaries.bottom = height + offsets.top;
  548. boundaries.left += offsets.left - offsets.marginLeft;
  549. boundaries.right = width + offsets.left;
  550. } else {
  551. // for all the other DOM elements, this one is good
  552. boundaries = offsets;
  553. }
  554. }
  555. // Add paddings
  556. padding = padding || 0;
  557. var isPaddingNumber = typeof padding === 'number';
  558. boundaries.left += isPaddingNumber ? padding : padding.left || 0;
  559. boundaries.top += isPaddingNumber ? padding : padding.top || 0;
  560. boundaries.right -= isPaddingNumber ? padding : padding.right || 0;
  561. boundaries.bottom -= isPaddingNumber ? padding : padding.bottom || 0;
  562. return boundaries;
  563. }
  564. function getArea(_ref) {
  565. var width = _ref.width,
  566. height = _ref.height;
  567. return width * height;
  568. }
  569. /**
  570. * Utility used to transform the `auto` placement to the placement with more
  571. * available space.
  572. * @method
  573. * @memberof Popper.Utils
  574. * @argument {Object} data - The data object generated by update method
  575. * @argument {Object} options - Modifiers configuration and options
  576. * @returns {Object} The data object, properly modified
  577. */
  578. function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement) {
  579. var padding = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
  580. if (placement.indexOf('auto') === -1) {
  581. return placement;
  582. }
  583. var boundaries = getBoundaries(popper, reference, padding, boundariesElement);
  584. var rects = {
  585. top: {
  586. width: boundaries.width,
  587. height: refRect.top - boundaries.top
  588. },
  589. right: {
  590. width: boundaries.right - refRect.right,
  591. height: boundaries.height
  592. },
  593. bottom: {
  594. width: boundaries.width,
  595. height: boundaries.bottom - refRect.bottom
  596. },
  597. left: {
  598. width: refRect.left - boundaries.left,
  599. height: boundaries.height
  600. }
  601. };
  602. var sortedAreas = Object.keys(rects).map(function (key) {
  603. return _extends({
  604. key: key
  605. }, rects[key], {
  606. area: getArea(rects[key])
  607. });
  608. }).sort(function (a, b) {
  609. return b.area - a.area;
  610. });
  611. var filteredAreas = sortedAreas.filter(function (_ref2) {
  612. var width = _ref2.width,
  613. height = _ref2.height;
  614. return width >= popper.clientWidth && height >= popper.clientHeight;
  615. });
  616. var computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key;
  617. var variation = placement.split('-')[1];
  618. return computedPlacement + (variation ? '-' + variation : '');
  619. }
  620. /**
  621. * Get offsets to the reference element
  622. * @method
  623. * @memberof Popper.Utils
  624. * @param {Object} state
  625. * @param {Element} popper - the popper element
  626. * @param {Element} reference - the reference element (the popper will be relative to this)
  627. * @param {Element} fixedPosition - is in fixed position mode
  628. * @returns {Object} An object containing the offsets which will be applied to the popper
  629. */
  630. function getReferenceOffsets(state, popper, reference) {
  631. var fixedPosition = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  632. var commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
  633. return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition);
  634. }
  635. /**
  636. * Get the outer sizes of the given element (offset size + margins)
  637. * @method
  638. * @memberof Popper.Utils
  639. * @argument {Element} element
  640. * @returns {Object} object containing width and height properties
  641. */
  642. function getOuterSizes(element) {
  643. var styles = getComputedStyle(element);
  644. var x = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
  645. var y = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
  646. var result = {
  647. width: element.offsetWidth + y,
  648. height: element.offsetHeight + x
  649. };
  650. return result;
  651. }
  652. /**
  653. * Get the opposite placement of the given one
  654. * @method
  655. * @memberof Popper.Utils
  656. * @argument {String} placement
  657. * @returns {String} flipped placement
  658. */
  659. function getOppositePlacement(placement) {
  660. var hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
  661. return placement.replace(/left|right|bottom|top/g, function (matched) {
  662. return hash[matched];
  663. });
  664. }
  665. /**
  666. * Get offsets to the popper
  667. * @method
  668. * @memberof Popper.Utils
  669. * @param {Object} position - CSS position the Popper will get applied
  670. * @param {HTMLElement} popper - the popper element
  671. * @param {Object} referenceOffsets - the reference offsets (the popper will be relative to this)
  672. * @param {String} placement - one of the valid placement options
  673. * @returns {Object} popperOffsets - An object containing the offsets which will be applied to the popper
  674. */
  675. function getPopperOffsets(popper, referenceOffsets, placement) {
  676. placement = placement.split('-')[0];
  677. // Get popper node sizes
  678. var popperRect = getOuterSizes(popper);
  679. // Add position, width and height to our offsets object
  680. var popperOffsets = {
  681. width: popperRect.width,
  682. height: popperRect.height
  683. };
  684. // depending by the popper placement we have to compute its offsets slightly differently
  685. var isHoriz = ['right', 'left'].indexOf(placement) !== -1;
  686. var mainSide = isHoriz ? 'top' : 'left';
  687. var secondarySide = isHoriz ? 'left' : 'top';
  688. var measurement = isHoriz ? 'height' : 'width';
  689. var secondaryMeasurement = !isHoriz ? 'height' : 'width';
  690. popperOffsets[mainSide] = referenceOffsets[mainSide] + referenceOffsets[measurement] / 2 - popperRect[measurement] / 2;
  691. if (placement === secondarySide) {
  692. popperOffsets[secondarySide] = referenceOffsets[secondarySide] - popperRect[secondaryMeasurement];
  693. } else {
  694. popperOffsets[secondarySide] = referenceOffsets[getOppositePlacement(secondarySide)];
  695. }
  696. return popperOffsets;
  697. }
  698. /**
  699. * Mimics the `find` method of Array
  700. * @method
  701. * @memberof Popper.Utils
  702. * @argument {Array} arr
  703. * @argument prop
  704. * @argument value
  705. * @returns index or -1
  706. */
  707. function find(arr, check) {
  708. // use native find if supported
  709. if (Array.prototype.find) {
  710. return arr.find(check);
  711. }
  712. // use `filter` to obtain the same behavior of `find`
  713. return arr.filter(check)[0];
  714. }
  715. /**
  716. * Return the index of the matching object
  717. * @method
  718. * @memberof Popper.Utils
  719. * @argument {Array} arr
  720. * @argument prop
  721. * @argument value
  722. * @returns index or -1
  723. */
  724. function findIndex(arr, prop, value) {
  725. // use native findIndex if supported
  726. if (Array.prototype.findIndex) {
  727. return arr.findIndex(function (cur) {
  728. return cur[prop] === value;
  729. });
  730. }
  731. // use `find` + `indexOf` if `findIndex` isn't supported
  732. var match = find(arr, function (obj) {
  733. return obj[prop] === value;
  734. });
  735. return arr.indexOf(match);
  736. }
  737. /**
  738. * Loop trough the list of modifiers and run them in order,
  739. * each of them will then edit the data object.
  740. * @method
  741. * @memberof Popper.Utils
  742. * @param {dataObject} data
  743. * @param {Array} modifiers
  744. * @param {String} ends - Optional modifier name used as stopper
  745. * @returns {dataObject}
  746. */
  747. function runModifiers(modifiers, data, ends) {
  748. var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
  749. modifiersToRun.forEach(function (modifier) {
  750. if (modifier['function']) {
  751. // eslint-disable-line dot-notation
  752. console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
  753. }
  754. var fn = modifier['function'] || modifier.fn; // eslint-disable-line dot-notation
  755. if (modifier.enabled && isFunction(fn)) {
  756. // Add properties to offsets to make them a complete clientRect object
  757. // we do this before each modifier to make sure the previous one doesn't
  758. // mess with these values
  759. data.offsets.popper = getClientRect(data.offsets.popper);
  760. data.offsets.reference = getClientRect(data.offsets.reference);
  761. data = fn(data, modifier);
  762. }
  763. });
  764. return data;
  765. }
  766. /**
  767. * Updates the position of the popper, computing the new offsets and applying
  768. * the new style.<br />
  769. * Prefer `scheduleUpdate` over `update` because of performance reasons.
  770. * @method
  771. * @memberof Popper
  772. */
  773. function update() {
  774. // if popper is destroyed, don't perform any further update
  775. if (this.state.isDestroyed) {
  776. return;
  777. }
  778. var data = {
  779. instance: this,
  780. styles: {},
  781. arrowStyles: {},
  782. attributes: {},
  783. flipped: false,
  784. offsets: {}
  785. };
  786. // compute reference element offsets
  787. data.offsets.reference = getReferenceOffsets(this.state, this.popper, this.reference, this.options.positionFixed);
  788. // compute auto placement, store placement inside the data object,
  789. // modifiers will be able to edit `placement` if needed
  790. // and refer to originalPlacement to know the original value
  791. data.placement = computeAutoPlacement(this.options.placement, data.offsets.reference, this.popper, this.reference, this.options.modifiers.flip.boundariesElement, this.options.modifiers.flip.padding);
  792. // store the computed placement inside `originalPlacement`
  793. data.originalPlacement = data.placement;
  794. data.positionFixed = this.options.positionFixed;
  795. // compute the popper offsets
  796. data.offsets.popper = getPopperOffsets(this.popper, data.offsets.reference, data.placement);
  797. data.offsets.popper.position = this.options.positionFixed ? 'fixed' : 'absolute';
  798. // run the modifiers
  799. data = runModifiers(this.modifiers, data);
  800. // the first `update` will call `onCreate` callback
  801. // the other ones will call `onUpdate` callback
  802. if (!this.state.isCreated) {
  803. this.state.isCreated = true;
  804. this.options.onCreate(data);
  805. } else {
  806. this.options.onUpdate(data);
  807. }
  808. }
  809. /**
  810. * Helper used to know if the given modifier is enabled.
  811. * @method
  812. * @memberof Popper.Utils
  813. * @returns {Boolean}
  814. */
  815. function isModifierEnabled(modifiers, modifierName) {
  816. return modifiers.some(function (_ref) {
  817. var name = _ref.name,
  818. enabled = _ref.enabled;
  819. return enabled && name === modifierName;
  820. });
  821. }
  822. /**
  823. * Get the prefixed supported property name
  824. * @method
  825. * @memberof Popper.Utils
  826. * @argument {String} property (camelCase)
  827. * @returns {String} prefixed property (camelCase or PascalCase, depending on the vendor prefix)
  828. */
  829. function getSupportedPropertyName(property) {
  830. var prefixes = [false, 'ms', 'Webkit', 'Moz', 'O'];
  831. var upperProp = property.charAt(0).toUpperCase() + property.slice(1);
  832. for (var i = 0; i < prefixes.length; i++) {
  833. var prefix = prefixes[i];
  834. var toCheck = prefix ? '' + prefix + upperProp : property;
  835. if (typeof document.body.style[toCheck] !== 'undefined') {
  836. return toCheck;
  837. }
  838. }
  839. return null;
  840. }
  841. /**
  842. * Destroys the popper.
  843. * @method
  844. * @memberof Popper
  845. */
  846. function destroy() {
  847. this.state.isDestroyed = true;
  848. // touch DOM only if `applyStyle` modifier is enabled
  849. if (isModifierEnabled(this.modifiers, 'applyStyle')) {
  850. this.popper.removeAttribute('x-placement');
  851. this.popper.style.position = '';
  852. this.popper.style.top = '';
  853. this.popper.style.left = '';
  854. this.popper.style.right = '';
  855. this.popper.style.bottom = '';
  856. this.popper.style.willChange = '';
  857. this.popper.style[getSupportedPropertyName('transform')] = '';
  858. }
  859. this.disableEventListeners();
  860. // remove the popper if user explicity asked for the deletion on destroy
  861. // do not use `remove` because IE11 doesn't support it
  862. if (this.options.removeOnDestroy) {
  863. this.popper.parentNode.removeChild(this.popper);
  864. }
  865. return this;
  866. }
  867. /**
  868. * Get the window associated with the element
  869. * @argument {Element} element
  870. * @returns {Window}
  871. */
  872. function getWindow(element) {
  873. var ownerDocument = element.ownerDocument;
  874. return ownerDocument ? ownerDocument.defaultView : window;
  875. }
  876. function attachToScrollParents(scrollParent, event, callback, scrollParents) {
  877. var isBody = scrollParent.nodeName === 'BODY';
  878. var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
  879. target.addEventListener(event, callback, { passive: true });
  880. if (!isBody) {
  881. attachToScrollParents(getScrollParent(target.parentNode), event, callback, scrollParents);
  882. }
  883. scrollParents.push(target);
  884. }
  885. /**
  886. * Setup needed event listeners used to update the popper position
  887. * @method
  888. * @memberof Popper.Utils
  889. * @private
  890. */
  891. function setupEventListeners(reference, options, state, updateBound) {
  892. // Resize event listener on window
  893. state.updateBound = updateBound;
  894. getWindow(reference).addEventListener('resize', state.updateBound, { passive: true });
  895. // Scroll event listener on scroll parents
  896. var scrollElement = getScrollParent(reference);
  897. attachToScrollParents(scrollElement, 'scroll', state.updateBound, state.scrollParents);
  898. state.scrollElement = scrollElement;
  899. state.eventsEnabled = true;
  900. return state;
  901. }
  902. /**
  903. * It will add resize/scroll events and start recalculating
  904. * position of the popper element when they are triggered.
  905. * @method
  906. * @memberof Popper
  907. */
  908. function enableEventListeners() {
  909. if (!this.state.eventsEnabled) {
  910. this.state = setupEventListeners(this.reference, this.options, this.state, this.scheduleUpdate);
  911. }
  912. }
  913. /**
  914. * Remove event listeners used to update the popper position
  915. * @method
  916. * @memberof Popper.Utils
  917. * @private
  918. */
  919. function removeEventListeners(reference, state) {
  920. // Remove resize event listener on window
  921. getWindow(reference).removeEventListener('resize', state.updateBound);
  922. // Remove scroll event listener on scroll parents
  923. state.scrollParents.forEach(function (target) {
  924. target.removeEventListener('scroll', state.updateBound);
  925. });
  926. // Reset state
  927. state.updateBound = null;
  928. state.scrollParents = [];
  929. state.scrollElement = null;
  930. state.eventsEnabled = false;
  931. return state;
  932. }
  933. /**
  934. * It will remove resize/scroll events and won't recalculate popper position
  935. * when they are triggered. It also won't trigger `onUpdate` callback anymore,
  936. * unless you call `update` method manually.
  937. * @method
  938. * @memberof Popper
  939. */
  940. function disableEventListeners() {
  941. if (this.state.eventsEnabled) {
  942. cancelAnimationFrame(this.scheduleUpdate);
  943. this.state = removeEventListeners(this.reference, this.state);
  944. }
  945. }
  946. /**
  947. * Tells if a given input is a number
  948. * @method
  949. * @memberof Popper.Utils
  950. * @param {*} input to check
  951. * @return {Boolean}
  952. */
  953. function isNumeric(n) {
  954. return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
  955. }
  956. /**
  957. * Set the style to the given popper
  958. * @method
  959. * @memberof Popper.Utils
  960. * @argument {Element} element - Element to apply the style to
  961. * @argument {Object} styles
  962. * Object with a list of properties and values which will be applied to the element
  963. */
  964. function setStyles(element, styles) {
  965. Object.keys(styles).forEach(function (prop) {
  966. var unit = '';
  967. // add unit if the value is numeric and is one of the following
  968. if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) {
  969. unit = 'px';
  970. }
  971. element.style[prop] = styles[prop] + unit;
  972. });
  973. }
  974. /**
  975. * Set the attributes to the given popper
  976. * @method
  977. * @memberof Popper.Utils
  978. * @argument {Element} element - Element to apply the attributes to
  979. * @argument {Object} styles
  980. * Object with a list of properties and values which will be applied to the element
  981. */
  982. function setAttributes(element, attributes) {
  983. Object.keys(attributes).forEach(function (prop) {
  984. var value = attributes[prop];
  985. if (value !== false) {
  986. element.setAttribute(prop, attributes[prop]);
  987. } else {
  988. element.removeAttribute(prop);
  989. }
  990. });
  991. }
  992. /**
  993. * @function
  994. * @memberof Modifiers
  995. * @argument {Object} data - The data object generated by `update` method
  996. * @argument {Object} data.styles - List of style properties - values to apply to popper element
  997. * @argument {Object} data.attributes - List of attribute properties - values to apply to popper element
  998. * @argument {Object} options - Modifiers configuration and options
  999. * @returns {Object} The same data object
  1000. */
  1001. function applyStyle(data) {
  1002. // any property present in `data.styles` will be applied to the popper,
  1003. // in this way we can make the 3rd party modifiers add custom styles to it
  1004. // Be aware, modifiers could override the properties defined in the previous
  1005. // lines of this modifier!
  1006. setStyles(data.instance.popper, data.styles);
  1007. // any property present in `data.attributes` will be applied to the popper,
  1008. // they will be set as HTML attributes of the element
  1009. setAttributes(data.instance.popper, data.attributes);
  1010. // if arrowElement is defined and arrowStyles has some properties
  1011. if (data.arrowElement && Object.keys(data.arrowStyles).length) {
  1012. setStyles(data.arrowElement, data.arrowStyles);
  1013. }
  1014. return data;
  1015. }
  1016. /**
  1017. * Set the x-placement attribute before everything else because it could be used
  1018. * to add margins to the popper margins needs to be calculated to get the
  1019. * correct popper offsets.
  1020. * @method
  1021. * @memberof Popper.modifiers
  1022. * @param {HTMLElement} reference - The reference element used to position the popper
  1023. * @param {HTMLElement} popper - The HTML element used as popper
  1024. * @param {Object} options - Popper.js options
  1025. */
  1026. function applyStyleOnLoad(reference, popper, options, modifierOptions, state) {
  1027. // compute reference element offsets
  1028. var referenceOffsets = getReferenceOffsets(state, popper, reference, options.positionFixed);
  1029. // compute auto placement, store placement inside the data object,
  1030. // modifiers will be able to edit `placement` if needed
  1031. // and refer to originalPlacement to know the original value
  1032. var placement = computeAutoPlacement(options.placement, referenceOffsets, popper, reference, options.modifiers.flip.boundariesElement, options.modifiers.flip.padding);
  1033. popper.setAttribute('x-placement', placement);
  1034. // Apply `position` to popper before anything else because
  1035. // without the position applied we can't guarantee correct computations
  1036. setStyles(popper, { position: options.positionFixed ? 'fixed' : 'absolute' });
  1037. return options;
  1038. }
  1039. /**
  1040. * @function
  1041. * @memberof Modifiers
  1042. * @argument {Object} data - The data object generated by `update` method
  1043. * @argument {Object} options - Modifiers configuration and options
  1044. * @returns {Object} The data object, properly modified
  1045. */
  1046. function computeStyle(data, options) {
  1047. var x = options.x,
  1048. y = options.y;
  1049. var popper = data.offsets.popper;
  1050. // Remove this legacy support in Popper.js v2
  1051. var legacyGpuAccelerationOption = find(data.instance.modifiers, function (modifier) {
  1052. return modifier.name === 'applyStyle';
  1053. }).gpuAcceleration;
  1054. if (legacyGpuAccelerationOption !== undefined) {
  1055. console.warn('WARNING: `gpuAcceleration` option moved to `computeStyle` modifier and will not be supported in future versions of Popper.js!');
  1056. }
  1057. var gpuAcceleration = legacyGpuAccelerationOption !== undefined ? legacyGpuAccelerationOption : options.gpuAcceleration;
  1058. var offsetParent = getOffsetParent(data.instance.popper);
  1059. var offsetParentRect = getBoundingClientRect(offsetParent);
  1060. // Styles
  1061. var styles = {
  1062. position: popper.position
  1063. };
  1064. // Avoid blurry text by using full pixel integers.
  1065. // For pixel-perfect positioning, top/bottom prefers rounded
  1066. // values, while left/right prefers floored values.
  1067. var offsets = {
  1068. left: Math.floor(popper.left),
  1069. top: Math.round(popper.top),
  1070. bottom: Math.round(popper.bottom),
  1071. right: Math.floor(popper.right)
  1072. };
  1073. var sideA = x === 'bottom' ? 'top' : 'bottom';
  1074. var sideB = y === 'right' ? 'left' : 'right';
  1075. // if gpuAcceleration is set to `true` and transform is supported,
  1076. // we use `translate3d` to apply the position to the popper we
  1077. // automatically use the supported prefixed version if needed
  1078. var prefixedProperty = getSupportedPropertyName('transform');
  1079. // now, let's make a step back and look at this code closely (wtf?)
  1080. // If the content of the popper grows once it's been positioned, it
  1081. // may happen that the popper gets misplaced because of the new content
  1082. // overflowing its reference element
  1083. // To avoid this problem, we provide two options (x and y), which allow
  1084. // the consumer to define the offset origin.
  1085. // If we position a popper on top of a reference element, we can set
  1086. // `x` to `top` to make the popper grow towards its top instead of
  1087. // its bottom.
  1088. var left = void 0,
  1089. top = void 0;
  1090. if (sideA === 'bottom') {
  1091. // when offsetParent is <html> the positioning is relative to the bottom of the screen (excluding the scrollbar)
  1092. // and not the bottom of the html element
  1093. if (offsetParent.nodeName === 'HTML') {
  1094. top = -offsetParent.clientHeight + offsets.bottom;
  1095. } else {
  1096. top = -offsetParentRect.height + offsets.bottom;
  1097. }
  1098. } else {
  1099. top = offsets.top;
  1100. }
  1101. if (sideB === 'right') {
  1102. if (offsetParent.nodeName === 'HTML') {
  1103. left = -offsetParent.clientWidth + offsets.right;
  1104. } else {
  1105. left = -offsetParentRect.width + offsets.right;
  1106. }
  1107. } else {
  1108. left = offsets.left;
  1109. }
  1110. if (gpuAcceleration && prefixedProperty) {
  1111. styles[prefixedProperty] = 'translate3d(' + left + 'px, ' + top + 'px, 0)';
  1112. styles[sideA] = 0;
  1113. styles[sideB] = 0;
  1114. styles.willChange = 'transform';
  1115. } else {
  1116. // othwerise, we use the standard `top`, `left`, `bottom` and `right` properties
  1117. var invertTop = sideA === 'bottom' ? -1 : 1;
  1118. var invertLeft = sideB === 'right' ? -1 : 1;
  1119. styles[sideA] = top * invertTop;
  1120. styles[sideB] = left * invertLeft;
  1121. styles.willChange = sideA + ', ' + sideB;
  1122. }
  1123. // Attributes
  1124. var attributes = {
  1125. 'x-placement': data.placement
  1126. };
  1127. // Update `data` attributes, styles and arrowStyles
  1128. data.attributes = _extends({}, attributes, data.attributes);
  1129. data.styles = _extends({}, styles, data.styles);
  1130. data.arrowStyles = _extends({}, data.offsets.arrow, data.arrowStyles);
  1131. return data;
  1132. }
  1133. /**
  1134. * Helper used to know if the given modifier depends from another one.<br />
  1135. * It checks if the needed modifier is listed and enabled.
  1136. * @method
  1137. * @memberof Popper.Utils
  1138. * @param {Array} modifiers - list of modifiers
  1139. * @param {String} requestingName - name of requesting modifier
  1140. * @param {String} requestedName - name of requested modifier
  1141. * @returns {Boolean}
  1142. */
  1143. function isModifierRequired(modifiers, requestingName, requestedName) {
  1144. var requesting = find(modifiers, function (_ref) {
  1145. var name = _ref.name;
  1146. return name === requestingName;
  1147. });
  1148. var isRequired = !!requesting && modifiers.some(function (modifier) {
  1149. return modifier.name === requestedName && modifier.enabled && modifier.order < requesting.order;
  1150. });
  1151. if (!isRequired) {
  1152. var _requesting = '`' + requestingName + '`';
  1153. var requested = '`' + requestedName + '`';
  1154. console.warn(requested + ' modifier is required by ' + _requesting + ' modifier in order to work, be sure to include it before ' + _requesting + '!');
  1155. }
  1156. return isRequired;
  1157. }
  1158. /**
  1159. * @function
  1160. * @memberof Modifiers
  1161. * @argument {Object} data - The data object generated by update method
  1162. * @argument {Object} options - Modifiers configuration and options
  1163. * @returns {Object} The data object, properly modified
  1164. */
  1165. function arrow(data, options) {
  1166. var _data$offsets$arrow;
  1167. // arrow depends on keepTogether in order to work
  1168. if (!isModifierRequired(data.instance.modifiers, 'arrow', 'keepTogether')) {
  1169. return data;
  1170. }
  1171. var arrowElement = options.element;
  1172. // if arrowElement is a string, suppose it's a CSS selector
  1173. if (typeof arrowElement === 'string') {
  1174. arrowElement = data.instance.popper.querySelector(arrowElement);
  1175. // if arrowElement is not found, don't run the modifier
  1176. if (!arrowElement) {
  1177. return data;
  1178. }
  1179. } else {
  1180. // if the arrowElement isn't a query selector we must check that the
  1181. // provided DOM node is child of its popper node
  1182. if (!data.instance.popper.contains(arrowElement)) {
  1183. console.warn('WARNING: `arrow.element` must be child of its popper element!');
  1184. return data;
  1185. }
  1186. }
  1187. var placement = data.placement.split('-')[0];
  1188. var _data$offsets = data.offsets,
  1189. popper = _data$offsets.popper,
  1190. reference = _data$offsets.reference;
  1191. var isVertical = ['left', 'right'].indexOf(placement) !== -1;
  1192. var len = isVertical ? 'height' : 'width';
  1193. var sideCapitalized = isVertical ? 'Top' : 'Left';
  1194. var side = sideCapitalized.toLowerCase();
  1195. var altSide = isVertical ? 'left' : 'top';
  1196. var opSide = isVertical ? 'bottom' : 'right';
  1197. var arrowElementSize = getOuterSizes(arrowElement)[len];
  1198. //
  1199. // extends keepTogether behavior making sure the popper and its
  1200. // reference have enough pixels in conjunction
  1201. //
  1202. // top/left side
  1203. if (reference[opSide] - arrowElementSize < popper[side]) {
  1204. data.offsets.popper[side] -= popper[side] - (reference[opSide] - arrowElementSize);
  1205. }
  1206. // bottom/right side
  1207. if (reference[side] + arrowElementSize > popper[opSide]) {
  1208. data.offsets.popper[side] += reference[side] + arrowElementSize - popper[opSide];
  1209. }
  1210. data.offsets.popper = getClientRect(data.offsets.popper);
  1211. // compute center of the popper
  1212. var center = reference[side] + reference[len] / 2 - arrowElementSize / 2;
  1213. // Compute the sideValue using the updated popper offsets
  1214. // take popper margin in account because we don't have this info available
  1215. var css = getStyleComputedProperty(data.instance.popper);
  1216. var popperMarginSide = parseFloat(css['margin' + sideCapitalized], 10);
  1217. var popperBorderSide = parseFloat(css['border' + sideCapitalized + 'Width'], 10);
  1218. var sideValue = center - data.offsets.popper[side] - popperMarginSide - popperBorderSide;
  1219. // prevent arrowElement from being placed not contiguously to its popper
  1220. sideValue = Math.max(Math.min(popper[len] - arrowElementSize, sideValue), 0);
  1221. data.arrowElement = arrowElement;
  1222. data.offsets.arrow = (_data$offsets$arrow = {}, defineProperty(_data$offsets$arrow, side, Math.round(sideValue)), defineProperty(_data$offsets$arrow, altSide, ''), _data$offsets$arrow);
  1223. return data;
  1224. }
  1225. /**
  1226. * Get the opposite placement variation of the given one
  1227. * @method
  1228. * @memberof Popper.Utils
  1229. * @argument {String} placement variation
  1230. * @returns {String} flipped placement variation
  1231. */
  1232. function getOppositeVariation(variation) {
  1233. if (variation === 'end') {
  1234. return 'start';
  1235. } else if (variation === 'start') {
  1236. return 'end';
  1237. }
  1238. return variation;
  1239. }
  1240. /**
  1241. * List of accepted placements to use as values of the `placement` option.<br />
  1242. * Valid placements are:
  1243. * - `auto`
  1244. * - `top`
  1245. * - `right`
  1246. * - `bottom`
  1247. * - `left`
  1248. *
  1249. * Each placement can have a variation from this list:
  1250. * - `-start`
  1251. * - `-end`
  1252. *
  1253. * Variations are interpreted easily if you think of them as the left to right
  1254. * written languages. Horizontally (`top` and `bottom`), `start` is left and `end`
  1255. * is right.<br />
  1256. * Vertically (`left` and `right`), `start` is top and `end` is bottom.
  1257. *
  1258. * Some valid examples are:
  1259. * - `top-end` (on top of reference, right aligned)
  1260. * - `right-start` (on right of reference, top aligned)
  1261. * - `bottom` (on bottom, centered)
  1262. * - `auto-end` (on the side with more space available, alignment depends by placement)
  1263. *
  1264. * @static
  1265. * @type {Array}
  1266. * @enum {String}
  1267. * @readonly
  1268. * @method placements
  1269. * @memberof Popper
  1270. */
  1271. var placements = ['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start'];
  1272. // Get rid of `auto` `auto-start` and `auto-end`
  1273. var validPlacements = placements.slice(3);
  1274. /**
  1275. * Given an initial placement, returns all the subsequent placements
  1276. * clockwise (or counter-clockwise).
  1277. *
  1278. * @method
  1279. * @memberof Popper.Utils
  1280. * @argument {String} placement - A valid placement (it accepts variations)
  1281. * @argument {Boolean} counter - Set to true to walk the placements counterclockwise
  1282. * @returns {Array} placements including their variations
  1283. */
  1284. function clockwise(placement) {
  1285. var counter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1286. var index = validPlacements.indexOf(placement);
  1287. var arr = validPlacements.slice(index + 1).concat(validPlacements.slice(0, index));
  1288. return counter ? arr.reverse() : arr;
  1289. }
  1290. var BEHAVIORS = {
  1291. FLIP: 'flip',
  1292. CLOCKWISE: 'clockwise',
  1293. COUNTERCLOCKWISE: 'counterclockwise'
  1294. };
  1295. /**
  1296. * @function
  1297. * @memberof Modifiers
  1298. * @argument {Object} data - The data object generated by update method
  1299. * @argument {Object} options - Modifiers configuration and options
  1300. * @returns {Object} The data object, properly modified
  1301. */
  1302. function flip(data, options) {
  1303. // if `inner` modifier is enabled, we can't use the `flip` modifier
  1304. if (isModifierEnabled(data.instance.modifiers, 'inner')) {
  1305. return data;
  1306. }
  1307. if (data.flipped && data.placement === data.originalPlacement) {
  1308. // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides
  1309. return data;
  1310. }
  1311. var boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, options.boundariesElement, data.positionFixed);
  1312. var placement = data.placement.split('-')[0];
  1313. var placementOpposite = getOppositePlacement(placement);
  1314. var variation = data.placement.split('-')[1] || '';
  1315. var flipOrder = [];
  1316. switch (options.behavior) {
  1317. case BEHAVIORS.FLIP:
  1318. flipOrder = [placement, placementOpposite];
  1319. break;
  1320. case BEHAVIORS.CLOCKWISE:
  1321. flipOrder = clockwise(placement);
  1322. break;
  1323. case BEHAVIORS.COUNTERCLOCKWISE:
  1324. flipOrder = clockwise(placement, true);
  1325. break;
  1326. default:
  1327. flipOrder = options.behavior;
  1328. }
  1329. flipOrder.forEach(function (step, index) {
  1330. if (placement !== step || flipOrder.length === index + 1) {
  1331. return data;
  1332. }
  1333. placement = data.placement.split('-')[0];
  1334. placementOpposite = getOppositePlacement(placement);
  1335. var popperOffsets = data.offsets.popper;
  1336. var refOffsets = data.offsets.reference;
  1337. // using floor because the reference offsets may contain decimals we are not going to consider here
  1338. var floor = Math.floor;
  1339. var overlapsRef = placement === 'left' && floor(popperOffsets.right) > floor(refOffsets.left) || placement === 'right' && floor(popperOffsets.left) < floor(refOffsets.right) || placement === 'top' && floor(popperOffsets.bottom) > floor(refOffsets.top) || placement === 'bottom' && floor(popperOffsets.top) < floor(refOffsets.bottom);
  1340. var overflowsLeft = floor(popperOffsets.left) < floor(boundaries.left);
  1341. var overflowsRight = floor(popperOffsets.right) > floor(boundaries.right);
  1342. var overflowsTop = floor(popperOffsets.top) < floor(boundaries.top);
  1343. var overflowsBottom = floor(popperOffsets.bottom) > floor(boundaries.bottom);
  1344. var overflowsBoundaries = placement === 'left' && overflowsLeft || placement === 'right' && overflowsRight || placement === 'top' && overflowsTop || placement === 'bottom' && overflowsBottom;
  1345. // flip the variation if required
  1346. var isVertical = ['top', 'bottom'].indexOf(placement) !== -1;
  1347. var flippedVariation = !!options.flipVariations && (isVertical && variation === 'start' && overflowsLeft || isVertical && variation === 'end' && overflowsRight || !isVertical && variation === 'start' && overflowsTop || !isVertical && variation === 'end' && overflowsBottom);
  1348. if (overlapsRef || overflowsBoundaries || flippedVariation) {
  1349. // this boolean to detect any flip loop
  1350. data.flipped = true;
  1351. if (overlapsRef || overflowsBoundaries) {
  1352. placement = flipOrder[index + 1];
  1353. }
  1354. if (flippedVariation) {
  1355. variation = getOppositeVariation(variation);
  1356. }
  1357. data.placement = placement + (variation ? '-' + variation : '');
  1358. // this object contains `position`, we want to preserve it along with
  1359. // any additional property we may add in the future
  1360. data.offsets.popper = _extends({}, data.offsets.popper, getPopperOffsets(data.instance.popper, data.offsets.reference, data.placement));
  1361. data = runModifiers(data.instance.modifiers, data, 'flip');
  1362. }
  1363. });
  1364. return data;
  1365. }
  1366. /**
  1367. * @function
  1368. * @memberof Modifiers
  1369. * @argument {Object} data - The data object generated by update method
  1370. * @argument {Object} options - Modifiers configuration and options
  1371. * @returns {Object} The data object, properly modified
  1372. */
  1373. function keepTogether(data) {
  1374. var _data$offsets = data.offsets,
  1375. popper = _data$offsets.popper,
  1376. reference = _data$offsets.reference;
  1377. var placement = data.placement.split('-')[0];
  1378. var floor = Math.floor;
  1379. var isVertical = ['top', 'bottom'].indexOf(placement) !== -1;
  1380. var side = isVertical ? 'right' : 'bottom';
  1381. var opSide = isVertical ? 'left' : 'top';
  1382. var measurement = isVertical ? 'width' : 'height';
  1383. if (popper[side] < floor(reference[opSide])) {
  1384. data.offsets.popper[opSide] = floor(reference[opSide]) - popper[measurement];
  1385. }
  1386. if (popper[opSide] > floor(reference[side])) {
  1387. data.offsets.popper[opSide] = floor(reference[side]);
  1388. }
  1389. return data;
  1390. }
  1391. /**
  1392. * Converts a string containing value + unit into a px value number
  1393. * @function
  1394. * @memberof {modifiers~offset}
  1395. * @private
  1396. * @argument {String} str - Value + unit string
  1397. * @argument {String} measurement - `height` or `width`
  1398. * @argument {Object} popperOffsets
  1399. * @argument {Object} referenceOffsets
  1400. * @returns {Number|String}
  1401. * Value in pixels, or original string if no values were extracted
  1402. */
  1403. function toValue(str, measurement, popperOffsets, referenceOffsets) {
  1404. // separate value from unit
  1405. var split = str.match(/((?:\-|\+)?\d*\.?\d*)(.*)/);
  1406. var value = +split[1];
  1407. var unit = split[2];
  1408. // If it's not a number it's an operator, I guess
  1409. if (!value) {
  1410. return str;
  1411. }
  1412. if (unit.indexOf('%') === 0) {
  1413. var element = void 0;
  1414. switch (unit) {
  1415. case '%p':
  1416. element = popperOffsets;
  1417. break;
  1418. case '%':
  1419. case '%r':
  1420. default:
  1421. element = referenceOffsets;
  1422. }
  1423. var rect = getClientRect(element);
  1424. return rect[measurement] / 100 * value;
  1425. } else if (unit === 'vh' || unit === 'vw') {
  1426. // if is a vh or vw, we calculate the size based on the viewport
  1427. var size = void 0;
  1428. if (unit === 'vh') {
  1429. size = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  1430. } else {
  1431. size = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  1432. }
  1433. return size / 100 * value;
  1434. } else {
  1435. // if is an explicit pixel unit, we get rid of the unit and keep the value
  1436. // if is an implicit unit, it's px, and we return just the value
  1437. return value;
  1438. }
  1439. }
  1440. /**
  1441. * Parse an `offset` string to extrapolate `x` and `y` numeric offsets.
  1442. * @function
  1443. * @memberof {modifiers~offset}
  1444. * @private
  1445. * @argument {String} offset
  1446. * @argument {Object} popperOffsets
  1447. * @argument {Object} referenceOffsets
  1448. * @argument {String} basePlacement
  1449. * @returns {Array} a two cells array with x and y offsets in numbers
  1450. */
  1451. function parseOffset(offset, popperOffsets, referenceOffsets, basePlacement) {
  1452. var offsets = [0, 0];
  1453. // Use height if placement is left or right and index is 0 otherwise use width
  1454. // in this way the first offset will use an axis and the second one
  1455. // will use the other one
  1456. var useHeight = ['right', 'left'].indexOf(basePlacement) !== -1;
  1457. // Split the offset string to obtain a list of values and operands
  1458. // The regex addresses values with the plus or minus sign in front (+10, -20, etc)
  1459. var fragments = offset.split(/(\+|\-)/).map(function (frag) {
  1460. return frag.trim();
  1461. });
  1462. // Detect if the offset string contains a pair of values or a single one
  1463. // they could be separated by comma or space
  1464. var divider = fragments.indexOf(find(fragments, function (frag) {
  1465. return frag.search(/,|\s/) !== -1;
  1466. }));
  1467. if (fragments[divider] && fragments[divider].indexOf(',') === -1) {
  1468. console.warn('Offsets separated by white space(s) are deprecated, use a comma (,) instead.');
  1469. }
  1470. // If divider is found, we divide the list of values and operands to divide
  1471. // them by ofset X and Y.
  1472. var splitRegex = /\s*,\s*|\s+/;
  1473. var ops = divider !== -1 ? [fragments.slice(0, divider).concat([fragments[divider].split(splitRegex)[0]]), [fragments[divider].split(splitRegex)[1]].concat(fragments.slice(divider + 1))] : [fragments];
  1474. // Convert the values with units to absolute pixels to allow our computations
  1475. ops = ops.map(function (op, index) {
  1476. // Most of the units rely on the orientation of the popper
  1477. var measurement = (index === 1 ? !useHeight : useHeight) ? 'height' : 'width';
  1478. var mergeWithPrevious = false;
  1479. return op
  1480. // This aggregates any `+` or `-` sign that aren't considered operators
  1481. // e.g.: 10 + +5 => [10, +, +5]
  1482. .reduce(function (a, b) {
  1483. if (a[a.length - 1] === '' && ['+', '-'].indexOf(b) !== -1) {
  1484. a[a.length - 1] = b;
  1485. mergeWithPrevious = true;
  1486. return a;
  1487. } else if (mergeWithPrevious) {
  1488. a[a.length - 1] += b;
  1489. mergeWithPrevious = false;
  1490. return a;
  1491. } else {
  1492. return a.concat(b);
  1493. }
  1494. }, [])
  1495. // Here we convert the string values into number values (in px)
  1496. .map(function (str) {
  1497. return toValue(str, measurement, popperOffsets, referenceOffsets);
  1498. });
  1499. });
  1500. // Loop trough the offsets arrays and execute the operations
  1501. ops.forEach(function (op, index) {
  1502. op.forEach(function (frag, index2) {
  1503. if (isNumeric(frag)) {
  1504. offsets[index] += frag * (op[index2 - 1] === '-' ? -1 : 1);
  1505. }
  1506. });
  1507. });
  1508. return offsets;
  1509. }
  1510. /**
  1511. * @function
  1512. * @memberof Modifiers
  1513. * @argument {Object} data - The data object generated by update method
  1514. * @argument {Object} options - Modifiers configuration and options
  1515. * @argument {Number|String} options.offset=0
  1516. * The offset value as described in the modifier description
  1517. * @returns {Object} The data object, properly modified
  1518. */
  1519. function offset(data, _ref) {
  1520. var offset = _ref.offset;
  1521. var placement = data.placement,
  1522. _data$offsets = data.offsets,
  1523. popper = _data$offsets.popper,
  1524. reference = _data$offsets.reference;
  1525. var basePlacement = placement.split('-')[0];
  1526. var offsets = void 0;
  1527. if (isNumeric(+offset)) {
  1528. offsets = [+offset, 0];
  1529. } else {
  1530. offsets = parseOffset(offset, popper, reference, basePlacement);
  1531. }
  1532. if (basePlacement === 'left') {
  1533. popper.top += offsets[0];
  1534. popper.left -= offsets[1];
  1535. } else if (basePlacement === 'right') {
  1536. popper.top += offsets[0];
  1537. popper.left += offsets[1];
  1538. } else if (basePlacement === 'top') {
  1539. popper.left += offsets[0];
  1540. popper.top -= offsets[1];
  1541. } else if (basePlacement === 'bottom') {
  1542. popper.left += offsets[0];
  1543. popper.top += offsets[1];
  1544. }
  1545. data.popper = popper;
  1546. return data;
  1547. }
  1548. /**
  1549. * @function
  1550. * @memberof Modifiers
  1551. * @argument {Object} data - The data object generated by `update` method
  1552. * @argument {Object} options - Modifiers configuration and options
  1553. * @returns {Object} The data object, properly modified
  1554. */
  1555. function preventOverflow(data, options) {
  1556. var boundariesElement = options.boundariesElement || getOffsetParent(data.instance.popper);
  1557. // If offsetParent is the reference element, we really want to
  1558. // go one step up and use the next offsetParent as reference to
  1559. // avoid to make this modifier completely useless and look like broken
  1560. if (data.instance.reference === boundariesElement) {
  1561. boundariesElement = getOffsetParent(boundariesElement);
  1562. }
  1563. // NOTE: DOM access here
  1564. // resets the popper's position so that the document size can be calculated excluding
  1565. // the size of the popper element itself
  1566. var transformProp = getSupportedPropertyName('transform');
  1567. var popperStyles = data.instance.popper.style; // assignment to help minification
  1568. var top = popperStyles.top,
  1569. left = popperStyles.left,
  1570. transform = popperStyles[transformProp];
  1571. popperStyles.top = '';
  1572. popperStyles.left = '';
  1573. popperStyles[transformProp] = '';
  1574. var boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, boundariesElement, data.positionFixed);
  1575. // NOTE: DOM access here
  1576. // restores the original style properties after the offsets have been computed
  1577. popperStyles.top = top;
  1578. popperStyles.left = left;
  1579. popperStyles[transformProp] = transform;
  1580. options.boundaries = boundaries;
  1581. var order = options.priority;
  1582. var popper = data.offsets.popper;
  1583. var check = {
  1584. primary: function primary(placement) {
  1585. var value = popper[placement];
  1586. if (popper[placement] < boundaries[placement] && !options.escapeWithReference) {
  1587. value = Math.max(popper[placement], boundaries[placement]);
  1588. }
  1589. return defineProperty({}, placement, value);
  1590. },
  1591. secondary: function secondary(placement) {
  1592. var mainSide = placement === 'right' ? 'left' : 'top';
  1593. var value = popper[mainSide];
  1594. if (popper[placement] > boundaries[placement] && !options.escapeWithReference) {
  1595. value = Math.min(popper[mainSide], boundaries[placement] - (placement === 'right' ? popper.width : popper.height));
  1596. }
  1597. return defineProperty({}, mainSide, value);
  1598. }
  1599. };
  1600. order.forEach(function (placement) {
  1601. var side = ['left', 'top'].indexOf(placement) !== -1 ? 'primary' : 'secondary';
  1602. popper = _extends({}, popper, check[side](placement));
  1603. });
  1604. data.offsets.popper = popper;
  1605. return data;
  1606. }
  1607. /**
  1608. * @function
  1609. * @memberof Modifiers
  1610. * @argument {Object} data - The data object generated by `update` method
  1611. * @argument {Object} options - Modifiers configuration and options
  1612. * @returns {Object} The data object, properly modified
  1613. */
  1614. function shift(data) {
  1615. var placement = data.placement;
  1616. var basePlacement = placement.split('-')[0];
  1617. var shiftvariation = placement.split('-')[1];
  1618. // if shift shiftvariation is specified, run the modifier
  1619. if (shiftvariation) {
  1620. var _data$offsets = data.offsets,
  1621. reference = _data$offsets.reference,
  1622. popper = _data$offsets.popper;
  1623. var isVertical = ['bottom', 'top'].indexOf(basePlacement) !== -1;
  1624. var side = isVertical ? 'left' : 'top';
  1625. var measurement = isVertical ? 'width' : 'height';
  1626. var shiftOffsets = {
  1627. start: defineProperty({}, side, reference[side]),
  1628. end: defineProperty({}, side, reference[side] + reference[measurement] - popper[measurement])
  1629. };
  1630. data.offsets.popper = _extends({}, popper, shiftOffsets[shiftvariation]);
  1631. }
  1632. return data;
  1633. }
  1634. /**
  1635. * @function
  1636. * @memberof Modifiers
  1637. * @argument {Object} data - The data object generated by update method
  1638. * @argument {Object} options - Modifiers configuration and options
  1639. * @returns {Object} The data object, properly modified
  1640. */
  1641. function hide(data) {
  1642. if (!isModifierRequired(data.instance.modifiers, 'hide', 'preventOverflow')) {
  1643. return data;
  1644. }
  1645. var refRect = data.offsets.reference;
  1646. var bound = find(data.instance.modifiers, function (modifier) {
  1647. return modifier.name === 'preventOverflow';
  1648. }).boundaries;
  1649. if (refRect.bottom < bound.top || refRect.left > bound.right || refRect.top > bound.bottom || refRect.right < bound.left) {
  1650. // Avoid unnecessary DOM access if visibility hasn't changed
  1651. if (data.hide === true) {
  1652. return data;
  1653. }
  1654. data.hide = true;
  1655. data.attributes['x-out-of-boundaries'] = '';
  1656. } else {
  1657. // Avoid unnecessary DOM access if visibility hasn't changed
  1658. if (data.hide === false) {
  1659. return data;
  1660. }
  1661. data.hide = false;
  1662. data.attributes['x-out-of-boundaries'] = false;
  1663. }
  1664. return data;
  1665. }
  1666. /**
  1667. * @function
  1668. * @memberof Modifiers
  1669. * @argument {Object} data - The data object generated by `update` method
  1670. * @argument {Object} options - Modifiers configuration and options
  1671. * @returns {Object} The data object, properly modified
  1672. */
  1673. function inner(data) {
  1674. var placement = data.placement;
  1675. var basePlacement = placement.split('-')[0];
  1676. var _data$offsets = data.offsets,
  1677. popper = _data$offsets.popper,
  1678. reference = _data$offsets.reference;
  1679. var isHoriz = ['left', 'right'].indexOf(basePlacement) !== -1;
  1680. var subtractLength = ['top', 'left'].indexOf(basePlacement) === -1;
  1681. popper[isHoriz ? 'left' : 'top'] = reference[basePlacement] - (subtractLength ? popper[isHoriz ? 'width' : 'height'] : 0);
  1682. data.placement = getOppositePlacement(placement);
  1683. data.offsets.popper = getClientRect(popper);
  1684. return data;
  1685. }
  1686. /**
  1687. * Modifier function, each modifier can have a function of this type assigned
  1688. * to its `fn` property.<br />
  1689. * These functions will be called on each update, this means that you must
  1690. * make sure they are performant enough to avoid performance bottlenecks.
  1691. *
  1692. * @function ModifierFn
  1693. * @argument {dataObject} data - The data object generated by `update` method
  1694. * @argument {Object} options - Modifiers configuration and options
  1695. * @returns {dataObject} The data object, properly modified
  1696. */
  1697. /**
  1698. * Modifiers are plugins used to alter the behavior of your poppers.<br />
  1699. * Popper.js uses a set of 9 modifiers to provide all the basic functionalities
  1700. * needed by the library.
  1701. *
  1702. * Usually you don't want to override the `order`, `fn` and `onLoad` props.
  1703. * All the other properties are configurations that could be tweaked.
  1704. * @namespace modifiers
  1705. */
  1706. var modifiers = {
  1707. /**
  1708. * Modifier used to shift the popper on the start or end of its reference
  1709. * element.<br />
  1710. * It will read the variation of the `placement` property.<br />
  1711. * It can be one either `-end` or `-start`.
  1712. * @memberof modifiers
  1713. * @inner
  1714. */
  1715. shift: {
  1716. /** @prop {number} order=100 - Index used to define the order of execution */
  1717. order: 100,
  1718. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1719. enabled: true,
  1720. /** @prop {ModifierFn} */
  1721. fn: shift
  1722. },
  1723. /**
  1724. * The `offset` modifier can shift your popper on both its axis.
  1725. *
  1726. * It accepts the following units:
  1727. * - `px` or unit-less, interpreted as pixels
  1728. * - `%` or `%r`, percentage relative to the length of the reference element
  1729. * - `%p`, percentage relative to the length of the popper element
  1730. * - `vw`, CSS viewport width unit
  1731. * - `vh`, CSS viewport height unit
  1732. *
  1733. * For length is intended the main axis relative to the placement of the popper.<br />
  1734. * This means that if the placement is `top` or `bottom`, the length will be the
  1735. * `width`. In case of `left` or `right`, it will be the `height`.
  1736. *
  1737. * You can provide a single value (as `Number` or `String`), or a pair of values
  1738. * as `String` divided by a comma or one (or more) white spaces.<br />
  1739. * The latter is a deprecated method because it leads to confusion and will be
  1740. * removed in v2.<br />
  1741. * Additionally, it accepts additions and subtractions between different units.
  1742. * Note that multiplications and divisions aren't supported.
  1743. *
  1744. * Valid examples are:
  1745. * ```
  1746. * 10
  1747. * '10%'
  1748. * '10, 10'
  1749. * '10%, 10'
  1750. * '10 + 10%'
  1751. * '10 - 5vh + 3%'
  1752. * '-10px + 5vh, 5px - 6%'
  1753. * ```
  1754. * > **NB**: If you desire to apply offsets to your poppers in a way that may make them overlap
  1755. * > with their reference element, unfortunately, you will have to disable the `flip` modifier.
  1756. * > You can read more on this at this [issue](https://github.com/FezVrasta/popper.js/issues/373).
  1757. *
  1758. * @memberof modifiers
  1759. * @inner
  1760. */
  1761. offset: {
  1762. /** @prop {number} order=200 - Index used to define the order of execution */
  1763. order: 200,
  1764. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1765. enabled: true,
  1766. /** @prop {ModifierFn} */
  1767. fn: offset,
  1768. /** @prop {Number|String} offset=0
  1769. * The offset value as described in the modifier description
  1770. */
  1771. offset: 0
  1772. },
  1773. /**
  1774. * Modifier used to prevent the popper from being positioned outside the boundary.
  1775. *
  1776. * A scenario exists where the reference itself is not within the boundaries.<br />
  1777. * We can say it has "escaped the boundaries" — or just "escaped".<br />
  1778. * In this case we need to decide whether the popper should either:
  1779. *
  1780. * - detach from the reference and remain "trapped" in the boundaries, or
  1781. * - if it should ignore the boundary and "escape with its reference"
  1782. *
  1783. * When `escapeWithReference` is set to`true` and reference is completely
  1784. * outside its boundaries, the popper will overflow (or completely leave)
  1785. * the boundaries in order to remain attached to the edge of the reference.
  1786. *
  1787. * @memberof modifiers
  1788. * @inner
  1789. */
  1790. preventOverflow: {
  1791. /** @prop {number} order=300 - Index used to define the order of execution */
  1792. order: 300,
  1793. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1794. enabled: true,
  1795. /** @prop {ModifierFn} */
  1796. fn: preventOverflow,
  1797. /**
  1798. * @prop {Array} [priority=['left','right','top','bottom']]
  1799. * Popper will try to prevent overflow following these priorities by default,
  1800. * then, it could overflow on the left and on top of the `boundariesElement`
  1801. */
  1802. priority: ['left', 'right', 'top', 'bottom'],
  1803. /**
  1804. * @prop {number} padding=5
  1805. * Amount of pixel used to define a minimum distance between the boundaries
  1806. * and the popper. This makes sure the popper always has a little padding
  1807. * between the edges of its container
  1808. */
  1809. padding: 5,
  1810. /**
  1811. * @prop {String|HTMLElement} boundariesElement='scrollParent'
  1812. * Boundaries used by the modifier. Can be `scrollParent`, `window`,
  1813. * `viewport` or any DOM element.
  1814. */
  1815. boundariesElement: 'scrollParent'
  1816. },
  1817. /**
  1818. * Modifier used to make sure the reference and its popper stay near each other
  1819. * without leaving any gap between the two. Especially useful when the arrow is
  1820. * enabled and you want to ensure that it points to its reference element.
  1821. * It cares only about the first axis. You can still have poppers with margin
  1822. * between the popper and its reference element.
  1823. * @memberof modifiers
  1824. * @inner
  1825. */
  1826. keepTogether: {
  1827. /** @prop {number} order=400 - Index used to define the order of execution */
  1828. order: 400,
  1829. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1830. enabled: true,
  1831. /** @prop {ModifierFn} */
  1832. fn: keepTogether
  1833. },
  1834. /**
  1835. * This modifier is used to move the `arrowElement` of the popper to make
  1836. * sure it is positioned between the reference element and its popper element.
  1837. * It will read the outer size of the `arrowElement` node to detect how many
  1838. * pixels of conjunction are needed.
  1839. *
  1840. * It has no effect if no `arrowElement` is provided.
  1841. * @memberof modifiers
  1842. * @inner
  1843. */
  1844. arrow: {
  1845. /** @prop {number} order=500 - Index used to define the order of execution */
  1846. order: 500,
  1847. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1848. enabled: true,
  1849. /** @prop {ModifierFn} */
  1850. fn: arrow,
  1851. /** @prop {String|HTMLElement} element='[x-arrow]' - Selector or node used as arrow */
  1852. element: '[x-arrow]'
  1853. },
  1854. /**
  1855. * Modifier used to flip the popper's placement when it starts to overlap its
  1856. * reference element.
  1857. *
  1858. * Requires the `preventOverflow` modifier before it in order to work.
  1859. *
  1860. * **NOTE:** this modifier will interrupt the current update cycle and will
  1861. * restart it if it detects the need to flip the placement.
  1862. * @memberof modifiers
  1863. * @inner
  1864. */
  1865. flip: {
  1866. /** @prop {number} order=600 - Index used to define the order of execution */
  1867. order: 600,
  1868. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1869. enabled: true,
  1870. /** @prop {ModifierFn} */
  1871. fn: flip,
  1872. /**
  1873. * @prop {String|Array} behavior='flip'
  1874. * The behavior used to change the popper's placement. It can be one of
  1875. * `flip`, `clockwise`, `counterclockwise` or an array with a list of valid
  1876. * placements (with optional variations)
  1877. */
  1878. behavior: 'flip',
  1879. /**
  1880. * @prop {number} padding=5
  1881. * The popper will flip if it hits the edges of the `boundariesElement`
  1882. */
  1883. padding: 5,
  1884. /**
  1885. * @prop {String|HTMLElement} boundariesElement='viewport'
  1886. * The element which will define the boundaries of the popper position.
  1887. * The popper will never be placed outside of the defined boundaries
  1888. * (except if `keepTogether` is enabled)
  1889. */
  1890. boundariesElement: 'viewport'
  1891. },
  1892. /**
  1893. * Modifier used to make the popper flow toward the inner of the reference element.
  1894. * By default, when this modifier is disabled, the popper will be placed outside
  1895. * the reference element.
  1896. * @memberof modifiers
  1897. * @inner
  1898. */
  1899. inner: {
  1900. /** @prop {number} order=700 - Index used to define the order of execution */
  1901. order: 700,
  1902. /** @prop {Boolean} enabled=false - Whether the modifier is enabled or not */
  1903. enabled: false,
  1904. /** @prop {ModifierFn} */
  1905. fn: inner
  1906. },
  1907. /**
  1908. * Modifier used to hide the popper when its reference element is outside of the
  1909. * popper boundaries. It will set a `x-out-of-boundaries` attribute which can
  1910. * be used to hide with a CSS selector the popper when its reference is
  1911. * out of boundaries.
  1912. *
  1913. * Requires the `preventOverflow` modifier before it in order to work.
  1914. * @memberof modifiers
  1915. * @inner
  1916. */
  1917. hide: {
  1918. /** @prop {number} order=800 - Index used to define the order of execution */
  1919. order: 800,
  1920. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1921. enabled: true,
  1922. /** @prop {ModifierFn} */
  1923. fn: hide
  1924. },
  1925. /**
  1926. * Computes the style that will be applied to the popper element to gets
  1927. * properly positioned.
  1928. *
  1929. * Note that this modifier will not touch the DOM, it just prepares the styles
  1930. * so that `applyStyle` modifier can apply it. This separation is useful
  1931. * in case you need to replace `applyStyle` with a custom implementation.
  1932. *
  1933. * This modifier has `850` as `order` value to maintain backward compatibility
  1934. * with previous versions of Popper.js. Expect the modifiers ordering method
  1935. * to change in future major versions of the library.
  1936. *
  1937. * @memberof modifiers
  1938. * @inner
  1939. */
  1940. computeStyle: {
  1941. /** @prop {number} order=850 - Index used to define the order of execution */
  1942. order: 850,
  1943. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1944. enabled: true,
  1945. /** @prop {ModifierFn} */
  1946. fn: computeStyle,
  1947. /**
  1948. * @prop {Boolean} gpuAcceleration=true
  1949. * If true, it uses the CSS 3D transformation to position the popper.
  1950. * Otherwise, it will use the `top` and `left` properties
  1951. */
  1952. gpuAcceleration: true,
  1953. /**
  1954. * @prop {string} [x='bottom']
  1955. * Where to anchor the X axis (`bottom` or `top`). AKA X offset origin.
  1956. * Change this if your popper should grow in a direction different from `bottom`
  1957. */
  1958. x: 'bottom',
  1959. /**
  1960. * @prop {string} [x='left']
  1961. * Where to anchor the Y axis (`left` or `right`). AKA Y offset origin.
  1962. * Change this if your popper should grow in a direction different from `right`
  1963. */
  1964. y: 'right'
  1965. },
  1966. /**
  1967. * Applies the computed styles to the popper element.
  1968. *
  1969. * All the DOM manipulations are limited to this modifier. This is useful in case
  1970. * you want to integrate Popper.js inside a framework or view library and you
  1971. * want to delegate all the DOM manipulations to it.
  1972. *
  1973. * Note that if you disable this modifier, you must make sure the popper element
  1974. * has its position set to `absolute` before Popper.js can do its work!
  1975. *
  1976. * Just disable this modifier and define your own to achieve the desired effect.
  1977. *
  1978. * @memberof modifiers
  1979. * @inner
  1980. */
  1981. applyStyle: {
  1982. /** @prop {number} order=900 - Index used to define the order of execution */
  1983. order: 900,
  1984. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1985. enabled: true,
  1986. /** @prop {ModifierFn} */
  1987. fn: applyStyle,
  1988. /** @prop {Function} */
  1989. onLoad: applyStyleOnLoad,
  1990. /**
  1991. * @deprecated since version 1.10.0, the property moved to `computeStyle` modifier
  1992. * @prop {Boolean} gpuAcceleration=true
  1993. * If true, it uses the CSS 3D transformation to position the popper.
  1994. * Otherwise, it will use the `top` and `left` properties
  1995. */
  1996. gpuAcceleration: undefined
  1997. }
  1998. };
  1999. /**
  2000. * The `dataObject` is an object containing all the information used by Popper.js.
  2001. * This object is passed to modifiers and to the `onCreate` and `onUpdate` callbacks.
  2002. * @name dataObject
  2003. * @property {Object} data.instance The Popper.js instance
  2004. * @property {String} data.placement Placement applied to popper
  2005. * @property {String} data.originalPlacement Placement originally defined on init
  2006. * @property {Boolean} data.flipped True if popper has been flipped by flip modifier
  2007. * @property {Boolean} data.hide True if the reference element is out of boundaries, useful to know when to hide the popper
  2008. * @property {HTMLElement} data.arrowElement Node used as arrow by arrow modifier
  2009. * @property {Object} data.styles Any CSS property defined here will be applied to the popper. It expects the JavaScript nomenclature (eg. `marginBottom`)
  2010. * @property {Object} data.arrowStyles Any CSS property defined here will be applied to the popper arrow. It expects the JavaScript nomenclature (eg. `marginBottom`)
  2011. * @property {Object} data.boundaries Offsets of the popper boundaries
  2012. * @property {Object} data.offsets The measurements of popper, reference and arrow elements
  2013. * @property {Object} data.offsets.popper `top`, `left`, `width`, `height` values
  2014. * @property {Object} data.offsets.reference `top`, `left`, `width`, `height` values
  2015. * @property {Object} data.offsets.arrow] `top` and `left` offsets, only one of them will be different from 0
  2016. */
  2017. /**
  2018. * Default options provided to Popper.js constructor.<br />
  2019. * These can be overridden using the `options` argument of Popper.js.<br />
  2020. * To override an option, simply pass an object with the same
  2021. * structure of the `options` object, as the 3rd argument. For example:
  2022. * ```
  2023. * new Popper(ref, pop, {
  2024. * modifiers: {
  2025. * preventOverflow: { enabled: false }
  2026. * }
  2027. * })
  2028. * ```
  2029. * @type {Object}
  2030. * @static
  2031. * @memberof Popper
  2032. */
  2033. var Defaults = {
  2034. /**
  2035. * Popper's placement.
  2036. * @prop {Popper.placements} placement='bottom'
  2037. */
  2038. placement: 'bottom',
  2039. /**
  2040. * Set this to true if you want popper to position it self in 'fixed' mode
  2041. * @prop {Boolean} positionFixed=false
  2042. */
  2043. positionFixed: false,
  2044. /**
  2045. * Whether events (resize, scroll) are initially enabled.
  2046. * @prop {Boolean} eventsEnabled=true
  2047. */
  2048. eventsEnabled: true,
  2049. /**
  2050. * Set to true if you want to automatically remove the popper when
  2051. * you call the `destroy` method.
  2052. * @prop {Boolean} removeOnDestroy=false
  2053. */
  2054. removeOnDestroy: false,
  2055. /**
  2056. * Callback called when the popper is created.<br />
  2057. * By default, it is set to no-op.<br />
  2058. * Access Popper.js instance with `data.instance`.
  2059. * @prop {onCreate}
  2060. */
  2061. onCreate: function onCreate() {},
  2062. /**
  2063. * Callback called when the popper is updated. This callback is not called
  2064. * on the initialization/creation of the popper, but only on subsequent
  2065. * updates.<br />
  2066. * By default, it is set to no-op.<br />
  2067. * Access Popper.js instance with `data.instance`.
  2068. * @prop {onUpdate}
  2069. */
  2070. onUpdate: function onUpdate() {},
  2071. /**
  2072. * List of modifiers used to modify the offsets before they are applied to the popper.
  2073. * They provide most of the functionalities of Popper.js.
  2074. * @prop {modifiers}
  2075. */
  2076. modifiers: modifiers
  2077. };
  2078. /**
  2079. * @callback onCreate
  2080. * @param {dataObject} data
  2081. */
  2082. /**
  2083. * @callback onUpdate
  2084. * @param {dataObject} data
  2085. */
  2086. // Utils
  2087. // Methods
  2088. var Popper = function () {
  2089. /**
  2090. * Creates a new Popper.js instance.
  2091. * @class Popper
  2092. * @param {HTMLElement|referenceObject} reference - The reference element used to position the popper
  2093. * @param {HTMLElement} popper - The HTML element used as the popper
  2094. * @param {Object} options - Your custom options to override the ones defined in [Defaults](#defaults)
  2095. * @return {Object} instance - The generated Popper.js instance
  2096. */
  2097. function Popper(reference, popper) {
  2098. var _this = this;
  2099. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  2100. classCallCheck(this, Popper);
  2101. this.scheduleUpdate = function () {
  2102. return requestAnimationFrame(_this.update);
  2103. };
  2104. // make update() debounced, so that it only runs at most once-per-tick
  2105. this.update = debounce(this.update.bind(this));
  2106. // with {} we create a new object with the options inside it
  2107. this.options = _extends({}, Popper.Defaults, options);
  2108. // init state
  2109. this.state = {
  2110. isDestroyed: false,
  2111. isCreated: false,
  2112. scrollParents: []
  2113. };
  2114. // get reference and popper elements (allow jQuery wrappers)
  2115. this.reference = reference && reference.jquery ? reference[0] : reference;
  2116. this.popper = popper && popper.jquery ? popper[0] : popper;
  2117. // Deep merge modifiers options
  2118. this.options.modifiers = {};
  2119. Object.keys(_extends({}, Popper.Defaults.modifiers, options.modifiers)).forEach(function (name) {
  2120. _this.options.modifiers[name] = _extends({}, Popper.Defaults.modifiers[name] || {}, options.modifiers ? options.modifiers[name] : {});
  2121. });
  2122. // Refactoring modifiers' list (Object => Array)
  2123. this.modifiers = Object.keys(this.options.modifiers).map(function (name) {
  2124. return _extends({
  2125. name: name
  2126. }, _this.options.modifiers[name]);
  2127. })
  2128. // sort the modifiers by order
  2129. .sort(function (a, b) {
  2130. return a.order - b.order;
  2131. });
  2132. // modifiers have the ability to execute arbitrary code when Popper.js get inited
  2133. // such code is executed in the same order of its modifier
  2134. // they could add new properties to their options configuration
  2135. // BE AWARE: don't add options to `options.modifiers.name` but to `modifierOptions`!
  2136. this.modifiers.forEach(function (modifierOptions) {
  2137. if (modifierOptions.enabled && isFunction(modifierOptions.onLoad)) {
  2138. modifierOptions.onLoad(_this.reference, _this.popper, _this.options, modifierOptions, _this.state);
  2139. }
  2140. });
  2141. // fire the first update to position the popper in the right place
  2142. this.update();
  2143. var eventsEnabled = this.options.eventsEnabled;
  2144. if (eventsEnabled) {
  2145. // setup event listeners, they will take care of update the position in specific situations
  2146. this.enableEventListeners();
  2147. }
  2148. this.state.eventsEnabled = eventsEnabled;
  2149. }
  2150. // We can't use class properties because they don't get listed in the
  2151. // class prototype and break stuff like Sinon stubs
  2152. createClass(Popper, [{
  2153. key: 'update',
  2154. value: function update$$1() {
  2155. return update.call(this);
  2156. }
  2157. }, {
  2158. key: 'destroy',
  2159. value: function destroy$$1() {
  2160. return destroy.call(this);
  2161. }
  2162. }, {
  2163. key: 'enableEventListeners',
  2164. value: function enableEventListeners$$1() {
  2165. return enableEventListeners.call(this);
  2166. }
  2167. }, {
  2168. key: 'disableEventListeners',
  2169. value: function disableEventListeners$$1() {
  2170. return disableEventListeners.call(this);
  2171. }
  2172. /**
  2173. * Schedules an update. It will run on the next UI update available.
  2174. * @method scheduleUpdate
  2175. * @memberof Popper
  2176. */
  2177. /**
  2178. * Collection of utilities useful when writing custom modifiers.
  2179. * Starting from version 1.7, this method is available only if you
  2180. * include `popper-utils.js` before `popper.js`.
  2181. *
  2182. * **DEPRECATION**: This way to access PopperUtils is deprecated
  2183. * and will be removed in v2! Use the PopperUtils module directly instead.
  2184. * Due to the high instability of the methods contained in Utils, we can't
  2185. * guarantee them to follow semver. Use them at your own risk!
  2186. * @static
  2187. * @private
  2188. * @type {Object}
  2189. * @deprecated since version 1.8
  2190. * @member Utils
  2191. * @memberof Popper
  2192. */
  2193. }]);
  2194. return Popper;
  2195. }();
  2196. /**
  2197. * The `referenceObject` is an object that provides an interface compatible with Popper.js
  2198. * and lets you use it as replacement of a real DOM node.<br />
  2199. * You can use this method to position a popper relatively to a set of coordinates
  2200. * in case you don't have a DOM node to use as reference.
  2201. *
  2202. * ```
  2203. * new Popper(referenceObject, popperNode);
  2204. * ```
  2205. *
  2206. * NB: This feature isn't supported in Internet Explorer 10.
  2207. * @name referenceObject
  2208. * @property {Function} data.getBoundingClientRect
  2209. * A function that returns a set of coordinates compatible with the native `getBoundingClientRect` method.
  2210. * @property {number} data.clientWidth
  2211. * An ES6 getter that will return the width of the virtual reference element.
  2212. * @property {number} data.clientHeight
  2213. * An ES6 getter that will return the height of the virtual reference element.
  2214. */
  2215. Popper.Utils = (typeof window !== 'undefined' ? window : global).PopperUtils;
  2216. Popper.placements = placements;
  2217. Popper.Defaults = Defaults;
  2218. export default Popper;
  2219. //# sourceMappingURL=popper.js.map