popper.js 83 KB

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