popper.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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 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] + 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, sideValue), 0);
  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) {
  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. });