close(element) {
element = element || this._element
- let rootElement = this._getRootElement(element)
- let customEvent = this._triggerCloseEvent(rootElement)
+ const rootElement = this._getRootElement(element)
+ const customEvent = this._triggerCloseEvent(rootElement)
if (customEvent.isDefaultPrevented()) {
return
// private
_getRootElement(element) {
- let selector = Util.getSelectorFromElement(element)
- let parent = false
+ const selector = Util.getSelectorFromElement(element)
+ let parent = false
if (selector) {
parent = $(selector)[0]
}
_triggerCloseEvent(element) {
- let closeEvent = $.Event(Event.CLOSE)
+ const closeEvent = $.Event(Event.CLOSE)
$(element).trigger(closeEvent)
return closeEvent
static _jQueryInterface(config) {
return this.each(function () {
- let $element = $(this)
- let data = $element.data(DATA_KEY)
+ const $element = $(this)
+ let data = $element.data(DATA_KEY)
if (!data) {
data = new Alert(this)
toggle() {
let triggerChangeEvent = true
- let rootElement = $(this._element).closest(
+ const rootElement = $(this._element).closest(
Selector.DATA_TOGGLE
)[0]
if (rootElement) {
- let input = $(this._element).find(Selector.INPUT)[0]
+ const input = $(this._element).find(Selector.INPUT)[0]
if (input) {
if (input.type === 'radio') {
triggerChangeEvent = false
} else {
- let activeElement = $(rootElement).find(Selector.ACTIVE)[0]
+ const activeElement = $(rootElement).find(Selector.ACTIVE)[0]
if (activeElement) {
$(activeElement).removeClass(ClassName.ACTIVE)
Button._jQueryInterface.call($(button), 'toggle')
})
.on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => {
- let button = $(event.target).closest(Selector.BUTTON)[0]
+ const button = $(event.target).closest(Selector.BUTTON)[0]
$(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type))
})
if (this._config.interval && !this._isPaused) {
this._interval = setInterval(
- (document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval
+ (document.visibilityState ? this.nextWhenVisible : this.next).bind(this),
+ this._config.interval
)
}
}
to(index) {
this._activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]
- let activeIndex = this._getItemIndex(this._activeElement)
+ const activeIndex = this._getItemIndex(this._activeElement)
- if (index > (this._items.length - 1) || index < 0) {
+ if (index > this._items.length - 1 || index < 0) {
return
}
return
}
- let direction = index > activeIndex ?
+ const direction = index > activeIndex ?
Direction.NEXT :
Direction.PREVIOUS
}
_getItemByDirection(direction, activeElement) {
- let isNextDirection = direction === Direction.NEXT
- let isPrevDirection = direction === Direction.PREVIOUS
- let activeIndex = this._getItemIndex(activeElement)
- let lastItemIndex = (this._items.length - 1)
- let isGoingToWrap = (isPrevDirection && activeIndex === 0) ||
- (isNextDirection && activeIndex === lastItemIndex)
+ const isNextDirection = direction === Direction.NEXT
+ const isPrevDirection = direction === Direction.PREVIOUS
+ const activeIndex = this._getItemIndex(activeElement)
+ const lastItemIndex = this._items.length - 1
+ const isGoingToWrap = isPrevDirection && activeIndex === 0 ||
+ isNextDirection && activeIndex === lastItemIndex
if (isGoingToWrap && !this._config.wrap) {
return activeElement
}
- let delta = direction === Direction.PREVIOUS ? -1 : 1
- let itemIndex = (activeIndex + delta) % this._items.length
+ const delta = direction === Direction.PREVIOUS ? -1 : 1
+ const itemIndex = (activeIndex + delta) % this._items.length
return itemIndex === -1 ?
this._items[this._items.length - 1] : this._items[itemIndex]
_triggerSlideEvent(relatedTarget, directionalClassname) {
- let slideEvent = $.Event(Event.SLIDE, {
+ const slideEvent = $.Event(Event.SLIDE, {
relatedTarget,
direction: directionalClassname
})
.find(Selector.ACTIVE)
.removeClass(ClassName.ACTIVE)
- let nextIndicator = this._indicatorsElement.children[
+ const nextIndicator = this._indicatorsElement.children[
this._getItemIndex(element)
]
}
_slide(direction, element) {
- let activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]
- let nextElement = element || activeElement &&
+ const activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]
+ const nextElement = element || activeElement &&
this._getItemByDirection(direction, activeElement)
- let isCycling = Boolean(this._interval)
+ const isCycling = Boolean(this._interval)
- let directionalClassName = direction === Direction.NEXT ?
+ const directionalClassName = direction === Direction.NEXT ?
ClassName.LEFT :
ClassName.RIGHT
return
}
- let slideEvent = this._triggerSlideEvent(nextElement, directionalClassName)
+ const slideEvent = this._triggerSlideEvent(nextElement, directionalClassName)
if (slideEvent.isDefaultPrevented()) {
return
}
this._setActiveIndicatorElement(nextElement)
- let slidEvent = $.Event(Event.SLID, {
+ const slidEvent = $.Event(Event.SLID, {
relatedTarget: nextElement,
direction: directionalClassName
})
static _jQueryInterface(config) {
return this.each(function () {
let data = $(this).data(DATA_KEY)
- let _config = $.extend({}, Default, $(this).data())
+ const _config = $.extend({}, Default, $(this).data())
if (typeof config === 'object') {
$.extend(_config, config)
}
- let action = typeof config === 'string' ? config : _config.slide
+ const action = typeof config === 'string' ? config : _config.slide
if (!data) {
data = new Carousel(this, _config)
}
static _dataApiClickHandler(event) {
- let selector = Util.getSelectorFromElement(this)
+ const selector = Util.getSelectorFromElement(this)
if (!selector) {
return
}
- let target = $(selector)[0]
+ const target = $(selector)[0]
if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
return
}
- let config = $.extend({}, $(target).data(), $(this).data())
- let slideIndex = this.getAttribute('data-slide-to')
+ const config = $.extend({}, $(target).data(), $(this).data())
+ const slideIndex = this.getAttribute('data-slide-to')
if (slideIndex) {
config.interval = false
$(window).on(Event.LOAD_DATA_API, () => {
$(Selector.DATA_RIDE).each(function () {
- let $carousel = $(this)
+ const $carousel = $(this)
Carousel._jQueryInterface.call($carousel, $carousel.data())
})
})
}
}
- let startEvent = $.Event(Event.SHOW)
+ const startEvent = $.Event(Event.SHOW)
$(this._element).trigger(startEvent)
if (startEvent.isDefaultPrevented()) {
return
}
}
- let dimension = this._getDimension()
+ const dimension = this._getDimension()
$(this._element)
.removeClass(ClassName.COLLAPSE)
this.setTransitioning(true)
- let complete = () => {
+ const complete = () => {
$(this._element)
.removeClass(ClassName.COLLAPSING)
.addClass(ClassName.COLLAPSE)
return
}
- let capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
- let scrollSize = `scroll${capitalizedDimension}`
+ const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
+ const scrollSize = `scroll${capitalizedDimension}`
$(this._element)
.one(Util.TRANSITION_END, complete)
return
}
- let startEvent = $.Event(Event.HIDE)
+ const startEvent = $.Event(Event.HIDE)
$(this._element).trigger(startEvent)
if (startEvent.isDefaultPrevented()) {
return
}
- let dimension = this._getDimension()
- let offsetDimension = dimension === Dimension.WIDTH ?
+ const dimension = this._getDimension()
+ const offsetDimension = dimension === Dimension.WIDTH ?
'offsetWidth' : 'offsetHeight'
this._element.style[dimension] = `${this._element[offsetDimension]}px`
this.setTransitioning(true)
- let complete = () => {
+ const complete = () => {
this.setTransitioning(false)
$(this._element)
.removeClass(ClassName.COLLAPSING)
}
_getDimension() {
- let hasWidth = $(this._element).hasClass(Dimension.WIDTH)
+ const hasWidth = $(this._element).hasClass(Dimension.WIDTH)
return hasWidth ? Dimension.WIDTH : Dimension.HEIGHT
}
_getParent() {
- let parent = $(this._config.parent)[0]
- let selector =
+ const parent = $(this._config.parent)[0]
+ const selector =
`[data-toggle="collapse"][data-parent="${this._config.parent}"]`
$(parent).find(selector).each((i, element) => {
_addAriaAndCollapsedClass(element, triggerArray) {
if (element) {
- let isOpen = $(element).hasClass(ClassName.ACTIVE)
+ const isOpen = $(element).hasClass(ClassName.ACTIVE)
element.setAttribute('aria-expanded', isOpen)
if (triggerArray.length) {
// static
static _getTargetFromElement(element) {
- let selector = Util.getSelectorFromElement(element)
+ const selector = Util.getSelectorFromElement(element)
return selector ? $(selector)[0] : null
}
static _jQueryInterface(config) {
return this.each(function () {
- let $this = $(this)
- let data = $this.data(DATA_KEY)
- let _config = $.extend(
+ const $this = $(this)
+ let data = $this.data(DATA_KEY)
+ const _config = $.extend(
{},
Default,
$this.data(),
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
event.preventDefault()
- let target = Collapse._getTargetFromElement(this)
- let data = $(target).data(DATA_KEY)
- let config = data ? 'toggle' : $(this).data()
+ const target = Collapse._getTargetFromElement(this)
+ const data = $(target).data(DATA_KEY)
+ const config = data ? 'toggle' : $(this).data()
Collapse._jQueryInterface.call($(target), config)
})
return false
}
- let parent = Dropdown._getParentFromElement(this)
- let isActive = $(parent).hasClass(ClassName.ACTIVE)
+ const parent = Dropdown._getParentFromElement(this)
+ const isActive = $(parent).hasClass(ClassName.ACTIVE)
Dropdown._clearMenus()
}
if ('ontouchstart' in document.documentElement &&
- (!$(parent).closest(Selector.NAVBAR_NAV).length)) {
+ !$(parent).closest(Selector.NAVBAR_NAV).length) {
// if mobile we use a backdrop because click events don't delegate
- let dropdown = document.createElement('div')
+ const dropdown = document.createElement('div')
dropdown.className = ClassName.BACKDROP
$(dropdown).insertBefore(this)
$(dropdown).on('click', Dropdown._clearMenus)
}
- let relatedTarget = { relatedTarget : this }
- let showEvent = $.Event(Event.SHOW, relatedTarget)
+ const relatedTarget = {
+ relatedTarget : this
+ }
+ const showEvent = $.Event(Event.SHOW, relatedTarget)
$(parent).trigger(showEvent)
}
this.focus()
- this.setAttribute('aria-expanded', 'true')
+ this.setAttribute('aria-expanded', true)
$(parent).toggleClass(ClassName.ACTIVE)
$(parent).trigger($.Event(Event.SHOWN, relatedTarget))
static _jQueryInterface(config) {
return this.each(function () {
- let data = $(this).data(DATA_KEY)
+ let data = $(this).data(DATA_KEY)
if (!data) {
- $(this).data(DATA_KEY, (data = new Dropdown(this)))
+ data = new Dropdown(this)
+ $(this).data(DATA_KEY, data)
}
if (typeof config === 'string') {
return
}
- let backdrop = $(Selector.BACKDROP)[0]
+ const backdrop = $(Selector.BACKDROP)[0]
if (backdrop) {
backdrop.parentNode.removeChild(backdrop)
}
- let toggles = $.makeArray($(Selector.DATA_TOGGLE))
+ const toggles = $.makeArray($(Selector.DATA_TOGGLE))
for (let i = 0; i < toggles.length; i++) {
- let parent = Dropdown._getParentFromElement(toggles[i])
- let relatedTarget = { relatedTarget : toggles[i] }
+ const parent = Dropdown._getParentFromElement(toggles[i])
+ const relatedTarget = {
+ relatedTarget : toggles[i]
+ }
if (!$(parent).hasClass(ClassName.ACTIVE)) {
continue
}
if (event && event.type === 'click' &&
- (/input|textarea/i.test(event.target.tagName)) &&
- ($.contains(parent, event.target))) {
+ /input|textarea/i.test(event.target.tagName) &&
+ $.contains(parent, event.target)) {
continue
}
- let hideEvent = $.Event(Event.HIDE, relatedTarget)
+ const hideEvent = $.Event(Event.HIDE, relatedTarget)
$(parent).trigger(hideEvent)
if (hideEvent.isDefaultPrevented()) {
continue
static _getParentFromElement(element) {
let parent
- let selector = Util.getSelectorFromElement(element)
+ const selector = Util.getSelectorFromElement(element)
if (selector) {
parent = $(selector)[0]
return
}
- let parent = Dropdown._getParentFromElement(this)
- let isActive = $(parent).hasClass(ClassName.ACTIVE)
+ const parent = Dropdown._getParentFromElement(this)
+ const isActive = $(parent).hasClass(ClassName.ACTIVE)
- if ((!isActive && event.which !== ESCAPE_KEYCODE) ||
- (isActive && event.which === ESCAPE_KEYCODE)) {
+ if (!isActive && event.which !== ESCAPE_KEYCODE ||
+ isActive && event.which === ESCAPE_KEYCODE) {
if (event.which === ESCAPE_KEYCODE) {
- let toggle = $(parent).find(Selector.DATA_TOGGLE)[0]
+ const toggle = $(parent).find(Selector.DATA_TOGGLE)[0]
$(toggle).trigger('focus')
}
}
show(relatedTarget) {
- let showEvent = $.Event(Event.SHOW, {
+ const showEvent = $.Event(Event.SHOW, {
relatedTarget
})
event.preventDefault()
}
- let hideEvent = $.Event(Event.HIDE)
+ const hideEvent = $.Event(Event.HIDE)
$(this._element).trigger(hideEvent)
$(this._dialog).off(Event.MOUSEDOWN_DISMISS)
if (Util.supportsTransitionEnd() &&
- ($(this._element).hasClass(ClassName.FADE))) {
+ $(this._element).hasClass(ClassName.FADE)) {
$(this._element)
.one(Util.TRANSITION_END, (event) => this._hideModal(event))
}
_showElement(relatedTarget) {
- let transition = Util.supportsTransitionEnd() &&
+ const transition = Util.supportsTransitionEnd() &&
$(this._element).hasClass(ClassName.FADE)
if (!this._element.parentNode ||
- (this._element.parentNode.nodeType !== Node.ELEMENT_NODE)) {
+ this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
// don't move modals dom position
document.body.appendChild(this._element)
}
this._enforceFocus()
}
- let shownEvent = $.Event(Event.SHOWN, {
+ const shownEvent = $.Event(Event.SHOWN, {
relatedTarget
})
- let transitionComplete = () => {
+ const transitionComplete = () => {
if (this._config.focus) {
this._element.focus()
}
.on(Event.FOCUSIN, (event) => {
if (document !== event.target &&
this._element !== event.target &&
- (!$(this._element).has(event.target).length)) {
+ !$(this._element).has(event.target).length) {
this._element.focus()
}
})
_hideModal() {
this._element.style.display = 'none'
- this._element.setAttribute('aria-hidden', 'true')
+ this._element.setAttribute('aria-hidden', true)
this._showBackdrop(() => {
$(document.body).removeClass(ClassName.OPEN)
this._resetAdjustments()
}
_showBackdrop(callback) {
- let animate = $(this._element).hasClass(ClassName.FADE) ?
+ const animate = $(this._element).hasClass(ClassName.FADE) ?
ClassName.FADE : ''
if (this._isShown && this._config.backdrop) {
- let doAnimate = Util.supportsTransitionEnd() && animate
+ const doAnimate = Util.supportsTransitionEnd() && animate
this._backdrop = document.createElement('div')
this._backdrop.className = ClassName.BACKDROP
} else if (!this._isShown && this._backdrop) {
$(this._backdrop).removeClass(ClassName.ACTIVE)
- let callbackRemove = () => {
+ const callbackRemove = () => {
this._removeBackdrop()
if (callback) {
callback()
}
if (Util.supportsTransitionEnd() &&
- ($(this._element).hasClass(ClassName.FADE))) {
+ $(this._element).hasClass(ClassName.FADE)) {
$(this._backdrop)
.one(Util.TRANSITION_END, callbackRemove)
.emulateTransitionEnd(BACKDROP_TRANSITION_DURATION)
}
_adjustDialog() {
- let isModalOverflowing =
+ const isModalOverflowing =
this._element.scrollHeight > document.documentElement.clientHeight
if (!this._isBodyOverflowing && isModalOverflowing) {
}
_setScrollbar() {
- let bodyPadding = parseInt(
+ const bodyPadding = parseInt(
$(Selector.FIXED_CONTENT).css('padding-right') || 0,
10
)
}
_getScrollbarWidth() { // thx d.walsh
- let scrollDiv = document.createElement('div')
+ const scrollDiv = document.createElement('div')
scrollDiv.className = ClassName.SCROLLBAR_MEASURER
document.body.appendChild(scrollDiv)
- let scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
+ const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
document.body.removeChild(scrollDiv)
return scrollbarWidth
}
static _jQueryInterface(config, relatedTarget) {
return this.each(function () {
- let data = $(this).data(DATA_KEY)
- let _config = $.extend(
+ let data = $(this).data(DATA_KEY)
+ const _config = $.extend(
{},
Modal.Default,
$(this).data(),
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
let target
- let selector = Util.getSelectorFromElement(this)
+ const selector = Util.getSelectorFromElement(this)
if (selector) {
target = $(selector)[0]
}
- let config = $(target).data(DATA_KEY) ?
+ const config = $(target).data(DATA_KEY) ?
'toggle' : $.extend({}, $(target).data(), $(this).data())
if (this.tagName === 'A') {
event.preventDefault()
}
- let $target = $(target).one(Event.SHOW, (showEvent) => {
+ const $target = $(target).one(Event.SHOW, (showEvent) => {
if (showEvent.isDefaultPrevented()) {
// only register focus restorer if modal will actually get shown
return
}
getTipElement() {
- return (this.tip = this.tip || $(this.config.template)[0])
+ return this.tip = this.tip || $(this.config.template)[0]
}
setContent() {
- let $tip = $(this.getTipElement())
+ const $tip = $(this.getTipElement())
// we use append for html objects to maintain js events
this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
static _jQueryInterface(config) {
return this.each(function () {
- let data = $(this).data(DATA_KEY)
- let _config = typeof config === 'object' ? config : null
+ let data = $(this).data(DATA_KEY)
+ const _config = typeof config === 'object' ? config : null
if (!data && /destroy|hide/.test(config)) {
return
// public
refresh() {
- let autoMethod = this._scrollElement !== this._scrollElement.window ?
+ const autoMethod = this._scrollElement !== this._scrollElement.window ?
OffsetMethod.POSITION : OffsetMethod.OFFSET
- let offsetMethod = this._config.method === 'auto' ?
+ const offsetMethod = this._config.method === 'auto' ?
autoMethod : this._config.method
- let offsetBase = offsetMethod === OffsetMethod.POSITION ?
+ const offsetBase = offsetMethod === OffsetMethod.POSITION ?
this._getScrollTop() : 0
this._offsets = []
this._scrollHeight = this._getScrollHeight()
- let targets = $.makeArray($(this._selector))
+ const targets = $.makeArray($(this._selector))
targets
.map((element) => {
let target
- let targetSelector = Util.getSelectorFromElement(element)
+ const targetSelector = Util.getSelectorFromElement(element)
if (targetSelector) {
target = $(targetSelector)[0]
}
_process() {
- let scrollTop = this._getScrollTop() + this._config.offset
- let scrollHeight = this._getScrollHeight()
- let maxScroll = this._config.offset
+ const scrollTop = this._getScrollTop() + this._config.offset
+ const scrollHeight = this._getScrollHeight()
+ const maxScroll = this._config.offset
+ scrollHeight
- this._scrollElement.offsetHeight
}
if (scrollTop >= maxScroll) {
- let target = this._targets[this._targets.length - 1]
+ const target = this._targets[this._targets.length - 1]
if (this._activeTarget !== target) {
this._activate(target)
}
for (let i = this._offsets.length; i--;) {
- let isActiveTarget = this._activeTarget !== this._targets[i]
+ const isActiveTarget = this._activeTarget !== this._targets[i]
&& scrollTop >= this._offsets[i]
&& (this._offsets[i + 1] === undefined ||
scrollTop < this._offsets[i + 1])
`${selector}[href="${target}"]`
})
- let $link = $(queries.join(','))
+ const $link = $(queries.join(','))
if ($link.hasClass(ClassName.DROPDOWN_ITEM)) {
$link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE)
static _jQueryInterface(config) {
return this.each(function () {
- let data = $(this).data(DATA_KEY)
- let _config = typeof config === 'object' && config || null
+ let data = $(this).data(DATA_KEY)
+ const _config = typeof config === 'object' && config
if (!data) {
data = new ScrollSpy(this, _config)
*/
$(window).on(Event.LOAD_DATA_API, () => {
- let scrollSpys = $.makeArray($(Selector.DATA_SPY))
+ const scrollSpys = $.makeArray($(Selector.DATA_SPY))
for (let i = scrollSpys.length; i--;) {
- let $spy = $(scrollSpys[i])
+ const $spy = $(scrollSpys[i])
ScrollSpy._jQueryInterface.call($spy, $spy.data())
}
})
show() {
if (this._element.parentNode &&
- (this._element.parentNode.nodeType === Node.ELEMENT_NODE) &&
- ($(this._element).hasClass(ClassName.ACTIVE))) {
+ this._element.parentNode.nodeType === Node.ELEMENT_NODE &&
+ $(this._element).hasClass(ClassName.ACTIVE)) {
return
}
let target
let previous
- let listElement = $(this._element).closest(Selector.LIST)[0]
- let selector = Util.getSelectorFromElement(this._element)
+ const listElement = $(this._element).closest(Selector.LIST)[0]
+ const selector = Util.getSelectorFromElement(this._element)
if (listElement) {
previous = $.makeArray($(listElement).find(Selector.ACTIVE))
previous = previous[previous.length - 1]
}
- let hideEvent = $.Event(Event.HIDE, {
+ const hideEvent = $.Event(Event.HIDE, {
relatedTarget: this._element
})
- let showEvent = $.Event(Event.SHOW, {
+ const showEvent = $.Event(Event.SHOW, {
relatedTarget: previous
})
$(this._element).trigger(showEvent)
if (showEvent.isDefaultPrevented() ||
- (hideEvent.isDefaultPrevented())) {
+ hideEvent.isDefaultPrevented()) {
return
}
listElement
)
- let complete = () => {
- let hiddenEvent = $.Event(Event.HIDDEN, {
+ const complete = () => {
+ const hiddenEvent = $.Event(Event.HIDDEN, {
relatedTarget: this._element
})
- let shownEvent = $.Event(Event.SHOWN, {
+ const shownEvent = $.Event(Event.SHOWN, {
relatedTarget: previous
})
// private
_activate(element, container, callback) {
- let active = $(container).find(Selector.ACTIVE_CHILD)[0]
- let isTransitioning = callback
+ const active = $(container).find(Selector.ACTIVE_CHILD)[0]
+ const isTransitioning = callback
&& Util.supportsTransitionEnd()
- && ((active && $(active).hasClass(ClassName.FADE))
+ && (active && $(active).hasClass(ClassName.FADE)
|| Boolean($(container).find(Selector.FADE_CHILD)[0]))
- let complete = () => this._transitionComplete(
+ const complete = () => this._transitionComplete(
element,
active,
isTransitioning,
if (active) {
$(active).removeClass(ClassName.ACTIVE)
- let dropdownChild = $(active).find(
+ const dropdownChild = $(active).find(
Selector.DROPDOWN_ACTIVE_CHILD
)[0]
}
if (element.parentNode &&
- ($(element.parentNode).hasClass(ClassName.DROPDOWN_MENU))) {
+ $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) {
- let dropdownElement = $(element).closest(Selector.DROPDOWN)[0]
+ const dropdownElement = $(element).closest(Selector.DROPDOWN)[0]
if (dropdownElement) {
$(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE)
}
static _jQueryInterface(config) {
return this.each(function () {
- let $this = $(this)
- let data = $this.data(DATA_KEY)
+ const $this = $(this)
+ let data = $this.data(DATA_KEY)
if (!data) {
- data = data = new Tab(this)
+ data = new Tab(this)
$this.data(DATA_KEY, data)
}
constructor(element, config) {
// private
- this._isEnabled = true
- this._timeout = 0
- this._hoverState = ''
- this._activeTrigger = {}
- this._tether = null
+ this._isEnabled = true
+ this._timeout = 0
+ this._hoverState = ''
+ this._activeTrigger = {}
+ this._tether = null
// protected
this.element = element
toggle(event) {
if (event) {
- let dataKey = this.constructor.DATA_KEY
+ const dataKey = this.constructor.DATA_KEY
let context = $(event.currentTarget).data(dataKey)
if (!context) {
$(this.tip).remove()
}
- this._isEnabled = null
- this._timeout = null
- this._hoverState = null
- this._activeTrigger = null
- this._tether = null
+ this._isEnabled = null
+ this._timeout = null
+ this._hoverState = null
+ this._activeTrigger = null
+ this._tether = null
this.element = null
this.config = null
if ($(this.element).css('display') === 'none') {
throw new Error('Please use show on visible elements')
}
- let showEvent = $.Event(this.constructor.Event.SHOW)
+ const showEvent = $.Event(this.constructor.Event.SHOW)
if (this.isWithContent() && this._isEnabled) {
$(this.element).trigger(showEvent)
- let isInTheDom = $.contains(
+ const isInTheDom = $.contains(
this.element.ownerDocument.documentElement,
this.element
)
return
}
- let tip = this.getTipElement()
- let tipId = Util.getUID(this.constructor.NAME)
+ const tip = this.getTipElement()
+ const tipId = Util.getUID(this.constructor.NAME)
tip.setAttribute('id', tipId)
this.element.setAttribute('aria-describedby', tipId)
$(tip).addClass(ClassName.FADE)
}
- let placement = typeof this.config.placement === 'function' ?
+ const placement = typeof this.config.placement === 'function' ?
this.config.placement.call(this, tip, this.element) :
this.config.placement
- let attachment = this._getAttachment(placement)
+ const attachment = this._getAttachment(placement)
$(tip)
.data(this.constructor.DATA_KEY, this)
$(tip).addClass(ClassName.ACTIVE)
- let complete = () => {
- let prevHoverState = this._hoverState
- this._hoverState = null
+ const complete = () => {
+ const prevHoverState = this._hoverState
+ this._hoverState = null
$(this.element).trigger(this.constructor.Event.SHOWN)
}
hide(callback) {
- let tip = this.getTipElement()
- let hideEvent = $.Event(this.constructor.Event.HIDE)
- let complete = () => {
+ const tip = this.getTipElement()
+ const hideEvent = $.Event(this.constructor.Event.HIDE)
+ const complete = () => {
if (this._hoverState !== HoverState.ACTIVE && tip.parentNode) {
tip.parentNode.removeChild(tip)
}
$(tip).removeClass(ClassName.ACTIVE)
if (Util.supportsTransitionEnd() &&
- ($(this.tip).hasClass(ClassName.FADE))) {
+ $(this.tip).hasClass(ClassName.FADE)) {
$(tip)
.one(Util.TRANSITION_END, complete)
}
getTipElement() {
- return (this.tip = this.tip || $(this.config.template)[0])
+ return this.tip = this.tip || $(this.config.template)[0]
}
setContent() {
- let $tip = $(this.getTipElement())
+ const $tip = $(this.getTipElement())
this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle())
}
setElementContent($element, content) {
- let html = this.config.html
+ const html = this.config.html
if (typeof content === 'object' && (content.nodeType || content.jquery)) {
// content is a DOM node or a jQuery
if (html) {
}
_setListeners() {
- let triggers = this.config.trigger.split(' ')
+ const triggers = this.config.trigger.split(' ')
triggers.forEach((trigger) => {
if (trigger === 'click') {
)
} else if (trigger !== Trigger.MANUAL) {
- let eventIn = trigger === Trigger.HOVER ?
+ const eventIn = trigger === Trigger.HOVER ?
this.constructor.Event.MOUSEENTER :
this.constructor.Event.FOCUSIN
- let eventOut = trigger === Trigger.HOVER ?
+ const eventOut = trigger === Trigger.HOVER ?
this.constructor.Event.MOUSELEAVE :
this.constructor.Event.FOCUSOUT
}
_fixTitle() {
- let titleType = typeof this.element.getAttribute('data-original-title')
+ const titleType = typeof this.element.getAttribute('data-original-title')
if (this.element.getAttribute('title') ||
- (titleType !== 'string')) {
+ titleType !== 'string') {
this.element.setAttribute(
'data-original-title',
this.element.getAttribute('title') || ''
}
_enter(event, context) {
- let dataKey = this.constructor.DATA_KEY
+ const dataKey = this.constructor.DATA_KEY
context = context || $(event.currentTarget).data(dataKey)
}
if ($(context.getTipElement()).hasClass(ClassName.ACTIVE) ||
- (context._hoverState === HoverState.ACTIVE)) {
+ context._hoverState === HoverState.ACTIVE) {
context._hoverState = HoverState.ACTIVE
return
}
}
_leave(event, context) {
- let dataKey = this.constructor.DATA_KEY
+ const dataKey = this.constructor.DATA_KEY
context = context || $(event.currentTarget).data(dataKey)
}
_isWithActiveTrigger() {
- for (let trigger in this._activeTrigger) {
+ for (const trigger in this._activeTrigger) {
if (this._activeTrigger[trigger]) {
return true
}
}
_getDelegateConfig() {
- let config = {}
+ const config = {}
if (this.config) {
- for (let key in this.config) {
+ for (const key in this.config) {
if (this.constructor.Default[key] !== this.config[key]) {
config[key] = this.config[key]
}
static _jQueryInterface(config) {
return this.each(function () {
- let data = $(this).data(DATA_KEY)
- let _config = typeof config === 'object' ?
- config : null
+ let data = $(this).data(DATA_KEY)
+ const _config = typeof config === 'object' && config
if (!data && /dispose|hide/.test(config)) {
return
// shoutout AngusCroll (https://goo.gl/pxwQGp)
function toType(obj) {
- return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
+ return {}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}
function isElement(obj) {
return false
}
- let el = document.createElement('bootstrap')
+ const el = document.createElement('bootstrap')
- for (let name in TransitionEndEvent) {
+ for (const name in TransitionEndEvent) {
if (el.style[name] !== undefined) {
- return { end: TransitionEndEvent[name] }
+ return {
+ end: TransitionEndEvent[name]
+ }
}
}
* --------------------------------------------------------------------------
*/
- let Util = {
+ const Util = {
TRANSITION_END: 'bsTransitionEnd',
getUID(prefix) {
do {
- /* eslint-disable no-bitwise */
+ // eslint-disable-next-line no-bitwise
prefix += ~~(Math.random() * MAX_UID) // "~~" acts like a faster Math.floor() here
- /* eslint-enable no-bitwise */
} while (document.getElementById(prefix))
return prefix
},
},
typeCheckConfig(componentName, config, configTypes) {
- for (let property in configTypes) {
+ for (const property in configTypes) {
if (configTypes.hasOwnProperty(property)) {
- let expectedTypes = configTypes[property]
- let value = config[property]
- let valueType
-
- if (value && isElement(value)) {
- valueType = 'element'
- } else {
- valueType = toType(value)
- }
+ const expectedTypes = configTypes[property]
+ const value = config[property]
+ const valueType = value && isElement(value) ?
+ 'element' : toType(value)
if (!new RegExp(expectedTypes).test(valueType)) {
throw new Error(
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('alert plugin')
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('button plugin')
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('carousel plugin')
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('collapse plugin')
assert.expect(2)
var html = [
'<div class="panel-group" id="accordion1">',
- '<div class="panel">',
- '<div id="collapse1" class="collapse"/>',
- '</div>',
+ '<div class="panel">',
+ '<div id="collapse1" class="collapse"/>',
+ '</div>',
'</div>',
'<div class="panel-group" id="accordion2">',
- '<div class="panel">',
- '<div id="collapse2" class="collapse active"/>',
- '</div>',
+ '<div class="panel">',
+ '<div id="collapse2" class="collapse active"/>',
+ '</div>',
'</div>'
].join('')
$(html).appendTo('#qunit-fixture')
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('dropdowns plugin')
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('modal plugin')
var paddingRight = parseInt($(document.body).css('padding-right'), 10)
assert.strictEqual(isNaN(paddingRight), false)
assert.strictEqual(paddingRight !== 0, true)
- $(document.body).css('padding-right', ''); // Because test case "should ignore other inline styles when trying to restore body padding after closing" fail if not
+ $(document.body).css('padding-right', '') // Because test case "should ignore other inline styles when trying to restore body padding after closing" fail if not
done()
})
.bootstrapModal('show')
*/
(function () {
- 'use strict';
+ 'use strict'
// Don't re-order tests.
QUnit.config.reorder = false
})
}())
-
-
-// bind polyfill
-// shoutout mdn: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill
-
-if (!Function.prototype.bind) {
- Function.prototype.bind = function (oThis) {
- if (typeof this !== 'function') {
- // closest thing possible to the ECMAScript 5
- // internal IsCallable function
- throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
- }
-
- var aArgs = Array.prototype.slice.call(arguments, 1)
- var fToBind = this
- var FNOP = function () {}
- var fBound = function () {
- return fToBind.apply(this instanceof FNOP ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)))
- }
-
- if (this.prototype) {
- // native functions don't have a prototype
- FNOP.prototype = this.prototype
- }
- fBound.prototype = new FNOP()
-
- return fBound
- }
-}
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('popover plugin')
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('scrollspy plugin')
.appendTo('#qunit-fixture')
.bootstrapScrollspy({ offset: 0, target: '#navigation' })
- !function testActiveElements() {
- if (++times > 3) return done()
+ function testActiveElements() {
+ if (++times > 3) { return done() }
$content.one('scroll', function () {
assert.ok($('#a-1').hasClass('active'), 'nav item for outer element has "active" class')
})
$content.scrollTop($content.scrollTop() + 10)
- }()
+ }
+
+ testActiveElements()
})
QUnit.test('should clear selection if above the first section', function (assert) {
$navbar.appendTo('#qunit-fixture')
$content.appendTo('#qunit-fixture')
- if (type === 'js') $content.bootstrapScrollspy({ target: '.navbar', offset: 0, method: 'position' })
- else if (type === 'data') $(window).trigger('load')
+ if (type === 'js') { $content.bootstrapScrollspy({ target: '.navbar', offset: 0, method: 'position' }) }
+ else if (type === 'data') { $(window).trigger('load') }
var $target = $('#div-' + type + 'm-2')
var scrollspy = $content.data('bs.scrollspy')
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('tabs plugin')
$(function () {
- 'use strict';
+ 'use strict'
QUnit.module('tooltip plugin')
var $tooltip = $($target.data('bs.tooltip').tip)
// this is some dumb hack stuff because sub pixels in firefox
- var top = Math.round($target.offset().top + ($target[0].offsetHeight / 2) - ($tooltip[0].offsetHeight / 2))
+ var top = Math.round($target.offset().top + $target[0].offsetHeight / 2 - $tooltip[0].offsetHeight / 2)
var top2 = Math.round($tooltip.offset().top)
var topDiff = top - top2
assert.ok(topDiff <= 1 && topDiff >= -1)
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
- .bootstrapTooltip({ delay: { show: 0, hide: 150 }})
+ .bootstrapTooltip({ delay: { show: 0, hide: 150 } })
setTimeout(function () {
assert.ok($('.tooltip').is('.fade.active'), '1ms: tooltip faded active')
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
- .bootstrapTooltip({ delay: { show: 150, hide: 0 }})
+ .bootstrapTooltip({ delay: { show: 150, hide: 0 } })
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.active'), '100ms: tooltip not faded active')
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
- .bootstrapTooltip({ delay: { show: 0, hide: 150 }})
+ .bootstrapTooltip({ delay: { show: 0, hide: 150 } })
setTimeout(function () {
assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.active'), '1ms: tooltip faded active')
$('#tt-outer').trigger('mouseleave')
assert.strictEqual(currentUid, $('#tt-content').text())
- assert.ok(obj._hoverState == 'out', 'the tooltip hoverState should be set to "out"')
+ assert.ok(obj._hoverState === 'out', 'the tooltip hoverState should be set to "out"')
$('#tt-outer').trigger('mouseenter')
- assert.ok(obj._hoverState == 'active', 'the tooltip hoverState should be set to "active"')
+ assert.ok(obj._hoverState === 'active', 'the tooltip hoverState should be set to "active"')
assert.strictEqual(currentUid, $('#tt-content').text())
})
var tooltip = $el.data('bs.tooltip')
var $tooltip = $(tooltip.getTipElement())
- function showingTooltip() { return $tooltip.hasClass('active') || tooltip._hoverState == 'active' }
+ function showingTooltip() { return $tooltip.hasClass('active') || tooltip._hoverState === 'active' }
var tests = [
['mouseenter', 'mouseleave'],
$.each(tests, function (idx, triggers) {
for (var i = 0, len = triggers.length; i < len; i++) {
- $el.trigger(triggers[i]);
- assert.equal(i < (len - 1), showingTooltip())
+ $el.trigger(triggers[i])
+ assert.equal(i < len - 1, showingTooltip())
}
})
})