dropdown.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*!
  2. * Bootstrap dropdown.js v5.0.2 (https://getbootstrap.com/)
  3. * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./dom/selector-engine.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./base-component.js')) :
  8. typeof define === 'function' && define.amd ? define(['@popperjs/core', './dom/selector-engine', './dom/event-handler', './dom/manipulator', './base-component'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Dropdown = factory(global.Popper, global.SelectorEngine, global.EventHandler, global.Manipulator, global.Base));
  10. }(this, (function (Popper, SelectorEngine, EventHandler, Manipulator, BaseComponent) { 'use strict';
  11. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  12. function _interopNamespace(e) {
  13. if (e && e.__esModule) return e;
  14. var n = Object.create(null);
  15. if (e) {
  16. Object.keys(e).forEach(function (k) {
  17. if (k !== 'default') {
  18. var d = Object.getOwnPropertyDescriptor(e, k);
  19. Object.defineProperty(n, k, d.get ? d : {
  20. enumerable: true,
  21. get: function () {
  22. return e[k];
  23. }
  24. });
  25. }
  26. });
  27. }
  28. n['default'] = e;
  29. return Object.freeze(n);
  30. }
  31. var Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);
  32. var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
  33. var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
  34. var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
  35. var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
  36. const toType = obj => {
  37. if (obj === null || obj === undefined) {
  38. return `${obj}`;
  39. }
  40. return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  41. };
  42. const getSelector = element => {
  43. let selector = element.getAttribute('data-bs-target');
  44. if (!selector || selector === '#') {
  45. let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
  46. // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
  47. // `document.querySelector` will rightfully complain it is invalid.
  48. // See https://github.com/twbs/bootstrap/issues/32273
  49. if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
  50. return null;
  51. } // Just in case some CMS puts out a full URL with the anchor appended
  52. if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
  53. hrefAttr = `#${hrefAttr.split('#')[1]}`;
  54. }
  55. selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
  56. }
  57. return selector;
  58. };
  59. const getElementFromSelector = element => {
  60. const selector = getSelector(element);
  61. return selector ? document.querySelector(selector) : null;
  62. };
  63. const isElement = obj => {
  64. if (!obj || typeof obj !== 'object') {
  65. return false;
  66. }
  67. if (typeof obj.jquery !== 'undefined') {
  68. obj = obj[0];
  69. }
  70. return typeof obj.nodeType !== 'undefined';
  71. };
  72. const getElement = obj => {
  73. if (isElement(obj)) {
  74. // it's a jQuery object or a node element
  75. return obj.jquery ? obj[0] : obj;
  76. }
  77. if (typeof obj === 'string' && obj.length > 0) {
  78. return SelectorEngine__default['default'].findOne(obj);
  79. }
  80. return null;
  81. };
  82. const typeCheckConfig = (componentName, config, configTypes) => {
  83. Object.keys(configTypes).forEach(property => {
  84. const expectedTypes = configTypes[property];
  85. const value = config[property];
  86. const valueType = value && isElement(value) ? 'element' : toType(value);
  87. if (!new RegExp(expectedTypes).test(valueType)) {
  88. throw new TypeError(`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
  89. }
  90. });
  91. };
  92. const isVisible = element => {
  93. if (!isElement(element) || element.getClientRects().length === 0) {
  94. return false;
  95. }
  96. return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
  97. };
  98. const isDisabled = element => {
  99. if (!element || element.nodeType !== Node.ELEMENT_NODE) {
  100. return true;
  101. }
  102. if (element.classList.contains('disabled')) {
  103. return true;
  104. }
  105. if (typeof element.disabled !== 'undefined') {
  106. return element.disabled;
  107. }
  108. return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
  109. };
  110. const noop = () => {};
  111. const getjQuery = () => {
  112. const {
  113. jQuery
  114. } = window;
  115. if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
  116. return jQuery;
  117. }
  118. return null;
  119. };
  120. const DOMContentLoadedCallbacks = [];
  121. const onDOMContentLoaded = callback => {
  122. if (document.readyState === 'loading') {
  123. // add listener on the first call when the document is in loading state
  124. if (!DOMContentLoadedCallbacks.length) {
  125. document.addEventListener('DOMContentLoaded', () => {
  126. DOMContentLoadedCallbacks.forEach(callback => callback());
  127. });
  128. }
  129. DOMContentLoadedCallbacks.push(callback);
  130. } else {
  131. callback();
  132. }
  133. };
  134. const isRTL = () => document.documentElement.dir === 'rtl';
  135. const defineJQueryPlugin = plugin => {
  136. onDOMContentLoaded(() => {
  137. const $ = getjQuery();
  138. /* istanbul ignore if */
  139. if ($) {
  140. const name = plugin.NAME;
  141. const JQUERY_NO_CONFLICT = $.fn[name];
  142. $.fn[name] = plugin.jQueryInterface;
  143. $.fn[name].Constructor = plugin;
  144. $.fn[name].noConflict = () => {
  145. $.fn[name] = JQUERY_NO_CONFLICT;
  146. return plugin.jQueryInterface;
  147. };
  148. }
  149. });
  150. };
  151. /**
  152. * Return the previous/next element of a list.
  153. *
  154. * @param {array} list The list of elements
  155. * @param activeElement The active element
  156. * @param shouldGetNext Choose to get next or previous element
  157. * @param isCycleAllowed
  158. * @return {Element|elem} The proper element
  159. */
  160. const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
  161. let index = list.indexOf(activeElement); // if the element does not exist in the list return an element depending on the direction and if cycle is allowed
  162. if (index === -1) {
  163. return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0];
  164. }
  165. const listLength = list.length;
  166. index += shouldGetNext ? 1 : -1;
  167. if (isCycleAllowed) {
  168. index = (index + listLength) % listLength;
  169. }
  170. return list[Math.max(0, Math.min(index, listLength - 1))];
  171. };
  172. /**
  173. * --------------------------------------------------------------------------
  174. * Bootstrap (v5.0.2): dropdown.js
  175. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  176. * --------------------------------------------------------------------------
  177. */
  178. /**
  179. * ------------------------------------------------------------------------
  180. * Constants
  181. * ------------------------------------------------------------------------
  182. */
  183. const NAME = 'dropdown';
  184. const DATA_KEY = 'bs.dropdown';
  185. const EVENT_KEY = `.${DATA_KEY}`;
  186. const DATA_API_KEY = '.data-api';
  187. const ESCAPE_KEY = 'Escape';
  188. const SPACE_KEY = 'Space';
  189. const TAB_KEY = 'Tab';
  190. const ARROW_UP_KEY = 'ArrowUp';
  191. const ARROW_DOWN_KEY = 'ArrowDown';
  192. const RIGHT_MOUSE_BUTTON = 2; // MouseEvent.button value for the secondary button, usually the right button
  193. const REGEXP_KEYDOWN = new RegExp(`${ARROW_UP_KEY}|${ARROW_DOWN_KEY}|${ESCAPE_KEY}`);
  194. const EVENT_HIDE = `hide${EVENT_KEY}`;
  195. const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
  196. const EVENT_SHOW = `show${EVENT_KEY}`;
  197. const EVENT_SHOWN = `shown${EVENT_KEY}`;
  198. const EVENT_CLICK = `click${EVENT_KEY}`;
  199. const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
  200. const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY}${DATA_API_KEY}`;
  201. const EVENT_KEYUP_DATA_API = `keyup${EVENT_KEY}${DATA_API_KEY}`;
  202. const CLASS_NAME_SHOW = 'show';
  203. const CLASS_NAME_DROPUP = 'dropup';
  204. const CLASS_NAME_DROPEND = 'dropend';
  205. const CLASS_NAME_DROPSTART = 'dropstart';
  206. const CLASS_NAME_NAVBAR = 'navbar';
  207. const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="dropdown"]';
  208. const SELECTOR_MENU = '.dropdown-menu';
  209. const SELECTOR_NAVBAR_NAV = '.navbar-nav';
  210. const SELECTOR_VISIBLE_ITEMS = '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)';
  211. const PLACEMENT_TOP = isRTL() ? 'top-end' : 'top-start';
  212. const PLACEMENT_TOPEND = isRTL() ? 'top-start' : 'top-end';
  213. const PLACEMENT_BOTTOM = isRTL() ? 'bottom-end' : 'bottom-start';
  214. const PLACEMENT_BOTTOMEND = isRTL() ? 'bottom-start' : 'bottom-end';
  215. const PLACEMENT_RIGHT = isRTL() ? 'left-start' : 'right-start';
  216. const PLACEMENT_LEFT = isRTL() ? 'right-start' : 'left-start';
  217. const Default = {
  218. offset: [0, 2],
  219. boundary: 'clippingParents',
  220. reference: 'toggle',
  221. display: 'dynamic',
  222. popperConfig: null,
  223. autoClose: true
  224. };
  225. const DefaultType = {
  226. offset: '(array|string|function)',
  227. boundary: '(string|element)',
  228. reference: '(string|element|object)',
  229. display: 'string',
  230. popperConfig: '(null|object|function)',
  231. autoClose: '(boolean|string)'
  232. };
  233. /**
  234. * ------------------------------------------------------------------------
  235. * Class Definition
  236. * ------------------------------------------------------------------------
  237. */
  238. class Dropdown extends BaseComponent__default['default'] {
  239. constructor(element, config) {
  240. super(element);
  241. this._popper = null;
  242. this._config = this._getConfig(config);
  243. this._menu = this._getMenuElement();
  244. this._inNavbar = this._detectNavbar();
  245. this._addEventListeners();
  246. } // Getters
  247. static get Default() {
  248. return Default;
  249. }
  250. static get DefaultType() {
  251. return DefaultType;
  252. }
  253. static get NAME() {
  254. return NAME;
  255. } // Public
  256. toggle() {
  257. if (isDisabled(this._element)) {
  258. return;
  259. }
  260. const isActive = this._element.classList.contains(CLASS_NAME_SHOW);
  261. if (isActive) {
  262. this.hide();
  263. return;
  264. }
  265. this.show();
  266. }
  267. show() {
  268. if (isDisabled(this._element) || this._menu.classList.contains(CLASS_NAME_SHOW)) {
  269. return;
  270. }
  271. const parent = Dropdown.getParentFromElement(this._element);
  272. const relatedTarget = {
  273. relatedTarget: this._element
  274. };
  275. const showEvent = EventHandler__default['default'].trigger(this._element, EVENT_SHOW, relatedTarget);
  276. if (showEvent.defaultPrevented) {
  277. return;
  278. } // Totally disable Popper for Dropdowns in Navbar
  279. if (this._inNavbar) {
  280. Manipulator__default['default'].setDataAttribute(this._menu, 'popper', 'none');
  281. } else {
  282. if (typeof Popper__namespace === 'undefined') {
  283. throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)');
  284. }
  285. let referenceElement = this._element;
  286. if (this._config.reference === 'parent') {
  287. referenceElement = parent;
  288. } else if (isElement(this._config.reference)) {
  289. referenceElement = getElement(this._config.reference);
  290. } else if (typeof this._config.reference === 'object') {
  291. referenceElement = this._config.reference;
  292. }
  293. const popperConfig = this._getPopperConfig();
  294. const isDisplayStatic = popperConfig.modifiers.find(modifier => modifier.name === 'applyStyles' && modifier.enabled === false);
  295. this._popper = Popper__namespace.createPopper(referenceElement, this._menu, popperConfig);
  296. if (isDisplayStatic) {
  297. Manipulator__default['default'].setDataAttribute(this._menu, 'popper', 'static');
  298. }
  299. } // If this is a touch-enabled device we add extra
  300. // empty mouseover listeners to the body's immediate children;
  301. // only needed because of broken event delegation on iOS
  302. // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
  303. if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) {
  304. [].concat(...document.body.children).forEach(elem => EventHandler__default['default'].on(elem, 'mouseover', noop));
  305. }
  306. this._element.focus();
  307. this._element.setAttribute('aria-expanded', true);
  308. this._menu.classList.toggle(CLASS_NAME_SHOW);
  309. this._element.classList.toggle(CLASS_NAME_SHOW);
  310. EventHandler__default['default'].trigger(this._element, EVENT_SHOWN, relatedTarget);
  311. }
  312. hide() {
  313. if (isDisabled(this._element) || !this._menu.classList.contains(CLASS_NAME_SHOW)) {
  314. return;
  315. }
  316. const relatedTarget = {
  317. relatedTarget: this._element
  318. };
  319. this._completeHide(relatedTarget);
  320. }
  321. dispose() {
  322. if (this._popper) {
  323. this._popper.destroy();
  324. }
  325. super.dispose();
  326. }
  327. update() {
  328. this._inNavbar = this._detectNavbar();
  329. if (this._popper) {
  330. this._popper.update();
  331. }
  332. } // Private
  333. _addEventListeners() {
  334. EventHandler__default['default'].on(this._element, EVENT_CLICK, event => {
  335. event.preventDefault();
  336. this.toggle();
  337. });
  338. }
  339. _completeHide(relatedTarget) {
  340. const hideEvent = EventHandler__default['default'].trigger(this._element, EVENT_HIDE, relatedTarget);
  341. if (hideEvent.defaultPrevented) {
  342. return;
  343. } // If this is a touch-enabled device we remove the extra
  344. // empty mouseover listeners we added for iOS support
  345. if ('ontouchstart' in document.documentElement) {
  346. [].concat(...document.body.children).forEach(elem => EventHandler__default['default'].off(elem, 'mouseover', noop));
  347. }
  348. if (this._popper) {
  349. this._popper.destroy();
  350. }
  351. this._menu.classList.remove(CLASS_NAME_SHOW);
  352. this._element.classList.remove(CLASS_NAME_SHOW);
  353. this._element.setAttribute('aria-expanded', 'false');
  354. Manipulator__default['default'].removeDataAttribute(this._menu, 'popper');
  355. EventHandler__default['default'].trigger(this._element, EVENT_HIDDEN, relatedTarget);
  356. }
  357. _getConfig(config) {
  358. config = { ...this.constructor.Default,
  359. ...Manipulator__default['default'].getDataAttributes(this._element),
  360. ...config
  361. };
  362. typeCheckConfig(NAME, config, this.constructor.DefaultType);
  363. if (typeof config.reference === 'object' && !isElement(config.reference) && typeof config.reference.getBoundingClientRect !== 'function') {
  364. // Popper virtual elements require a getBoundingClientRect method
  365. throw new TypeError(`${NAME.toUpperCase()}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`);
  366. }
  367. return config;
  368. }
  369. _getMenuElement() {
  370. return SelectorEngine__default['default'].next(this._element, SELECTOR_MENU)[0];
  371. }
  372. _getPlacement() {
  373. const parentDropdown = this._element.parentNode;
  374. if (parentDropdown.classList.contains(CLASS_NAME_DROPEND)) {
  375. return PLACEMENT_RIGHT;
  376. }
  377. if (parentDropdown.classList.contains(CLASS_NAME_DROPSTART)) {
  378. return PLACEMENT_LEFT;
  379. } // We need to trim the value because custom properties can also include spaces
  380. const isEnd = getComputedStyle(this._menu).getPropertyValue('--bs-position').trim() === 'end';
  381. if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) {
  382. return isEnd ? PLACEMENT_TOPEND : PLACEMENT_TOP;
  383. }
  384. return isEnd ? PLACEMENT_BOTTOMEND : PLACEMENT_BOTTOM;
  385. }
  386. _detectNavbar() {
  387. return this._element.closest(`.${CLASS_NAME_NAVBAR}`) !== null;
  388. }
  389. _getOffset() {
  390. const {
  391. offset
  392. } = this._config;
  393. if (typeof offset === 'string') {
  394. return offset.split(',').map(val => Number.parseInt(val, 10));
  395. }
  396. if (typeof offset === 'function') {
  397. return popperData => offset(popperData, this._element);
  398. }
  399. return offset;
  400. }
  401. _getPopperConfig() {
  402. const defaultBsPopperConfig = {
  403. placement: this._getPlacement(),
  404. modifiers: [{
  405. name: 'preventOverflow',
  406. options: {
  407. boundary: this._config.boundary
  408. }
  409. }, {
  410. name: 'offset',
  411. options: {
  412. offset: this._getOffset()
  413. }
  414. }]
  415. }; // Disable Popper if we have a static display
  416. if (this._config.display === 'static') {
  417. defaultBsPopperConfig.modifiers = [{
  418. name: 'applyStyles',
  419. enabled: false
  420. }];
  421. }
  422. return { ...defaultBsPopperConfig,
  423. ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
  424. };
  425. }
  426. _selectMenuItem({
  427. key,
  428. target
  429. }) {
  430. const items = SelectorEngine__default['default'].find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(isVisible);
  431. if (!items.length) {
  432. return;
  433. } // if target isn't included in items (e.g. when expanding the dropdown)
  434. // allow cycling to get the last item in case key equals ARROW_UP_KEY
  435. getNextActiveElement(items, target, key === ARROW_DOWN_KEY, !items.includes(target)).focus();
  436. } // Static
  437. static dropdownInterface(element, config) {
  438. const data = Dropdown.getOrCreateInstance(element, config);
  439. if (typeof config === 'string') {
  440. if (typeof data[config] === 'undefined') {
  441. throw new TypeError(`No method named "${config}"`);
  442. }
  443. data[config]();
  444. }
  445. }
  446. static jQueryInterface(config) {
  447. return this.each(function () {
  448. Dropdown.dropdownInterface(this, config);
  449. });
  450. }
  451. static clearMenus(event) {
  452. if (event && (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY)) {
  453. return;
  454. }
  455. const toggles = SelectorEngine__default['default'].find(SELECTOR_DATA_TOGGLE);
  456. for (let i = 0, len = toggles.length; i < len; i++) {
  457. const context = Dropdown.getInstance(toggles[i]);
  458. if (!context || context._config.autoClose === false) {
  459. continue;
  460. }
  461. if (!context._element.classList.contains(CLASS_NAME_SHOW)) {
  462. continue;
  463. }
  464. const relatedTarget = {
  465. relatedTarget: context._element
  466. };
  467. if (event) {
  468. const composedPath = event.composedPath();
  469. const isMenuTarget = composedPath.includes(context._menu);
  470. if (composedPath.includes(context._element) || context._config.autoClose === 'inside' && !isMenuTarget || context._config.autoClose === 'outside' && isMenuTarget) {
  471. continue;
  472. } // Tab navigation through the dropdown menu or events from contained inputs shouldn't close the menu
  473. if (context._menu.contains(event.target) && (event.type === 'keyup' && event.key === TAB_KEY || /input|select|option|textarea|form/i.test(event.target.tagName))) {
  474. continue;
  475. }
  476. if (event.type === 'click') {
  477. relatedTarget.clickEvent = event;
  478. }
  479. }
  480. context._completeHide(relatedTarget);
  481. }
  482. }
  483. static getParentFromElement(element) {
  484. return getElementFromSelector(element) || element.parentNode;
  485. }
  486. static dataApiKeydownHandler(event) {
  487. // If not input/textarea:
  488. // - And not a key in REGEXP_KEYDOWN => not a dropdown command
  489. // If input/textarea:
  490. // - If space key => not a dropdown command
  491. // - If key is other than escape
  492. // - If key is not up or down => not a dropdown command
  493. // - If trigger inside the menu => not a dropdown command
  494. if (/input|textarea/i.test(event.target.tagName) ? event.key === SPACE_KEY || event.key !== ESCAPE_KEY && (event.key !== ARROW_DOWN_KEY && event.key !== ARROW_UP_KEY || event.target.closest(SELECTOR_MENU)) : !REGEXP_KEYDOWN.test(event.key)) {
  495. return;
  496. }
  497. const isActive = this.classList.contains(CLASS_NAME_SHOW);
  498. if (!isActive && event.key === ESCAPE_KEY) {
  499. return;
  500. }
  501. event.preventDefault();
  502. event.stopPropagation();
  503. if (isDisabled(this)) {
  504. return;
  505. }
  506. const getToggleButton = () => this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine__default['default'].prev(this, SELECTOR_DATA_TOGGLE)[0];
  507. if (event.key === ESCAPE_KEY) {
  508. getToggleButton().focus();
  509. Dropdown.clearMenus();
  510. return;
  511. }
  512. if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) {
  513. if (!isActive) {
  514. getToggleButton().click();
  515. }
  516. Dropdown.getInstance(getToggleButton())._selectMenuItem(event);
  517. return;
  518. }
  519. if (!isActive || event.key === SPACE_KEY) {
  520. Dropdown.clearMenus();
  521. }
  522. }
  523. }
  524. /**
  525. * ------------------------------------------------------------------------
  526. * Data Api implementation
  527. * ------------------------------------------------------------------------
  528. */
  529. EventHandler__default['default'].on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler);
  530. EventHandler__default['default'].on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
  531. EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, Dropdown.clearMenus);
  532. EventHandler__default['default'].on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus);
  533. EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
  534. event.preventDefault();
  535. Dropdown.dropdownInterface(this);
  536. });
  537. /**
  538. * ------------------------------------------------------------------------
  539. * jQuery
  540. * ------------------------------------------------------------------------
  541. * add .Dropdown to jQuery only if jQuery is present
  542. */
  543. defineJQueryPlugin(Dropdown);
  544. return Dropdown;
  545. })));
  546. //# sourceMappingURL=dropdown.js.map