dropdown.js 20.9 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap dropdown.js v4.3.1 (https://getbootstrap.com/)
Mark Otto's avatar
Mark Otto committed
3
  * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
Dist    
XhmikosR committed
4
5
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
XhmikosR's avatar
XhmikosR committed
7
8
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('popper.js'), require('./dom/selector-engine.js')) :
  typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/event-handler.js', './dom/manipulator.js', 'popper.js', './dom/selector-engine.js'], factory) :
XhmikosR's avatar
XhmikosR committed
9
10
11
12
13
14
  (global = global || self, global.Dropdown = factory(global.Data, global.EventHandler, global.Manipulator, global.Popper, global.SelectorEngine));
}(this, function (Data, EventHandler, Manipulator, Popper, SelectorEngine) { 'use strict';

  Data = Data && Data.hasOwnProperty('default') ? Data['default'] : Data;
  EventHandler = EventHandler && EventHandler.hasOwnProperty('default') ? EventHandler['default'] : EventHandler;
  Manipulator = Manipulator && Manipulator.hasOwnProperty('default') ? Manipulator['default'] : Manipulator;
Mark Otto's avatar
dist    
Mark Otto committed
15
  Popper = Popper && Popper.hasOwnProperty('default') ? Popper['default'] : Popper;
XhmikosR's avatar
XhmikosR committed
16
  SelectorEngine = SelectorEngine && SelectorEngine.hasOwnProperty('default') ? SelectorEngine['default'] : SelectorEngine;
Mark Otto's avatar
dist    
Mark Otto committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

  function _defineProperties(target, props) {
    for (var i = 0; i < props.length; i++) {
      var descriptor = props[i];
      descriptor.enumerable = descriptor.enumerable || false;
      descriptor.configurable = true;
      if ("value" in descriptor) descriptor.writable = true;
      Object.defineProperty(target, descriptor.key, descriptor);
    }
  }

  function _createClass(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
  }

  function _defineProperty(obj, key, value) {
    if (key in obj) {
      Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
      });
    } else {
      obj[key] = value;
    }

    return obj;
  }

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);

    if (Object.getOwnPropertySymbols) {
      var symbols = Object.getOwnPropertySymbols(object);
      if (enumerableOnly) symbols = symbols.filter(function (sym) {
        return Object.getOwnPropertyDescriptor(object, sym).enumerable;
      });
      keys.push.apply(keys, symbols);
    }

    return keys;
  }

  function _objectSpread2(target) {
Mark Otto's avatar
dist    
Mark Otto committed
64
65
66
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i] != null ? arguments[i] : {};

67
68
69
70
71
72
73
74
75
76
      if (i % 2) {
        ownKeys(source, true).forEach(function (key) {
          _defineProperty(target, key, source[key]);
        });
      } else if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
      } else {
        ownKeys(source).forEach(function (key) {
          Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
Mark Otto's avatar
dist    
Mark Otto committed
77
78
      }
    }
Mark Otto's avatar
dist    
Mark Otto committed
79

Mark Otto's avatar
dist    
Mark Otto committed
80
81
    return target;
  }
fat's avatar
fat committed
82

XhmikosR's avatar
XhmikosR committed
83
84
85
86
87
88
89
90
91
92
93
  /**
   * --------------------------------------------------------------------------
   * Bootstrap (v4.3.1): util/index.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */

  var toType = function toType(obj) {
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  };

XhmikosR's avatar
XhmikosR committed
94
  var getSelector = function getSelector(element) {
XhmikosR's avatar
XhmikosR committed
95
96
97
98
    var selector = element.getAttribute('data-target');

    if (!selector || selector === '#') {
      var hrefAttr = element.getAttribute('href');
XhmikosR's avatar
XhmikosR committed
99
      selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
XhmikosR's avatar
XhmikosR committed
100
101
    }

XhmikosR's avatar
XhmikosR committed
102
103
104
105
106
107
    return selector;
  };

  var getElementFromSelector = function getElementFromSelector(element) {
    var selector = getSelector(element);
    return selector ? document.querySelector(selector) : null;
XhmikosR's avatar
XhmikosR committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  };

  var isElement = function isElement(obj) {
    return (obj[0] || obj).nodeType;
  };

  var typeCheckConfig = function typeCheckConfig(componentName, config, configTypes) {
    Object.keys(configTypes).forEach(function (property) {
      var expectedTypes = configTypes[property];
      var value = config[property];
      var valueType = value && isElement(value) ? 'element' : toType(value);

      if (!new RegExp(expectedTypes).test(valueType)) {
        throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
      }
    });
  };

  var makeArray = function makeArray(nodeList) {
    if (!nodeList) {
      return [];
    }

    return [].slice.call(nodeList);
  };

  var noop = function noop() {
    return function () {};
  };

XhmikosR's avatar
XhmikosR committed
138
139
140
141
142
143
144
145
146
147
148
  var getjQuery = function getjQuery() {
    var _window = window,
        jQuery = _window.jQuery;

    if (jQuery && !document.body.hasAttribute('data-no-jquery')) {
      return jQuery;
    }

    return null;
  };

XhmikosR's avatar
Dist    
XhmikosR committed
149
150
151
152
153
154
155
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'dropdown';
XhmikosR's avatar
XhmikosR committed
156
  var VERSION = '4.3.1';
XhmikosR's avatar
Dist    
XhmikosR committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  var DATA_KEY = 'bs.dropdown';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key

  var SPACE_KEYCODE = 32; // KeyboardEvent.which value for space key

  var TAB_KEYCODE = 9; // KeyboardEvent.which value for tab key

  var ARROW_UP_KEYCODE = 38; // KeyboardEvent.which value for up arrow key

  var ARROW_DOWN_KEYCODE = 40; // KeyboardEvent.which value for down arrow key

  var RIGHT_MOUSE_BUTTON_WHICH = 3; // MouseEvent.which value for the right button (assuming a right-handed mouse)

  var REGEXP_KEYDOWN = new RegExp(ARROW_UP_KEYCODE + "|" + ARROW_DOWN_KEYCODE + "|" + ESCAPE_KEYCODE);
  var Event = {
    HIDE: "hide" + EVENT_KEY,
    HIDDEN: "hidden" + EVENT_KEY,
    SHOW: "show" + EVENT_KEY,
    SHOWN: "shown" + EVENT_KEY,
    CLICK: "click" + EVENT_KEY,
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY,
    KEYDOWN_DATA_API: "keydown" + EVENT_KEY + DATA_API_KEY,
    KEYUP_DATA_API: "keyup" + EVENT_KEY + DATA_API_KEY
  };
  var ClassName = {
    DISABLED: 'disabled',
    SHOW: 'show',
    DROPUP: 'dropup',
    DROPRIGHT: 'dropright',
    DROPLEFT: 'dropleft',
    MENURIGHT: 'dropdown-menu-right',
    POSITION_STATIC: 'position-static'
  };
  var Selector = {
    DATA_TOGGLE: '[data-toggle="dropdown"]',
    FORM_CHILD: '.dropdown form',
    MENU: '.dropdown-menu',
    NAVBAR_NAV: '.navbar-nav',
    VISIBLE_ITEMS: '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)'
  };
  var AttachmentMap = {
    TOP: 'top-start',
    TOPEND: 'top-end',
    BOTTOM: 'bottom-start',
    BOTTOMEND: 'bottom-end',
    RIGHT: 'right-start',
    RIGHTEND: 'right-end',
    LEFT: 'left-start',
    LEFTEND: 'left-end'
  };
  var Default = {
    offset: 0,
    flip: true,
    boundary: 'scrollParent',
    reference: 'toggle',
XhmikosR's avatar
XhmikosR committed
214
215
    display: 'dynamic',
    popperConfig: null
XhmikosR's avatar
Dist    
XhmikosR committed
216
217
218
219
220
221
  };
  var DefaultType = {
    offset: '(number|string|function)',
    flip: 'boolean',
    boundary: '(string|element)',
    reference: '(string|element)',
XhmikosR's avatar
XhmikosR committed
222
223
    display: 'string',
    popperConfig: '(null|object)'
XhmikosR's avatar
Dist    
XhmikosR committed
224
  };
XhmikosR's avatar
XhmikosR committed
225
226
227
228
229
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
230

XhmikosR's avatar
Dist    
XhmikosR committed
231
232
233
234
235
236
237
238
239
  var Dropdown =
  /*#__PURE__*/
  function () {
    function Dropdown(element, config) {
      this._element = element;
      this._popper = null;
      this._config = this._getConfig(config);
      this._menu = this._getMenuElement();
      this._inNavbar = this._detectNavbar();
fat's avatar
fat committed
240

XhmikosR's avatar
Dist    
XhmikosR committed
241
      this._addEventListeners();
XhmikosR's avatar
XhmikosR committed
242
243

      Data.setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
244
    } // Getters
Jacob Thornton's avatar
Jacob Thornton committed
245

fat's avatar
fat committed
246

XhmikosR's avatar
Dist    
XhmikosR committed
247
    var _proto = Dropdown.prototype;
fat's avatar
fat committed
248

XhmikosR's avatar
Dist    
XhmikosR committed
249
250
    // Public
    _proto.toggle = function toggle() {
XhmikosR's avatar
XhmikosR committed
251
      if (this._element.disabled || this._element.classList.contains(ClassName.DISABLED)) {
XhmikosR's avatar
Dist    
XhmikosR committed
252
253
        return;
      }
fat's avatar
fat committed
254

XhmikosR's avatar
XhmikosR committed
255
      var isActive = this._menu.classList.contains(ClassName.SHOW);
fat's avatar
fat committed
256

XhmikosR's avatar
XhmikosR committed
257
      Dropdown.clearMenus();
fat's avatar
fat committed
258

XhmikosR's avatar
Dist    
XhmikosR committed
259
260
261
      if (isActive) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
262

XhmikosR's avatar
XhmikosR committed
263
264
265
266
267
268
269
270
271
      this.show();
    };

    _proto.show = function show() {
      if (this._element.disabled || this._element.classList.contains(ClassName.DISABLED) || this._menu.classList.contains(ClassName.SHOW)) {
        return;
      }

      var parent = Dropdown.getParentFromElement(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
272
273
274
      var relatedTarget = {
        relatedTarget: this._element
      };
XhmikosR's avatar
XhmikosR committed
275
      var showEvent = EventHandler.trigger(parent, Event.SHOW, relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
276

XhmikosR's avatar
XhmikosR committed
277
      if (showEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
278
279
        return;
      } // Disable totally Popper.js for Dropdown in Navbar
Mark Otto's avatar
dist    
Mark Otto committed
280

Mark Otto's avatar
grunt    
Mark Otto committed
281

XhmikosR's avatar
Dist    
XhmikosR committed
282
283
      if (!this._inNavbar) {
        if (typeof Popper === 'undefined') {
XhmikosR's avatar
XhmikosR committed
284
          throw new TypeError('Bootstrap\'s dropdowns require Popper.js (https://popper.js.org)');
XhmikosR's avatar
Dist    
XhmikosR committed
285
        }
Mark Otto's avatar
dist    
Mark Otto committed
286

XhmikosR's avatar
Dist    
XhmikosR committed
287
        var referenceElement = this._element;
Mark Otto's avatar
dist    
Mark Otto committed
288

XhmikosR's avatar
Dist    
XhmikosR committed
289
290
        if (this._config.reference === 'parent') {
          referenceElement = parent;
XhmikosR's avatar
XhmikosR committed
291
        } else if (isElement(this._config.reference)) {
XhmikosR's avatar
Dist    
XhmikosR committed
292
          referenceElement = this._config.reference; // Check if it's jQuery element
Mark Otto's avatar
dist    
Mark Otto committed
293

XhmikosR's avatar
Dist    
XhmikosR committed
294
295
          if (typeof this._config.reference.jquery !== 'undefined') {
            referenceElement = this._config.reference[0];
Mark Otto's avatar
dist    
Mark Otto committed
296
          }
XhmikosR's avatar
Dist    
XhmikosR committed
297
298
299
        } // If boundary is not `scrollParent`, then set position to `static`
        // to allow the menu to "escape" the scroll parent's boundaries
        // https://github.com/twbs/bootstrap/issues/24251
fat's avatar
fat committed
300

Mark Otto's avatar
dist    
Mark Otto committed
301

XhmikosR's avatar
Dist    
XhmikosR committed
302
        if (this._config.boundary !== 'scrollParent') {
XhmikosR's avatar
XhmikosR committed
303
          parent.classList.add(ClassName.POSITION_STATIC);
Mark Otto's avatar
dist    
Mark Otto committed
304
        }
Mark Otto's avatar
dist    
Mark Otto committed
305

XhmikosR's avatar
Dist    
XhmikosR committed
306
307
308
309
310
        this._popper = new Popper(referenceElement, this._menu, this._getPopperConfig());
      } // If this is a touch-enabled device we add extra
      // empty mouseover listeners to the body's immediate children;
      // only needed because of broken event delegation on iOS
      // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
Mark Otto's avatar
dist    
Mark Otto committed
311
312


XhmikosR's avatar
XhmikosR committed
313
314
315
316
      if ('ontouchstart' in document.documentElement && !makeArray(SelectorEngine.closest(parent, Selector.NAVBAR_NAV)).length) {
        makeArray(document.body.children).forEach(function (elem) {
          return EventHandler.on(elem, 'mouseover', null, noop());
        });
XhmikosR's avatar
Dist    
XhmikosR committed
317
      }
Mark Otto's avatar
dist    
Mark Otto committed
318

XhmikosR's avatar
Dist    
XhmikosR committed
319
      this._element.focus();
Mark Otto's avatar
dist    
Mark Otto committed
320

XhmikosR's avatar
Dist    
XhmikosR committed
321
      this._element.setAttribute('aria-expanded', true);
fat's avatar
fat committed
322

XhmikosR's avatar
XhmikosR committed
323
324
325
      Manipulator.toggleClass(this._menu, ClassName.SHOW);
      Manipulator.toggleClass(parent, ClassName.SHOW);
      EventHandler.trigger(parent, Event.SHOWN, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
326
327
328
    };

    _proto.hide = function hide() {
XhmikosR's avatar
XhmikosR committed
329
      if (this._element.disabled || this._element.classList.contains(ClassName.DISABLED) || !this._menu.classList.contains(ClassName.SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
330
331
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
332

XhmikosR's avatar
XhmikosR committed
333
      var parent = Dropdown.getParentFromElement(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
334
335
      var relatedTarget = {
        relatedTarget: this._element
Mark Otto's avatar
dist    
Mark Otto committed
336
      };
XhmikosR's avatar
XhmikosR committed
337
      var hideEvent = EventHandler.trigger(parent, Event.HIDE, relatedTarget);
Johann-S's avatar
build    
Johann-S committed
338

XhmikosR's avatar
XhmikosR committed
339
      if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
340
341
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
342

XhmikosR's avatar
XhmikosR committed
343
344
345
346
      if (this._popper) {
        this._popper.destroy();
      }

XhmikosR's avatar
XhmikosR committed
347
348
349
      Manipulator.toggleClass(this._menu, ClassName.SHOW);
      Manipulator.toggleClass(parent, ClassName.SHOW);
      EventHandler.trigger(parent, Event.HIDDEN, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
350
    };
Mark Otto's avatar
dist    
Mark Otto committed
351

XhmikosR's avatar
Dist    
XhmikosR committed
352
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
353
354
      Data.removeData(this._element, DATA_KEY);
      EventHandler.off(this._element, EVENT_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
355
356
      this._element = null;
      this._menu = null;
Mark Otto's avatar
dist    
Mark Otto committed
357

XhmikosR's avatar
XhmikosR committed
358
      if (this._popper) {
XhmikosR's avatar
Dist    
XhmikosR committed
359
        this._popper.destroy();
Mark Otto's avatar
dist    
Mark Otto committed
360

XhmikosR's avatar
Dist    
XhmikosR committed
361
362
363
        this._popper = null;
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
364

XhmikosR's avatar
Dist    
XhmikosR committed
365
366
    _proto.update = function update() {
      this._inNavbar = this._detectNavbar();
Mark Otto's avatar
dist    
Mark Otto committed
367

XhmikosR's avatar
XhmikosR committed
368
      if (this._popper) {
XhmikosR's avatar
Dist    
XhmikosR committed
369
370
        this._popper.scheduleUpdate();
      }
Mark Otto's avatar
Mark Otto committed
371
372
    } // Private
    ;
Mark Otto's avatar
dist    
Mark Otto committed
373

XhmikosR's avatar
Dist    
XhmikosR committed
374
375
    _proto._addEventListeners = function _addEventListeners() {
      var _this = this;
Mark Otto's avatar
dist    
Mark Otto committed
376

XhmikosR's avatar
XhmikosR committed
377
      EventHandler.on(this._element, Event.CLICK, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
378
379
380
381
382
383
        event.preventDefault();
        event.stopPropagation();

        _this.toggle();
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
384

XhmikosR's avatar
Dist    
XhmikosR committed
385
    _proto._getConfig = function _getConfig(config) {
386
      config = _objectSpread2({}, this.constructor.Default, {}, Manipulator.getDataAttributes(this._element), {}, config);
XhmikosR's avatar
XhmikosR committed
387
      typeCheckConfig(NAME, config, this.constructor.DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
388
389
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
390

XhmikosR's avatar
Dist    
XhmikosR committed
391
    _proto._getMenuElement = function _getMenuElement() {
XhmikosR's avatar
XhmikosR committed
392
      var parent = Dropdown.getParentFromElement(this._element);
393
      return SelectorEngine.findOne(Selector.MENU, parent);
XhmikosR's avatar
Dist    
XhmikosR committed
394
    };
Mark Otto's avatar
dist    
Mark Otto committed
395

XhmikosR's avatar
Dist    
XhmikosR committed
396
    _proto._getPlacement = function _getPlacement() {
XhmikosR's avatar
XhmikosR committed
397
      var parentDropdown = this._element.parentNode;
XhmikosR's avatar
Dist    
XhmikosR committed
398
      var placement = AttachmentMap.BOTTOM; // Handle dropup
Mark Otto's avatar
dist    
Mark Otto committed
399

XhmikosR's avatar
XhmikosR committed
400
      if (parentDropdown.classList.contains(ClassName.DROPUP)) {
XhmikosR's avatar
Dist    
XhmikosR committed
401
        placement = AttachmentMap.TOP;
Mark Otto's avatar
dist    
Mark Otto committed
402

XhmikosR's avatar
XhmikosR committed
403
        if (this._menu.classList.contains(ClassName.MENURIGHT)) {
XhmikosR's avatar
Dist    
XhmikosR committed
404
405
          placement = AttachmentMap.TOPEND;
        }
XhmikosR's avatar
XhmikosR committed
406
      } else if (parentDropdown.classList.contains(ClassName.DROPRIGHT)) {
XhmikosR's avatar
Dist    
XhmikosR committed
407
        placement = AttachmentMap.RIGHT;
XhmikosR's avatar
XhmikosR committed
408
      } else if (parentDropdown.classList.contains(ClassName.DROPLEFT)) {
XhmikosR's avatar
Dist    
XhmikosR committed
409
        placement = AttachmentMap.LEFT;
XhmikosR's avatar
XhmikosR committed
410
      } else if (this._menu.classList.contains(ClassName.MENURIGHT)) {
XhmikosR's avatar
Dist    
XhmikosR committed
411
412
        placement = AttachmentMap.BOTTOMEND;
      }
Mark Otto's avatar
dist    
Mark Otto committed
413

XhmikosR's avatar
Dist    
XhmikosR committed
414
415
416
417
      return placement;
    };

    _proto._detectNavbar = function _detectNavbar() {
XhmikosR's avatar
XhmikosR committed
418
      return Boolean(SelectorEngine.closest(this._element, '.navbar'));
XhmikosR's avatar
Dist    
XhmikosR committed
419
    };
Mark Otto's avatar
dist    
Mark Otto committed
420

Mark Otto's avatar
Mark Otto committed
421
    _proto._getOffset = function _getOffset() {
XhmikosR's avatar
Dist    
XhmikosR committed
422
423
      var _this2 = this;

Mark Otto's avatar
Mark Otto committed
424
      var offset = {};
XhmikosR's avatar
Dist    
XhmikosR committed
425
426

      if (typeof this._config.offset === 'function') {
Mark Otto's avatar
Mark Otto committed
427
        offset.fn = function (data) {
428
          data.offsets = _objectSpread2({}, data.offsets, {}, _this2._config.offset(data.offsets, _this2._element) || {});
XhmikosR's avatar
Dist    
XhmikosR committed
429
430
431
          return data;
        };
      } else {
Mark Otto's avatar
Mark Otto committed
432
        offset.offset = this._config.offset;
XhmikosR's avatar
Dist    
XhmikosR committed
433
      }
Mark Otto's avatar
dist    
Mark Otto committed
434

Mark Otto's avatar
Mark Otto committed
435
436
437
438
      return offset;
    };

    _proto._getPopperConfig = function _getPopperConfig() {
XhmikosR's avatar
Dist    
XhmikosR committed
439
440
441
      var popperConfig = {
        placement: this._getPlacement(),
        modifiers: {
Mark Otto's avatar
Mark Otto committed
442
          offset: this._getOffset(),
XhmikosR's avatar
Dist    
XhmikosR committed
443
444
445
446
447
          flip: {
            enabled: this._config.flip
          },
          preventOverflow: {
            boundariesElement: this._config.boundary
Mark Otto's avatar
dist    
Mark Otto committed
448
          }
XhmikosR's avatar
XhmikosR committed
449
450
        }
      }; // Disable Popper.js if we have a static display
Mark Otto's avatar
build    
Mark Otto committed
451

XhmikosR's avatar
Dist    
XhmikosR committed
452
453
454
455
456
      if (this._config.display === 'static') {
        popperConfig.modifiers.applyStyle = {
          enabled: false
        };
      }
Mark Otto's avatar
dist    
Mark Otto committed
457

XhmikosR's avatar
XhmikosR committed
458
      return _objectSpread2({}, popperConfig, {}, this._config.popperConfig);
Mark Otto's avatar
Mark Otto committed
459
460
    } // Static
    ;
fat's avatar
fat committed
461

XhmikosR's avatar
XhmikosR committed
462
    Dropdown.dropdownInterface = function dropdownInterface(element, config) {
XhmikosR's avatar
XhmikosR committed
463
      var data = Data.getData(element, DATA_KEY);
fat's avatar
fat committed
464

XhmikosR's avatar
XhmikosR committed
465
      var _config = typeof config === 'object' ? config : null;
fat's avatar
fat committed
466

XhmikosR's avatar
XhmikosR committed
467
468
469
470
471
472
      if (!data) {
        data = new Dropdown(element, _config);
      }

      if (typeof config === 'string') {
        if (typeof data[config] === 'undefined') {
XhmikosR's avatar
Dist.    
XhmikosR committed
473
          throw new TypeError("No method named \"" + config + "\"");
XhmikosR's avatar
Dist    
XhmikosR committed
474
        }
Johann-S's avatar
build    
Johann-S committed
475

XhmikosR's avatar
XhmikosR committed
476
477
478
        data[config]();
      }
    };
fat's avatar
fat committed
479

XhmikosR's avatar
XhmikosR committed
480
    Dropdown.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
XhmikosR committed
481
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
482
        Dropdown.dropdownInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
483
484
      });
    };
fat's avatar
fat committed
485

XhmikosR's avatar
XhmikosR committed
486
    Dropdown.clearMenus = function clearMenus(event) {
XhmikosR's avatar
Dist    
XhmikosR committed
487
488
489
      if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) {
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
490

XhmikosR's avatar
XhmikosR committed
491
      var toggles = makeArray(SelectorEngine.find(Selector.DATA_TOGGLE));
Mark Otto's avatar
grunt    
Mark Otto committed
492

XhmikosR's avatar
Dist    
XhmikosR committed
493
      for (var i = 0, len = toggles.length; i < len; i++) {
XhmikosR's avatar
XhmikosR committed
494
        var parent = Dropdown.getParentFromElement(toggles[i]);
XhmikosR's avatar
XhmikosR committed
495
        var context = Data.getData(toggles[i], DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
496
497
498
        var relatedTarget = {
          relatedTarget: toggles[i]
        };
Mark Otto's avatar
grunt    
Mark Otto committed
499

XhmikosR's avatar
Dist    
XhmikosR committed
500
501
        if (event && event.type === 'click') {
          relatedTarget.clickEvent = event;
Mark Otto's avatar
dist    
Mark Otto committed
502
        }
Mark Otto's avatar
dist    
Mark Otto committed
503

XhmikosR's avatar
Dist    
XhmikosR committed
504
505
        if (!context) {
          continue;
Mark Otto's avatar
dist    
Mark Otto committed
506
        }
fat's avatar
fat committed
507

XhmikosR's avatar
Dist    
XhmikosR committed
508
        var dropdownMenu = context._menu;
Mark Otto's avatar
dist    
Mark Otto committed
509

XhmikosR's avatar
XhmikosR committed
510
        if (!parent.classList.contains(ClassName.SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
511
512
          continue;
        }
Mark Otto's avatar
dist    
Mark Otto committed
513

XhmikosR's avatar
XhmikosR committed
514
        if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && parent.contains(event.target)) {
XhmikosR's avatar
Dist    
XhmikosR committed
515
          continue;
Mark Otto's avatar
dist    
Mark Otto committed
516
        }
fat's avatar
fat committed
517

XhmikosR's avatar
XhmikosR committed
518
        var hideEvent = EventHandler.trigger(parent, Event.HIDE, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
519

XhmikosR's avatar
XhmikosR committed
520
        if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
521
522
523
          continue;
        } // If this is a touch-enabled device we remove the extra
        // empty mouseover listeners we added for iOS support
fat's avatar
fat committed
524

XhmikosR's avatar
Dist    
XhmikosR committed
525
526

        if ('ontouchstart' in document.documentElement) {
XhmikosR's avatar
XhmikosR committed
527
528
529
          makeArray(document.body.children).forEach(function (elem) {
            return EventHandler.off(elem, 'mouseover', null, noop());
          });
Mark Otto's avatar
dist    
Mark Otto committed
530
        }
fat's avatar
fat committed
531

XhmikosR's avatar
Dist    
XhmikosR committed
532
        toggles[i].setAttribute('aria-expanded', 'false');
XhmikosR's avatar
XhmikosR committed
533
534
535
536
537

        if (context._popper) {
          context._popper.destroy();
        }

XhmikosR's avatar
XhmikosR committed
538
539
540
        dropdownMenu.classList.remove(ClassName.SHOW);
        parent.classList.remove(ClassName.SHOW);
        EventHandler.trigger(parent, Event.HIDDEN, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
541
542
      }
    };
fat's avatar
fat committed
543

XhmikosR's avatar
XhmikosR committed
544
545
    Dropdown.getParentFromElement = function getParentFromElement(element) {
      return getElementFromSelector(element) || element.parentNode;
XhmikosR's avatar
XhmikosR committed
546
    };
fat's avatar
fat committed
547

XhmikosR's avatar
XhmikosR committed
548
    Dropdown.dataApiKeydownHandler = function dataApiKeydownHandler(event) {
XhmikosR's avatar
Dist    
XhmikosR committed
549
550
551
552
553
554
555
      // If not input/textarea:
      //  - And not a key in REGEXP_KEYDOWN => not a dropdown command
      // If input/textarea:
      //  - If space key => not a dropdown command
      //  - If key is other than escape
      //    - If key is not up or down => not a dropdown command
      //    - If trigger inside the menu => not a dropdown command
XhmikosR's avatar
XhmikosR committed
556
      if (/input|textarea/i.test(event.target.tagName) ? event.which === SPACE_KEYCODE || event.which !== ESCAPE_KEYCODE && (event.which !== ARROW_DOWN_KEYCODE && event.which !== ARROW_UP_KEYCODE || SelectorEngine.closest(event.target, Selector.MENU)) : !REGEXP_KEYDOWN.test(event.which)) {
XhmikosR's avatar
Dist    
XhmikosR committed
557
558
        return;
      }
fat's avatar
fat committed
559

XhmikosR's avatar
Dist    
XhmikosR committed
560
561
      event.preventDefault();
      event.stopPropagation();
fat's avatar
fat committed
562

XhmikosR's avatar
XhmikosR committed
563
      if (this.disabled || this.classList.contains(ClassName.DISABLED)) {
XhmikosR's avatar
Dist    
XhmikosR committed
564
565
        return;
      }
Mark Otto's avatar
Mark Otto committed
566

XhmikosR's avatar
XhmikosR committed
567
      var parent = Dropdown.getParentFromElement(this);
XhmikosR's avatar
XhmikosR committed
568
      var isActive = parent.classList.contains(ClassName.SHOW);
Mark Otto's avatar
Mark Otto committed
569

Mark Otto's avatar
dist    
Mark Otto committed
570
      if (!isActive || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) {
XhmikosR's avatar
Dist    
XhmikosR committed
571
        if (event.which === ESCAPE_KEYCODE) {
Mark Otto's avatar
dist v5    
Mark Otto committed
572
          SelectorEngine.findOne(Selector.DATA_TOGGLE, parent).focus();
Mark Otto's avatar
dist    
Mark Otto committed
573
        }
fat's avatar
fat committed
574

XhmikosR's avatar
XhmikosR committed
575
        Dropdown.clearMenus();
XhmikosR's avatar
Dist    
XhmikosR committed
576
577
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
578

XhmikosR's avatar
XhmikosR committed
579
      var items = makeArray(SelectorEngine.find(Selector.VISIBLE_ITEMS, parent));
Mark Otto's avatar
dist    
Mark Otto committed
580

XhmikosR's avatar
XhmikosR committed
581
      if (!items.length) {
XhmikosR's avatar
Dist    
XhmikosR committed
582
583
        return;
      }
fat's avatar
fat committed
584

XhmikosR's avatar
Dist    
XhmikosR committed
585
      var index = items.indexOf(event.target);
fat's avatar
fat committed
586

XhmikosR's avatar
Dist    
XhmikosR committed
587
588
589
590
      if (event.which === ARROW_UP_KEYCODE && index > 0) {
        // Up
        index--;
      }
Mark Otto's avatar
dist    
Mark Otto committed
591

XhmikosR's avatar
Dist    
XhmikosR committed
592
593
594
595
      if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) {
        // Down
        index++;
      }
Mark Otto's avatar
dist    
Mark Otto committed
596

XhmikosR's avatar
Dist    
XhmikosR committed
597
598
599
      if (index < 0) {
        index = 0;
      }
fat's avatar
fat committed
600

XhmikosR's avatar
Dist    
XhmikosR committed
601
      items[index].focus();
Mark Otto's avatar
dist    
Mark Otto committed
602
    };
Mark Otto's avatar
dist    
Mark Otto committed
603

XhmikosR's avatar
XhmikosR committed
604
    Dropdown.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
605
606
607
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
    _createClass(Dropdown, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }, {
      key: "DefaultType",
      get: function get() {
        return DefaultType;
      }
    }]);

Mark Otto's avatar
dist    
Mark Otto committed
625
    return Dropdown;
XhmikosR's avatar
Dist    
XhmikosR committed
626
627
628
629
630
631
632
633
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */


XhmikosR's avatar
XhmikosR committed
634
635
636
637
  EventHandler.on(document, Event.KEYDOWN_DATA_API, Selector.DATA_TOGGLE, Dropdown.dataApiKeydownHandler);
  EventHandler.on(document, Event.KEYDOWN_DATA_API, Selector.MENU, Dropdown.dataApiKeydownHandler);
  EventHandler.on(document, Event.CLICK_DATA_API, Dropdown.clearMenus);
  EventHandler.on(document, Event.KEYUP_DATA_API, Dropdown.clearMenus);
XhmikosR's avatar
XhmikosR committed
638
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
639
640
    event.preventDefault();
    event.stopPropagation();
XhmikosR's avatar
XhmikosR committed
641
    Dropdown.dropdownInterface(this, 'toggle');
XhmikosR's avatar
XhmikosR committed
642
643
644
  });
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) {
    return e.stopPropagation();
XhmikosR's avatar
Dist    
XhmikosR committed
645
  });
XhmikosR's avatar
XhmikosR committed
646
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
647
648
649
650
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
651
   * add .dropdown to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
652
653
   */

654
655
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
656
657
658
659
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    $.fn[NAME] = Dropdown.jQueryInterface;
    $.fn[NAME].Constructor = Dropdown;
XhmikosR's avatar
Dist    
XhmikosR committed
660

XhmikosR's avatar
XhmikosR committed
661
662
663
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Dropdown.jQueryInterface;
XhmikosR's avatar
XhmikosR committed
664
665
    };
  }
fat's avatar
fat committed
666
667

  return Dropdown;
Mark Otto's avatar
dist    
Mark Otto committed
668

Mark Otto's avatar
Mark Otto committed
669
}));
Mark Otto's avatar
dist    
Mark Otto committed
670
//# sourceMappingURL=dropdown.js.map