Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

popper-1.12.6.js 79KB

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