mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-12 00:08:59 +01:00
1 line
15 KiB
Plaintext
1 line
15 KiB
Plaintext
{"version":3,"sources":["../src/dropdown.js"],"names":["Dropdown","$","NAME","VERSION","DATA_KEY","EVENT_KEY","DATA_API_KEY","JQUERY_NO_CONFLICT","fn","ESCAPE_KEYCODE","ARROW_UP_KEYCODE","ARROW_DOWN_KEYCODE","RIGHT_MOUSE_BUTTON_WHICH","Event","HIDE","HIDDEN","SHOW","SHOWN","CLICK","CLICK_DATA_API","KEYDOWN_DATA_API","ClassName","BACKDROP","DISABLED","ACTIVE","Selector","DATA_TOGGLE","FORM_CHILD","ROLE_MENU","ROLE_LISTBOX","NAVBAR_NAV","VISIBLE_ITEMS","element","_element","_addEventListeners","toggle","disabled","hasClass","parent","_getParentFromElement","isActive","_clearMenus","document","documentElement","closest","length","dropdown","createElement","className","insertBefore","on","relatedTarget","showEvent","trigger","isDefaultPrevented","focus","setAttribute","toggleClass","dispose","removeData","off","_jQueryInterface","config","each","data","undefined","Error","call","event","which","backdrop","parentNode","removeChild","toggles","makeArray","i","type","test","target","tagName","contains","hideEvent","removeClass","selector","Util","getSelectorFromElement","_dataApiKeydownHandler","preventDefault","stopPropagation","find","items","get","index","indexOf","prototype","e","Constructor","noConflict","jQuery"],"mappings":";;;;AAGA;;;;;;;AAOA,IAAMA,WAAY,UAACC,CAAD,EAAO;;AAGvB;;;;;;AAMA,MAAMC,OAA2B,UAAjC;AACA,MAAMC,UAA2B,eAAjC;AACA,MAAMC,WAA2B,aAAjC;AACA,MAAMC,kBAA+BD,QAArC;AACA,MAAME,eAA2B,WAAjC;AACA,MAAMC,qBAA2BN,EAAEO,EAAF,CAAKN,IAAL,CAAjC;AACA,MAAMO,iBAA2B,EAAjC,CAfuB,CAea;AACpC,MAAMC,mBAA2B,EAAjC,CAhBuB,CAgBa;AACpC,MAAMC,qBAA2B,EAAjC,CAjBuB,CAiBa;AACpC,MAAMC,2BAA2B,CAAjC,CAl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C,MAAMM,cALZ,EAK4BM,SAASC,WALrC,EAKkD1B,SAAS8F,SAAT,CAAmB3D,MALrE,EAMGe,EANH,CAMMrC,MAAMM,cANZ,EAM4BM,SAASE,UANrC,EAMiD,UAACoE,CAAD,EAAO;AACpDA,MAAEP,eAAF;AACD,GARH;;AAWA;;;;;;AAMAvF,IAAEO,EAAF,CAAKN,IAAL,IAAyBF,SAAS6D,gBAAlC;AACA5D,IAAEO,EAAF,CAAKN,IAAL,EAAW8F,WAAX,GAAyBhG,QAAzB;AACAC,IAAEO,EAAF,CAAKN,IAAL,EAAW+F,UAAX,GAAyB,YAAY;AACnChG,MAAEO,EAAF,CAAKN,IAAL,IAAaK,kBAAb;AACA,WAAOP,SAAS6D,gBAAhB;AACD,GAHD;;AAKA,SAAO7D,QAAP;AAED,CAjSgB,CAiSdkG,MAjSc,CAAjB","file":"dropdown.js","sourcesContent":["import Util from './util'\n\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.0.0-alpha.5): dropdown.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst Dropdown = (($) => {\n\n\n /**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\n const NAME = 'dropdown'\n const VERSION = '4.0.0-alpha.5'\n const DATA_KEY = 'bs.dropdown'\n const EVENT_KEY = `.${DATA_KEY}`\n const DATA_API_KEY = '.data-api'\n const JQUERY_NO_CONFLICT = $.fn[NAME]\n const ESCAPE_KEYCODE = 27 // KeyboardEvent.which value for Escape (Esc) key\n const ARROW_UP_KEYCODE = 38 // KeyboardEvent.which value for up arrow key\n const ARROW_DOWN_KEYCODE = 40 // KeyboardEvent.which value for down arrow key\n const RIGHT_MOUSE_BUTTON_WHICH = 3 // MouseEvent.which value for the right button (assuming a right-handed mouse)\n\n const Event = {\n HIDE : `hide${EVENT_KEY}`,\n HIDDEN : `hidden${EVENT_KEY}`,\n SHOW : `show${EVENT_KEY}`,\n SHOWN : `shown${EVENT_KEY}`,\n CLICK : `click${EVENT_KEY}`,\n CLICK_DATA_API : `click${EVENT_KEY}${DATA_API_KEY}`,\n KEYDOWN_DATA_API : `keydown${EVENT_KEY}${DATA_API_KEY}`\n }\n\n const ClassName = {\n BACKDROP : 'dropdown-backdrop',\n DISABLED : 'disabled',\n ACTIVE : 'active'\n }\n\n const Selector = {\n BACKDROP : '.dropdown-backdrop',\n DATA_TOGGLE : '[data-toggle=\"dropdown\"]',\n FORM_CHILD : '.dropdown form',\n ROLE_MENU : '[role=\"menu\"]',\n ROLE_LISTBOX : '[role=\"listbox\"]',\n NAVBAR_NAV : '.navbar-nav',\n VISIBLE_ITEMS : '[role=\"menu\"] li:not(.disabled) a, '\n + '[role=\"listbox\"] li:not(.disabled) a'\n }\n\n\n /**\n * ------------------------------------------------------------------------\n * Class Definition\n * ------------------------------------------------------------------------\n */\n\n class Dropdown {\n\n constructor(element) {\n this._element = element\n\n this._addEventListeners()\n }\n\n\n // getters\n\n static get VERSION() {\n return VERSION\n }\n\n\n // public\n\n toggle() {\n if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {\n return false\n }\n\n const parent = Dropdown._getParentFromElement(this)\n const isActive = $(parent).hasClass(ClassName.ACTIVE)\n\n Dropdown._clearMenus()\n\n if (isActive) {\n return false\n }\n\n if ('ontouchstart' in document.documentElement &&\n !$(parent).closest(Selector.NAVBAR_NAV).length) {\n\n // if mobile we use a backdrop because click events don't delegate\n const dropdown = document.createElement('div')\n dropdown.className = ClassName.BACKDROP\n $(dropdown).insertBefore(this)\n $(dropdown).on('click', Dropdown._clearMenus)\n }\n\n const relatedTarget = {\n relatedTarget : this\n }\n const showEvent = $.Event(Event.SHOW, relatedTarget)\n\n $(parent).trigger(showEvent)\n\n if (showEvent.isDefaultPrevented()) {\n return false\n }\n\n this.focus()\n this.setAttribute('aria-expanded', true)\n\n $(parent).toggleClass(ClassName.ACTIVE)\n $(parent).trigger($.Event(Event.SHOWN, relatedTarget))\n\n return false\n }\n\n dispose() {\n $.removeData(this._element, DATA_KEY)\n $(this._element).off(EVENT_KEY)\n this._element = null\n }\n\n\n // private\n\n _addEventListeners() {\n $(this._element).on(Event.CLICK, this.toggle)\n }\n\n\n // static\n\n static _jQueryInterface(config) {\n return this.each(function () {\n let data = $(this).data(DATA_KEY)\n\n if (!data) {\n data = new Dropdown(this)\n $(this).data(DATA_KEY, data)\n }\n\n if (typeof config === 'string') {\n if (data[config] === undefined) {\n throw new Error(`No method named \"${config}\"`)\n }\n data[config].call(this)\n }\n })\n }\n\n static _clearMenus(event) {\n if (event && event.which === RIGHT_MOUSE_BUTTON_WHICH) {\n return\n }\n\n const backdrop = $(Selector.BACKDROP)[0]\n if (backdrop) {\n backdrop.parentNode.removeChild(backdrop)\n }\n\n const toggles = $.makeArray($(Selector.DATA_TOGGLE))\n\n for (let i = 0; i < toggles.length; i++) {\n const parent = Dropdown._getParentFromElement(toggles[i])\n const relatedTarget = {\n relatedTarget : toggles[i]\n }\n\n if (!$(parent).hasClass(ClassName.ACTIVE)) {\n continue\n }\n\n if (event && event.type === 'click' &&\n /input|textarea/i.test(event.target.tagName) &&\n $.contains(parent, event.target)) {\n continue\n }\n\n const hideEvent = $.Event(Event.HIDE, relatedTarget)\n $(parent).trigger(hideEvent)\n if (hideEvent.isDefaultPrevented()) {\n continue\n }\n\n toggles[i].setAttribute('aria-expanded', 'false')\n\n $(parent)\n .removeClass(ClassName.ACTIVE)\n .trigger($.Event(Event.HIDDEN, relatedTarget))\n }\n }\n\n static _getParentFromElement(element) {\n let parent\n const selector = Util.getSelectorFromElement(element)\n\n if (selector) {\n parent = $(selector)[0]\n }\n\n return parent || element.parentNode\n }\n\n static _dataApiKeydownHandler(event) {\n if (!/(38|40|27|32)/.test(event.which) ||\n /input|textarea/i.test(event.target.tagName)) {\n return\n }\n\n event.preventDefault()\n event.stopPropagation()\n\n if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {\n return\n }\n\n const parent = Dropdown._getParentFromElement(this)\n const isActive = $(parent).hasClass(ClassName.ACTIVE)\n\n if (!isActive && event.which !== ESCAPE_KEYCODE ||\n isActive && event.which === ESCAPE_KEYCODE) {\n\n if (event.which === ESCAPE_KEYCODE) {\n const toggle = $(parent).find(Selector.DATA_TOGGLE)[0]\n $(toggle).trigger('focus')\n }\n\n $(this).trigger('click')\n return\n }\n\n const items = $(parent).find(Selector.VISIBLE_ITEMS).get()\n\n if (!items.length) {\n return\n }\n\n let index = items.indexOf(event.target)\n\n if (event.which === ARROW_UP_KEYCODE && index > 0) { // up\n index--\n }\n\n if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) { // down\n index++\n }\n\n if (index < 0) {\n index = 0\n }\n\n items[index].focus()\n }\n\n }\n\n\n /**\n * ------------------------------------------------------------------------\n * Data Api implementation\n * ------------------------------------------------------------------------\n */\n\n $(document)\n .on(Event.KEYDOWN_DATA_API, Selector.DATA_TOGGLE, Dropdown._dataApiKeydownHandler)\n .on(Event.KEYDOWN_DATA_API, Selector.ROLE_MENU, Dropdown._dataApiKeydownHandler)\n .on(Event.KEYDOWN_DATA_API, Selector.ROLE_LISTBOX, Dropdown._dataApiKeydownHandler)\n .on(Event.CLICK_DATA_API, Dropdown._clearMenus)\n .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, Dropdown.prototype.toggle)\n .on(Event.CLICK_DATA_API, Selector.FORM_CHILD, (e) => {\n e.stopPropagation()\n })\n\n\n /**\n * ------------------------------------------------------------------------\n * jQuery\n * ------------------------------------------------------------------------\n */\n\n $.fn[NAME] = Dropdown._jQueryInterface\n $.fn[NAME].Constructor = Dropdown\n $.fn[NAME].noConflict = function () {\n $.fn[NAME] = JQUERY_NO_CONFLICT\n return Dropdown._jQueryInterface\n }\n\n return Dropdown\n\n})(jQuery)\n\nexport default Dropdown\n"]} |