Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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