1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-28 06:20:15 +02:00

js tests passing + eslint

This commit is contained in:
Jacob Thornton
2015-08-18 19:22:46 -07:00
parent f1827e5f9c
commit 18ff57a183
28 changed files with 485 additions and 217 deletions

View File

@@ -86,8 +86,8 @@ const Alert = (($) => {
// private
_getRootElement(element) {
let parent = false
let selector = Util.getSelectorFromElement(element)
let parent = false
if (selector) {
parent = $(selector)[0]
@@ -101,7 +101,8 @@ const Alert = (($) => {
}
_triggerCloseEvent(element) {
var closeEvent = $.Event(Event.CLOSE)
let closeEvent = $.Event(Event.CLOSE)
$(element).trigger(closeEvent)
return closeEvent
}

View File

@@ -20,7 +20,6 @@ const Button = (($) => {
const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api'
const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 150
const ClassName = {
ACTIVE : 'active',
@@ -67,7 +66,7 @@ const Button = (($) => {
toggle() {
let triggerChangeEvent = true
let rootElement = $(this._element).closest(
let rootElement = $(this._element).closest(
Selector.DATA_TOGGLE
)[0]
@@ -137,7 +136,7 @@ const Button = (($) => {
*/
$(document)
.on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
.on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => {
event.preventDefault()
let button = event.target
@@ -148,8 +147,8 @@ const Button = (($) => {
Button._jQueryInterface.call($(button), 'toggle')
})
.on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
var button = $(event.target).closest(Selector.BUTTON)[0]
.on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => {
let button = $(event.target).closest(Selector.BUTTON)[0]
$(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type))
})

View File

@@ -171,13 +171,13 @@ const Carousel = (($) => {
return
}
if (activeIndex == index) {
if (activeIndex === index) {
this.pause()
this.cycle()
return
}
var direction = index > activeIndex ?
let direction = index > activeIndex ?
Direction.NEXT :
Direction.PREVIOUS
@@ -213,7 +213,7 @@ const Carousel = (($) => {
.on(Event.KEYDOWN, $.proxy(this._keydown, this))
}
if (this._config.pause == 'hover' &&
if (this._config.pause === 'hover' &&
!('ontouchstart' in document.documentElement)) {
$(this._element)
.on(Event.MOUSEENTER, $.proxy(this.pause, this))
@@ -224,7 +224,9 @@ const Carousel = (($) => {
_keydown(event) {
event.preventDefault()
if (/input|textarea/i.test(event.target.tagName)) return
if (/input|textarea/i.test(event.target.tagName)) {
return
}
switch (event.which) {
case 37: this.prev(); break
@@ -244,13 +246,13 @@ const Carousel = (($) => {
let activeIndex = this._getItemIndex(activeElement)
let lastItemIndex = (this._items.length - 1)
let isGoingToWrap = (isPrevDirection && activeIndex === 0) ||
(isNextDirection && activeIndex == lastItemIndex)
(isNextDirection && activeIndex === lastItemIndex)
if (isGoingToWrap && !this._config.wrap) {
return activeElement
}
let delta = direction == Direction.PREVIOUS ? -1 : 1
let delta = direction === Direction.PREVIOUS ? -1 : 1
let itemIndex = (activeIndex + delta) % this._items.length
return itemIndex === -1 ?
@@ -260,7 +262,7 @@ const Carousel = (($) => {
_triggerSlideEvent(relatedTarget, directionalClassname) {
let slideEvent = $.Event(Event.SLIDE, {
relatedTarget: relatedTarget,
relatedTarget,
direction: directionalClassname
})
@@ -290,9 +292,9 @@ const Carousel = (($) => {
let nextElement = element || activeElement &&
this._getItemByDirection(direction, activeElement)
let isCycling = !!this._interval
let isCycling = Boolean(this._interval)
let directionalClassName = direction == Direction.NEXT ?
let directionalClassName = direction === Direction.NEXT ?
ClassName.LEFT :
ClassName.RIGHT
@@ -319,7 +321,7 @@ const Carousel = (($) => {
this._setActiveIndicatorElement(nextElement)
var slidEvent = $.Event(Event.SLID, {
let slidEvent = $.Event(Event.SLID, {
relatedTarget: nextElement,
direction: directionalClassName
})
@@ -372,7 +374,7 @@ const Carousel = (($) => {
static _jQueryInterface(config) {
return this.each(function () {
let data = $(this).data(DATA_KEY)
let data = $(this).data(DATA_KEY)
let _config = $.extend({}, Default, $(this).data())
if (typeof config === 'object') {
@@ -386,7 +388,7 @@ const Carousel = (($) => {
$(this).data(DATA_KEY, data)
}
if (typeof config == 'number') {
if (typeof config === 'number') {
data.to(config)
} else if (action) {
@@ -412,9 +414,9 @@ const Carousel = (($) => {
return
}
let config = $.extend({}, $(target).data(), $(this).data())
let config = $.extend({}, $(target).data(), $(this).data())
let slideIndex = this.getAttribute('data-slide-to')
if (slideIndex) {
config.interval = false
}
@@ -440,7 +442,7 @@ const Carousel = (($) => {
$(document)
.on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler)
$(window).on(Event.LOAD_DATA_API, function () {
$(window).on(Event.LOAD_DATA_API, () => {
$(Selector.DATA_RIDE).each(function () {
let $carousel = $(this)
Carousel._jQueryInterface.call($carousel, $carousel.data())

View File

@@ -182,15 +182,14 @@ const Collapse = (($) => {
return
}
let scrollSize = 'scroll'
+ (dimension[0].toUpperCase()
+ dimension.slice(1))
let capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
let scrollSize = `scroll${capitalizedDimension}`
$(this._element)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(TRANSITION_DURATION)
this._element.style[dimension] = this._element[scrollSize] + 'px'
this._element.style[dimension] = `${this._element[scrollSize]}px`
}
hide() {
@@ -205,11 +204,11 @@ const Collapse = (($) => {
return
}
let dimension = this._getDimension()
let dimension = this._getDimension()
let offsetDimension = dimension === Dimension.WIDTH ?
'offsetWidth' : 'offsetHeight'
this._element.style[dimension] = this._element[offsetDimension] + 'px'
this._element.style[dimension] = `${this._element[offsetDimension]}px`
Util.reflow(this._element)
@@ -239,7 +238,8 @@ const Collapse = (($) => {
this._element.style[dimension] = 0
if (!Util.supportsTransitionEnd()) {
return complete()
complete()
return
}
$(this._element)
@@ -266,7 +266,7 @@ const Collapse = (($) => {
_getConfig(config) {
config = $.extend({}, Default, config)
config.toggle = !!config.toggle // coerce string values
config.toggle = Boolean(config.toggle) // coerce string values
Util.typeCheckConfig(NAME, config, DefaultType)
return config
}
@@ -351,8 +351,7 @@ const Collapse = (($) => {
event.preventDefault()
let target = Collapse._getTargetFromElement(this)
let data = $(target).data(DATA_KEY)
let data = $(target).data(DATA_KEY)
let config = data ? 'toggle' : $(this).data()
Collapse._jQueryInterface.call($(target), config)

View File

@@ -78,7 +78,7 @@ const Dropdown = (($) => {
toggle() {
if (this.disabled || $(this).hasClass(ClassName.DISABLED)) {
return
return false
}
let parent = Dropdown._getParentFromElement(this)
@@ -106,7 +106,7 @@ const Dropdown = (($) => {
$(parent).trigger(showEvent)
if (showEvent.isDefaultPrevented()) {
return
return false
}
this.focus()
@@ -239,9 +239,17 @@ const Dropdown = (($) => {
let index = items.indexOf(event.target)
if (event.which === 38 && index > 0) index-- // up
if (event.which === 40 && index < items.length - 1) index++ // down
if (!~index) index = 0
if (event.which === 38 && index > 0) { // up
index--
}
if (event.which === 40 && index < items.length - 1) { // down
index++
}
if (!~index) {
index = 0
}
items[index].focus()
}
@@ -261,9 +269,9 @@ const Dropdown = (($) => {
.on(Event.KEYDOWN_DATA_API, Selector.ROLE_LISTBOX, Dropdown._dataApiKeydownHandler)
.on(Event.CLICK_DATA_API, Dropdown._clearMenus)
.on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, Dropdown.prototype.toggle)
.on(Event.CLICK_DATA_API, Selector.FORM_CHILD, function (e) {
e.stopPropagation()
})
.on(Event.CLICK_DATA_API, Selector.FORM_CHILD, (e) => {
e.stopPropagation()
})
/**

View File

@@ -110,7 +110,7 @@ const Modal = (($) => {
show(relatedTarget) {
let showEvent = $.Event(Event.SHOW, {
relatedTarget: relatedTarget
relatedTarget
})
$(this._element).trigger(showEvent)
@@ -231,14 +231,18 @@ const Modal = (($) => {
$(this._element).addClass(ClassName.IN)
if (this._config.focus) this._enforceFocus()
if (this._config.focus) {
this._enforceFocus()
}
let shownEvent = $.Event(Event.SHOWN, {
relatedTarget: relatedTarget
relatedTarget
})
let transitionComplete = () => {
if (this._config.focus) this._element.focus()
if (this._config.focus) {
this._element.focus()
}
$(this._element).trigger(shownEvent)
}
@@ -389,11 +393,11 @@ const Modal = (($) => {
this._element.scrollHeight > document.documentElement.clientHeight
if (!this._isBodyOverflowing && isModalOverflowing) {
this._element.style.paddingLeft = this._scrollbarWidth + 'px'
this._element.style.paddingLeft = `${this._scrollbarWidth}px`
}
if (this._isBodyOverflowing && !isModalOverflowing) {
this._element.style.paddingRight = this._scrollbarWidth + 'px'
this._element.style.paddingRight = `${this._scrollbarWidth}px~`
}
}
@@ -423,7 +427,7 @@ const Modal = (($) => {
if (this._isBodyOverflowing) {
document.body.style.paddingRight =
bodyPadding + this._scrollbarWidth + 'px'
bodyPadding + `${this._scrollbarWidth}px`
}
}

View File

@@ -141,7 +141,7 @@ const Popover = (($) => {
_getContent() {
return this.element.getAttribute('data-content')
|| (typeof this.config.content == 'function' ?
|| (typeof this.config.content === 'function' ?
this.config.content.call(this.element) :
this.config.content)
}

View File

@@ -293,7 +293,7 @@ const ScrollSpy = (($) => {
* ------------------------------------------------------------------------
*/
$(window).on(Event.LOAD_DATA_API, function () {
$(window).on(Event.LOAD_DATA_API, () => {
let scrollSpys = $.makeArray($(Selector.DATA_SPY))
for (let i = scrollSpys.length; i--;) {

View File

@@ -77,7 +77,7 @@ const Tab = (($) => {
show() {
if (this._element.parentNode &&
(this._element.parentNode.nodeType == Node.ELEMENT_NODE) &&
(this._element.parentNode.nodeType === Node.ELEMENT_NODE) &&
($(this._element).parent().hasClass(ClassName.ACTIVE))) {
return
}
@@ -157,7 +157,7 @@ const Tab = (($) => {
let isTransitioning = callback
&& Util.supportsTransitionEnd()
&& ((active && $(active).hasClass(ClassName.FADE))
|| !!$(container).find(Selector.FADE_CHILD)[0])
|| Boolean($(container).find(Selector.FADE_CHILD)[0]))
let complete = $.proxy(
this._transitionComplete,

View File

@@ -174,11 +174,9 @@ const Tooltip = (($) => {
}
toggle(event) {
let context = this
let dataKey = this.constructor.DATA_KEY
if (event) {
context = $(event.currentTarget).data(dataKey)
let dataKey = this.constructor.DATA_KEY
let context = $(event.currentTarget).data(dataKey)
if (!context) {
context = new this.constructor(
@@ -197,9 +195,13 @@ const Tooltip = (($) => {
}
} else {
$(context.getTipElement()).hasClass(ClassName.IN) ?
context._leave(null, context) :
context._enter(null, context)
if ($(this.getTipElement()).hasClass(ClassName.IN)) {
this._leave(null, this)
return
}
this._enter(null, this)
}
}
@@ -267,9 +269,9 @@ const Tooltip = (($) => {
$(this.element).trigger(this.constructor.Event.INSERTED)
this._tether = new Tether({
attachment,
element : tip,
target : this.element,
attachment : attachment,
classes : TetherClass,
classPrefix : CLASS_PREFIX,
offset : this.config.offset,
@@ -292,11 +294,14 @@ const Tooltip = (($) => {
}
}
Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE) ?
if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
$(this.tip)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(Tooltip._TRANSITION_DURATION) :
complete()
.emulateTransitionEnd(Tooltip._TRANSITION_DURATION)
return
}
complete()
}
}
@@ -343,7 +348,7 @@ const Tooltip = (($) => {
// protected
isWithContent() {
return !!this.getTitle()
return Boolean(this.getTitle())
}
getTipElement() {
@@ -407,10 +412,10 @@ const Tooltip = (($) => {
)
} else if (trigger !== Trigger.MANUAL) {
let eventIn = trigger == Trigger.HOVER ?
let eventIn = trigger === Trigger.HOVER ?
this.constructor.Event.MOUSEENTER :
this.constructor.Event.FOCUSIN
let eventOut = trigger == Trigger.HOVER ?
let eventOut = trigger === Trigger.HOVER ?
this.constructor.Event.MOUSELEAVE :
this.constructor.Event.FOCUSOUT
@@ -471,7 +476,7 @@ const Tooltip = (($) => {
if (event) {
context._activeTrigger[
event.type == 'focusin' ? Trigger.FOCUS : Trigger.HOVER
event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER
] = true
}
@@ -512,7 +517,7 @@ const Tooltip = (($) => {
if (event) {
context._activeTrigger[
event.type == 'focusout' ? Trigger.FOCUS : Trigger.HOVER
event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER
] = false
}
@@ -575,9 +580,8 @@ const Tooltip = (($) => {
if (this.config) {
for (let key in this.config) {
let value = this.config[key]
if (this.constructor.Default[key] !== value) {
config[key] = value
if (this.constructor.Default[key] !== this.config[key]) {
config[key] = this.config[key]
}
}
}

View File

@@ -29,14 +29,14 @@ const Util = (($) => {
}
function isElement(obj) {
return (obj[0] || obj).nodeType;
return (obj[0] || obj).nodeType
}
function getSpecialTransitionEndEvent() {
return {
bindType: transition.end,
delegateType: transition.end,
handle: function (event) {
handle(event) {
if ($(event.target).is(this)) {
return event.handleObj.handler.apply(this, arguments)
}
@@ -51,7 +51,7 @@ const Util = (($) => {
let el = document.createElement('bootstrap')
for (var name in TransitionEndEvent) {
for (let name in TransitionEndEvent) {
if (el.style[name] !== undefined) {
return { end: TransitionEndEvent[name] }
}
@@ -63,7 +63,7 @@ const Util = (($) => {
function transitionEndEmulator(duration) {
let called = false
$(this).one(Util.TRANSITION_END, function () {
$(this).one(Util.TRANSITION_END, () => {
called = true
})
@@ -98,8 +98,9 @@ const Util = (($) => {
TRANSITION_END: 'bsTransitionEnd',
getUID(prefix) {
do prefix += ~~(Math.random() * 1000000)
while (document.getElementById(prefix))
do {
prefix += ~~(Math.random() * 1000000)
} while (document.getElementById(prefix))
return prefix
},
@@ -123,28 +124,31 @@ const Util = (($) => {
},
supportsTransitionEnd() {
return !!transition
return Boolean(transition)
},
typeCheckConfig(componentName, config, configTypes) {
for (let property in configTypes) {
let expectedTypes = configTypes[property]
let value = config[property]
let valueType
if (configTypes.hasOwnProperty(property)) {
let expectedTypes = configTypes[property]
let value = config[property]
let valueType
if (value && isElement(value)) valueType = 'element'
else valueType = toType(value)
if (value && isElement(value)) {
valueType = 'element'
} else {
valueType = toType(value)
}
if (!new RegExp(expectedTypes).test(valueType)) {
throw new Error(
`${componentName.toUpperCase()}: ` +
`Option "${property}" provided type "${valueType}" ` +
`but expected type "${expectedTypes}".`)
if (!new RegExp(expectedTypes).test(valueType)) {
throw new Error(
`${componentName.toUpperCase()}: ` +
`Option "${property}" provided type "${valueType}" ` +
`but expected type "${expectedTypes}".`)
}
}
}
}
}
setTransitionEndSupport()