dropdown.js 21.4 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
  (global = global || self, global.Dropdown = factory(global.Data, global.EventHandler, global.Manipulator, global.Popper, global.SelectorEngine));
XhmikosR's avatar
XhmikosR committed
10
}(this, (function (Data, EventHandler, Manipulator, Popper, SelectorEngine) { 'use strict';
XhmikosR's avatar
XhmikosR committed
11
12
13
14

  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
  };

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

XhmikosR's avatar
XhmikosR committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  var isVisible = function isVisible(element) {
    if (!element) {
      return false;
    }

    if (element.style && element.parentNode && element.parentNode.style) {
      var elementStyle = getComputedStyle(element);
      var parentNodeStyle = getComputedStyle(element.parentNode);
      return elementStyle.display !== 'none' && parentNodeStyle.display !== 'none' && elementStyle.visibility !== 'hidden';
    }

    return false;
  };

XhmikosR's avatar
XhmikosR committed
148
149
150
151
  var noop = function noop() {
    return function () {};
  };

XhmikosR's avatar
XhmikosR committed
152
153
154
155
156
157
158
159
160
161
162
  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
163
164
165
166
167
168
169
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'dropdown';
XhmikosR's avatar
XhmikosR committed
170
  var VERSION = '4.3.1';
XhmikosR's avatar
Dist    
XhmikosR committed
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
215
216
217
218
219
220
221
222
223
224
225
226
227
  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
228
229
    display: 'dynamic',
    popperConfig: null
XhmikosR's avatar
Dist    
XhmikosR committed
230
231
232
233
234
235
  };
  var DefaultType = {
    offset: '(number|string|function)',
    flip: 'boolean',
    boundary: '(string|element)',
    reference: '(string|element)',
XhmikosR's avatar
XhmikosR committed
236
237
    display: 'string',
    popperConfig: '(null|object)'
XhmikosR's avatar
Dist    
XhmikosR committed
238
  };
XhmikosR's avatar
XhmikosR committed
239
240
241
242
243
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
244

XhmikosR's avatar
Dist    
XhmikosR committed
245
246
247
248
249
250
251
252
253
  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
254

XhmikosR's avatar
Dist    
XhmikosR committed
255
      this._addEventListeners();
XhmikosR's avatar
XhmikosR committed
256
257

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

fat's avatar
fat committed
260

XhmikosR's avatar
Dist    
XhmikosR committed
261
    var _proto = Dropdown.prototype;
fat's avatar
fat committed
262

XhmikosR's avatar
Dist    
XhmikosR committed
263
264
    // Public
    _proto.toggle = function toggle() {
XhmikosR's avatar
XhmikosR committed
265
      if (this._element.disabled || this._element.classList.contains(ClassName.DISABLED)) {
XhmikosR's avatar
Dist    
XhmikosR committed
266
267
        return;
      }
fat's avatar
fat committed
268

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

XhmikosR's avatar
XhmikosR committed
271
      Dropdown.clearMenus();
fat's avatar
fat committed
272

XhmikosR's avatar
Dist    
XhmikosR committed
273
274
275
      if (isActive) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
276

XhmikosR's avatar
XhmikosR committed
277
278
279
280
281
282
283
284
285
      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
286
287
288
      var relatedTarget = {
        relatedTarget: this._element
      };
XhmikosR's avatar
XhmikosR committed
289
      var showEvent = EventHandler.trigger(parent, Event.SHOW, relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
290

XhmikosR's avatar
XhmikosR committed
291
      if (showEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
292
293
        return;
      } // Disable totally Popper.js for Dropdown in Navbar
Mark Otto's avatar
dist    
Mark Otto committed
294

Mark Otto's avatar
grunt    
Mark Otto committed
295

XhmikosR's avatar
Dist    
XhmikosR committed
296
297
      if (!this._inNavbar) {
        if (typeof Popper === 'undefined') {
XhmikosR's avatar
XhmikosR committed
298
          throw new TypeError('Bootstrap\'s dropdowns require Popper.js (https://popper.js.org)');
XhmikosR's avatar
Dist    
XhmikosR committed
299
        }
Mark Otto's avatar
dist    
Mark Otto committed
300

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

XhmikosR's avatar
Dist    
XhmikosR committed
303
304
        if (this._config.reference === 'parent') {
          referenceElement = parent;
XhmikosR's avatar
XhmikosR committed
305
        } else if (isElement(this._config.reference)) {
XhmikosR's avatar
Dist    
XhmikosR committed
306
          referenceElement = this._config.reference; // Check if it's jQuery element
Mark Otto's avatar
dist    
Mark Otto committed
307

XhmikosR's avatar
Dist    
XhmikosR committed
308
309
          if (typeof this._config.reference.jquery !== 'undefined') {
            referenceElement = this._config.reference[0];
Mark Otto's avatar
dist    
Mark Otto committed
310
          }
XhmikosR's avatar
Dist    
XhmikosR committed
311
312
313
        } // 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
314

Mark Otto's avatar
dist    
Mark Otto committed
315

XhmikosR's avatar
Dist    
XhmikosR committed
316
        if (this._config.boundary !== 'scrollParent') {
XhmikosR's avatar
XhmikosR committed
317
          parent.classList.add(ClassName.POSITION_STATIC);
Mark Otto's avatar
dist    
Mark Otto committed
318
        }
Mark Otto's avatar
dist    
Mark Otto committed
319

XhmikosR's avatar
Dist    
XhmikosR committed
320
321
322
323
324
        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
325
326


XhmikosR's avatar
XhmikosR committed
327
328
329
330
      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
331
      }
Mark Otto's avatar
dist    
Mark Otto committed
332

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

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

XhmikosR's avatar
XhmikosR committed
337
338
339
      Manipulator.toggleClass(this._menu, ClassName.SHOW);
      Manipulator.toggleClass(parent, ClassName.SHOW);
      EventHandler.trigger(parent, Event.SHOWN, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
340
341
342
    };

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

XhmikosR's avatar
XhmikosR committed
347
      var parent = Dropdown.getParentFromElement(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
348
349
      var relatedTarget = {
        relatedTarget: this._element
Mark Otto's avatar
dist    
Mark Otto committed
350
      };
XhmikosR's avatar
XhmikosR committed
351
      var hideEvent = EventHandler.trigger(parent, Event.HIDE, relatedTarget);
Johann-S's avatar
build    
Johann-S committed
352

XhmikosR's avatar
XhmikosR committed
353
      if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
354
355
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
356

XhmikosR's avatar
XhmikosR committed
357
358
359
360
      if (this._popper) {
        this._popper.destroy();
      }

XhmikosR's avatar
XhmikosR committed
361
362
363
      Manipulator.toggleClass(this._menu, ClassName.SHOW);
      Manipulator.toggleClass(parent, ClassName.SHOW);
      EventHandler.trigger(parent, Event.HIDDEN, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
364
    };
Mark Otto's avatar
dist    
Mark Otto committed
365

XhmikosR's avatar
Dist    
XhmikosR committed
366
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
367
368
      Data.removeData(this._element, DATA_KEY);
      EventHandler.off(this._element, EVENT_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
369
370
      this._element = null;
      this._menu = null;
Mark Otto's avatar
dist    
Mark Otto committed
371

XhmikosR's avatar
XhmikosR committed
372
      if (this._popper) {
XhmikosR's avatar
Dist    
XhmikosR committed
373
        this._popper.destroy();
Mark Otto's avatar
dist    
Mark Otto committed
374

XhmikosR's avatar
Dist    
XhmikosR committed
375
376
377
        this._popper = null;
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
378

XhmikosR's avatar
Dist    
XhmikosR committed
379
380
    _proto.update = function update() {
      this._inNavbar = this._detectNavbar();
Mark Otto's avatar
dist    
Mark Otto committed
381

XhmikosR's avatar
XhmikosR committed
382
      if (this._popper) {
XhmikosR's avatar
Dist    
XhmikosR committed
383
384
        this._popper.scheduleUpdate();
      }
Mark Otto's avatar
Mark Otto committed
385
386
    } // Private
    ;
Mark Otto's avatar
dist    
Mark Otto committed
387

XhmikosR's avatar
Dist    
XhmikosR committed
388
389
    _proto._addEventListeners = function _addEventListeners() {
      var _this = this;
Mark Otto's avatar
dist    
Mark Otto committed
390

XhmikosR's avatar
XhmikosR committed
391
      EventHandler.on(this._element, Event.CLICK, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
392
393
394
395
396
397
        event.preventDefault();
        event.stopPropagation();

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

XhmikosR's avatar
Dist    
XhmikosR committed
399
    _proto._getConfig = function _getConfig(config) {
400
      config = _objectSpread2({}, this.constructor.Default, {}, Manipulator.getDataAttributes(this._element), {}, config);
XhmikosR's avatar
XhmikosR committed
401
      typeCheckConfig(NAME, config, this.constructor.DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
402
403
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
404

XhmikosR's avatar
Dist    
XhmikosR committed
405
    _proto._getMenuElement = function _getMenuElement() {
XhmikosR's avatar
XhmikosR committed
406
      var parent = Dropdown.getParentFromElement(this._element);
407
      return SelectorEngine.findOne(Selector.MENU, parent);
XhmikosR's avatar
Dist    
XhmikosR committed
408
    };
Mark Otto's avatar
dist    
Mark Otto committed
409

XhmikosR's avatar
Dist    
XhmikosR committed
410
    _proto._getPlacement = function _getPlacement() {
XhmikosR's avatar
XhmikosR committed
411
      var parentDropdown = this._element.parentNode;
XhmikosR's avatar
Dist    
XhmikosR committed
412
      var placement = AttachmentMap.BOTTOM; // Handle dropup
Mark Otto's avatar
dist    
Mark Otto committed
413

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

XhmikosR's avatar
XhmikosR committed
417
        if (this._menu.classList.contains(ClassName.MENURIGHT)) {
XhmikosR's avatar
Dist    
XhmikosR committed
418
419
          placement = AttachmentMap.TOPEND;
        }
XhmikosR's avatar
XhmikosR committed
420
      } else if (parentDropdown.classList.contains(ClassName.DROPRIGHT)) {
XhmikosR's avatar
Dist    
XhmikosR committed
421
        placement = AttachmentMap.RIGHT;
XhmikosR's avatar
XhmikosR committed
422
      } else if (parentDropdown.classList.contains(ClassName.DROPLEFT)) {
XhmikosR's avatar
Dist    
XhmikosR committed
423
        placement = AttachmentMap.LEFT;
XhmikosR's avatar
XhmikosR committed
424
      } else if (this._menu.classList.contains(ClassName.MENURIGHT)) {
XhmikosR's avatar
Dist    
XhmikosR committed
425
426
        placement = AttachmentMap.BOTTOMEND;
      }
Mark Otto's avatar
dist    
Mark Otto committed
427

XhmikosR's avatar
Dist    
XhmikosR committed
428
429
430
431
      return placement;
    };

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

Mark Otto's avatar
Mark Otto committed
435
    _proto._getOffset = function _getOffset() {
XhmikosR's avatar
Dist    
XhmikosR committed
436
437
      var _this2 = this;

Mark Otto's avatar
Mark Otto committed
438
      var offset = {};
XhmikosR's avatar
Dist    
XhmikosR committed
439
440

      if (typeof this._config.offset === 'function') {
Mark Otto's avatar
Mark Otto committed
441
        offset.fn = function (data) {
442
          data.offsets = _objectSpread2({}, data.offsets, {}, _this2._config.offset(data.offsets, _this2._element) || {});
XhmikosR's avatar
Dist    
XhmikosR committed
443
444
445
          return data;
        };
      } else {
Mark Otto's avatar
Mark Otto committed
446
        offset.offset = this._config.offset;
XhmikosR's avatar
Dist    
XhmikosR committed
447
      }
Mark Otto's avatar
dist    
Mark Otto committed
448

Mark Otto's avatar
Mark Otto committed
449
450
451
452
      return offset;
    };

    _proto._getPopperConfig = function _getPopperConfig() {
XhmikosR's avatar
Dist    
XhmikosR committed
453
454
455
      var popperConfig = {
        placement: this._getPlacement(),
        modifiers: {
Mark Otto's avatar
Mark Otto committed
456
          offset: this._getOffset(),
XhmikosR's avatar
Dist    
XhmikosR committed
457
458
459
460
461
          flip: {
            enabled: this._config.flip
          },
          preventOverflow: {
            boundariesElement: this._config.boundary
Mark Otto's avatar
dist    
Mark Otto committed
462
          }
XhmikosR's avatar
XhmikosR committed
463
464
        }
      }; // Disable Popper.js if we have a static display
Mark Otto's avatar
build    
Mark Otto committed
465

XhmikosR's avatar
Dist    
XhmikosR committed
466
467
468
469
470
      if (this._config.display === 'static') {
        popperConfig.modifiers.applyStyle = {
          enabled: false
        };
      }
Mark Otto's avatar
dist    
Mark Otto committed
471

XhmikosR's avatar
XhmikosR committed
472
      return _objectSpread2({}, popperConfig, {}, this._config.popperConfig);
Mark Otto's avatar
Mark Otto committed
473
474
    } // Static
    ;
fat's avatar
fat committed
475

XhmikosR's avatar
XhmikosR committed
476
    Dropdown.dropdownInterface = function dropdownInterface(element, config) {
XhmikosR's avatar
XhmikosR committed
477
      var data = Data.getData(element, DATA_KEY);
fat's avatar
fat committed
478

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

XhmikosR's avatar
XhmikosR committed
481
482
483
484
485
486
      if (!data) {
        data = new Dropdown(element, _config);
      }

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

XhmikosR's avatar
XhmikosR committed
490
491
492
        data[config]();
      }
    };
fat's avatar
fat committed
493

XhmikosR's avatar
XhmikosR committed
494
    Dropdown.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
XhmikosR committed
495
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
496
        Dropdown.dropdownInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
497
498
      });
    };
fat's avatar
fat committed
499

XhmikosR's avatar
XhmikosR committed
500
    Dropdown.clearMenus = function clearMenus(event) {
XhmikosR's avatar
Dist    
XhmikosR committed
501
502
503
      if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) {
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
504

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

XhmikosR's avatar
Dist    
XhmikosR committed
507
      for (var i = 0, len = toggles.length; i < len; i++) {
XhmikosR's avatar
XhmikosR committed
508
        var parent = Dropdown.getParentFromElement(toggles[i]);
XhmikosR's avatar
XhmikosR committed
509
        var context = Data.getData(toggles[i], DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
510
511
512
        var relatedTarget = {
          relatedTarget: toggles[i]
        };
Mark Otto's avatar
grunt    
Mark Otto committed
513

XhmikosR's avatar
Dist    
XhmikosR committed
514
515
        if (event && event.type === 'click') {
          relatedTarget.clickEvent = event;
Mark Otto's avatar
dist    
Mark Otto committed
516
        }
Mark Otto's avatar
dist    
Mark Otto committed
517

XhmikosR's avatar
Dist    
XhmikosR committed
518
519
        if (!context) {
          continue;
Mark Otto's avatar
dist    
Mark Otto committed
520
        }
fat's avatar
fat committed
521

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

XhmikosR's avatar
XhmikosR committed
524
        if (!parent.classList.contains(ClassName.SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
525
526
          continue;
        }
Mark Otto's avatar
dist    
Mark Otto committed
527

XhmikosR's avatar
XhmikosR committed
528
        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
529
          continue;
Mark Otto's avatar
dist    
Mark Otto committed
530
        }
fat's avatar
fat committed
531

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

XhmikosR's avatar
XhmikosR committed
534
        if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
535
536
537
          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
538

XhmikosR's avatar
Dist    
XhmikosR committed
539
540

        if ('ontouchstart' in document.documentElement) {
XhmikosR's avatar
XhmikosR committed
541
542
543
          makeArray(document.body.children).forEach(function (elem) {
            return EventHandler.off(elem, 'mouseover', null, noop());
          });
Mark Otto's avatar
dist    
Mark Otto committed
544
        }
fat's avatar
fat committed
545

XhmikosR's avatar
Dist    
XhmikosR committed
546
        toggles[i].setAttribute('aria-expanded', 'false');
XhmikosR's avatar
XhmikosR committed
547
548
549
550
551

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

XhmikosR's avatar
XhmikosR committed
552
553
554
        dropdownMenu.classList.remove(ClassName.SHOW);
        parent.classList.remove(ClassName.SHOW);
        EventHandler.trigger(parent, Event.HIDDEN, relatedTarget);
XhmikosR's avatar
Dist    
XhmikosR committed
555
556
      }
    };
fat's avatar
fat committed
557

XhmikosR's avatar
XhmikosR committed
558
559
    Dropdown.getParentFromElement = function getParentFromElement(element) {
      return getElementFromSelector(element) || element.parentNode;
XhmikosR's avatar
XhmikosR committed
560
    };
fat's avatar
fat committed
561

XhmikosR's avatar
XhmikosR committed
562
    Dropdown.dataApiKeydownHandler = function dataApiKeydownHandler(event) {
XhmikosR's avatar
Dist    
XhmikosR committed
563
564
565
566
567
568
569
      // 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
570
      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
571
572
        return;
      }
fat's avatar
fat committed
573

XhmikosR's avatar
Dist    
XhmikosR committed
574
575
      event.preventDefault();
      event.stopPropagation();
fat's avatar
fat committed
576

XhmikosR's avatar
XhmikosR committed
577
      if (this.disabled || this.classList.contains(ClassName.DISABLED)) {
XhmikosR's avatar
Dist    
XhmikosR committed
578
579
        return;
      }
Mark Otto's avatar
Mark Otto committed
580

XhmikosR's avatar
XhmikosR committed
581
      var parent = Dropdown.getParentFromElement(this);
XhmikosR's avatar
XhmikosR committed
582
      var isActive = parent.classList.contains(ClassName.SHOW);
Mark Otto's avatar
Mark Otto committed
583

Mark Otto's avatar
dist    
Mark Otto committed
584
      if (!isActive || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) {
XhmikosR's avatar
Dist    
XhmikosR committed
585
        if (event.which === ESCAPE_KEYCODE) {
Mark Otto's avatar
dist v5    
Mark Otto committed
586
          SelectorEngine.findOne(Selector.DATA_TOGGLE, parent).focus();
Mark Otto's avatar
dist    
Mark Otto committed
587
        }
fat's avatar
fat committed
588

XhmikosR's avatar
XhmikosR committed
589
        Dropdown.clearMenus();
XhmikosR's avatar
Dist    
XhmikosR committed
590
591
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
592

XhmikosR's avatar
XhmikosR committed
593
      var items = makeArray(SelectorEngine.find(Selector.VISIBLE_ITEMS, parent)).filter(isVisible);
Mark Otto's avatar
dist    
Mark Otto committed
594

XhmikosR's avatar
XhmikosR committed
595
      if (!items.length) {
XhmikosR's avatar
Dist    
XhmikosR committed
596
597
        return;
      }
fat's avatar
fat committed
598

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

XhmikosR's avatar
Dist    
XhmikosR committed
601
602
603
604
      if (event.which === ARROW_UP_KEYCODE && index > 0) {
        // Up
        index--;
      }
Mark Otto's avatar
dist    
Mark Otto committed
605

XhmikosR's avatar
Dist    
XhmikosR committed
606
607
608
609
      if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) {
        // Down
        index++;
      }
Mark Otto's avatar
dist    
Mark Otto committed
610

XhmikosR's avatar
Dist    
XhmikosR committed
611
612
613
      if (index < 0) {
        index = 0;
      }
fat's avatar
fat committed
614

XhmikosR's avatar
Dist    
XhmikosR committed
615
      items[index].focus();
Mark Otto's avatar
dist    
Mark Otto committed
616
    };
Mark Otto's avatar
dist    
Mark Otto committed
617

XhmikosR's avatar
XhmikosR committed
618
    Dropdown.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
619
620
621
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
    _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
639
    return Dropdown;
XhmikosR's avatar
Dist    
XhmikosR committed
640
641
642
643
644
645
646
647
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */


XhmikosR's avatar
XhmikosR committed
648
649
650
651
  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
652
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
653
654
    event.preventDefault();
    event.stopPropagation();
XhmikosR's avatar
XhmikosR committed
655
    Dropdown.dropdownInterface(this, 'toggle');
XhmikosR's avatar
XhmikosR committed
656
657
658
  });
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) {
    return e.stopPropagation();
XhmikosR's avatar
Dist    
XhmikosR committed
659
  });
XhmikosR's avatar
XhmikosR committed
660
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
661
662
663
664
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
665
   * add .dropdown to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
666
667
   */

668
669
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
670
671
672
673
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    $.fn[NAME] = Dropdown.jQueryInterface;
    $.fn[NAME].Constructor = Dropdown;
XhmikosR's avatar
Dist    
XhmikosR committed
674

XhmikosR's avatar
XhmikosR committed
675
676
677
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Dropdown.jQueryInterface;
XhmikosR's avatar
XhmikosR committed
678
679
    };
  }
fat's avatar
fat committed
680
681

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

XhmikosR's avatar
XhmikosR committed
683
})));
Mark Otto's avatar
dist    
Mark Otto committed
684
//# sourceMappingURL=dropdown.js.map