PageSourceSearch

https://rlec.pt/plugins/themes/default/js/lib/bootstrap/dropdown.js?v=3.5.0.5

js rlec.pt collected 2026-09-26 01:39:49 UTC 13,932 bytes, 431 lines download raw bytes

1var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2
3var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
5function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7/**
8 * --------------------------------------------------------------------------
9 * Bootstrap (v4.0.0-beta): dropdown.js
10 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
11 * --------------------------------------------------------------------------
12 */
13
14var Dropdown = function ($) {
15
16  /**
17   * Check for Popper dependency
18   * Popper - https://popper.js.org
19   */
20  if (typeof Popper === 'undefined') {
21    throw new Error('Bootstrap dropdown require Popper.js (https://popper.js.org)');
22  }
23
24  /**
25   * ------------------------------------------------------------------------
26   * Constants
27   * ------------------------------------------------------------------------
28   */
29
30  var NAME = 'dropdown';
31  var VERSION = '4.0.0-beta';
32  var DATA_KEY = 'bs.dropdown';
33  var EVENT_KEY = '.' + DATA_KEY;
34  var DATA_API_KEY = '.data-api';
35  var JQUERY_NO_CONFLICT = $.fn[NAME];
36  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
37  var SPACE_KEYCODE = 32; // KeyboardEvent.which value for space key
38  var TAB_KEYCODE = 9; // KeyboardEvent.which value for tab key
39  var ARROW_UP_KEYCODE = 38; // KeyboardEvent.which value for up arrow key
40  var ARROW_DOWN_KEYCODE = 40; // KeyboardEvent.which value for down arrow key
41  var RIGHT_MOUSE_BUTTON_WHICH = 3; // MouseEvent.which value for the right button (assuming a right-handed mouse)
42  var REGEXP_KEYDOWN = new RegExp(ARROW_UP_KEYCODE + '|' + ARROW_DOWN_KEYCODE + '|' + ESCAPE_KEYCODE);
43
44  var Event = {
45    HIDE: 'hide' + EVENT_KEY,
46    HIDDEN: 'hidden' + EVENT_KEY,
47    SHOW: 'show' + EVENT_KEY,
48    SHOWN: 'shown' + EVENT_KEY,
49    CLICK: 'click' + EVENT_KEY,
50    CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY,
51    KEYDOWN_DATA_API: 'keydown' + EVENT_KEY + DATA_API_KEY,
52    KEYUP_DATA_API: 'keyup' + EVENT_KEY + DATA_API_KEY
53  };
54
55  var ClassName = {
56    DISABLED: 'disabled',
57    SHOW: 'show',
58    DROPUP: 'dropup',
59    MENURIGHT: 'dropdown-menu-right',
60    MENULEFT: 'dropdown-menu-left'
61  };
62
63  var Selector = {
64    DATA_TOGGLE: '[data-toggle="dropdown"]',
65    FORM_CHILD: '.dropdown form',
66    MENU: '.dropdown-menu',
67    NAVBAR_NAV: '.navbar-nav',
68    VISIBLE_ITEMS: '.dropdown-menu .dropdown-item:not(.disabled)'
69  };
70
71  var AttachmentMap = {
72    TOP: 'top-start',
73    TOPEND: 'top-end',
74    BOTTOM: 'bottom-start',
75    BOTTOMEND: 'bottom-end'
76  };
77
78  var Default = {
79    placement: AttachmentMap.BOTTOM,
80    offset: 0,
81    flip: true
82  };
83
84  var DefaultType = {
85    placement: 'string',
86    offset: '(number|string)',
87    flip: 'boolean'
88
89    /**
90     * ------------------------------------------------------------------------
91     * Class Definition
92     * ------------------------------------------------------------------------
93     */
94
95  };
96  var Dropdown = function () {
97    function Dropdown(element, config) {
98      _classCallCheck(this, Dropdown);
99
100      this._element = element;
101      this._popper = null;
102      this._config = this._getConfig(config);
103      this._menu = this._getMenuElement();
104      this._inNavbar = this._detectNavbar();
105
106      this._addEventListeners();
107    }
108
109    // getters
110
111    // public
112
vendor: 9,807 bytes, lines 113-431
113    Dropdown.prototype.toggle = function toggle() {
114      if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED)) {
115        return;
116      }
117
118      var parent = Dropdown._getParentFromElement(this._element);
119      var isActive = $(this._menu).hasClass(ClassName.SHOW);
120
121      Dropdown._clearMenus();
122
123      if (isActive) {
124        return;
125      }
126
127      var relatedTarget = {
128        relatedTarget: this._element
129      };
130      var showEvent = $.Event(Event.SHOW, relatedTarget);
131
132      $(parent).trigger(showEvent);
133
134      if (showEvent.isDefaultPrevented()) {
135        return;
136      }
137
138      var element = this._element;
139      // for dropup with alignment we use the parent as popper container
140      if ($(parent).hasClass(ClassName.DROPUP)) {
141        if ($(this._menu).hasClass(ClassName.MENULEFT) || $(this._menu).hasClass(ClassName.MENURIGHT)) {
142          element = parent;
143        }
144      }
145      this._popper = new Popper(element, this._menu, this._getPopperConfig());
146
147      // if this is a touch-enabled device we add extra
148      // empty mouseover listeners to the body's immediate children;
149      // only needed because of broken event delegation on iOS
150      // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
151      if ('ontouchstart' in document.documentElement && !$(parent).closest(Selector.NAVBAR_NAV).length) {
152        $('body').children().on('mouseover', null, $.noop);
153      }
154
155      this._element.focus();
156      this._element.setAttribute('aria-expanded', true);
157
158      $(this._menu).toggleClass(ClassName.SHOW);
159      $(parent).toggleClass(ClassName.SHOW).trigger($.Event(Event.SHOWN, relatedTarget));
160    };
161
162    Dropdown.prototype.dispose = function dispose() {
163      $.removeData(this._element, DATA_KEY);
164      $(this._element).off(EVENT_KEY);
165      this._element = null;
166      this._menu = null;
167      if (this._popper !== null) {
168        this._popper.destroy();
169      }
170      this._popper = null;
171    };
172
173    Dropdown.prototype.update = function update() {
174      this._inNavbar = this._detectNavbar();
175      if (this._popper !== null) {
176        this._popper.scheduleUpdate();
177      }
178    };
179
180    // private
181
182    Dropdown.prototype._addEventListeners = function _addEventListeners() {
183      var _this = this;
184
185      $(this._element).on(Event.CLICK, function (event) {
186        event.preventDefault();
187        event.stopPropagation();
188        _this.toggle();
189      });
190    };
191
192    Dropdown.prototype._getConfig = function _getConfig(config) {
193      var elementData = $(this._element).data();
194      if (elementData.placement !== undefined) {
195        elementData.placement = AttachmentMap[elementData.placement.toUpperCase()];
196      }
197
198      config = $.extend({}, this.constructor.Default, $(this._element).data(), config);
199
200      Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
201
202      return config;
203    };
204
205    Dropdown.prototype._getMenuElement = function _getMenuElement() {
206      if (!this._menu) {
207        var parent = Dropdown._getParentFromElement(this._element);
208        this._menu = $(parent).find(Selector.MENU)[0];
209      }
210      return this._menu;
211    };
212
213    Dropdown.prototype._getPlacement = function _getPlacement() {
214      var $parentDropdown = $(this._element).parent();
215      var placement = this._config.placement;
216
217      // Handle dropup
218      if ($parentDropdown.hasClass(ClassName.DROPUP) || this._config.placement === AttachmentMap.TOP) {
219        placement = AttachmentMap.TOP;
220        if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
221          placement = AttachmentMap.TOPEND;
222        }
223      } else if ($(this._menu).hasClass(ClassName.MENURIGHT)) {
224        placement = AttachmentMap.BOTTOMEND;
225      }
226      return placement;
227    };
228
229    Dropdown.prototype._detectNavbar = function _detectNavbar() {
230      return $(this._element).closest('.navbar').length > 0;
231    };
232
233    Dropdown.prototype._getPopperConfig = function _getPopperConfig() {
234      var popperConfig = {
235        placement: this._getPlacement(),
236        modifiers: {
237          offset: {
238            offset: this._config.offset
239          },
240          flip: {
241            enabled: this._config.flip
242          }
243        }
244
245        // Disable Popper.js for Dropdown in Navbar
246      };if (this._inNavbar) {
247        popperConfig.modifiers.applyStyle = {
248          enabled: !this._inNavbar
249        };
250      }
251      return popperConfig;
252    };
253
254    // static
255
256    Dropdown._jQueryInterface = function _jQueryInterface(config) {
257      return this.each(function () {
258        var data = $(this).data(DATA_KEY);
259        var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' ? config : null;
260
261        if (!data) {
262          data = new Dropdown(this, _config);
263          $(this).data(DATA_KEY, data);
264        }
265
266        if (typeof config === 'string') {
267          if (data[config] === undefined) {
268            throw new Error('No method named "' + config + '"');
269          }
270          data[config]();
271        }
272      });
273    };
274
275    Dropdown._clearMenus = function _clearMenus(event) {
276      if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) {
277        return;
278      }
279
280      var toggles = $.makeArray($(Selector.DATA_TOGGLE));
281      for (var i = 0; i < toggles.length; i++) {
282        var parent = Dropdown._getParentFromElement(toggles[i]);
283        var context = $(toggles[i]).data(DATA_KEY);
284        var relatedTarget = {
285          relatedTarget: toggles[i]
286        };
287
288        if (!context) {
289          continue;
290        }
291
292        var dropdownMenu = context._menu;
293        if (!$(parent).hasClass(ClassName.SHOW)) {
294          continue;
295        }
296
297        if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && $.contains(parent, event.target)) {
298          continue;
299        }
300
301        var hideEvent = $.Event(Event.HIDE, relatedTarget);
302        $(parent).trigger(hideEvent);
303        if (hideEvent.isDefaultPrevented()) {
304          continue;
305        }
306
307        // if this is a touch-enabled device we remove the extra
308        // empty mouseover listeners we added for iOS support
309        if ('ontouchstart' in document.documentElement) {
310          $('body').children().off('mouseover', null, $.noop);
311        }
312
313        toggles[i].setAttribute('aria-expanded', 'false');
314
315        $(dropdownMenu).removeClass(ClassName.SHOW);
316        $(parent).removeClass(ClassName.SHOW).trigger($.Event(Event.HIDDEN, relatedTarget));
317      }
318    };
319
320    Dropdown._getParentFromElement = function _getParentFromElement(element) {
321      var parent = void 0;
322      var selector = Util.getSelectorFromElement(element);
323
324      if (selector) {
325        parent = $(selector)[0];
326      }
327
328      return parent || element.parentNode;
329    };
330
331    Dropdown._dataApiKeydownHandler = function _dataApiKeydownHandler(event) {
332      if (!REGEXP_KEYDOWN.test(event.which) || /button/i.test(event.target.tagName) && event.which === SPACE_KEYCODE || /input|textarea/i.test(event.target.tagName)) {
333        return;
334      }
335
336      event.preventDefault();
337      event.stopPropagation();
338
339      if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
340        return;
341      }
342
343      var parent = Dropdown._getParentFromElement(this);
344      var isActive = $(parent).hasClass(ClassName.SHOW);
345
346      if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) {
347
348        if (event.which === ESCAPE_KEYCODE) {
349          var toggle = $(parent).find(Selector.DATA_TOGGLE)[0];
350          $(toggle).trigger('focus');
351        }
352
353        $(this).trigger('click');
354        return;
355      }
356
357      var items = $(parent).find(Selector.VISIBLE_ITEMS).get();
358
359      if (!items.length) {
360        return;
361      }
362
363      var index = items.indexOf(event.target);
364
365      if (event.which === ARROW_UP_KEYCODE && index > 0) {
366        // up
367        index--;
368      }
369
370      if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) {
371        // down
372        index++;
373      }
374
375      if (index < 0) {
376        index = 0;
377      }
378
379      items[index].focus();
380    };
381
382    _createClass(Dropdown, null, [{
383      key: 'VERSION',
384      get: function get() {
385        return VERSION;
386      }
387    }, {
388      key: 'Default',
389      get: function get() {
390        return Default;
391      }
392    }, {
393      key: 'DefaultType',
394      get: function get() {
395        return DefaultType;
396      }
397    }]);
398
399    return Dropdown;
400  }();
401
402  /**
403   * ------------------------------------------------------------------------
404   * Data Api implementation
405   * ------------------------------------------------------------------------
406   */
407
408  $(document).on(Event.KEYDOWN_DATA_API, Selector.DATA_TOGGLE, Dropdown._dataApiKeydownHandler).on(Event.KEYDOWN_DATA_API, Selector.MENU, Dropdown._dataApiKeydownHandler).on(Event.CLICK_DATA_API + ' ' + Event.KEYUP_DATA_API, Dropdown._clearMenus).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
409    event.preventDefault();
410    event.stopPropagation();
411    Dropdown._jQueryInterface.call($(this), 'toggle');
412  }).on(Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) {
413    e.stopPropagation();
414  });
415
416  /**
417   * ------------------------------------------------------------------------
418   * jQuery
419   * ------------------------------------------------------------------------
420   */
421
422  $.fn[NAME] = Dropdown._jQueryInterface;
423  $.fn[NAME].Constructor = Dropdown;
424  $.fn[NAME].noConflict = function () {
425    $.fn[NAME] = JQUERY_NO_CONFLICT;
426    return Dropdown._jQueryInterface;
427  };
428
429  return Dropdown;
430}(jQuery); /* global Popper */
431//# sourceMappingURL=dropdown.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.