mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-09 15:16:51 +02:00
JS: minor refactoring (#35183)
* add missing comments * shorten block comments * reorder constants * reorder public/private methods * sort exports alphabetically in util/index.js * fix a couple of typos
This commit is contained in:
@@ -16,9 +16,7 @@ import SelectorEngine from './dom/selector-engine'
|
||||
import BaseComponent from './base-component'
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Constants
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
const NAME = 'tab'
|
||||
@@ -46,20 +44,16 @@ const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle'
|
||||
const SELECTOR_DROPDOWN_ACTIVE_CHILD = ':scope > .dropdown-menu .active'
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Class Definition
|
||||
* ------------------------------------------------------------------------
|
||||
* Class definition
|
||||
*/
|
||||
|
||||
class Tab extends BaseComponent {
|
||||
// Getters
|
||||
|
||||
static get NAME() {
|
||||
return NAME
|
||||
}
|
||||
|
||||
// Public
|
||||
|
||||
show() {
|
||||
if ((this._element.parentNode &&
|
||||
this._element.parentNode.nodeType === Node.ELEMENT_NODE &&
|
||||
@@ -78,9 +72,7 @@ class Tab extends BaseComponent {
|
||||
}
|
||||
|
||||
const hideEvent = previous ?
|
||||
EventHandler.trigger(previous, EVENT_HIDE, {
|
||||
relatedTarget: this._element
|
||||
}) :
|
||||
EventHandler.trigger(previous, EVENT_HIDE, { relatedTarget: this._element }) :
|
||||
null
|
||||
|
||||
const showEvent = EventHandler.trigger(this._element, EVENT_SHOW, {
|
||||
@@ -94,12 +86,8 @@ class Tab extends BaseComponent {
|
||||
this._activate(this._element, listElement)
|
||||
|
||||
const complete = () => {
|
||||
EventHandler.trigger(previous, EVENT_HIDDEN, {
|
||||
relatedTarget: this._element
|
||||
})
|
||||
EventHandler.trigger(this._element, EVENT_SHOWN, {
|
||||
relatedTarget: previous
|
||||
})
|
||||
EventHandler.trigger(previous, EVENT_HIDDEN, { relatedTarget: this._element })
|
||||
EventHandler.trigger(this._element, EVENT_SHOWN, { relatedTarget: previous })
|
||||
}
|
||||
|
||||
if (target) {
|
||||
@@ -110,7 +98,6 @@ class Tab extends BaseComponent {
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_activate(element, container, callback) {
|
||||
const activeElements = container && (container.nodeName === 'UL' || container.nodeName === 'OL') ?
|
||||
SelectorEngine.find(SELECTOR_ACTIVE_UL, container) :
|
||||
@@ -178,7 +165,6 @@ class Tab extends BaseComponent {
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Tab.getOrCreateInstance(this)
|
||||
@@ -195,9 +181,7 @@ class Tab extends BaseComponent {
|
||||
}
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Data Api implementation
|
||||
* ------------------------------------------------------------------------
|
||||
* Data API implementation
|
||||
*/
|
||||
|
||||
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
||||
@@ -214,10 +198,7 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (
|
||||
})
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* jQuery
|
||||
* ------------------------------------------------------------------------
|
||||
* add .Tab to jQuery only if jQuery is present
|
||||
*/
|
||||
|
||||
defineJQueryPlugin(Tab)
|
||||
|
Reference in New Issue
Block a user