* Creates a new Popper.js instance. * @class Popper * @param {Element|referenceObject} reference - The reference element used to position the popper * @param {Element} popper - The HTML / XML element used as the popper * @param {Object} options - Your custom options to override t
(reference, popper)
| 3972 | * @return {Object} instance - The generated Popper.js instance |
| 3973 | */ |
| 3974 | function Popper(reference, popper) { |
| 3975 | var _this = this; |
| 3976 | |
| 3977 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
| 3978 | classCallCheck(this, Popper); |
| 3979 | |
| 3980 | this.scheduleUpdate = function () { |
| 3981 | return requestAnimationFrame(_this.update); |
| 3982 | }; |
| 3983 | |
| 3984 | // make update() debounced, so that it only runs at most once-per-tick |
| 3985 | this.update = debounce(this.update.bind(this)); |
| 3986 | |
| 3987 | // with {} we create a new object with the options inside it |
| 3988 | this.options = _extends({}, Popper.Defaults, options); |
| 3989 | |
| 3990 | // init state |
| 3991 | this.state = { |
| 3992 | isDestroyed: false, |
| 3993 | isCreated: false, |
| 3994 | scrollParents: [] |
| 3995 | }; |
| 3996 | |
| 3997 | // get reference and popper elements (allow jQuery wrappers) |
| 3998 | this.reference = reference && reference.jquery ? reference[0] : reference; |
| 3999 | this.popper = popper && popper.jquery ? popper[0] : popper; |
| 4000 | |
| 4001 | // Deep merge modifiers options |
| 4002 | this.options.modifiers = {}; |
| 4003 | Object.keys(_extends({}, Popper.Defaults.modifiers, options.modifiers)).forEach(function (name) { |
| 4004 | _this.options.modifiers[name] = _extends({}, Popper.Defaults.modifiers[name] || {}, options.modifiers ? options.modifiers[name] : {}); |
| 4005 | }); |
| 4006 | |
| 4007 | // Refactoring modifiers' list (Object => Array) |
| 4008 | this.modifiers = Object.keys(this.options.modifiers).map(function (name) { |
| 4009 | return _extends({ |
| 4010 | name: name |
| 4011 | }, _this.options.modifiers[name]); |
| 4012 | }) |
| 4013 | // sort the modifiers by order |
| 4014 | .sort(function (a, b) { |
| 4015 | return a.order - b.order; |
| 4016 | }); |
| 4017 | |
| 4018 | // modifiers have the ability to execute arbitrary code when Popper.js get inited |
| 4019 | // such code is executed in the same order of its modifier |
| 4020 | // they could add new properties to their options configuration |
| 4021 | // BE AWARE: don't add options to `options.modifiers.name` but to `modifierOptions`! |
| 4022 | this.modifiers.forEach(function (modifierOptions) { |
| 4023 | if (modifierOptions.enabled && isFunction(modifierOptions.onLoad)) { |
| 4024 | modifierOptions.onLoad(_this.reference, _this.popper, _this.options, modifierOptions, _this.state); |
| 4025 | } |
| 4026 | }); |
| 4027 | |
| 4028 | // fire the first update to position the popper in the right place |
| 4029 | this.update(); |
| 4030 | |
| 4031 | var eventsEnabled = this.options.eventsEnabled; |
nothing calls this directly
no test coverage detected