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) {
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
138
  };

  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
139
140
141
142
143
144
145
146
147
148
149
  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
150
151
152
153
154
155
156
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'dropdown';
XhmikosR's avatar
XhmikosR committed
157
  var VERSION = '4.3.1';
XhmikosR's avatar
Dist    
XhmikosR committed
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
214
  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
215
216
    display: 'dynamic',
    popperConfig: null
XhmikosR's avatar
Dist    
XhmikosR committed
217
218
219
220
221
222
  };
  var DefaultType = {
    offset: '(number|string|function)',
    flip: 'boolean',
    boundary: '(string|element)',
    reference: '(string|element)',
XhmikosR's avatar
XhmikosR committed
223
224
    display: 'string',
    popperConfig: '(null|object)'
Mark Otto's avatar
dist    
Mark Otto committed
225
226
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
227
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
228
229
     * ------------------------------------------------------------------------
     */
fat's avatar
fat committed
230

XhmikosR's avatar
Dist    
XhmikosR committed
231
  };
fat's avatar
fat committed
232

XhmikosR's avatar
Dist    
XhmikosR committed
233
234
235
236
237
238
239
240
241
  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
242

XhmikosR's avatar
Dist    
XhmikosR committed
243
      this._addEventListeners();
XhmikosR's avatar
XhmikosR committed
244
245

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

fat's avatar
fat committed
248

XhmikosR's avatar
Dist    
XhmikosR committed
249
    var _proto = Dropdown.prototype;
fat's avatar
fat committed
250

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

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

XhmikosR's avatar
XhmikosR committed
259
      Dropdown.clearMenus();
fat's avatar
fat committed
260

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

XhmikosR's avatar
XhmikosR committed
265
266
267
268
269
270
271
272
273
      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
274
275
276
      var relatedTarget = {
        relatedTarget: this._element
      };
XhmikosR's avatar
XhmikosR committed
277
      var showEvent = EventHandler.trigger(parent, Event.SHOW, relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
278

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

Mark Otto's avatar
grunt    
Mark Otto committed
283

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
296
297
          if (typeof this._config.reference.jquery !== 'undefined') {
            referenceElement = this._config.reference[0];
Mark Otto's avatar
dist    
Mark Otto committed
298
          }
XhmikosR's avatar
Dist    
XhmikosR committed
299
300
301
        } // 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
302

Mark Otto's avatar
dist    
Mark Otto committed
303

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

XhmikosR's avatar
Dist    
XhmikosR committed
308
309
310
311
312
        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
313
314


XhmikosR's avatar
XhmikosR committed
315
316
317
318
      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
319
      }
Mark Otto's avatar
dist    
Mark Otto committed
320

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
416
417
418
419
      return placement;
    };

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

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

Mark Otto's avatar
Mark Otto committed
426
      var offset = {};
XhmikosR's avatar
Dist    
XhmikosR committed
427
428

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

Mark Otto's avatar
Mark Otto committed
437
438
439
440
      return offset;
    };

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

Mark Otto's avatar
dist    
Mark Otto committed
453
      };
Mark Otto's avatar
build    
Mark Otto committed
454

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

XhmikosR's avatar
XhmikosR committed
461
      return _objectSpread2({}, popperConfig, {}, this._config.popperConfig);
Mark Otto's avatar
Mark Otto committed
462
463
    } // Static
    ;
fat's avatar
fat committed
464

XhmikosR's avatar
XhmikosR committed
465
    Dropdown.dropdownInterface = function dropdownInterface(element, config) {
XhmikosR's avatar
XhmikosR committed
466
      var data = Data.getData(element, DATA_KEY);
fat's avatar
fat committed
467

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

XhmikosR's avatar
XhmikosR committed
470
471
472
473
474
475
      if (!data) {
        data = new Dropdown(element, _config);
      }

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

XhmikosR's avatar
XhmikosR committed
479
480
481
        data[config]();
      }
    };
fat's avatar
fat committed
482

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

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

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
507
508
        if (!context) {
          continue;
Mark Otto's avatar
dist    
Mark Otto committed
509
        }
fat's avatar
fat committed
510

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

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

XhmikosR's avatar
XhmikosR committed
517
        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
518
          continue;
Mark Otto's avatar
dist    
Mark Otto committed
519
        }
fat's avatar
fat committed
520

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

XhmikosR's avatar
XhmikosR committed
523
        if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
524
525
526
          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
527

XhmikosR's avatar
Dist    
XhmikosR committed
528
529

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

XhmikosR's avatar
Dist    
XhmikosR committed
535
        toggles[i].setAttribute('aria-expanded', 'false');
XhmikosR's avatar
XhmikosR committed
536
537
538
539
540

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

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

XhmikosR's avatar
XhmikosR committed
547
548
    Dropdown.getParentFromElement = function getParentFromElement(element) {
      return getElementFromSelector(element) || element.parentNode;
XhmikosR's avatar
XhmikosR committed
549
    };
fat's avatar
fat committed
550

XhmikosR's avatar
XhmikosR committed
551
    Dropdown.dataApiKeydownHandler = function dataApiKeydownHandler(event) {
XhmikosR's avatar
Dist    
XhmikosR committed
552
553
554
555
556
557
558
      // 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
559
      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
560
561
        return;
      }
fat's avatar
fat committed
562

XhmikosR's avatar
Dist    
XhmikosR committed
563
564
      event.preventDefault();
      event.stopPropagation();
fat's avatar
fat committed
565

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

XhmikosR's avatar
XhmikosR committed
570
      var parent = Dropdown.getParentFromElement(this);
XhmikosR's avatar
XhmikosR committed
571
      var isActive = parent.classList.contains(ClassName.SHOW);
Mark Otto's avatar
Mark Otto committed
572

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

XhmikosR's avatar
XhmikosR committed
578
        Dropdown.clearMenus();
XhmikosR's avatar
Dist    
XhmikosR committed
579
580
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
581

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

XhmikosR's avatar
XhmikosR committed
584
      if (!items.length) {
XhmikosR's avatar
Dist    
XhmikosR committed
585
586
        return;
      }
fat's avatar
fat committed
587

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
600
601
602
      if (index < 0) {
        index = 0;
      }
fat's avatar
fat committed
603

XhmikosR's avatar
Dist    
XhmikosR committed
604
      items[index].focus();
Mark Otto's avatar
dist    
Mark Otto committed
605
    };
Mark Otto's avatar
dist    
Mark Otto committed
606

XhmikosR's avatar
XhmikosR committed
607
    Dropdown.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
608
609
610
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
    _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
628
    return Dropdown;
XhmikosR's avatar
Dist    
XhmikosR committed
629
630
631
632
633
634
635
636
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */


XhmikosR's avatar
XhmikosR committed
637
638
639
640
  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
641
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
642
643
    event.preventDefault();
    event.stopPropagation();
XhmikosR's avatar
XhmikosR committed
644
    Dropdown.dropdownInterface(this, 'toggle');
XhmikosR's avatar
XhmikosR committed
645
646
647
  });
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) {
    return e.stopPropagation();
XhmikosR's avatar
Dist    
XhmikosR committed
648
  });
XhmikosR's avatar
XhmikosR committed
649
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
650
651
652
653
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
654
   * add .dropdown to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
655
656
   */

657
658
  /* istanbul ignore if */

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

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

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

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