OSDN Git Service

Merge pull request #41 from Bytom/dev
[bytom/vapor.git] / tools / side_chain_tool / web / node_modules / bootstrap / js / dist / dropdown.js
1 (function (global, factory) {
2   typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('popper.js'), require('./util.js')) :
3   typeof define === 'function' && define.amd ? define(['jquery', 'popper.js', './util.js'], factory) :
4   (global.Dropdown = factory(global.jQuery,global.Popper,global.Util));
5 }(this, (function ($,Popper,Util) { 'use strict';
6
7   $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
8   Popper = Popper && Popper.hasOwnProperty('default') ? Popper['default'] : Popper;
9   Util = Util && Util.hasOwnProperty('default') ? Util['default'] : Util;
10
11   function _defineProperties(target, props) {
12     for (var i = 0; i < props.length; i++) {
13       var descriptor = props[i];
14       descriptor.enumerable = descriptor.enumerable || false;
15       descriptor.configurable = true;
16       if ("value" in descriptor) descriptor.writable = true;
17       Object.defineProperty(target, descriptor.key, descriptor);
18     }
19   }
20
21   function _createClass(Constructor, protoProps, staticProps) {
22     if (protoProps) _defineProperties(Constructor.prototype, protoProps);
23     if (staticProps) _defineProperties(Constructor, staticProps);
24     return Constructor;
25   }
26
27   function _defineProperty(obj, key, value) {
28     if (key in obj) {
29       Object.defineProperty(obj, key, {
30         value: value,
31         enumerable: true,
32         configurable: true,
33         writable: true
34       });
35     } else {
36       obj[key] = value;
37     }
38
39     return obj;
40   }
41
42   function _objectSpread(target) {
43     for (var i = 1; i < arguments.length; i++) {
44       var source = arguments[i] != null ? arguments[i] : {};
45       var ownKeys = Object.keys(source);
46
47       if (typeof Object.getOwnPropertySymbols === 'function') {
48         ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
49           return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50         }));
51       }
52
53       ownKeys.forEach(function (key) {
54         _defineProperty(target, key, source[key]);
55       });
56     }
57
58     return target;
59   }
60
61   /**
62    * --------------------------------------------------------------------------
63    * Bootstrap (v4.1.3): dropdown.js
64    * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
65    * --------------------------------------------------------------------------
66    */
67
68   var Dropdown = function ($$$1) {
69     /**
70      * ------------------------------------------------------------------------
71      * Constants
72      * ------------------------------------------------------------------------
73      */
74     var NAME = 'dropdown';
75     var VERSION = '4.1.3';
76     var DATA_KEY = 'bs.dropdown';
77     var EVENT_KEY = "." + DATA_KEY;
78     var DATA_API_KEY = '.data-api';
79     var JQUERY_NO_CONFLICT = $$$1.fn[NAME];
80     var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
81
82     var SPACE_KEYCODE = 32; // KeyboardEvent.which value for space key
83
84     var TAB_KEYCODE = 9; // KeyboardEvent.which value for tab key
85
86     var ARROW_UP_KEYCODE = 38; // KeyboardEvent.which value for up arrow key
87
88     var ARROW_DOWN_KEYCODE = 40; // KeyboardEvent.which value for down arrow key
89
90     var RIGHT_MOUSE_BUTTON_WHICH = 3; // MouseEvent.which value for the right button (assuming a right-handed mouse)
91
92     var REGEXP_KEYDOWN = new RegExp(ARROW_UP_KEYCODE + "|" + ARROW_DOWN_KEYCODE + "|" + ESCAPE_KEYCODE);
93     var Event = {
94       HIDE: "hide" + EVENT_KEY,
95       HIDDEN: "hidden" + EVENT_KEY,
96       SHOW: "show" + EVENT_KEY,
97       SHOWN: "shown" + EVENT_KEY,
98       CLICK: "click" + EVENT_KEY,
99       CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY,
100       KEYDOWN_DATA_API: "keydown" + EVENT_KEY + DATA_API_KEY,
101       KEYUP_DATA_API: "keyup" + EVENT_KEY + DATA_API_KEY
102     };
103     var ClassName = {
104       DISABLED: 'disabled',
105       SHOW: 'show',
106       DROPUP: 'dropup',
107       DROPRIGHT: 'dropright',
108       DROPLEFT: 'dropleft',
109       MENURIGHT: 'dropdown-menu-right',
110       MENULEFT: 'dropdown-menu-left',
111       POSITION_STATIC: 'position-static'
112     };
113     var Selector = {
114       DATA_TOGGLE: '[data-toggle="dropdown"]',
115       FORM_CHILD: '.dropdown form',
116       MENU: '.dropdown-menu',
117       NAVBAR_NAV: '.navbar-nav',
118       VISIBLE_ITEMS: '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)'
119     };
120     var AttachmentMap = {
121       TOP: 'top-start',
122       TOPEND: 'top-end',
123       BOTTOM: 'bottom-start',
124       BOTTOMEND: 'bottom-end',
125       RIGHT: 'right-start',
126       RIGHTEND: 'right-end',
127       LEFT: 'left-start',
128       LEFTEND: 'left-end'
129     };
130     var Default = {
131       offset: 0,
132       flip: true,
133       boundary: 'scrollParent',
134       reference: 'toggle',
135       display: 'dynamic'
136     };
137     var DefaultType = {
138       offset: '(number|string|function)',
139       flip: 'boolean',
140       boundary: '(string|element)',
141       reference: '(string|element)',
142       display: 'string'
143       /**
144        * ------------------------------------------------------------------------
145        * Class Definition
146        * ------------------------------------------------------------------------
147        */
148
149     };
150
151     var Dropdown =
152     /*#__PURE__*/
153     function () {
154       function Dropdown(element, config) {
155         this._element = element;
156         this._popper = null;
157         this._config = this._getConfig(config);
158         this._menu = this._getMenuElement();
159         this._inNavbar = this._detectNavbar();
160
161         this._addEventListeners();
162       } // Getters
163
164
165       var _proto = Dropdown.prototype;
166
167       // Public
168       _proto.toggle = function toggle() {
169         if (this._element.disabled || $$$1(this._element).hasClass(ClassName.DISABLED)) {
170           return;
171         }
172
173         var parent = Dropdown._getParentFromElement(this._element);
174
175         var isActive = $$$1(this._menu).hasClass(ClassName.SHOW);
176
177         Dropdown._clearMenus();
178
179         if (isActive) {
180           return;
181         }
182
183         var relatedTarget = {
184           relatedTarget: this._element
185         };
186         var showEvent = $$$1.Event(Event.SHOW, relatedTarget);
187         $$$1(parent).trigger(showEvent);
188
189         if (showEvent.isDefaultPrevented()) {
190           return;
191         } // Disable totally Popper.js for Dropdown in Navbar
192
193
194         if (!this._inNavbar) {
195           /**
196            * Check for Popper dependency
197            * Popper - https://popper.js.org
198            */
199           if (typeof Popper === 'undefined') {
200             throw new TypeError('Bootstrap dropdown require Popper.js (https://popper.js.org)');
201           }
202
203           var referenceElement = this._element;
204
205           if (this._config.reference === 'parent') {
206             referenceElement = parent;
207           } else if (Util.isElement(this._config.reference)) {
208             referenceElement = this._config.reference; // Check if it's jQuery element
209
210             if (typeof this._config.reference.jquery !== 'undefined') {
211               referenceElement = this._config.reference[0];
212             }
213           } // If boundary is not `scrollParent`, then set position to `static`
214           // to allow the menu to "escape" the scroll parent's boundaries
215           // https://github.com/twbs/bootstrap/issues/24251
216
217
218           if (this._config.boundary !== 'scrollParent') {
219             $$$1(parent).addClass(ClassName.POSITION_STATIC);
220           }
221
222           this._popper = new Popper(referenceElement, this._menu, this._getPopperConfig());
223         } // If this is a touch-enabled device we add extra
224         // empty mouseover listeners to the body's immediate children;
225         // only needed because of broken event delegation on iOS
226         // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
227
228
229         if ('ontouchstart' in document.documentElement && $$$1(parent).closest(Selector.NAVBAR_NAV).length === 0) {
230           $$$1(document.body).children().on('mouseover', null, $$$1.noop);
231         }
232
233         this._element.focus();
234
235         this._element.setAttribute('aria-expanded', true);
236
237         $$$1(this._menu).toggleClass(ClassName.SHOW);
238         $$$1(parent).toggleClass(ClassName.SHOW).trigger($$$1.Event(Event.SHOWN, relatedTarget));
239       };
240
241       _proto.dispose = function dispose() {
242         $$$1.removeData(this._element, DATA_KEY);
243         $$$1(this._element).off(EVENT_KEY);
244         this._element = null;
245         this._menu = null;
246
247         if (this._popper !== null) {
248           this._popper.destroy();
249
250           this._popper = null;
251         }
252       };
253
254       _proto.update = function update() {
255         this._inNavbar = this._detectNavbar();
256
257         if (this._popper !== null) {
258           this._popper.scheduleUpdate();
259         }
260       }; // Private
261
262
263       _proto._addEventListeners = function _addEventListeners() {
264         var _this = this;
265
266         $$$1(this._element).on(Event.CLICK, function (event) {
267           event.preventDefault();
268           event.stopPropagation();
269
270           _this.toggle();
271         });
272       };
273
274       _proto._getConfig = function _getConfig(config) {
275         config = _objectSpread({}, this.constructor.Default, $$$1(this._element).data(), config);
276         Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
277         return config;
278       };
279
280       _proto._getMenuElement = function _getMenuElement() {
281         if (!this._menu) {
282           var parent = Dropdown._getParentFromElement(this._element);
283
284           if (parent) {
285             this._menu = parent.querySelector(Selector.MENU);
286           }
287         }
288
289         return this._menu;
290       };
291
292       _proto._getPlacement = function _getPlacement() {
293         var $parentDropdown = $$$1(this._element.parentNode);
294         var placement = AttachmentMap.BOTTOM; // Handle dropup
295
296         if ($parentDropdown.hasClass(ClassName.DROPUP)) {
297           placement = AttachmentMap.TOP;
298
299           if ($$$1(this._menu).hasClass(ClassName.MENURIGHT)) {
300             placement = AttachmentMap.TOPEND;
301           }
302         } else if ($parentDropdown.hasClass(ClassName.DROPRIGHT)) {
303           placement = AttachmentMap.RIGHT;
304         } else if ($parentDropdown.hasClass(ClassName.DROPLEFT)) {
305           placement = AttachmentMap.LEFT;
306         } else if ($$$1(this._menu).hasClass(ClassName.MENURIGHT)) {
307           placement = AttachmentMap.BOTTOMEND;
308         }
309
310         return placement;
311       };
312
313       _proto._detectNavbar = function _detectNavbar() {
314         return $$$1(this._element).closest('.navbar').length > 0;
315       };
316
317       _proto._getPopperConfig = function _getPopperConfig() {
318         var _this2 = this;
319
320         var offsetConf = {};
321
322         if (typeof this._config.offset === 'function') {
323           offsetConf.fn = function (data) {
324             data.offsets = _objectSpread({}, data.offsets, _this2._config.offset(data.offsets) || {});
325             return data;
326           };
327         } else {
328           offsetConf.offset = this._config.offset;
329         }
330
331         var popperConfig = {
332           placement: this._getPlacement(),
333           modifiers: {
334             offset: offsetConf,
335             flip: {
336               enabled: this._config.flip
337             },
338             preventOverflow: {
339               boundariesElement: this._config.boundary
340             }
341           } // Disable Popper.js if we have a static display
342
343         };
344
345         if (this._config.display === 'static') {
346           popperConfig.modifiers.applyStyle = {
347             enabled: false
348           };
349         }
350
351         return popperConfig;
352       }; // Static
353
354
355       Dropdown._jQueryInterface = function _jQueryInterface(config) {
356         return this.each(function () {
357           var data = $$$1(this).data(DATA_KEY);
358
359           var _config = typeof config === 'object' ? config : null;
360
361           if (!data) {
362             data = new Dropdown(this, _config);
363             $$$1(this).data(DATA_KEY, data);
364           }
365
366           if (typeof config === 'string') {
367             if (typeof data[config] === 'undefined') {
368               throw new TypeError("No method named \"" + config + "\"");
369             }
370
371             data[config]();
372           }
373         });
374       };
375
376       Dropdown._clearMenus = function _clearMenus(event) {
377         if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) {
378           return;
379         }
380
381         var toggles = [].slice.call(document.querySelectorAll(Selector.DATA_TOGGLE));
382
383         for (var i = 0, len = toggles.length; i < len; i++) {
384           var parent = Dropdown._getParentFromElement(toggles[i]);
385
386           var context = $$$1(toggles[i]).data(DATA_KEY);
387           var relatedTarget = {
388             relatedTarget: toggles[i]
389           };
390
391           if (event && event.type === 'click') {
392             relatedTarget.clickEvent = event;
393           }
394
395           if (!context) {
396             continue;
397           }
398
399           var dropdownMenu = context._menu;
400
401           if (!$$$1(parent).hasClass(ClassName.SHOW)) {
402             continue;
403           }
404
405           if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && $$$1.contains(parent, event.target)) {
406             continue;
407           }
408
409           var hideEvent = $$$1.Event(Event.HIDE, relatedTarget);
410           $$$1(parent).trigger(hideEvent);
411
412           if (hideEvent.isDefaultPrevented()) {
413             continue;
414           } // If this is a touch-enabled device we remove the extra
415           // empty mouseover listeners we added for iOS support
416
417
418           if ('ontouchstart' in document.documentElement) {
419             $$$1(document.body).children().off('mouseover', null, $$$1.noop);
420           }
421
422           toggles[i].setAttribute('aria-expanded', 'false');
423           $$$1(dropdownMenu).removeClass(ClassName.SHOW);
424           $$$1(parent).removeClass(ClassName.SHOW).trigger($$$1.Event(Event.HIDDEN, relatedTarget));
425         }
426       };
427
428       Dropdown._getParentFromElement = function _getParentFromElement(element) {
429         var parent;
430         var selector = Util.getSelectorFromElement(element);
431
432         if (selector) {
433           parent = document.querySelector(selector);
434         }
435
436         return parent || element.parentNode;
437       }; // eslint-disable-next-line complexity
438
439
440       Dropdown._dataApiKeydownHandler = function _dataApiKeydownHandler(event) {
441         // If not input/textarea:
442         //  - And not a key in REGEXP_KEYDOWN => not a dropdown command
443         // If input/textarea:
444         //  - If space key => not a dropdown command
445         //  - If key is other than escape
446         //    - If key is not up or down => not a dropdown command
447         //    - If trigger inside the menu => not a dropdown command
448         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 || $$$1(event.target).closest(Selector.MENU).length) : !REGEXP_KEYDOWN.test(event.which)) {
449           return;
450         }
451
452         event.preventDefault();
453         event.stopPropagation();
454
455         if (this.disabled || $$$1(this).hasClass(ClassName.DISABLED)) {
456           return;
457         }
458
459         var parent = Dropdown._getParentFromElement(this);
460
461         var isActive = $$$1(parent).hasClass(ClassName.SHOW);
462
463         if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) {
464           if (event.which === ESCAPE_KEYCODE) {
465             var toggle = parent.querySelector(Selector.DATA_TOGGLE);
466             $$$1(toggle).trigger('focus');
467           }
468
469           $$$1(this).trigger('click');
470           return;
471         }
472
473         var items = [].slice.call(parent.querySelectorAll(Selector.VISIBLE_ITEMS));
474
475         if (items.length === 0) {
476           return;
477         }
478
479         var index = items.indexOf(event.target);
480
481         if (event.which === ARROW_UP_KEYCODE && index > 0) {
482           // Up
483           index--;
484         }
485
486         if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) {
487           // Down
488           index++;
489         }
490
491         if (index < 0) {
492           index = 0;
493         }
494
495         items[index].focus();
496       };
497
498       _createClass(Dropdown, null, [{
499         key: "VERSION",
500         get: function get() {
501           return VERSION;
502         }
503       }, {
504         key: "Default",
505         get: function get() {
506           return Default;
507         }
508       }, {
509         key: "DefaultType",
510         get: function get() {
511           return DefaultType;
512         }
513       }]);
514
515       return Dropdown;
516     }();
517     /**
518      * ------------------------------------------------------------------------
519      * Data Api implementation
520      * ------------------------------------------------------------------------
521      */
522
523
524     $$$1(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) {
525       event.preventDefault();
526       event.stopPropagation();
527
528       Dropdown._jQueryInterface.call($$$1(this), 'toggle');
529     }).on(Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) {
530       e.stopPropagation();
531     });
532     /**
533      * ------------------------------------------------------------------------
534      * jQuery
535      * ------------------------------------------------------------------------
536      */
537
538     $$$1.fn[NAME] = Dropdown._jQueryInterface;
539     $$$1.fn[NAME].Constructor = Dropdown;
540
541     $$$1.fn[NAME].noConflict = function () {
542       $$$1.fn[NAME] = JQUERY_NO_CONFLICT;
543       return Dropdown._jQueryInterface;
544     };
545
546     return Dropdown;
547   }($, Popper);
548
549   return Dropdown;
550
551 })));
552 //# sourceMappingURL=dropdown.js.map