mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
1 line
No EOL
14 KiB
Text
1 line
No EOL
14 KiB
Text
{"version":3,"sources":["js/src/dropdown.js"],"names":[],"mappings":";;;;;;;;;;;;;AAUA,IAAM,QAAQ,GAAG,CAAC,UAAC,CAAC,EAAK;;;;;;;;AASvB,MAAM,IAAI,GAAkB,UAAU,CAAA;AACtC,MAAM,OAAO,GAAe,OAAO,CAAA;AACnC,MAAM,QAAQ,GAAc,aAAa,CAAA;AACzC,MAAM,SAAS,SAAiB,QAAQ,AAAE,CAAA;AAC1C,MAAM,YAAY,GAAU,WAAW,CAAA;AACvC,MAAM,kBAAkB,GAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;;AAEtC,MAAM,KAAK,GAAG;AACZ,QAAI,WAAsB,SAAS,AAAE;AACrC,UAAM,aAAsB,SAAS,AAAE;AACvC,QAAI,WAAsB,SAAS,AAAE;AACrC,SAAK,YAAsB,SAAS,AAAE;AACtC,SAAK,YAAsB,SAAS,AAAE;AACtC,kBAAc,YAAa,SAAS,QAAG,YAAY,AAAE;AACrD,oBAAgB,cAAa,SAAS,QAAG,YAAY,AAAE;GACxD,CAAA;;AAED,MAAM,SAAS,GAAG;AAChB,YAAQ,EAAG,mBAAmB;AAC9B,YAAQ,EAAG,UAAU;AACrB,QAAI,EAAO,MAAM;GAClB,CAAA;;AAED,MAAM,QAAQ,GAAG;AACf,YAAQ,EAAQ,oBAAoB;AACpC,eAAW,EAAK,0BAA0B;AAC1C,cAAU,EAAM,gBAAgB;AAChC,aAAS,EAAO,eAAe;AAC/B,gBAAY,EAAI,kBAAkB;AAClC,cAAU,EAAM,aAAa;AAC7B,iBAAa,EAAG,qCAAqC,GACrC,sCAAsC;GACvD,CAAA;;;;;;;;MASK,QAAQ;AAED,aAFP,QAAQ,CAEA,OAAO,EAAE;4BAFjB,QAAQ;;AAGV,UAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;;AAEvB,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,sBAAsB,CAAC,CAClF,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,WAAW,CAAC,CAC9C,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CACzE,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,UAAU,EAAG,UAAU,CAAC,EAAE;AAC1D,KAAC,CAAC,eAAe,EAAE,CAAA;GACpB,CAAC,CAAA;;;;;;;;AASL,GAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAe,QAAQ,CAAC,gBAAgB,CAAA;AAClD,GAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,GAAG,QAAQ,CAAA;AACjC,GAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,GAAI,YAAY;AACnC,KAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAA;AAC/B,WAAO,QAAQ,CAAC,gBAAgB,CAAA;GACjC,CAAA;;AAED,SAAO,QAAQ,CAAA;CAEhB,CAAA,CAAE,MAAM,CAAC,CAAA","file":"js/src/dropdown.js","sourcesContent":["import Util from './util'\n\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.0.0): 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'\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\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 OPEN : 'open'\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\n }\n\n let parent = Dropdown._getParentFromElement(this)\n let isActive = $(parent).hasClass(ClassName.OPEN)\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 let dropdown = document.createElement('div')\n dropdown.className = ClassName.BACKDROP\n $(dropdown).insertBefore(this)\n $(dropdown).on('click', Dropdown._clearMenus)\n }\n\n let relatedTarget = { relatedTarget : this }\n let showEvent = $.Event(Event.SHOW, relatedTarget)\n\n $(parent).trigger(showEvent)\n\n if (showEvent.isDefaultPrevented()) {\n return\n }\n\n this.focus()\n this.setAttribute('aria-expanded', 'true')\n\n $(parent).toggleClass(ClassName.OPEN)\n $(parent).trigger(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 $(this).data(DATA_KEY, (data = new Dropdown(this)))\n }\n\n if (typeof config === 'string') {\n data[config].call(this)\n }\n })\n }\n\n static _clearMenus(event) {\n if (event && event.which === 3) {\n return\n }\n\n let backdrop = $(Selector.BACKDROP)[0]\n if (backdrop) {\n backdrop.parentNode.removeChild(backdrop)\n }\n\n let toggles = $.makeArray($(Selector.DATA_TOGGLE))\n\n for (let i = 0; i < toggles.length; i++) {\n let parent = Dropdown._getParentFromElement(toggles[i])\n let relatedTarget = { relatedTarget : toggles[i] }\n\n if (!$(parent).hasClass(ClassName.OPEN)) {\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 let 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.OPEN)\n .trigger(Event.HIDDEN, relatedTarget)\n }\n }\n\n static _getParentFromElement(element) {\n let parent\n let 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 let parent = Dropdown._getParentFromElement(this)\n let isActive = $(parent).hasClass(ClassName.OPEN)\n\n if ((!isActive && event.which !== 27) ||\n (isActive && event.which === 27)) {\n\n if (event.which === 27) {\n let toggle = $(parent).find(Selector.DATA_TOGGLE)[0]\n $(toggle).trigger('focus')\n }\n\n $(this).trigger('click')\n return\n }\n\n let items = $.makeArray($(Selector.VISIBLE_ITEMS))\n\n items = items.filter((item) => {\n return item.offsetWidth || item.offsetHeight\n })\n\n if (!items.length) {\n return\n }\n\n let index = items.indexOf(event.target)\n\n if (event.which === 38 && index > 0) index-- // up\n if (event.which === 40 && index < items.length - 1) index++ // down\n if (!~index) index = 0\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, function (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"]} |