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