aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/tab.js.map
blob: d0a5cde51516fff906598fe07ff7c7a7655d3de7 (plain) (blame)
1
{"version":3,"file":"tab.js","sources":["../src/tab.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.4.1): tab.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport $ from 'jquery'\nimport Util from './util'\n\n/**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\nconst NAME               = 'tab'\nconst VERSION            = '4.4.1'\nconst DATA_KEY           = 'bs.tab'\nconst EVENT_KEY          = `.${DATA_KEY}`\nconst DATA_API_KEY       = '.data-api'\nconst JQUERY_NO_CONFLICT = $.fn[NAME]\n\nconst 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\nconst ClassName = {\n  DROPDOWN_MENU : 'dropdown-menu',\n  ACTIVE        : 'active',\n  DISABLED      : 'disabled',\n  FADE          : 'fade',\n  SHOW          : 'show'\n}\n\nconst 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\nclass 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' || listElement.nodeName === 'OL' ? 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    const activeElements = container && (container.nodeName === 'UL' || container.nodeName === 'OL')\n      ? $(container).find(Selector.ACTIVE_UL)\n      : $(container).children(Selector.ACTIVE)\n\n    const active = activeElements[0]\n    const isTransitioning = callback && (active && $(active).hasClass(ClassName.FADE))\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        .removeClass(ClassName.SHOW)\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.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\n    if (element.classList.contains(ClassName.FADE)) {\n      element.classList.add(ClassName.SHOW)\n    }\n\n    if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) {\n      const dropdownElement = $(element).closest(Selector.DROPDOWN)[0]\n\n      if (dropdownElement) {\n        const dropdownToggleList = [].slice.call(dropdownElement.querySelectorAll(Selector.DROPDOWN_TOGGLE))\n\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\nexport default Tab\n"],"names":["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","Tab","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","removeClass","one","TRANSITION_END","emulateTransitionEnd","dropdownChild","getAttribute","setAttribute","addClass","reflow","classList","contains","add","dropdownElement","dropdownToggleList","slice","call","querySelectorAll","_jQueryInterface","config","each","$this","data","TypeError","on","event","preventDefault","Constructor","noConflict"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUA;;;;;;EAMA,IAAMA,IAAI,GAAiB,KAA3B;EACA,IAAMC,OAAO,GAAc,OAA3B;EACA,IAAMC,QAAQ,GAAa,QAA3B;EACA,IAAMC,SAAS,SAAgBD,QAA/B;EACA,IAAME,YAAY,GAAS,WAA3B;EACA,IAAMC,kBAAkB,GAAGC,CAAC,CAACC,EAAF,CAAKP,IAAL,CAA3B;EAEA,IAAMQ,KAAK,GAAG;EACZC,EAAAA,IAAI,WAAoBN,SADZ;EAEZO,EAAAA,MAAM,a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