popper.js 83 KB

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