mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-17 09:52:29 +01:00
Make JS compliant with the new ESLint rules.
This commit is contained in:
parent
26c16743fc
commit
c2616fb74e
@ -67,8 +67,8 @@ const Alert = (($) => {
|
|||||||
close(element) {
|
close(element) {
|
||||||
element = element || this._element
|
element = element || this._element
|
||||||
|
|
||||||
let rootElement = this._getRootElement(element)
|
const rootElement = this._getRootElement(element)
|
||||||
let customEvent = this._triggerCloseEvent(rootElement)
|
const customEvent = this._triggerCloseEvent(rootElement)
|
||||||
|
|
||||||
if (customEvent.isDefaultPrevented()) {
|
if (customEvent.isDefaultPrevented()) {
|
||||||
return
|
return
|
||||||
@ -86,8 +86,8 @@ const Alert = (($) => {
|
|||||||
// private
|
// private
|
||||||
|
|
||||||
_getRootElement(element) {
|
_getRootElement(element) {
|
||||||
let selector = Util.getSelectorFromElement(element)
|
const selector = Util.getSelectorFromElement(element)
|
||||||
let parent = false
|
let parent = false
|
||||||
|
|
||||||
if (selector) {
|
if (selector) {
|
||||||
parent = $(selector)[0]
|
parent = $(selector)[0]
|
||||||
@ -101,7 +101,7 @@ const Alert = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_triggerCloseEvent(element) {
|
_triggerCloseEvent(element) {
|
||||||
let closeEvent = $.Event(Event.CLOSE)
|
const closeEvent = $.Event(Event.CLOSE)
|
||||||
|
|
||||||
$(element).trigger(closeEvent)
|
$(element).trigger(closeEvent)
|
||||||
return closeEvent
|
return closeEvent
|
||||||
@ -133,8 +133,8 @@ const Alert = (($) => {
|
|||||||
|
|
||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let $element = $(this)
|
const $element = $(this)
|
||||||
let data = $element.data(DATA_KEY)
|
let data = $element.data(DATA_KEY)
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Alert(this)
|
data = new Alert(this)
|
||||||
|
@ -66,12 +66,12 @@ const Button = (($) => {
|
|||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
let triggerChangeEvent = true
|
let triggerChangeEvent = true
|
||||||
let rootElement = $(this._element).closest(
|
const rootElement = $(this._element).closest(
|
||||||
Selector.DATA_TOGGLE
|
Selector.DATA_TOGGLE
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
if (rootElement) {
|
if (rootElement) {
|
||||||
let input = $(this._element).find(Selector.INPUT)[0]
|
const input = $(this._element).find(Selector.INPUT)[0]
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
if (input.type === 'radio') {
|
if (input.type === 'radio') {
|
||||||
@ -80,7 +80,7 @@ const Button = (($) => {
|
|||||||
triggerChangeEvent = false
|
triggerChangeEvent = false
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let activeElement = $(rootElement).find(Selector.ACTIVE)[0]
|
const activeElement = $(rootElement).find(Selector.ACTIVE)[0]
|
||||||
|
|
||||||
if (activeElement) {
|
if (activeElement) {
|
||||||
$(activeElement).removeClass(ClassName.ACTIVE)
|
$(activeElement).removeClass(ClassName.ACTIVE)
|
||||||
@ -151,7 +151,7 @@ const Button = (($) => {
|
|||||||
Button._jQueryInterface.call($(button), 'toggle')
|
Button._jQueryInterface.call($(button), 'toggle')
|
||||||
})
|
})
|
||||||
.on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => {
|
.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))
|
$(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -161,7 +161,8 @@ const Carousel = (($) => {
|
|||||||
|
|
||||||
if (this._config.interval && !this._isPaused) {
|
if (this._config.interval && !this._isPaused) {
|
||||||
this._interval = setInterval(
|
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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,9 +170,9 @@ const Carousel = (($) => {
|
|||||||
to(index) {
|
to(index) {
|
||||||
this._activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +187,7 @@ const Carousel = (($) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let direction = index > activeIndex ?
|
const direction = index > activeIndex ?
|
||||||
Direction.NEXT :
|
Direction.NEXT :
|
||||||
Direction.PREVIOUS
|
Direction.PREVIOUS
|
||||||
|
|
||||||
@ -255,19 +256,19 @@ const Carousel = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getItemByDirection(direction, activeElement) {
|
_getItemByDirection(direction, activeElement) {
|
||||||
let isNextDirection = direction === Direction.NEXT
|
const isNextDirection = direction === Direction.NEXT
|
||||||
let isPrevDirection = direction === Direction.PREVIOUS
|
const isPrevDirection = direction === Direction.PREVIOUS
|
||||||
let activeIndex = this._getItemIndex(activeElement)
|
const activeIndex = this._getItemIndex(activeElement)
|
||||||
let lastItemIndex = (this._items.length - 1)
|
const lastItemIndex = this._items.length - 1
|
||||||
let isGoingToWrap = (isPrevDirection && activeIndex === 0) ||
|
const isGoingToWrap = isPrevDirection && activeIndex === 0 ||
|
||||||
(isNextDirection && activeIndex === lastItemIndex)
|
isNextDirection && activeIndex === lastItemIndex
|
||||||
|
|
||||||
if (isGoingToWrap && !this._config.wrap) {
|
if (isGoingToWrap && !this._config.wrap) {
|
||||||
return activeElement
|
return activeElement
|
||||||
}
|
}
|
||||||
|
|
||||||
let delta = direction === Direction.PREVIOUS ? -1 : 1
|
const delta = direction === Direction.PREVIOUS ? -1 : 1
|
||||||
let itemIndex = (activeIndex + delta) % this._items.length
|
const itemIndex = (activeIndex + delta) % this._items.length
|
||||||
|
|
||||||
return itemIndex === -1 ?
|
return itemIndex === -1 ?
|
||||||
this._items[this._items.length - 1] : this._items[itemIndex]
|
this._items[this._items.length - 1] : this._items[itemIndex]
|
||||||
@ -275,7 +276,7 @@ const Carousel = (($) => {
|
|||||||
|
|
||||||
|
|
||||||
_triggerSlideEvent(relatedTarget, directionalClassname) {
|
_triggerSlideEvent(relatedTarget, directionalClassname) {
|
||||||
let slideEvent = $.Event(Event.SLIDE, {
|
const slideEvent = $.Event(Event.SLIDE, {
|
||||||
relatedTarget,
|
relatedTarget,
|
||||||
direction: directionalClassname
|
direction: directionalClassname
|
||||||
})
|
})
|
||||||
@ -291,7 +292,7 @@ const Carousel = (($) => {
|
|||||||
.find(Selector.ACTIVE)
|
.find(Selector.ACTIVE)
|
||||||
.removeClass(ClassName.ACTIVE)
|
.removeClass(ClassName.ACTIVE)
|
||||||
|
|
||||||
let nextIndicator = this._indicatorsElement.children[
|
const nextIndicator = this._indicatorsElement.children[
|
||||||
this._getItemIndex(element)
|
this._getItemIndex(element)
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -302,13 +303,13 @@ const Carousel = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_slide(direction, element) {
|
_slide(direction, element) {
|
||||||
let activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]
|
const activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]
|
||||||
let nextElement = element || activeElement &&
|
const nextElement = element || activeElement &&
|
||||||
this._getItemByDirection(direction, 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.LEFT :
|
||||||
ClassName.RIGHT
|
ClassName.RIGHT
|
||||||
|
|
||||||
@ -317,7 +318,7 @@ const Carousel = (($) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let slideEvent = this._triggerSlideEvent(nextElement, directionalClassName)
|
const slideEvent = this._triggerSlideEvent(nextElement, directionalClassName)
|
||||||
if (slideEvent.isDefaultPrevented()) {
|
if (slideEvent.isDefaultPrevented()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -335,7 +336,7 @@ const Carousel = (($) => {
|
|||||||
|
|
||||||
this._setActiveIndicatorElement(nextElement)
|
this._setActiveIndicatorElement(nextElement)
|
||||||
|
|
||||||
let slidEvent = $.Event(Event.SLID, {
|
const slidEvent = $.Event(Event.SLID, {
|
||||||
relatedTarget: nextElement,
|
relatedTarget: nextElement,
|
||||||
direction: directionalClassName
|
direction: directionalClassName
|
||||||
})
|
})
|
||||||
@ -389,13 +390,13 @@ const Carousel = (($) => {
|
|||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let data = $(this).data(DATA_KEY)
|
let data = $(this).data(DATA_KEY)
|
||||||
let _config = $.extend({}, Default, $(this).data())
|
const _config = $.extend({}, Default, $(this).data())
|
||||||
|
|
||||||
if (typeof config === 'object') {
|
if (typeof config === 'object') {
|
||||||
$.extend(_config, config)
|
$.extend(_config, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
let action = typeof config === 'string' ? config : _config.slide
|
const action = typeof config === 'string' ? config : _config.slide
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Carousel(this, _config)
|
data = new Carousel(this, _config)
|
||||||
@ -417,20 +418,20 @@ const Carousel = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static _dataApiClickHandler(event) {
|
static _dataApiClickHandler(event) {
|
||||||
let selector = Util.getSelectorFromElement(this)
|
const selector = Util.getSelectorFromElement(this)
|
||||||
|
|
||||||
if (!selector) {
|
if (!selector) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let target = $(selector)[0]
|
const target = $(selector)[0]
|
||||||
|
|
||||||
if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
|
if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = $.extend({}, $(target).data(), $(this).data())
|
const config = $.extend({}, $(target).data(), $(this).data())
|
||||||
let slideIndex = this.getAttribute('data-slide-to')
|
const slideIndex = this.getAttribute('data-slide-to')
|
||||||
|
|
||||||
if (slideIndex) {
|
if (slideIndex) {
|
||||||
config.interval = false
|
config.interval = false
|
||||||
@ -459,7 +460,7 @@ const Carousel = (($) => {
|
|||||||
|
|
||||||
$(window).on(Event.LOAD_DATA_API, () => {
|
$(window).on(Event.LOAD_DATA_API, () => {
|
||||||
$(Selector.DATA_RIDE).each(function () {
|
$(Selector.DATA_RIDE).each(function () {
|
||||||
let $carousel = $(this)
|
const $carousel = $(this)
|
||||||
Carousel._jQueryInterface.call($carousel, $carousel.data())
|
Carousel._jQueryInterface.call($carousel, $carousel.data())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -134,7 +134,7 @@ const Collapse = (($) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let startEvent = $.Event(Event.SHOW)
|
const startEvent = $.Event(Event.SHOW)
|
||||||
$(this._element).trigger(startEvent)
|
$(this._element).trigger(startEvent)
|
||||||
if (startEvent.isDefaultPrevented()) {
|
if (startEvent.isDefaultPrevented()) {
|
||||||
return
|
return
|
||||||
@ -147,7 +147,7 @@ const Collapse = (($) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let dimension = this._getDimension()
|
const dimension = this._getDimension()
|
||||||
|
|
||||||
$(this._element)
|
$(this._element)
|
||||||
.removeClass(ClassName.COLLAPSE)
|
.removeClass(ClassName.COLLAPSE)
|
||||||
@ -164,7 +164,7 @@ const Collapse = (($) => {
|
|||||||
|
|
||||||
this.setTransitioning(true)
|
this.setTransitioning(true)
|
||||||
|
|
||||||
let complete = () => {
|
const complete = () => {
|
||||||
$(this._element)
|
$(this._element)
|
||||||
.removeClass(ClassName.COLLAPSING)
|
.removeClass(ClassName.COLLAPSING)
|
||||||
.addClass(ClassName.COLLAPSE)
|
.addClass(ClassName.COLLAPSE)
|
||||||
@ -182,8 +182,8 @@ const Collapse = (($) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
|
const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
|
||||||
let scrollSize = `scroll${capitalizedDimension}`
|
const scrollSize = `scroll${capitalizedDimension}`
|
||||||
|
|
||||||
$(this._element)
|
$(this._element)
|
||||||
.one(Util.TRANSITION_END, complete)
|
.one(Util.TRANSITION_END, complete)
|
||||||
@ -198,14 +198,14 @@ const Collapse = (($) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let startEvent = $.Event(Event.HIDE)
|
const startEvent = $.Event(Event.HIDE)
|
||||||
$(this._element).trigger(startEvent)
|
$(this._element).trigger(startEvent)
|
||||||
if (startEvent.isDefaultPrevented()) {
|
if (startEvent.isDefaultPrevented()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let dimension = this._getDimension()
|
const dimension = this._getDimension()
|
||||||
let offsetDimension = dimension === Dimension.WIDTH ?
|
const offsetDimension = dimension === Dimension.WIDTH ?
|
||||||
'offsetWidth' : 'offsetHeight'
|
'offsetWidth' : 'offsetHeight'
|
||||||
|
|
||||||
this._element.style[dimension] = `${this._element[offsetDimension]}px`
|
this._element.style[dimension] = `${this._element[offsetDimension]}px`
|
||||||
@ -227,7 +227,7 @@ const Collapse = (($) => {
|
|||||||
|
|
||||||
this.setTransitioning(true)
|
this.setTransitioning(true)
|
||||||
|
|
||||||
let complete = () => {
|
const complete = () => {
|
||||||
this.setTransitioning(false)
|
this.setTransitioning(false)
|
||||||
$(this._element)
|
$(this._element)
|
||||||
.removeClass(ClassName.COLLAPSING)
|
.removeClass(ClassName.COLLAPSING)
|
||||||
@ -272,13 +272,13 @@ const Collapse = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getDimension() {
|
_getDimension() {
|
||||||
let hasWidth = $(this._element).hasClass(Dimension.WIDTH)
|
const hasWidth = $(this._element).hasClass(Dimension.WIDTH)
|
||||||
return hasWidth ? Dimension.WIDTH : Dimension.HEIGHT
|
return hasWidth ? Dimension.WIDTH : Dimension.HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
_getParent() {
|
_getParent() {
|
||||||
let parent = $(this._config.parent)[0]
|
const parent = $(this._config.parent)[0]
|
||||||
let selector =
|
const selector =
|
||||||
`[data-toggle="collapse"][data-parent="${this._config.parent}"]`
|
`[data-toggle="collapse"][data-parent="${this._config.parent}"]`
|
||||||
|
|
||||||
$(parent).find(selector).each((i, element) => {
|
$(parent).find(selector).each((i, element) => {
|
||||||
@ -293,7 +293,7 @@ const Collapse = (($) => {
|
|||||||
|
|
||||||
_addAriaAndCollapsedClass(element, triggerArray) {
|
_addAriaAndCollapsedClass(element, triggerArray) {
|
||||||
if (element) {
|
if (element) {
|
||||||
let isOpen = $(element).hasClass(ClassName.ACTIVE)
|
const isOpen = $(element).hasClass(ClassName.ACTIVE)
|
||||||
element.setAttribute('aria-expanded', isOpen)
|
element.setAttribute('aria-expanded', isOpen)
|
||||||
|
|
||||||
if (triggerArray.length) {
|
if (triggerArray.length) {
|
||||||
@ -308,15 +308,15 @@ const Collapse = (($) => {
|
|||||||
// static
|
// static
|
||||||
|
|
||||||
static _getTargetFromElement(element) {
|
static _getTargetFromElement(element) {
|
||||||
let selector = Util.getSelectorFromElement(element)
|
const selector = Util.getSelectorFromElement(element)
|
||||||
return selector ? $(selector)[0] : null
|
return selector ? $(selector)[0] : null
|
||||||
}
|
}
|
||||||
|
|
||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let $this = $(this)
|
const $this = $(this)
|
||||||
let data = $this.data(DATA_KEY)
|
let data = $this.data(DATA_KEY)
|
||||||
let _config = $.extend(
|
const _config = $.extend(
|
||||||
{},
|
{},
|
||||||
Default,
|
Default,
|
||||||
$this.data(),
|
$this.data(),
|
||||||
@ -353,9 +353,9 @@ const Collapse = (($) => {
|
|||||||
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
|
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
let target = Collapse._getTargetFromElement(this)
|
const target = Collapse._getTargetFromElement(this)
|
||||||
let data = $(target).data(DATA_KEY)
|
const data = $(target).data(DATA_KEY)
|
||||||
let config = data ? 'toggle' : $(this).data()
|
const config = data ? 'toggle' : $(this).data()
|
||||||
|
|
||||||
Collapse._jQueryInterface.call($(target), config)
|
Collapse._jQueryInterface.call($(target), config)
|
||||||
})
|
})
|
||||||
|
@ -85,8 +85,8 @@ const Dropdown = (($) => {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
let parent = Dropdown._getParentFromElement(this)
|
const parent = Dropdown._getParentFromElement(this)
|
||||||
let isActive = $(parent).hasClass(ClassName.ACTIVE)
|
const isActive = $(parent).hasClass(ClassName.ACTIVE)
|
||||||
|
|
||||||
Dropdown._clearMenus()
|
Dropdown._clearMenus()
|
||||||
|
|
||||||
@ -95,17 +95,19 @@ const Dropdown = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('ontouchstart' in document.documentElement &&
|
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
|
// 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.className = ClassName.BACKDROP
|
||||||
$(dropdown).insertBefore(this)
|
$(dropdown).insertBefore(this)
|
||||||
$(dropdown).on('click', Dropdown._clearMenus)
|
$(dropdown).on('click', Dropdown._clearMenus)
|
||||||
}
|
}
|
||||||
|
|
||||||
let relatedTarget = { relatedTarget : this }
|
const relatedTarget = {
|
||||||
let showEvent = $.Event(Event.SHOW, relatedTarget)
|
relatedTarget : this
|
||||||
|
}
|
||||||
|
const showEvent = $.Event(Event.SHOW, relatedTarget)
|
||||||
|
|
||||||
$(parent).trigger(showEvent)
|
$(parent).trigger(showEvent)
|
||||||
|
|
||||||
@ -114,7 +116,7 @@ const Dropdown = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.focus()
|
this.focus()
|
||||||
this.setAttribute('aria-expanded', 'true')
|
this.setAttribute('aria-expanded', true)
|
||||||
|
|
||||||
$(parent).toggleClass(ClassName.ACTIVE)
|
$(parent).toggleClass(ClassName.ACTIVE)
|
||||||
$(parent).trigger($.Event(Event.SHOWN, relatedTarget))
|
$(parent).trigger($.Event(Event.SHOWN, relatedTarget))
|
||||||
@ -140,10 +142,11 @@ const Dropdown = (($) => {
|
|||||||
|
|
||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let data = $(this).data(DATA_KEY)
|
let data = $(this).data(DATA_KEY)
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
$(this).data(DATA_KEY, (data = new Dropdown(this)))
|
data = new Dropdown(this)
|
||||||
|
$(this).data(DATA_KEY, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
@ -160,28 +163,30 @@ const Dropdown = (($) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let backdrop = $(Selector.BACKDROP)[0]
|
const backdrop = $(Selector.BACKDROP)[0]
|
||||||
if (backdrop) {
|
if (backdrop) {
|
||||||
backdrop.parentNode.removeChild(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++) {
|
for (let i = 0; i < toggles.length; i++) {
|
||||||
let parent = Dropdown._getParentFromElement(toggles[i])
|
const parent = Dropdown._getParentFromElement(toggles[i])
|
||||||
let relatedTarget = { relatedTarget : toggles[i] }
|
const relatedTarget = {
|
||||||
|
relatedTarget : toggles[i]
|
||||||
|
}
|
||||||
|
|
||||||
if (!$(parent).hasClass(ClassName.ACTIVE)) {
|
if (!$(parent).hasClass(ClassName.ACTIVE)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event && event.type === 'click' &&
|
if (event && event.type === 'click' &&
|
||||||
(/input|textarea/i.test(event.target.tagName)) &&
|
/input|textarea/i.test(event.target.tagName) &&
|
||||||
($.contains(parent, event.target))) {
|
$.contains(parent, event.target)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
let hideEvent = $.Event(Event.HIDE, relatedTarget)
|
const hideEvent = $.Event(Event.HIDE, relatedTarget)
|
||||||
$(parent).trigger(hideEvent)
|
$(parent).trigger(hideEvent)
|
||||||
if (hideEvent.isDefaultPrevented()) {
|
if (hideEvent.isDefaultPrevented()) {
|
||||||
continue
|
continue
|
||||||
@ -197,7 +202,7 @@ const Dropdown = (($) => {
|
|||||||
|
|
||||||
static _getParentFromElement(element) {
|
static _getParentFromElement(element) {
|
||||||
let parent
|
let parent
|
||||||
let selector = Util.getSelectorFromElement(element)
|
const selector = Util.getSelectorFromElement(element)
|
||||||
|
|
||||||
if (selector) {
|
if (selector) {
|
||||||
parent = $(selector)[0]
|
parent = $(selector)[0]
|
||||||
@ -219,14 +224,14 @@ const Dropdown = (($) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let parent = Dropdown._getParentFromElement(this)
|
const parent = Dropdown._getParentFromElement(this)
|
||||||
let isActive = $(parent).hasClass(ClassName.ACTIVE)
|
const isActive = $(parent).hasClass(ClassName.ACTIVE)
|
||||||
|
|
||||||
if ((!isActive && event.which !== ESCAPE_KEYCODE) ||
|
if (!isActive && event.which !== ESCAPE_KEYCODE ||
|
||||||
(isActive && event.which === ESCAPE_KEYCODE)) {
|
isActive && event.which === ESCAPE_KEYCODE) {
|
||||||
|
|
||||||
if (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')
|
$(toggle).trigger('focus')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ const Modal = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show(relatedTarget) {
|
show(relatedTarget) {
|
||||||
let showEvent = $.Event(Event.SHOW, {
|
const showEvent = $.Event(Event.SHOW, {
|
||||||
relatedTarget
|
relatedTarget
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ const Modal = (($) => {
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
let hideEvent = $.Event(Event.HIDE)
|
const hideEvent = $.Event(Event.HIDE)
|
||||||
|
|
||||||
$(this._element).trigger(hideEvent)
|
$(this._element).trigger(hideEvent)
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ const Modal = (($) => {
|
|||||||
$(this._dialog).off(Event.MOUSEDOWN_DISMISS)
|
$(this._dialog).off(Event.MOUSEDOWN_DISMISS)
|
||||||
|
|
||||||
if (Util.supportsTransitionEnd() &&
|
if (Util.supportsTransitionEnd() &&
|
||||||
($(this._element).hasClass(ClassName.FADE))) {
|
$(this._element).hasClass(ClassName.FADE)) {
|
||||||
|
|
||||||
$(this._element)
|
$(this._element)
|
||||||
.one(Util.TRANSITION_END, (event) => this._hideModal(event))
|
.one(Util.TRANSITION_END, (event) => this._hideModal(event))
|
||||||
@ -212,11 +212,11 @@ const Modal = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_showElement(relatedTarget) {
|
_showElement(relatedTarget) {
|
||||||
let transition = Util.supportsTransitionEnd() &&
|
const transition = Util.supportsTransitionEnd() &&
|
||||||
$(this._element).hasClass(ClassName.FADE)
|
$(this._element).hasClass(ClassName.FADE)
|
||||||
|
|
||||||
if (!this._element.parentNode ||
|
if (!this._element.parentNode ||
|
||||||
(this._element.parentNode.nodeType !== Node.ELEMENT_NODE)) {
|
this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
|
||||||
// don't move modals dom position
|
// don't move modals dom position
|
||||||
document.body.appendChild(this._element)
|
document.body.appendChild(this._element)
|
||||||
}
|
}
|
||||||
@ -235,11 +235,11 @@ const Modal = (($) => {
|
|||||||
this._enforceFocus()
|
this._enforceFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
let shownEvent = $.Event(Event.SHOWN, {
|
const shownEvent = $.Event(Event.SHOWN, {
|
||||||
relatedTarget
|
relatedTarget
|
||||||
})
|
})
|
||||||
|
|
||||||
let transitionComplete = () => {
|
const transitionComplete = () => {
|
||||||
if (this._config.focus) {
|
if (this._config.focus) {
|
||||||
this._element.focus()
|
this._element.focus()
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ const Modal = (($) => {
|
|||||||
.on(Event.FOCUSIN, (event) => {
|
.on(Event.FOCUSIN, (event) => {
|
||||||
if (document !== event.target &&
|
if (document !== event.target &&
|
||||||
this._element !== event.target &&
|
this._element !== event.target &&
|
||||||
(!$(this._element).has(event.target).length)) {
|
!$(this._element).has(event.target).length) {
|
||||||
this._element.focus()
|
this._element.focus()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -290,7 +290,7 @@ const Modal = (($) => {
|
|||||||
|
|
||||||
_hideModal() {
|
_hideModal() {
|
||||||
this._element.style.display = 'none'
|
this._element.style.display = 'none'
|
||||||
this._element.setAttribute('aria-hidden', 'true')
|
this._element.setAttribute('aria-hidden', true)
|
||||||
this._showBackdrop(() => {
|
this._showBackdrop(() => {
|
||||||
$(document.body).removeClass(ClassName.OPEN)
|
$(document.body).removeClass(ClassName.OPEN)
|
||||||
this._resetAdjustments()
|
this._resetAdjustments()
|
||||||
@ -307,11 +307,11 @@ const Modal = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_showBackdrop(callback) {
|
_showBackdrop(callback) {
|
||||||
let animate = $(this._element).hasClass(ClassName.FADE) ?
|
const animate = $(this._element).hasClass(ClassName.FADE) ?
|
||||||
ClassName.FADE : ''
|
ClassName.FADE : ''
|
||||||
|
|
||||||
if (this._isShown && this._config.backdrop) {
|
if (this._isShown && this._config.backdrop) {
|
||||||
let doAnimate = Util.supportsTransitionEnd() && animate
|
const doAnimate = Util.supportsTransitionEnd() && animate
|
||||||
|
|
||||||
this._backdrop = document.createElement('div')
|
this._backdrop = document.createElement('div')
|
||||||
this._backdrop.className = ClassName.BACKDROP
|
this._backdrop.className = ClassName.BACKDROP
|
||||||
@ -359,7 +359,7 @@ const Modal = (($) => {
|
|||||||
} else if (!this._isShown && this._backdrop) {
|
} else if (!this._isShown && this._backdrop) {
|
||||||
$(this._backdrop).removeClass(ClassName.ACTIVE)
|
$(this._backdrop).removeClass(ClassName.ACTIVE)
|
||||||
|
|
||||||
let callbackRemove = () => {
|
const callbackRemove = () => {
|
||||||
this._removeBackdrop()
|
this._removeBackdrop()
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback()
|
callback()
|
||||||
@ -367,7 +367,7 @@ const Modal = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Util.supportsTransitionEnd() &&
|
if (Util.supportsTransitionEnd() &&
|
||||||
($(this._element).hasClass(ClassName.FADE))) {
|
$(this._element).hasClass(ClassName.FADE)) {
|
||||||
$(this._backdrop)
|
$(this._backdrop)
|
||||||
.one(Util.TRANSITION_END, callbackRemove)
|
.one(Util.TRANSITION_END, callbackRemove)
|
||||||
.emulateTransitionEnd(BACKDROP_TRANSITION_DURATION)
|
.emulateTransitionEnd(BACKDROP_TRANSITION_DURATION)
|
||||||
@ -391,7 +391,7 @@ const Modal = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_adjustDialog() {
|
_adjustDialog() {
|
||||||
let isModalOverflowing =
|
const isModalOverflowing =
|
||||||
this._element.scrollHeight > document.documentElement.clientHeight
|
this._element.scrollHeight > document.documentElement.clientHeight
|
||||||
|
|
||||||
if (!this._isBodyOverflowing && isModalOverflowing) {
|
if (!this._isBodyOverflowing && isModalOverflowing) {
|
||||||
@ -414,7 +414,7 @@ const Modal = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_setScrollbar() {
|
_setScrollbar() {
|
||||||
let bodyPadding = parseInt(
|
const bodyPadding = parseInt(
|
||||||
$(Selector.FIXED_CONTENT).css('padding-right') || 0,
|
$(Selector.FIXED_CONTENT).css('padding-right') || 0,
|
||||||
10
|
10
|
||||||
)
|
)
|
||||||
@ -432,10 +432,10 @@ const Modal = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getScrollbarWidth() { // thx d.walsh
|
_getScrollbarWidth() { // thx d.walsh
|
||||||
let scrollDiv = document.createElement('div')
|
const scrollDiv = document.createElement('div')
|
||||||
scrollDiv.className = ClassName.SCROLLBAR_MEASURER
|
scrollDiv.className = ClassName.SCROLLBAR_MEASURER
|
||||||
document.body.appendChild(scrollDiv)
|
document.body.appendChild(scrollDiv)
|
||||||
let scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
|
const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
|
||||||
document.body.removeChild(scrollDiv)
|
document.body.removeChild(scrollDiv)
|
||||||
return scrollbarWidth
|
return scrollbarWidth
|
||||||
}
|
}
|
||||||
@ -445,8 +445,8 @@ const Modal = (($) => {
|
|||||||
|
|
||||||
static _jQueryInterface(config, relatedTarget) {
|
static _jQueryInterface(config, relatedTarget) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let data = $(this).data(DATA_KEY)
|
let data = $(this).data(DATA_KEY)
|
||||||
let _config = $.extend(
|
const _config = $.extend(
|
||||||
{},
|
{},
|
||||||
Modal.Default,
|
Modal.Default,
|
||||||
$(this).data(),
|
$(this).data(),
|
||||||
@ -480,20 +480,20 @@ const Modal = (($) => {
|
|||||||
|
|
||||||
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
|
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
|
||||||
let target
|
let target
|
||||||
let selector = Util.getSelectorFromElement(this)
|
const selector = Util.getSelectorFromElement(this)
|
||||||
|
|
||||||
if (selector) {
|
if (selector) {
|
||||||
target = $(selector)[0]
|
target = $(selector)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = $(target).data(DATA_KEY) ?
|
const config = $(target).data(DATA_KEY) ?
|
||||||
'toggle' : $.extend({}, $(target).data(), $(this).data())
|
'toggle' : $.extend({}, $(target).data(), $(this).data())
|
||||||
|
|
||||||
if (this.tagName === 'A') {
|
if (this.tagName === 'A') {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
let $target = $(target).one(Event.SHOW, (showEvent) => {
|
const $target = $(target).one(Event.SHOW, (showEvent) => {
|
||||||
if (showEvent.isDefaultPrevented()) {
|
if (showEvent.isDefaultPrevented()) {
|
||||||
// only register focus restorer if modal will actually get shown
|
// only register focus restorer if modal will actually get shown
|
||||||
return
|
return
|
||||||
|
@ -107,11 +107,11 @@ const Popover = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTipElement() {
|
getTipElement() {
|
||||||
return (this.tip = this.tip || $(this.config.template)[0])
|
return this.tip = this.tip || $(this.config.template)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
setContent() {
|
setContent() {
|
||||||
let $tip = $(this.getTipElement())
|
const $tip = $(this.getTipElement())
|
||||||
|
|
||||||
// we use append for html objects to maintain js events
|
// we use append for html objects to maintain js events
|
||||||
this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
|
this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
|
||||||
@ -138,8 +138,8 @@ const Popover = (($) => {
|
|||||||
|
|
||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let data = $(this).data(DATA_KEY)
|
let data = $(this).data(DATA_KEY)
|
||||||
let _config = typeof config === 'object' ? config : null
|
const _config = typeof config === 'object' ? config : null
|
||||||
|
|
||||||
if (!data && /destroy|hide/.test(config)) {
|
if (!data && /destroy|hide/.test(config)) {
|
||||||
return
|
return
|
||||||
|
@ -108,13 +108,13 @@ const ScrollSpy = (($) => {
|
|||||||
// public
|
// public
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
let autoMethod = this._scrollElement !== this._scrollElement.window ?
|
const autoMethod = this._scrollElement !== this._scrollElement.window ?
|
||||||
OffsetMethod.POSITION : OffsetMethod.OFFSET
|
OffsetMethod.POSITION : OffsetMethod.OFFSET
|
||||||
|
|
||||||
let offsetMethod = this._config.method === 'auto' ?
|
const offsetMethod = this._config.method === 'auto' ?
|
||||||
autoMethod : this._config.method
|
autoMethod : this._config.method
|
||||||
|
|
||||||
let offsetBase = offsetMethod === OffsetMethod.POSITION ?
|
const offsetBase = offsetMethod === OffsetMethod.POSITION ?
|
||||||
this._getScrollTop() : 0
|
this._getScrollTop() : 0
|
||||||
|
|
||||||
this._offsets = []
|
this._offsets = []
|
||||||
@ -122,12 +122,12 @@ const ScrollSpy = (($) => {
|
|||||||
|
|
||||||
this._scrollHeight = this._getScrollHeight()
|
this._scrollHeight = this._getScrollHeight()
|
||||||
|
|
||||||
let targets = $.makeArray($(this._selector))
|
const targets = $.makeArray($(this._selector))
|
||||||
|
|
||||||
targets
|
targets
|
||||||
.map((element) => {
|
.map((element) => {
|
||||||
let target
|
let target
|
||||||
let targetSelector = Util.getSelectorFromElement(element)
|
const targetSelector = Util.getSelectorFromElement(element)
|
||||||
|
|
||||||
if (targetSelector) {
|
if (targetSelector) {
|
||||||
target = $(targetSelector)[0]
|
target = $(targetSelector)[0]
|
||||||
@ -197,9 +197,9 @@ const ScrollSpy = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_process() {
|
_process() {
|
||||||
let scrollTop = this._getScrollTop() + this._config.offset
|
const scrollTop = this._getScrollTop() + this._config.offset
|
||||||
let scrollHeight = this._getScrollHeight()
|
const scrollHeight = this._getScrollHeight()
|
||||||
let maxScroll = this._config.offset
|
const maxScroll = this._config.offset
|
||||||
+ scrollHeight
|
+ scrollHeight
|
||||||
- this._scrollElement.offsetHeight
|
- this._scrollElement.offsetHeight
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ const ScrollSpy = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scrollTop >= maxScroll) {
|
if (scrollTop >= maxScroll) {
|
||||||
let target = this._targets[this._targets.length - 1]
|
const target = this._targets[this._targets.length - 1]
|
||||||
|
|
||||||
if (this._activeTarget !== target) {
|
if (this._activeTarget !== target) {
|
||||||
this._activate(target)
|
this._activate(target)
|
||||||
@ -222,7 +222,7 @@ const ScrollSpy = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = this._offsets.length; i--;) {
|
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]
|
&& scrollTop >= this._offsets[i]
|
||||||
&& (this._offsets[i + 1] === undefined ||
|
&& (this._offsets[i + 1] === undefined ||
|
||||||
scrollTop < this._offsets[i + 1])
|
scrollTop < this._offsets[i + 1])
|
||||||
@ -244,7 +244,7 @@ const ScrollSpy = (($) => {
|
|||||||
`${selector}[href="${target}"]`
|
`${selector}[href="${target}"]`
|
||||||
})
|
})
|
||||||
|
|
||||||
let $link = $(queries.join(','))
|
const $link = $(queries.join(','))
|
||||||
|
|
||||||
if ($link.hasClass(ClassName.DROPDOWN_ITEM)) {
|
if ($link.hasClass(ClassName.DROPDOWN_ITEM)) {
|
||||||
$link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE)
|
$link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE)
|
||||||
@ -269,8 +269,8 @@ const ScrollSpy = (($) => {
|
|||||||
|
|
||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let data = $(this).data(DATA_KEY)
|
let data = $(this).data(DATA_KEY)
|
||||||
let _config = typeof config === 'object' && config || null
|
const _config = typeof config === 'object' && config
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new ScrollSpy(this, _config)
|
data = new ScrollSpy(this, _config)
|
||||||
@ -297,10 +297,10 @@ const ScrollSpy = (($) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$(window).on(Event.LOAD_DATA_API, () => {
|
$(window).on(Event.LOAD_DATA_API, () => {
|
||||||
let scrollSpys = $.makeArray($(Selector.DATA_SPY))
|
const scrollSpys = $.makeArray($(Selector.DATA_SPY))
|
||||||
|
|
||||||
for (let i = scrollSpys.length; i--;) {
|
for (let i = scrollSpys.length; i--;) {
|
||||||
let $spy = $(scrollSpys[i])
|
const $spy = $(scrollSpys[i])
|
||||||
ScrollSpy._jQueryInterface.call($spy, $spy.data())
|
ScrollSpy._jQueryInterface.call($spy, $spy.data())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -78,26 +78,26 @@ const Tab = (($) => {
|
|||||||
|
|
||||||
show() {
|
show() {
|
||||||
if (this._element.parentNode &&
|
if (this._element.parentNode &&
|
||||||
(this._element.parentNode.nodeType === Node.ELEMENT_NODE) &&
|
this._element.parentNode.nodeType === Node.ELEMENT_NODE &&
|
||||||
($(this._element).hasClass(ClassName.ACTIVE))) {
|
$(this._element).hasClass(ClassName.ACTIVE)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let target
|
let target
|
||||||
let previous
|
let previous
|
||||||
let listElement = $(this._element).closest(Selector.LIST)[0]
|
const listElement = $(this._element).closest(Selector.LIST)[0]
|
||||||
let selector = Util.getSelectorFromElement(this._element)
|
const selector = Util.getSelectorFromElement(this._element)
|
||||||
|
|
||||||
if (listElement) {
|
if (listElement) {
|
||||||
previous = $.makeArray($(listElement).find(Selector.ACTIVE))
|
previous = $.makeArray($(listElement).find(Selector.ACTIVE))
|
||||||
previous = previous[previous.length - 1]
|
previous = previous[previous.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
let hideEvent = $.Event(Event.HIDE, {
|
const hideEvent = $.Event(Event.HIDE, {
|
||||||
relatedTarget: this._element
|
relatedTarget: this._element
|
||||||
})
|
})
|
||||||
|
|
||||||
let showEvent = $.Event(Event.SHOW, {
|
const showEvent = $.Event(Event.SHOW, {
|
||||||
relatedTarget: previous
|
relatedTarget: previous
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ const Tab = (($) => {
|
|||||||
$(this._element).trigger(showEvent)
|
$(this._element).trigger(showEvent)
|
||||||
|
|
||||||
if (showEvent.isDefaultPrevented() ||
|
if (showEvent.isDefaultPrevented() ||
|
||||||
(hideEvent.isDefaultPrevented())) {
|
hideEvent.isDefaultPrevented()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,12 +121,12 @@ const Tab = (($) => {
|
|||||||
listElement
|
listElement
|
||||||
)
|
)
|
||||||
|
|
||||||
let complete = () => {
|
const complete = () => {
|
||||||
let hiddenEvent = $.Event(Event.HIDDEN, {
|
const hiddenEvent = $.Event(Event.HIDDEN, {
|
||||||
relatedTarget: this._element
|
relatedTarget: this._element
|
||||||
})
|
})
|
||||||
|
|
||||||
let shownEvent = $.Event(Event.SHOWN, {
|
const shownEvent = $.Event(Event.SHOWN, {
|
||||||
relatedTarget: previous
|
relatedTarget: previous
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -150,13 +150,13 @@ const Tab = (($) => {
|
|||||||
// private
|
// private
|
||||||
|
|
||||||
_activate(element, container, callback) {
|
_activate(element, container, callback) {
|
||||||
let active = $(container).find(Selector.ACTIVE_CHILD)[0]
|
const active = $(container).find(Selector.ACTIVE_CHILD)[0]
|
||||||
let isTransitioning = callback
|
const isTransitioning = callback
|
||||||
&& Util.supportsTransitionEnd()
|
&& Util.supportsTransitionEnd()
|
||||||
&& ((active && $(active).hasClass(ClassName.FADE))
|
&& (active && $(active).hasClass(ClassName.FADE)
|
||||||
|| Boolean($(container).find(Selector.FADE_CHILD)[0]))
|
|| Boolean($(container).find(Selector.FADE_CHILD)[0]))
|
||||||
|
|
||||||
let complete = () => this._transitionComplete(
|
const complete = () => this._transitionComplete(
|
||||||
element,
|
element,
|
||||||
active,
|
active,
|
||||||
isTransitioning,
|
isTransitioning,
|
||||||
@ -181,7 +181,7 @@ const Tab = (($) => {
|
|||||||
if (active) {
|
if (active) {
|
||||||
$(active).removeClass(ClassName.ACTIVE)
|
$(active).removeClass(ClassName.ACTIVE)
|
||||||
|
|
||||||
let dropdownChild = $(active).find(
|
const dropdownChild = $(active).find(
|
||||||
Selector.DROPDOWN_ACTIVE_CHILD
|
Selector.DROPDOWN_ACTIVE_CHILD
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
@ -203,9 +203,9 @@ const Tab = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element.parentNode &&
|
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) {
|
if (dropdownElement) {
|
||||||
$(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE)
|
$(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE)
|
||||||
}
|
}
|
||||||
@ -223,11 +223,11 @@ const Tab = (($) => {
|
|||||||
|
|
||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let $this = $(this)
|
const $this = $(this)
|
||||||
let data = $this.data(DATA_KEY)
|
let data = $this.data(DATA_KEY)
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = data = new Tab(this)
|
data = new Tab(this)
|
||||||
$this.data(DATA_KEY, data)
|
$this.data(DATA_KEY, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,11 +121,11 @@ const Tooltip = (($) => {
|
|||||||
constructor(element, config) {
|
constructor(element, config) {
|
||||||
|
|
||||||
// private
|
// private
|
||||||
this._isEnabled = true
|
this._isEnabled = true
|
||||||
this._timeout = 0
|
this._timeout = 0
|
||||||
this._hoverState = ''
|
this._hoverState = ''
|
||||||
this._activeTrigger = {}
|
this._activeTrigger = {}
|
||||||
this._tether = null
|
this._tether = null
|
||||||
|
|
||||||
// protected
|
// protected
|
||||||
this.element = element
|
this.element = element
|
||||||
@ -184,7 +184,7 @@ const Tooltip = (($) => {
|
|||||||
|
|
||||||
toggle(event) {
|
toggle(event) {
|
||||||
if (event) {
|
if (event) {
|
||||||
let dataKey = this.constructor.DATA_KEY
|
const dataKey = this.constructor.DATA_KEY
|
||||||
let context = $(event.currentTarget).data(dataKey)
|
let context = $(event.currentTarget).data(dataKey)
|
||||||
|
|
||||||
if (!context) {
|
if (!context) {
|
||||||
@ -227,11 +227,11 @@ const Tooltip = (($) => {
|
|||||||
$(this.tip).remove()
|
$(this.tip).remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
this._isEnabled = null
|
this._isEnabled = null
|
||||||
this._timeout = null
|
this._timeout = null
|
||||||
this._hoverState = null
|
this._hoverState = null
|
||||||
this._activeTrigger = null
|
this._activeTrigger = null
|
||||||
this._tether = null
|
this._tether = null
|
||||||
|
|
||||||
this.element = null
|
this.element = null
|
||||||
this.config = null
|
this.config = null
|
||||||
@ -242,12 +242,12 @@ const Tooltip = (($) => {
|
|||||||
if ($(this.element).css('display') === 'none') {
|
if ($(this.element).css('display') === 'none') {
|
||||||
throw new Error('Please use show on visible elements')
|
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) {
|
if (this.isWithContent() && this._isEnabled) {
|
||||||
$(this.element).trigger(showEvent)
|
$(this.element).trigger(showEvent)
|
||||||
|
|
||||||
let isInTheDom = $.contains(
|
const isInTheDom = $.contains(
|
||||||
this.element.ownerDocument.documentElement,
|
this.element.ownerDocument.documentElement,
|
||||||
this.element
|
this.element
|
||||||
)
|
)
|
||||||
@ -256,8 +256,8 @@ const Tooltip = (($) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let tip = this.getTipElement()
|
const tip = this.getTipElement()
|
||||||
let tipId = Util.getUID(this.constructor.NAME)
|
const tipId = Util.getUID(this.constructor.NAME)
|
||||||
|
|
||||||
tip.setAttribute('id', tipId)
|
tip.setAttribute('id', tipId)
|
||||||
this.element.setAttribute('aria-describedby', tipId)
|
this.element.setAttribute('aria-describedby', tipId)
|
||||||
@ -268,11 +268,11 @@ const Tooltip = (($) => {
|
|||||||
$(tip).addClass(ClassName.FADE)
|
$(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.call(this, tip, this.element) :
|
||||||
this.config.placement
|
this.config.placement
|
||||||
|
|
||||||
let attachment = this._getAttachment(placement)
|
const attachment = this._getAttachment(placement)
|
||||||
|
|
||||||
$(tip)
|
$(tip)
|
||||||
.data(this.constructor.DATA_KEY, this)
|
.data(this.constructor.DATA_KEY, this)
|
||||||
@ -296,9 +296,9 @@ const Tooltip = (($) => {
|
|||||||
|
|
||||||
$(tip).addClass(ClassName.ACTIVE)
|
$(tip).addClass(ClassName.ACTIVE)
|
||||||
|
|
||||||
let complete = () => {
|
const complete = () => {
|
||||||
let prevHoverState = this._hoverState
|
const prevHoverState = this._hoverState
|
||||||
this._hoverState = null
|
this._hoverState = null
|
||||||
|
|
||||||
$(this.element).trigger(this.constructor.Event.SHOWN)
|
$(this.element).trigger(this.constructor.Event.SHOWN)
|
||||||
|
|
||||||
@ -319,9 +319,9 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hide(callback) {
|
hide(callback) {
|
||||||
let tip = this.getTipElement()
|
const tip = this.getTipElement()
|
||||||
let hideEvent = $.Event(this.constructor.Event.HIDE)
|
const hideEvent = $.Event(this.constructor.Event.HIDE)
|
||||||
let complete = () => {
|
const complete = () => {
|
||||||
if (this._hoverState !== HoverState.ACTIVE && tip.parentNode) {
|
if (this._hoverState !== HoverState.ACTIVE && tip.parentNode) {
|
||||||
tip.parentNode.removeChild(tip)
|
tip.parentNode.removeChild(tip)
|
||||||
}
|
}
|
||||||
@ -344,7 +344,7 @@ const Tooltip = (($) => {
|
|||||||
$(tip).removeClass(ClassName.ACTIVE)
|
$(tip).removeClass(ClassName.ACTIVE)
|
||||||
|
|
||||||
if (Util.supportsTransitionEnd() &&
|
if (Util.supportsTransitionEnd() &&
|
||||||
($(this.tip).hasClass(ClassName.FADE))) {
|
$(this.tip).hasClass(ClassName.FADE)) {
|
||||||
|
|
||||||
$(tip)
|
$(tip)
|
||||||
.one(Util.TRANSITION_END, complete)
|
.one(Util.TRANSITION_END, complete)
|
||||||
@ -365,11 +365,11 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTipElement() {
|
getTipElement() {
|
||||||
return (this.tip = this.tip || $(this.config.template)[0])
|
return this.tip = this.tip || $(this.config.template)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
setContent() {
|
setContent() {
|
||||||
let $tip = $(this.getTipElement())
|
const $tip = $(this.getTipElement())
|
||||||
|
|
||||||
this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle())
|
this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle())
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setElementContent($element, content) {
|
setElementContent($element, content) {
|
||||||
let html = this.config.html
|
const html = this.config.html
|
||||||
if (typeof content === 'object' && (content.nodeType || content.jquery)) {
|
if (typeof content === 'object' && (content.nodeType || content.jquery)) {
|
||||||
// content is a DOM node or a jQuery
|
// content is a DOM node or a jQuery
|
||||||
if (html) {
|
if (html) {
|
||||||
@ -422,7 +422,7 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_setListeners() {
|
_setListeners() {
|
||||||
let triggers = this.config.trigger.split(' ')
|
const triggers = this.config.trigger.split(' ')
|
||||||
|
|
||||||
triggers.forEach((trigger) => {
|
triggers.forEach((trigger) => {
|
||||||
if (trigger === 'click') {
|
if (trigger === 'click') {
|
||||||
@ -433,10 +433,10 @@ const Tooltip = (($) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
} else if (trigger !== Trigger.MANUAL) {
|
} else if (trigger !== Trigger.MANUAL) {
|
||||||
let eventIn = trigger === Trigger.HOVER ?
|
const eventIn = trigger === Trigger.HOVER ?
|
||||||
this.constructor.Event.MOUSEENTER :
|
this.constructor.Event.MOUSEENTER :
|
||||||
this.constructor.Event.FOCUSIN
|
this.constructor.Event.FOCUSIN
|
||||||
let eventOut = trigger === Trigger.HOVER ?
|
const eventOut = trigger === Trigger.HOVER ?
|
||||||
this.constructor.Event.MOUSELEAVE :
|
this.constructor.Event.MOUSELEAVE :
|
||||||
this.constructor.Event.FOCUSOUT
|
this.constructor.Event.FOCUSOUT
|
||||||
|
|
||||||
@ -465,9 +465,9 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fixTitle() {
|
_fixTitle() {
|
||||||
let titleType = typeof this.element.getAttribute('data-original-title')
|
const titleType = typeof this.element.getAttribute('data-original-title')
|
||||||
if (this.element.getAttribute('title') ||
|
if (this.element.getAttribute('title') ||
|
||||||
(titleType !== 'string')) {
|
titleType !== 'string') {
|
||||||
this.element.setAttribute(
|
this.element.setAttribute(
|
||||||
'data-original-title',
|
'data-original-title',
|
||||||
this.element.getAttribute('title') || ''
|
this.element.getAttribute('title') || ''
|
||||||
@ -477,7 +477,7 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_enter(event, context) {
|
_enter(event, context) {
|
||||||
let dataKey = this.constructor.DATA_KEY
|
const dataKey = this.constructor.DATA_KEY
|
||||||
|
|
||||||
context = context || $(event.currentTarget).data(dataKey)
|
context = context || $(event.currentTarget).data(dataKey)
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($(context.getTipElement()).hasClass(ClassName.ACTIVE) ||
|
if ($(context.getTipElement()).hasClass(ClassName.ACTIVE) ||
|
||||||
(context._hoverState === HoverState.ACTIVE)) {
|
context._hoverState === HoverState.ACTIVE) {
|
||||||
context._hoverState = HoverState.ACTIVE
|
context._hoverState = HoverState.ACTIVE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -518,7 +518,7 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_leave(event, context) {
|
_leave(event, context) {
|
||||||
let dataKey = this.constructor.DATA_KEY
|
const dataKey = this.constructor.DATA_KEY
|
||||||
|
|
||||||
context = context || $(event.currentTarget).data(dataKey)
|
context = context || $(event.currentTarget).data(dataKey)
|
||||||
|
|
||||||
@ -557,7 +557,7 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_isWithActiveTrigger() {
|
_isWithActiveTrigger() {
|
||||||
for (let trigger in this._activeTrigger) {
|
for (const trigger in this._activeTrigger) {
|
||||||
if (this._activeTrigger[trigger]) {
|
if (this._activeTrigger[trigger]) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -591,10 +591,10 @@ const Tooltip = (($) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getDelegateConfig() {
|
_getDelegateConfig() {
|
||||||
let config = {}
|
const config = {}
|
||||||
|
|
||||||
if (this.config) {
|
if (this.config) {
|
||||||
for (let key in this.config) {
|
for (const key in this.config) {
|
||||||
if (this.constructor.Default[key] !== this.config[key]) {
|
if (this.constructor.Default[key] !== this.config[key]) {
|
||||||
config[key] = this.config[key]
|
config[key] = this.config[key]
|
||||||
}
|
}
|
||||||
@ -609,9 +609,8 @@ const Tooltip = (($) => {
|
|||||||
|
|
||||||
static _jQueryInterface(config) {
|
static _jQueryInterface(config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
let data = $(this).data(DATA_KEY)
|
let data = $(this).data(DATA_KEY)
|
||||||
let _config = typeof config === 'object' ?
|
const _config = typeof config === 'object' && config
|
||||||
config : null
|
|
||||||
|
|
||||||
if (!data && /dispose|hide/.test(config)) {
|
if (!data && /dispose|hide/.test(config)) {
|
||||||
return
|
return
|
||||||
|
@ -27,7 +27,7 @@ const Util = (($) => {
|
|||||||
|
|
||||||
// shoutout AngusCroll (https://goo.gl/pxwQGp)
|
// shoutout AngusCroll (https://goo.gl/pxwQGp)
|
||||||
function toType(obj) {
|
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) {
|
function isElement(obj) {
|
||||||
@ -52,11 +52,13 @@ const Util = (($) => {
|
|||||||
return false
|
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) {
|
if (el.style[name] !== undefined) {
|
||||||
return { end: TransitionEndEvent[name] }
|
return {
|
||||||
|
end: TransitionEndEvent[name]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,15 +98,14 @@ const Util = (($) => {
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let Util = {
|
const Util = {
|
||||||
|
|
||||||
TRANSITION_END: 'bsTransitionEnd',
|
TRANSITION_END: 'bsTransitionEnd',
|
||||||
|
|
||||||
getUID(prefix) {
|
getUID(prefix) {
|
||||||
do {
|
do {
|
||||||
/* eslint-disable no-bitwise */
|
// eslint-disable-next-line no-bitwise
|
||||||
prefix += ~~(Math.random() * MAX_UID) // "~~" acts like a faster Math.floor() here
|
prefix += ~~(Math.random() * MAX_UID) // "~~" acts like a faster Math.floor() here
|
||||||
/* eslint-enable no-bitwise */
|
|
||||||
} while (document.getElementById(prefix))
|
} while (document.getElementById(prefix))
|
||||||
return prefix
|
return prefix
|
||||||
},
|
},
|
||||||
@ -133,17 +134,12 @@ const Util = (($) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
typeCheckConfig(componentName, config, configTypes) {
|
typeCheckConfig(componentName, config, configTypes) {
|
||||||
for (let property in configTypes) {
|
for (const property in configTypes) {
|
||||||
if (configTypes.hasOwnProperty(property)) {
|
if (configTypes.hasOwnProperty(property)) {
|
||||||
let expectedTypes = configTypes[property]
|
const expectedTypes = configTypes[property]
|
||||||
let value = config[property]
|
const value = config[property]
|
||||||
let valueType
|
const valueType = value && isElement(value) ?
|
||||||
|
'element' : toType(value)
|
||||||
if (value && isElement(value)) {
|
|
||||||
valueType = 'element'
|
|
||||||
} else {
|
|
||||||
valueType = toType(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!new RegExp(expectedTypes).test(valueType)) {
|
if (!new RegExp(expectedTypes).test(valueType)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('alert plugin')
|
QUnit.module('alert plugin')
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('button plugin')
|
QUnit.module('button plugin')
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('carousel plugin')
|
QUnit.module('carousel plugin')
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('collapse plugin')
|
QUnit.module('collapse plugin')
|
||||||
|
|
||||||
@ -56,14 +56,14 @@ $(function () {
|
|||||||
assert.expect(2)
|
assert.expect(2)
|
||||||
var html = [
|
var html = [
|
||||||
'<div class="panel-group" id="accordion1">',
|
'<div class="panel-group" id="accordion1">',
|
||||||
'<div class="panel">',
|
'<div class="panel">',
|
||||||
'<div id="collapse1" class="collapse"/>',
|
'<div id="collapse1" class="collapse"/>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="panel-group" id="accordion2">',
|
'<div class="panel-group" id="accordion2">',
|
||||||
'<div class="panel">',
|
'<div class="panel">',
|
||||||
'<div id="collapse2" class="collapse active"/>',
|
'<div id="collapse2" class="collapse active"/>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'</div>'
|
'</div>'
|
||||||
].join('')
|
].join('')
|
||||||
$(html).appendTo('#qunit-fixture')
|
$(html).appendTo('#qunit-fixture')
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('dropdowns plugin')
|
QUnit.module('dropdowns plugin')
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('modal plugin')
|
QUnit.module('modal plugin')
|
||||||
|
|
||||||
@ -374,7 +374,7 @@ $(function () {
|
|||||||
var paddingRight = parseInt($(document.body).css('padding-right'), 10)
|
var paddingRight = parseInt($(document.body).css('padding-right'), 10)
|
||||||
assert.strictEqual(isNaN(paddingRight), false)
|
assert.strictEqual(isNaN(paddingRight), false)
|
||||||
assert.strictEqual(paddingRight !== 0, true)
|
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()
|
done()
|
||||||
})
|
})
|
||||||
.bootstrapModal('show')
|
.bootstrapModal('show')
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
// Don't re-order tests.
|
// Don't re-order tests.
|
||||||
QUnit.config.reorder = false
|
QUnit.config.reorder = false
|
||||||
@ -70,32 +70,3 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
}())
|
}())
|
||||||
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('popover plugin')
|
QUnit.module('popover plugin')
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('scrollspy plugin')
|
QUnit.module('scrollspy plugin')
|
||||||
|
|
||||||
@ -231,8 +231,8 @@ $(function () {
|
|||||||
.appendTo('#qunit-fixture')
|
.appendTo('#qunit-fixture')
|
||||||
.bootstrapScrollspy({ offset: 0, target: '#navigation' })
|
.bootstrapScrollspy({ offset: 0, target: '#navigation' })
|
||||||
|
|
||||||
!function testActiveElements() {
|
function testActiveElements() {
|
||||||
if (++times > 3) return done()
|
if (++times > 3) { return done() }
|
||||||
|
|
||||||
$content.one('scroll', function () {
|
$content.one('scroll', function () {
|
||||||
assert.ok($('#a-1').hasClass('active'), 'nav item for outer element has "active" class')
|
assert.ok($('#a-1').hasClass('active'), 'nav item for outer element has "active" class')
|
||||||
@ -241,7 +241,9 @@ $(function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
$content.scrollTop($content.scrollTop() + 10)
|
$content.scrollTop($content.scrollTop() + 10)
|
||||||
}()
|
}
|
||||||
|
|
||||||
|
testActiveElements()
|
||||||
})
|
})
|
||||||
|
|
||||||
QUnit.test('should clear selection if above the first section', function (assert) {
|
QUnit.test('should clear selection if above the first section', function (assert) {
|
||||||
@ -399,8 +401,8 @@ $(function () {
|
|||||||
$navbar.appendTo('#qunit-fixture')
|
$navbar.appendTo('#qunit-fixture')
|
||||||
$content.appendTo('#qunit-fixture')
|
$content.appendTo('#qunit-fixture')
|
||||||
|
|
||||||
if (type === 'js') $content.bootstrapScrollspy({ target: '.navbar', offset: 0, method: 'position' })
|
if (type === 'js') { $content.bootstrapScrollspy({ target: '.navbar', offset: 0, method: 'position' }) }
|
||||||
else if (type === 'data') $(window).trigger('load')
|
else if (type === 'data') { $(window).trigger('load') }
|
||||||
|
|
||||||
var $target = $('#div-' + type + 'm-2')
|
var $target = $('#div-' + type + 'm-2')
|
||||||
var scrollspy = $content.data('bs.scrollspy')
|
var scrollspy = $content.data('bs.scrollspy')
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('tabs plugin')
|
QUnit.module('tabs plugin')
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
QUnit.module('tooltip plugin')
|
QUnit.module('tooltip plugin')
|
||||||
|
|
||||||
@ -382,7 +382,7 @@ $(function () {
|
|||||||
var $tooltip = $($target.data('bs.tooltip').tip)
|
var $tooltip = $($target.data('bs.tooltip').tip)
|
||||||
|
|
||||||
// this is some dumb hack stuff because sub pixels in firefox
|
// 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 top2 = Math.round($tooltip.offset().top)
|
||||||
var topDiff = top - top2
|
var topDiff = top - top2
|
||||||
assert.ok(topDiff <= 1 && topDiff >= -1)
|
assert.ok(topDiff <= 1 && topDiff >= -1)
|
||||||
@ -540,7 +540,7 @@ $(function () {
|
|||||||
|
|
||||||
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
|
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
|
||||||
.appendTo('#qunit-fixture')
|
.appendTo('#qunit-fixture')
|
||||||
.bootstrapTooltip({ delay: { show: 0, hide: 150 }})
|
.bootstrapTooltip({ delay: { show: 0, hide: 150 } })
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
assert.ok($('.tooltip').is('.fade.active'), '1ms: tooltip faded active')
|
assert.ok($('.tooltip').is('.fade.active'), '1ms: tooltip faded active')
|
||||||
@ -587,7 +587,7 @@ $(function () {
|
|||||||
|
|
||||||
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
|
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
|
||||||
.appendTo('#qunit-fixture')
|
.appendTo('#qunit-fixture')
|
||||||
.bootstrapTooltip({ delay: { show: 150, hide: 0 }})
|
.bootstrapTooltip({ delay: { show: 150, hide: 0 } })
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
assert.ok(!$('.tooltip').is('.fade.active'), '100ms: tooltip not faded active')
|
assert.ok(!$('.tooltip').is('.fade.active'), '100ms: tooltip not faded active')
|
||||||
@ -608,7 +608,7 @@ $(function () {
|
|||||||
|
|
||||||
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
|
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
|
||||||
.appendTo('#qunit-fixture')
|
.appendTo('#qunit-fixture')
|
||||||
.bootstrapTooltip({ delay: { show: 0, hide: 150 }})
|
.bootstrapTooltip({ delay: { show: 0, hide: 150 } })
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.active'), '1ms: tooltip faded active')
|
assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.active'), '1ms: tooltip faded active')
|
||||||
@ -723,10 +723,10 @@ $(function () {
|
|||||||
$('#tt-outer').trigger('mouseleave')
|
$('#tt-outer').trigger('mouseleave')
|
||||||
assert.strictEqual(currentUid, $('#tt-content').text())
|
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')
|
$('#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())
|
assert.strictEqual(currentUid, $('#tt-content').text())
|
||||||
})
|
})
|
||||||
@ -788,7 +788,7 @@ $(function () {
|
|||||||
var tooltip = $el.data('bs.tooltip')
|
var tooltip = $el.data('bs.tooltip')
|
||||||
var $tooltip = $(tooltip.getTipElement())
|
var $tooltip = $(tooltip.getTipElement())
|
||||||
|
|
||||||
function showingTooltip() { return $tooltip.hasClass('active') || tooltip._hoverState == 'active' }
|
function showingTooltip() { return $tooltip.hasClass('active') || tooltip._hoverState === 'active' }
|
||||||
|
|
||||||
var tests = [
|
var tests = [
|
||||||
['mouseenter', 'mouseleave'],
|
['mouseenter', 'mouseleave'],
|
||||||
@ -812,8 +812,8 @@ $(function () {
|
|||||||
|
|
||||||
$.each(tests, function (idx, triggers) {
|
$.each(tests, function (idx, triggers) {
|
||||||
for (var i = 0, len = triggers.length; i < len; i++) {
|
for (var i = 0, len = triggers.length; i < len; i++) {
|
||||||
$el.trigger(triggers[i]);
|
$el.trigger(triggers[i])
|
||||||
assert.equal(i < (len - 1), showingTooltip())
|
assert.equal(i < len - 1, showingTooltip())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user