0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00
Bootstrap/js/dist/tab.js.map
Mark Otto c0fd91788e dist
2018-08-18 20:22:08 -07:00

1 line
15 KiB
Plaintext

{"version":3,"file":"tab.js","sources":["../src/tab.js"],"sourcesContent":["import $ from 'jquery'\nimport Util from './util'\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.1.3): tab.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst Tab = (($) => {\n /**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\n const NAME = 'tab'\n const VERSION = '4.1.3'\n const DATA_KEY = 'bs.tab'\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_DATA_API : `click${EVENT_KEY}${DATA_API_KEY}`\n }\n\n const ClassName = {\n DROPDOWN_MENU : 'dropdown-menu',\n ACTIVE : 'active',\n DISABLED : 'disabled',\n FADE : 'fade',\n SHOW : 'show'\n }\n\n const Selector = {\n DROPDOWN : '.dropdown',\n NAV_LIST_GROUP : '.nav, .list-group',\n ACTIVE : '.active',\n ACTIVE_UL : '> li > .active',\n DATA_TOGGLE : '[data-toggle=\"tab\"], [data-toggle=\"pill\"], [data-toggle=\"list\"]',\n DROPDOWN_TOGGLE : '.dropdown-toggle',\n DROPDOWN_ACTIVE_CHILD : '> .dropdown-menu .active'\n }\n\n /**\n * ------------------------------------------------------------------------\n * Class Definition\n * ------------------------------------------------------------------------\n */\n\n class Tab {\n constructor(element) {\n this._element = element\n }\n\n // Getters\n\n static get VERSION() {\n return VERSION\n }\n\n // Public\n\n show() {\n if (this._element.parentNode &&\n this._element.parentNode.nodeType === Node.ELEMENT_NODE &&\n $(this._element).hasClass(ClassName.ACTIVE) ||\n $(this._element).hasClass(ClassName.DISABLED)) {\n return\n }\n\n let target\n let previous\n const listElement = $(this._element).closest(Selector.NAV_LIST_GROUP)[0]\n const selector = Util.getSelectorFromElement(this._element)\n\n if (listElement) {\n const itemSelector = listElement.nodeName === 'UL' ? Selector.ACTIVE_UL : Selector.ACTIVE\n previous = $.makeArray($(listElement).find(itemSelector))\n previous = previous[previous.length - 1]\n }\n\n const hideEvent = $.Event(Event.HIDE, {\n relatedTarget: this._element\n })\n\n const showEvent = $.Event(Event.SHOW, {\n relatedTarget: previous\n })\n\n if (previous) {\n $(previous).trigger(hideEvent)\n }\n\n $(this._element).trigger(showEvent)\n\n if (showEvent.isDefaultPrevented() ||\n hideEvent.isDefaultPrevented()) {\n return\n }\n\n if (selector) {\n target = document.querySelector(selector)\n }\n\n this._activate(\n this._element,\n listElement\n )\n\n const complete = () => {\n const hiddenEvent = $.Event(Event.HIDDEN, {\n relatedTarget: this._element\n })\n\n const shownEvent = $.Event(Event.SHOWN, {\n relatedTarget: previous\n })\n\n $(previous).trigger(hiddenEvent)\n $(this._element).trigger(shownEvent)\n }\n\n if (target) {\n this._activate(target, target.parentNode, complete)\n } else {\n complete()\n }\n }\n\n dispose() {\n $.removeData(this._element, DATA_KEY)\n this._element = null\n }\n\n // Private\n\n _activate(element, container, callback) {\n let activeElements\n if (container.nodeName === 'UL') {\n activeElements = $(container).find(Selector.ACTIVE_UL)\n } else {\n activeElements = $(container).children(Selector.ACTIVE)\n }\n\n const active = activeElements[0]\n const isTransitioning = callback &&\n (active && $(active).hasClass(ClassName.FADE))\n\n const complete = () => this._transitionComplete(\n element,\n active,\n callback\n )\n\n if (active && isTransitioning) {\n const transitionDuration = Util.getTransitionDurationFromElement(active)\n\n $(active)\n .one(Util.TRANSITION_END, complete)\n .emulateTransitionEnd(transitionDuration)\n } else {\n complete()\n }\n }\n\n _transitionComplete(element, active, callback) {\n if (active) {\n $(active).removeClass(`${ClassName.SHOW} ${ClassName.ACTIVE}`)\n\n const dropdownChild = $(active.parentNode).find(\n Selector.DROPDOWN_ACTIVE_CHILD\n )[0]\n\n if (dropdownChild) {\n $(dropdownChild).removeClass(ClassName.ACTIVE)\n }\n\n if (active.getAttribute('role') === 'tab') {\n active.setAttribute('aria-selected', false)\n }\n }\n\n $(element).addClass(ClassName.ACTIVE)\n if (element.getAttribute('role') === 'tab') {\n element.setAttribute('aria-selected', true)\n }\n\n Util.reflow(element)\n $(element).addClass(ClassName.SHOW)\n\n if (element.parentNode &&\n $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) {\n const dropdownElement = $(element).closest(Selector.DROPDOWN)[0]\n if (dropdownElement) {\n const dropdownToggleList = [].slice.call(dropdownElement.querySelectorAll(Selector.DROPDOWN_TOGGLE))\n $(dropdownToggleList).addClass(ClassName.ACTIVE)\n }\n\n element.setAttribute('aria-expanded', true)\n }\n\n if (callback) {\n callback()\n }\n }\n\n // Static\n\n static _jQueryInterface(config) {\n return this.each(function () {\n const $this = $(this)\n let data = $this.data(DATA_KEY)\n\n if (!data) {\n data = new Tab(this)\n $this.data(DATA_KEY, data)\n }\n\n if (typeof config === 'string') {\n if (typeof data[config] === 'undefined') {\n throw new TypeError(`No method named \"${config}\"`)\n }\n data[config]()\n }\n })\n }\n }\n\n /**\n * ------------------------------------------------------------------------\n * Data Api implementation\n * ------------------------------------------------------------------------\n */\n\n $(document)\n .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {\n event.preventDefault()\n Tab._jQueryInterface.call($(this), 'show')\n })\n\n /**\n * ------------------------------------------------------------------------\n * jQuery\n * ------------------------------------------------------------------------\n */\n\n $.fn[NAME] = Tab._jQueryInterface\n $.fn[NAME].Constructor = Tab\n $.fn[NAME].noConflict = () => {\n $.fn[NAME] = JQUERY_NO_CONFLICT\n return Tab._jQueryInterface\n }\n\n return Tab\n})($)\n\nexport default Tab\n"],"names":["Tab","$","NAME","VERSION","DATA_KEY","EVENT_KEY","DATA_API_KEY","JQUERY_NO_CONFLICT","fn","Event","HIDE","HIDDEN","SHOW","SHOWN","CLICK_DATA_API","ClassName","DROPDOWN_MENU","ACTIVE","DISABLED","FADE","Selector","DROPDOWN","NAV_LIST_GROUP","ACTIVE_UL","DATA_TOGGLE","DROPDOWN_TOGGLE","DROPDOWN_ACTIVE_CHILD","element","_element","show","parentNode","nodeType","Node","ELEMENT_NODE","hasClass","target","previous","listElement","closest","selector","Util","getSelectorFromElement","itemSelector","nodeName","makeArray","find","length","hideEvent","relatedTarget","showEvent","trigger","isDefaultPrevented","document","querySelector","_activate","complete","hiddenEvent","shownEvent","dispose","removeData","container","callback","activeElements","children","active","isTransitioning","_transitionComplete","transitionDuration","getTransitionDurationFromElement","one","TRANSITION_END","emulateTransitionEnd","removeClass","dropdownChild","getAttribute","setAttribute","addClass","reflow","dropdownElement","dropdownToggleList","slice","call","querySelectorAll","_jQueryInterface","config","each","$this","data","TypeError","on","event","preventDefault","Constructor","noConflict"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;EAGA;;;;;;;EAOA,IAAMA,GAAG,GAAI,UAACC,IAAD,EAAO;EAClB;;;;;EAMA,MAAMC,IAAI,GAAiB,KAA3B;EACA,MAAMC,OAAO,GAAc,OAA3B;EACA,MAAMC,QAAQ,GAAa,QAA3B;EACA,MAAMC,SAAS,SAAgBD,QAA/B;EACA,MAAME,YAAY,GAAS,WAA3B;EACA,MAAMC,kBAAkB,GAAGN,IAAC,CAACO,EAAF,CAAKN,IAAL,CAA3B;EAEA,MAAMO,KAAK,GAAG;EACZC,IAAAA,IAAI,WAAoBL,SADZ;EAEZM,IAAAA,MAAM,aAAoBN,SAFd;EAGZO,IAAAA,IAAI,WAAoBP,SAHZ;EAIZQ,IAAAA,KAAK,YAAoBR,SAJb;EAKZS,IAAAA,cAAc,YAAWT,SAAX,GAAuBC;EALzB,GAAd;EAQA,MAAMS,SAAS,GAAG;EAChBC,IAAAA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