popper.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. 'use strict';
  2. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3. /**
  4. * @fileOverview Kickass library to create and place poppers near their reference elements.
  5. * @version {{version}}
  6. * @license
  7. * Copyright (c) 2016 Federico Zivolo and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in all
  17. * copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. */
  27. //
  28. // Cross module loader
  29. // Supported: Node, AMD, Browser globals
  30. //
  31. ;(function (root, factory) {
  32. if (typeof define === 'function' && define.amd) {
  33. // AMD. Register as an anonymous module.
  34. define(factory);
  35. } else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object' && module.exports) {
  36. // Node. Does not work with strict CommonJS, but
  37. // only CommonJS-like environments that support module.exports,
  38. // like Node.
  39. module.exports = factory();
  40. } else {
  41. // Browser globals (root is window)
  42. root.Popper = factory();
  43. }
  44. })(undefined, function () {
  45. 'use strict';
  46. var root = window;
  47. // default options
  48. var DEFAULTS = {
  49. // placement of the popper
  50. placement: 'bottom',
  51. gpuAcceleration: true,
  52. // shift popper from its origin by the given amount of pixels (can be negative)
  53. offset: 0,
  54. // the element which will act as boundary of the popper
  55. boundariesElement: 'viewport',
  56. // amount of pixel used to define a minimum distance between the boundaries and the popper
  57. boundariesPadding: 5,
  58. // popper will try to prevent overflow following this order,
  59. // by default, then, it could overflow on the left and on top of the boundariesElement
  60. preventOverflowOrder: ['left', 'right', 'top', 'bottom'],
  61. // the behavior used by flip to change the placement of the popper
  62. flipBehavior: 'flip',
  63. arrowElement: '[x-arrow]',
  64. arrowOffset: 0,
  65. // list of functions used to modify the offsets before they are applied to the popper
  66. modifiers: ['shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle'],
  67. modifiersIgnored: [],
  68. forceAbsolute: false
  69. };
  70. /**
  71. * Create a new Popper.js instance
  72. * @constructor Popper
  73. * @param {HTMLElement} reference - The reference element used to position the popper
  74. * @param {HTMLElement|Object} popper
  75. * The HTML element used as popper, or a configuration used to generate the popper.
  76. * @param {String} [popper.tagName='div'] The tag name of the generated popper.
  77. * @param {Array} [popper.classNames=['popper']] Array of classes to apply to the generated popper.
  78. * @param {Array} [popper.attributes] Array of attributes to apply, specify `attr:value` to assign a value to it.
  79. * @param {HTMLElement|String} [popper.parent=window.document.body] The parent element, given as HTMLElement or as query string.
  80. * @param {String} [popper.content=''] The content of the popper, it can be text, html, or node; if it is not text, set `contentType` to `html` or `node`.
  81. * @param {String} [popper.contentType='text'] If `html`, the `content` will be parsed as HTML. If `node`, it will be appended as-is.
  82. * @param {String} [popper.arrowTagName='div'] Same as `popper.tagName` but for the arrow element.
  83. * @param {Array} [popper.arrowClassNames='popper__arrow'] Same as `popper.classNames` but for the arrow element.
  84. * @param {String} [popper.arrowAttributes=['x-arrow']] Same as `popper.attributes` but for the arrow element.
  85. * @param {Object} options
  86. * @param {String} [options.placement=bottom]
  87. * Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -right),
  88. * left(-start, -end)`
  89. *
  90. * @param {HTMLElement|String} [options.arrowElement='[x-arrow]']
  91. * The DOM Node used as arrow for the popper, or a CSS selector used to get the DOM node. It must be child of
  92. * its parent Popper. Popper.js will apply to the given element the style required to align the arrow with its
  93. * reference element.
  94. * By default, it will look for a child node of the popper with the `x-arrow` attribute.
  95. *
  96. * @param {Boolean} [options.gpuAcceleration=true]
  97. * When this property is set to true, the popper position will be applied using CSS3 translate3d, allowing the
  98. * browser to use the GPU to accelerate the rendering.
  99. * If set to false, the popper will be placed using `top` and `left` properties, not using the GPU.
  100. *
  101. * @param {Number} [options.offset=0]
  102. * Amount of pixels the popper will be shifted (can be negative).
  103. *
  104. * @param {String|Element} [options.boundariesElement='viewport']
  105. * The element which will define the boundaries of the popper position, the popper will never be placed outside
  106. * of the defined boundaries (except if `keepTogether` is enabled)
  107. *
  108. * @param {Number} [options.boundariesPadding=5]
  109. * Additional padding for the boundaries
  110. *
  111. * @param {Array} [options.preventOverflowOrder=['left', 'right', 'top', 'bottom']]
  112. * Order used when Popper.js tries to avoid overflows from the boundaries, they will be checked in order,
  113. * this means that the last ones will never overflow
  114. *
  115. * @param {String|Array} [options.flipBehavior='flip']
  116. * The behavior used by the `flip` modifier to change the placement of the popper when the latter is trying to
  117. * overlap its reference element. Defining `flip` as value, the placement will be flipped on
  118. * its axis (`right - left`, `top - bottom`).
  119. * You can even pass an array of placements (eg: `['right', 'left', 'top']` ) to manually specify
  120. * how alter the placement when a flip is needed. (eg. in the above example, it would first flip from right to left,
  121. * then, if even in its new placement, the popper is overlapping its reference element, it will be moved to top)
  122. *
  123. * @param {Array} [options.modifiers=[ 'shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle']]
  124. * List of functions used to modify the data before they are applied to the popper, add your custom functions
  125. * to this array to edit the offsets and placement.
  126. * The function should reflect the @params and @returns of preventOverflow
  127. *
  128. * @param {Array} [options.modifiersIgnored=[]]
  129. * Put here any built-in modifier name you want to exclude from the modifiers list
  130. * The function should reflect the @params and @returns of preventOverflow
  131. *
  132. * @param {Boolean} [options.removeOnDestroy=false]
  133. * Set to true if you want to automatically remove the popper when you call the `destroy` method.
  134. */
  135. function Popper(reference, popper, options) {
  136. this._reference = reference.jquery ? reference[0] : reference;
  137. this.state = {};
  138. // if the popper variable is a configuration object, parse it to generate an HTMLElement
  139. // generate a default popper if is not defined
  140. var isNotDefined = typeof popper === 'undefined' || popper === null;
  141. var isConfig = popper && Object.prototype.toString.call(popper) === '[object Object]';
  142. if (isNotDefined || isConfig) {
  143. this._popper = this.parse(isConfig ? popper : {});
  144. }
  145. // otherwise, use the given HTMLElement as popper
  146. else {
  147. this._popper = popper.jquery ? popper[0] : popper;
  148. }
  149. // with {} we create a new object with the options inside it
  150. this._options = Object.assign({}, DEFAULTS, options);
  151. // refactoring modifiers' list
  152. this._options.modifiers = this._options.modifiers.map(function (modifier) {
  153. // remove ignored modifiers
  154. if (this._options.modifiersIgnored.indexOf(modifier) !== -1) return;
  155. // set the x-placement attribute before everything else because it could be used to add margins to the popper
  156. // margins needs to be calculated to get the correct popper offsets
  157. if (modifier === 'applyStyle') {
  158. this._popper.setAttribute('x-placement', this._options.placement);
  159. }
  160. // return predefined modifier identified by string or keep the custom one
  161. return this.modifiers[modifier] || modifier;
  162. }.bind(this));
  163. // make sure to apply the popper position before any computation
  164. this.state.position = this._getPosition(this._popper, this._reference);
  165. setStyle(this._popper, { position: this.state.position, top: 0 });
  166. // fire the first update to position the popper in the right place
  167. this.update();
  168. // setup event listeners, they will take care of update the position in specific situations
  169. this._setupEventListeners();
  170. return this;
  171. }
  172. //
  173. // Methods
  174. //
  175. /**
  176. * Destroy the popper
  177. * @method
  178. * @memberof Popper
  179. */
  180. Popper.prototype.destroy = function () {
  181. this._popper.removeAttribute('x-placement');
  182. this._popper.style.left = '';
  183. this._popper.style.position = '';
  184. this._popper.style.top = '';
  185. this._popper.style[getSupportedPropertyName('transform')] = '';
  186. this._removeEventListeners();
  187. // remove the popper if user explicity asked for the deletion on destroy
  188. if (this._options.removeOnDestroy) {
  189. this._popper.remove();
  190. }
  191. return this;
  192. };
  193. /**
  194. * Updates the position of the popper, computing the new offsets and applying the new style
  195. * @method
  196. * @memberof Popper
  197. */
  198. Popper.prototype.update = function () {
  199. var data = { instance: this, styles: {} };
  200. // store placement inside the data object, modifiers will be able to edit `placement` if needed
  201. // and refer to _originalPlacement to know the original value
  202. data.placement = this._options.placement;
  203. data._originalPlacement = this._options.placement;
  204. // compute the popper and reference offsets and put them inside data.offsets
  205. data.offsets = this._getOffsets(this._popper, this._reference, data.placement);
  206. // get boundaries
  207. data.boundaries = this._getBoundaries(data, this._options.boundariesPadding, this._options.boundariesElement);
  208. data = this.runModifiers(data, this._options.modifiers);
  209. if (typeof this.state.updateCallback === 'function') {
  210. this.state.updateCallback(data);
  211. }
  212. };
  213. /**
  214. * If a function is passed, it will be executed after the initialization of popper with as first argument the Popper instance.
  215. * @method
  216. * @memberof Popper
  217. * @param {Function} callback
  218. */
  219. Popper.prototype.onCreate = function (callback) {
  220. // the createCallbacks return as first argument the popper instance
  221. callback(this);
  222. return this;
  223. };
  224. /**
  225. * If a function is passed, it will be executed after each update of popper with as first argument the set of coordinates and informations
  226. * used to style popper and its arrow.
  227. * NOTE: it doesn't get fired on the first call of the `Popper.update()` method inside the `Popper` constructor!
  228. * @method
  229. * @memberof Popper
  230. * @param {Function} callback
  231. */
  232. Popper.prototype.onUpdate = function (callback) {
  233. this.state.updateCallback = callback;
  234. return this;
  235. };
  236. /**
  237. * Helper used to generate poppers from a configuration file
  238. * @method
  239. * @memberof Popper
  240. * @param config {Object} configuration
  241. * @returns {HTMLElement} popper
  242. */
  243. Popper.prototype.parse = function (config) {
  244. var defaultConfig = {
  245. tagName: 'div',
  246. classNames: ['popper'],
  247. attributes: [],
  248. parent: root.document.body,
  249. content: '',
  250. contentType: 'text',
  251. arrowTagName: 'div',
  252. arrowClassNames: ['popper__arrow'],
  253. arrowAttributes: ['x-arrow']
  254. };
  255. config = Object.assign({}, defaultConfig, config);
  256. var d = root.document;
  257. var popper = d.createElement(config.tagName);
  258. addClassNames(popper, config.classNames);
  259. addAttributes(popper, config.attributes);
  260. if (config.contentType === 'node') {
  261. popper.appendChild(config.content.jquery ? config.content[0] : config.content);
  262. } else if (config.contentType === 'html') {
  263. popper.innerHTML = config.content;
  264. } else {
  265. popper.textContent = config.content;
  266. }
  267. if (config.arrowTagName) {
  268. var arrow = d.createElement(config.arrowTagName);
  269. addClassNames(arrow, config.arrowClassNames);
  270. addAttributes(arrow, config.arrowAttributes);
  271. popper.appendChild(arrow);
  272. }
  273. var parent = config.parent.jquery ? config.parent[0] : config.parent;
  274. // if the given parent is a string, use it to match an element
  275. // if more than one element is matched, the first one will be used as parent
  276. // if no elements are matched, the script will throw an error
  277. if (typeof parent === 'string') {
  278. parent = d.querySelectorAll(config.parent);
  279. if (parent.length > 1) {
  280. console.warn('WARNING: the given `parent` query(' + config.parent + ') matched more than one element, the first one will be used');
  281. }
  282. if (parent.length === 0) {
  283. throw 'ERROR: the given `parent` doesn\'t exists!';
  284. }
  285. parent = parent[0];
  286. }
  287. // if the given parent is a DOM nodes list or an array of nodes with more than one element,
  288. // the first one will be used as parent
  289. if (parent.length > 1 && parent instanceof Element === false) {
  290. console.warn('WARNING: you have passed as parent a list of elements, the first one will be used');
  291. parent = parent[0];
  292. }
  293. // append the generated popper to its parent
  294. parent.appendChild(popper);
  295. return popper;
  296. /**
  297. * Adds class names to the given element
  298. * @function
  299. * @ignore
  300. * @param {HTMLElement} target
  301. * @param {Array} classes
  302. */
  303. function addClassNames(element, classNames) {
  304. classNames.forEach(function (className) {
  305. element.classList.add(className);
  306. });
  307. }
  308. /**
  309. * Adds attributes to the given element
  310. * @function
  311. * @ignore
  312. * @param {HTMLElement} target
  313. * @param {Array} attributes
  314. * @example
  315. * addAttributes(element, [ 'data-info:foobar' ]);
  316. */
  317. function addAttributes(element, attributes) {
  318. attributes.forEach(function (attribute) {
  319. element.setAttribute(attribute.split(':')[0], attribute.split(':')[1] || '');
  320. });
  321. }
  322. };
  323. /**
  324. * Helper used to get the position which will be applied to the popper
  325. * @method
  326. * @memberof Popper
  327. * @param config {HTMLElement} popper element
  328. * @param reference {HTMLElement} reference element
  329. * @returns {String} position
  330. */
  331. Popper.prototype._getPosition = function (popper, reference) {
  332. var container = getOffsetParent(reference);
  333. if (this._options.forceAbsolute) {
  334. return 'absolute';
  335. }
  336. // Decide if the popper will be fixed
  337. // If the reference element is inside a fixed context, the popper will be fixed as well to allow them to scroll together
  338. var isParentFixed = isFixed(reference, container);
  339. return isParentFixed ? 'fixed' : 'absolute';
  340. };
  341. /**
  342. * Get offsets to the popper
  343. * @method
  344. * @memberof Popper
  345. * @access private
  346. * @param {Element} popper - the popper element
  347. * @param {Element} reference - the reference element (the popper will be relative to this)
  348. * @returns {Object} An object containing the offsets which will be applied to the popper
  349. */
  350. Popper.prototype._getOffsets = function (popper, reference, placement) {
  351. placement = placement.split('-')[0];
  352. var popperOffsets = {};
  353. popperOffsets.position = this.state.position;
  354. var isParentFixed = popperOffsets.position === 'fixed';
  355. //
  356. // Get reference element position
  357. //
  358. var referenceOffsets = getOffsetRectRelativeToCustomParent(reference, getOffsetParent(popper), isParentFixed);
  359. //
  360. // Get popper sizes
  361. //
  362. var popperRect = getOuterSizes(popper);
  363. //
  364. // Compute offsets of popper
  365. //
  366. // depending by the popper placement we have to compute its offsets slightly differently
  367. if (['right', 'left'].indexOf(placement) !== -1) {
  368. popperOffsets.top = referenceOffsets.top + referenceOffsets.height / 2 - popperRect.height / 2;
  369. if (placement === 'left') {
  370. popperOffsets.left = referenceOffsets.left - popperRect.width;
  371. } else {
  372. popperOffsets.left = referenceOffsets.right;
  373. }
  374. } else {
  375. popperOffsets.left = referenceOffsets.left + referenceOffsets.width / 2 - popperRect.width / 2;
  376. if (placement === 'top') {
  377. popperOffsets.top = referenceOffsets.top - popperRect.height;
  378. } else {
  379. popperOffsets.top = referenceOffsets.bottom;
  380. }
  381. }
  382. // Add width and height to our offsets object
  383. popperOffsets.width = popperRect.width;
  384. popperOffsets.height = popperRect.height;
  385. return {
  386. popper: popperOffsets,
  387. reference: referenceOffsets
  388. };
  389. };
  390. /**
  391. * Setup needed event listeners used to update the popper position
  392. * @method
  393. * @memberof Popper
  394. * @access private
  395. */
  396. Popper.prototype._setupEventListeners = function () {
  397. // NOTE: 1 DOM access here
  398. this.state.updateBound = this.update.bind(this);
  399. root.addEventListener('resize', this.state.updateBound);
  400. // if the boundariesElement is window we don't need to listen for the scroll event
  401. if (this._options.boundariesElement !== 'window') {
  402. var target = getScrollParent(this._reference);
  403. // here it could be both `body` or `documentElement` thanks to Firefox, we then check both
  404. if (target === root.document.body || target === root.document.documentElement) {
  405. target = root;
  406. }
  407. target.addEventListener('scroll', this.state.updateBound);
  408. this.state.scrollTarget = target;
  409. }
  410. };
  411. /**
  412. * Remove event listeners used to update the popper position
  413. * @method
  414. * @memberof Popper
  415. * @access private
  416. */
  417. Popper.prototype._removeEventListeners = function () {
  418. // NOTE: 1 DOM access here
  419. root.removeEventListener('resize', this.state.updateBound);
  420. if (this._options.boundariesElement !== 'window' && this.state.scrollTarget) {
  421. this.state.scrollTarget.removeEventListener('scroll', this.state.updateBound);
  422. this.state.scrollTarget = null;
  423. }
  424. this.state.updateBound = null;
  425. };
  426. /**
  427. * Computed the boundaries limits and return them
  428. * @method
  429. * @memberof Popper
  430. * @access private
  431. * @param {Object} data - Object containing the property "offsets" generated by `_getOffsets`
  432. * @param {Number} padding - Boundaries padding
  433. * @param {Element} boundariesElement - Element used to define the boundaries
  434. * @returns {Object} Coordinates of the boundaries
  435. */
  436. Popper.prototype._getBoundaries = function (data, padding, boundariesElement) {
  437. // NOTE: 1 DOM access here
  438. var boundaries = {};
  439. var width, height;
  440. if (boundariesElement === 'window') {
  441. var body = root.document.body,
  442. html = root.document.documentElement;
  443. height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
  444. width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth);
  445. boundaries = {
  446. top: 0,
  447. right: width,
  448. bottom: height,
  449. left: 0
  450. };
  451. } else if (boundariesElement === 'viewport') {
  452. var offsetParent = getOffsetParent(this._popper);
  453. var scrollParent = getScrollParent(this._popper);
  454. var offsetParentRect = getOffsetRect(offsetParent);
  455. // Thanks the fucking native API, `document.body.scrollTop` & `document.documentElement.scrollTop`
  456. var getScrollTopValue = function getScrollTopValue(element) {
  457. return element == document.body ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : element.scrollTop;
  458. };
  459. var getScrollLeftValue = function getScrollLeftValue(element) {
  460. return element == document.body ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : element.scrollLeft;
  461. };
  462. // if the popper is fixed we don't have to substract scrolling from the boundaries
  463. var scrollTop = data.offsets.popper.position === 'fixed' ? 0 : getScrollTopValue(scrollParent);
  464. var scrollLeft = data.offsets.popper.position === 'fixed' ? 0 : getScrollLeftValue(scrollParent);
  465. boundaries = {
  466. top: 0 - (offsetParentRect.top - scrollTop),
  467. right: root.document.documentElement.clientWidth - (offsetParentRect.left - scrollLeft),
  468. bottom: root.document.documentElement.clientHeight - (offsetParentRect.top - scrollTop),
  469. left: 0 - (offsetParentRect.left - scrollLeft)
  470. };
  471. } else {
  472. if (getOffsetParent(this._popper) === boundariesElement) {
  473. boundaries = {
  474. top: 0,
  475. left: 0,
  476. right: boundariesElement.clientWidth,
  477. bottom: boundariesElement.clientHeight
  478. };
  479. } else {
  480. boundaries = getOffsetRect(boundariesElement);
  481. }
  482. }
  483. boundaries.left += padding;
  484. boundaries.right -= padding;
  485. boundaries.top = boundaries.top + padding;
  486. boundaries.bottom = boundaries.bottom - padding;
  487. return boundaries;
  488. };
  489. /**
  490. * Loop trough the list of modifiers and run them in order, each of them will then edit the data object
  491. * @method
  492. * @memberof Popper
  493. * @access public
  494. * @param {Object} data
  495. * @param {Array} modifiers
  496. * @param {Function} ends
  497. */
  498. Popper.prototype.runModifiers = function (data, modifiers, ends) {
  499. var modifiersToRun = modifiers.slice();
  500. if (ends !== undefined) {
  501. modifiersToRun = this._options.modifiers.slice(0, getArrayKeyIndex(this._options.modifiers, ends));
  502. }
  503. modifiersToRun.forEach(function (modifier) {
  504. if (isFunction(modifier)) {
  505. data = modifier.call(this, data);
  506. }
  507. }.bind(this));
  508. return data;
  509. };
  510. /**
  511. * Helper used to know if the given modifier depends from another one.
  512. * @method
  513. * @memberof Popper
  514. * @param {String} requesting - name of requesting modifier
  515. * @param {String} requested - name of requested modifier
  516. * @returns {Boolean}
  517. */
  518. Popper.prototype.isModifierRequired = function (requesting, requested) {
  519. var index = getArrayKeyIndex(this._options.modifiers, requesting);
  520. return !!this._options.modifiers.slice(0, index).filter(function (modifier) {
  521. return modifier === requested;
  522. }).length;
  523. };
  524. //
  525. // Modifiers
  526. //
  527. /**
  528. * Modifiers list
  529. * @namespace Popper.modifiers
  530. * @memberof Popper
  531. * @type {Object}
  532. */
  533. Popper.prototype.modifiers = {};
  534. /**
  535. * Apply the computed styles to the popper element
  536. * @method
  537. * @memberof Popper.modifiers
  538. * @argument {Object} data - The data object generated by `update` method
  539. * @returns {Object} The same data object
  540. */
  541. Popper.prototype.modifiers.applyStyle = function (data) {
  542. // apply the final offsets to the popper
  543. // NOTE: 1 DOM access here
  544. var styles = {
  545. position: data.offsets.popper.position
  546. };
  547. // round top and left to avoid blurry text
  548. var left = Math.round(data.offsets.popper.left);
  549. var top = Math.round(data.offsets.popper.top);
  550. // if gpuAcceleration is set to true and transform is supported, we use `translate3d` to apply the position to the popper
  551. // we automatically use the supported prefixed version if needed
  552. var prefixedProperty;
  553. if (this._options.gpuAcceleration && (prefixedProperty = getSupportedPropertyName('transform'))) {
  554. styles[prefixedProperty] = 'translate3d(' + left + 'px, ' + top + 'px, 0)';
  555. styles.top = 0;
  556. styles.left = 0;
  557. }
  558. // othwerise, we use the standard `left` and `top` properties
  559. else {
  560. styles.left = left;
  561. styles.top = top;
  562. }
  563. // any property present in `data.styles` will be applied to the popper,
  564. // in this way we can make the 3rd party modifiers add custom styles to it
  565. // Be aware, modifiers could override the properties defined in the previous
  566. // lines of this modifier!
  567. Object.assign(styles, data.styles);
  568. setStyle(this._popper, styles);
  569. // set an attribute which will be useful to style the tooltip (use it to properly position its arrow)
  570. // NOTE: 1 DOM access here
  571. this._popper.setAttribute('x-placement', data.placement);
  572. // if the arrow modifier is required and the arrow style has been computed, apply the arrow style
  573. if (this.isModifierRequired(this.modifiers.applyStyle, this.modifiers.arrow) && data.offsets.arrow) {
  574. setStyle(data.arrowElement, data.offsets.arrow);
  575. }
  576. return data;
  577. };
  578. /**
  579. * Modifier used to shift the popper on the start or end of its reference element side
  580. * @method
  581. * @memberof Popper.modifiers
  582. * @argument {Object} data - The data object generated by `update` method
  583. * @returns {Object} The data object, properly modified
  584. */
  585. Popper.prototype.modifiers.shift = function (data) {
  586. var placement = data.placement;
  587. var basePlacement = placement.split('-')[0];
  588. var shiftVariation = placement.split('-')[1];
  589. // if shift shiftVariation is specified, run the modifier
  590. if (shiftVariation) {
  591. var reference = data.offsets.reference;
  592. var popper = getPopperClientRect(data.offsets.popper);
  593. var shiftOffsets = {
  594. y: {
  595. start: { top: reference.top },
  596. end: { top: reference.top + reference.height - popper.height }
  597. },
  598. x: {
  599. start: { left: reference.left },
  600. end: { left: reference.left + reference.width - popper.width }
  601. }
  602. };
  603. var axis = ['bottom', 'top'].indexOf(basePlacement) !== -1 ? 'x' : 'y';
  604. data.offsets.popper = Object.assign(popper, shiftOffsets[axis][shiftVariation]);
  605. }
  606. return data;
  607. };
  608. /**
  609. * Modifier used to make sure the popper does not overflows from it's boundaries
  610. * @method
  611. * @memberof Popper.modifiers
  612. * @argument {Object} data - The data object generated by `update` method
  613. * @returns {Object} The data object, properly modified
  614. */
  615. Popper.prototype.modifiers.preventOverflow = function (data) {
  616. var order = this._options.preventOverflowOrder;
  617. var popper = getPopperClientRect(data.offsets.popper);
  618. var check = {
  619. left: function left() {
  620. var left = popper.left;
  621. if (popper.left < data.boundaries.left) {
  622. left = Math.max(popper.left, data.boundaries.left);
  623. }
  624. return { left: left };
  625. },
  626. right: function right() {
  627. var left = popper.left;
  628. if (popper.right > data.boundaries.right) {
  629. left = Math.min(popper.left, data.boundaries.right - popper.width);
  630. }
  631. return { left: left };
  632. },
  633. top: function top() {
  634. var top = popper.top;
  635. if (popper.top < data.boundaries.top) {
  636. top = Math.max(popper.top, data.boundaries.top);
  637. }
  638. return { top: top };
  639. },
  640. bottom: function bottom() {
  641. var top = popper.top;
  642. if (popper.bottom > data.boundaries.bottom) {
  643. top = Math.min(popper.top, data.boundaries.bottom - popper.height);
  644. }
  645. return { top: top };
  646. }
  647. };
  648. order.forEach(function (direction) {
  649. data.offsets.popper = Object.assign(popper, check[direction]());
  650. });
  651. return data;
  652. };
  653. /**
  654. * Modifier used to make sure the popper is always near its reference
  655. * @method
  656. * @memberof Popper.modifiers
  657. * @argument {Object} data - The data object generated by _update method
  658. * @returns {Object} The data object, properly modified
  659. */
  660. Popper.prototype.modifiers.keepTogether = function (data) {
  661. var popper = getPopperClientRect(data.offsets.popper);
  662. var reference = data.offsets.reference;
  663. var f = Math.floor;
  664. if (popper.right < f(reference.left)) {
  665. data.offsets.popper.left = f(reference.left) - popper.width;
  666. }
  667. if (popper.left > f(reference.right)) {
  668. data.offsets.popper.left = f(reference.right);
  669. }
  670. if (popper.bottom < f(reference.top)) {
  671. data.offsets.popper.top = f(reference.top) - popper.height;
  672. }
  673. if (popper.top > f(reference.bottom)) {
  674. data.offsets.popper.top = f(reference.bottom);
  675. }
  676. return data;
  677. };
  678. /**
  679. * Modifier used to flip the placement of the popper when the latter is starting overlapping its reference element.
  680. * Requires the `preventOverflow` modifier before it in order to work.
  681. * **NOTE:** This modifier will run all its previous modifiers everytime it tries to flip the popper!
  682. * @method
  683. * @memberof Popper.modifiers
  684. * @argument {Object} data - The data object generated by _update method
  685. * @returns {Object} The data object, properly modified
  686. */
  687. Popper.prototype.modifiers.flip = function (data) {
  688. // check if preventOverflow is in the list of modifiers before the flip modifier.
  689. // otherwise flip would not work as expected.
  690. if (!this.isModifierRequired(this.modifiers.flip, this.modifiers.preventOverflow)) {
  691. console.warn('WARNING: preventOverflow modifier is required by flip modifier in order to work, be sure to include it before flip!');
  692. return data;
  693. }
  694. if (data.flipped && data.placement === data._originalPlacement) {
  695. // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides
  696. return data;
  697. }
  698. var placement = data.placement.split('-')[0];
  699. var placementOpposite = getOppositePlacement(placement);
  700. var variation = data.placement.split('-')[1] || '';
  701. var flipOrder = [];
  702. if (this._options.flipBehavior === 'flip') {
  703. flipOrder = [placement, placementOpposite];
  704. } else {
  705. flipOrder = this._options.flipBehavior;
  706. }
  707. flipOrder.forEach(function (step, index) {
  708. if (placement !== step || flipOrder.length === index + 1) {
  709. return;
  710. }
  711. placement = data.placement.split('-')[0];
  712. placementOpposite = getOppositePlacement(placement);
  713. var popperOffsets = getPopperClientRect(data.offsets.popper);
  714. // this boolean is used to distinguish right and bottom from top and left
  715. // they need different computations to get flipped
  716. var a = ['right', 'bottom'].indexOf(placement) !== -1;
  717. // using Math.floor because the reference offsets may contain decimals we are not going to consider here
  718. if (a && Math.floor(data.offsets.reference[placement]) > Math.floor(popperOffsets[placementOpposite]) || !a && Math.floor(data.offsets.reference[placement]) < Math.floor(popperOffsets[placementOpposite])) {
  719. // we'll use this boolean to detect any flip loop
  720. data.flipped = true;
  721. data.placement = flipOrder[index + 1];
  722. if (variation) {
  723. data.placement += '-' + variation;
  724. }
  725. data.offsets.popper = this._getOffsets(this._popper, this._reference, data.placement).popper;
  726. data = this.runModifiers(data, this._options.modifiers, this._flip);
  727. }
  728. }.bind(this));
  729. return data;
  730. };
  731. /**
  732. * Modifier used to add an offset to the popper, useful if you more granularity positioning your popper.
  733. * The offsets will shift the popper on the side of its reference element.
  734. * @method
  735. * @memberof Popper.modifiers
  736. * @argument {Object} data - The data object generated by _update method
  737. * @returns {Object} The data object, properly modified
  738. */
  739. Popper.prototype.modifiers.offset = function (data) {
  740. var offset = this._options.offset;
  741. var popper = data.offsets.popper;
  742. if (data.placement.indexOf('left') !== -1) {
  743. popper.top -= offset;
  744. } else if (data.placement.indexOf('right') !== -1) {
  745. popper.top += offset;
  746. } else if (data.placement.indexOf('top') !== -1) {
  747. popper.left -= offset;
  748. } else if (data.placement.indexOf('bottom') !== -1) {
  749. popper.left += offset;
  750. }
  751. return data;
  752. };
  753. /**
  754. * Modifier used to move the arrows on the edge of the popper to make sure them are always between the popper and the reference element
  755. * It will use the CSS outer size of the arrow element to know how many pixels of conjuction are needed
  756. * @method
  757. * @memberof Popper.modifiers
  758. * @argument {Object} data - The data object generated by _update method
  759. * @returns {Object} The data object, properly modified
  760. */
  761. Popper.prototype.modifiers.arrow = function (data) {
  762. var arrow = this._options.arrowElement;
  763. var arrowOffset = this._options.arrowOffset;
  764. // if the arrowElement is a string, suppose it's a CSS selector
  765. if (typeof arrow === 'string') {
  766. arrow = this._popper.querySelector(arrow);
  767. }
  768. // if arrow element is not found, don't run the modifier
  769. if (!arrow) {
  770. return data;
  771. }
  772. // the arrow element must be child of its popper
  773. if (!this._popper.contains(arrow)) {
  774. console.warn('WARNING: `arrowElement` must be child of its popper element!');
  775. return data;
  776. }
  777. // arrow depends on keepTogether in order to work
  778. if (!this.isModifierRequired(this.modifiers.arrow, this.modifiers.keepTogether)) {
  779. console.warn('WARNING: keepTogether modifier is required by arrow modifier in order to work, be sure to include it before arrow!');
  780. return data;
  781. }
  782. var arrowStyle = {};
  783. var placement = data.placement.split('-')[0];
  784. var popper = getPopperClientRect(data.offsets.popper);
  785. var reference = data.offsets.reference;
  786. var isVertical = ['left', 'right'].indexOf(placement) !== -1;
  787. var len = isVertical ? 'height' : 'width';
  788. var side = isVertical ? 'top' : 'left';
  789. var translate = isVertical ? 'translateY' : 'translateX';
  790. var altSide = isVertical ? 'left' : 'top';
  791. var opSide = isVertical ? 'bottom' : 'right';
  792. var arrowSize = getOuterSizes(arrow)[len];
  793. //
  794. // extends keepTogether behavior making sure the popper and its reference have enough pixels in conjuction
  795. //
  796. // top/left side
  797. if (reference[opSide] - arrowSize < popper[side]) {
  798. data.offsets.popper[side] -= popper[side] - (reference[opSide] - arrowSize);
  799. }
  800. // bottom/right side
  801. if (reference[side] + arrowSize > popper[opSide]) {
  802. data.offsets.popper[side] += reference[side] + arrowSize - popper[opSide];
  803. }
  804. // compute center of the popper
  805. var center = reference[side] + (arrowOffset || reference[len] / 2 - arrowSize / 2);
  806. var sideValue = center - popper[side];
  807. // prevent arrow from being placed not contiguously to its popper
  808. sideValue = Math.max(Math.min(popper[len] - arrowSize - 8, sideValue), 8);
  809. arrowStyle[side] = sideValue;
  810. arrowStyle[altSide] = ''; // make sure to remove any old style from the arrow
  811. data.offsets.arrow = arrowStyle;
  812. data.arrowElement = arrow;
  813. return data;
  814. };
  815. //
  816. // Helpers
  817. //
  818. /**
  819. * Get the outer sizes of the given element (offset size + margins)
  820. * @function
  821. * @ignore
  822. * @argument {Element} element
  823. * @returns {Object} object containing width and height properties
  824. */
  825. function getOuterSizes(element) {
  826. // NOTE: 1 DOM access here
  827. var _display = element.style.display,
  828. _visibility = element.style.visibility;
  829. element.style.display = 'block';element.style.visibility = 'hidden';
  830. var calcWidthToForceRepaint = element.offsetWidth;
  831. // original method
  832. var styles = root.getComputedStyle(element);
  833. var x = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
  834. var y = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
  835. var result = { width: element.offsetWidth + y, height: element.offsetHeight + x };
  836. // reset element styles
  837. element.style.display = _display;element.style.visibility = _visibility;
  838. return result;
  839. }
  840. /**
  841. * Get the opposite placement of the given one/
  842. * @function
  843. * @ignore
  844. * @argument {String} placement
  845. * @returns {String} flipped placement
  846. */
  847. function getOppositePlacement(placement) {
  848. var hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
  849. return placement.replace(/left|right|bottom|top/g, function (matched) {
  850. return hash[matched];
  851. });
  852. }
  853. /**
  854. * Given the popper offsets, generate an output similar to getBoundingClientRect
  855. * @function
  856. * @ignore
  857. * @argument {Object} popperOffsets
  858. * @returns {Object} ClientRect like output
  859. */
  860. function getPopperClientRect(popperOffsets) {
  861. var offsets = Object.assign({}, popperOffsets);
  862. offsets.right = offsets.left + offsets.width;
  863. offsets.bottom = offsets.top + offsets.height;
  864. return offsets;
  865. }
  866. /**
  867. * Given an array and the key to find, returns its index
  868. * @function
  869. * @ignore
  870. * @argument {Array} arr
  871. * @argument keyToFind
  872. * @returns index or null
  873. */
  874. function getArrayKeyIndex(arr, keyToFind) {
  875. var i = 0,
  876. key;
  877. for (key in arr) {
  878. if (arr[key] === keyToFind) {
  879. return i;
  880. }
  881. i++;
  882. }
  883. return null;
  884. }
  885. /**
  886. * Get CSS computed property of the given element
  887. * @function
  888. * @ignore
  889. * @argument {Eement} element
  890. * @argument {String} property
  891. */
  892. function getStyleComputedProperty(element, property) {
  893. // NOTE: 1 DOM access here
  894. var css = root.getComputedStyle(element, null);
  895. return css[property];
  896. }
  897. /**
  898. * Returns the offset parent of the given element
  899. * @function
  900. * @ignore
  901. * @argument {Element} element
  902. * @returns {Element} offset parent
  903. */
  904. function getOffsetParent(element) {
  905. // NOTE: 1 DOM access here
  906. var offsetParent = element.offsetParent;
  907. return offsetParent === root.document.body || !offsetParent ? root.document.documentElement : offsetParent;
  908. }
  909. /**
  910. * Returns the scrolling parent of the given element
  911. * @function
  912. * @ignore
  913. * @argument {Element} element
  914. * @returns {Element} offset parent
  915. */
  916. function getScrollParent(element) {
  917. var parent = element.parentNode;
  918. if (!parent) {
  919. return element;
  920. }
  921. if (parent === root.document) {
  922. // Firefox puts the scrollTOp value on `documentElement` instead of `body`, we then check which of them is
  923. // greater than 0 and return the proper element
  924. if (root.document.body.scrollTop || root.document.body.scrollLeft) {
  925. return root.document.body;
  926. } else {
  927. return root.document.documentElement;
  928. }
  929. }
  930. // Firefox want us to check `-x` and `-y` variations as well
  931. if (['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-x')) !== -1 || ['scroll', 'auto'].indexOf(getStyleComputedProperty(parent, 'overflow-y')) !== -1) {
  932. // If the detected scrollParent is body, we perform an additional check on its parentNode
  933. // in this way we'll get body if the browser is Chrome-ish, or documentElement otherwise
  934. // fixes issue #65
  935. return parent;
  936. }
  937. return getScrollParent(element.parentNode);
  938. }
  939. /**
  940. * Check if the given element is fixed or is inside a fixed parent
  941. * @function
  942. * @ignore
  943. * @argument {Element} element
  944. * @argument {Element} customContainer
  945. * @returns {Boolean} answer to "isFixed?"
  946. */
  947. function isFixed(element) {
  948. if (element === root.document.body) {
  949. return false;
  950. }
  951. if (getStyleComputedProperty(element, 'position') === 'fixed') {
  952. return true;
  953. }
  954. return element.parentNode ? isFixed(element.parentNode) : element;
  955. }
  956. /**
  957. * Set the style to the given popper
  958. * @function
  959. * @ignore
  960. * @argument {Element} element - Element to apply the style to
  961. * @argument {Object} styles - Object with a list of properties and values which will be applied to the element
  962. */
  963. function setStyle(element, styles) {
  964. function is_numeric(n) {
  965. return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
  966. }
  967. Object.keys(styles).forEach(function (prop) {
  968. var unit = '';
  969. // add unit if the value is numeric and is one of the following
  970. if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && is_numeric(styles[prop])) {
  971. unit = 'px';
  972. }
  973. element.style[prop] = styles[prop] + unit;
  974. });
  975. }
  976. /**
  977. * Check if the given variable is a function
  978. * @function
  979. * @ignore
  980. * @argument {*} functionToCheck - variable to check
  981. * @returns {Boolean} answer to: is a function?
  982. */
  983. function isFunction(functionToCheck) {
  984. var getType = {};
  985. return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
  986. }
  987. /**
  988. * Get the position of the given element, relative to its offset parent
  989. * @function
  990. * @ignore
  991. * @param {Element} element
  992. * @return {Object} position - Coordinates of the element and its `scrollTop`
  993. */
  994. function getOffsetRect(element) {
  995. var elementRect = {
  996. width: element.offsetWidth,
  997. height: element.offsetHeight,
  998. left: element.offsetLeft,
  999. top: element.offsetTop
  1000. };
  1001. elementRect.right = elementRect.left + elementRect.width;
  1002. elementRect.bottom = elementRect.top + elementRect.height;
  1003. // position
  1004. return elementRect;
  1005. }
  1006. /**
  1007. * Get bounding client rect of given element
  1008. * @function
  1009. * @ignore
  1010. * @param {HTMLElement} element
  1011. * @return {Object} client rect
  1012. */
  1013. function getBoundingClientRect(element) {
  1014. var rect = element.getBoundingClientRect();
  1015. // whether the IE version is lower than 11
  1016. var isIE = navigator.userAgent.indexOf("MSIE") != -1;
  1017. // fix ie document bounding top always 0 bug
  1018. var rectTop = isIE && element.tagName === 'HTML' ? -element.scrollTop : rect.top;
  1019. return {
  1020. left: rect.left,
  1021. top: rectTop,
  1022. right: rect.right,
  1023. bottom: rect.bottom,
  1024. width: rect.right - rect.left,
  1025. height: rect.bottom - rectTop
  1026. };
  1027. }
  1028. /**
  1029. * Given an element and one of its parents, return the offset
  1030. * @function
  1031. * @ignore
  1032. * @param {HTMLElement} element
  1033. * @param {HTMLElement} parent
  1034. * @return {Object} rect
  1035. */
  1036. function getOffsetRectRelativeToCustomParent(element, parent, fixed) {
  1037. var elementRect = getBoundingClientRect(element);
  1038. var parentRect = getBoundingClientRect(parent);
  1039. if (fixed) {
  1040. var scrollParent = getScrollParent(parent);
  1041. parentRect.top += scrollParent.scrollTop;
  1042. parentRect.bottom += scrollParent.scrollTop;
  1043. parentRect.left += scrollParent.scrollLeft;
  1044. parentRect.right += scrollParent.scrollLeft;
  1045. }
  1046. var rect = {
  1047. top: elementRect.top - parentRect.top,
  1048. left: elementRect.left - parentRect.left,
  1049. bottom: elementRect.top - parentRect.top + elementRect.height,
  1050. right: elementRect.left - parentRect.left + elementRect.width,
  1051. width: elementRect.width,
  1052. height: elementRect.height
  1053. };
  1054. return rect;
  1055. }
  1056. /**
  1057. * Get the prefixed supported property name
  1058. * @function
  1059. * @ignore
  1060. * @argument {String} property (camelCase)
  1061. * @returns {String} prefixed property (camelCase)
  1062. */
  1063. function getSupportedPropertyName(property) {
  1064. var prefixes = ['', 'ms', 'webkit', 'moz', 'o'];
  1065. for (var i = 0; i < prefixes.length; i++) {
  1066. var toCheck = prefixes[i] ? prefixes[i] + property.charAt(0).toUpperCase() + property.slice(1) : property;
  1067. if (typeof root.document.body.style[toCheck] !== 'undefined') {
  1068. return toCheck;
  1069. }
  1070. }
  1071. return null;
  1072. }
  1073. /**
  1074. * The Object.assign() method is used to copy the values of all enumerable own properties from one or more source
  1075. * objects to a target object. It will return the target object.
  1076. * This polyfill doesn't support symbol properties, since ES5 doesn't have symbols anyway
  1077. * Source: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  1078. * @function
  1079. * @ignore
  1080. */
  1081. if (!Object.assign) {
  1082. Object.defineProperty(Object, 'assign', {
  1083. enumerable: false,
  1084. configurable: true,
  1085. writable: true,
  1086. value: function value(target) {
  1087. if (target === undefined || target === null) {
  1088. throw new TypeError('Cannot convert first argument to object');
  1089. }
  1090. var to = Object(target);
  1091. for (var i = 1; i < arguments.length; i++) {
  1092. var nextSource = arguments[i];
  1093. if (nextSource === undefined || nextSource === null) {
  1094. continue;
  1095. }
  1096. nextSource = Object(nextSource);
  1097. var keysArray = Object.keys(nextSource);
  1098. for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
  1099. var nextKey = keysArray[nextIndex];
  1100. var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
  1101. if (desc !== undefined && desc.enumerable) {
  1102. to[nextKey] = nextSource[nextKey];
  1103. }
  1104. }
  1105. }
  1106. return to;
  1107. }
  1108. });
  1109. }
  1110. return Popper;
  1111. });