popper.js 93 KB

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