Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ESLint configuration. #21005

Merged
merged 2 commits into from
Nov 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
420 changes: 222 additions & 198 deletions js/.eslintrc.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions js/src/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const Alert = (($) => {
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
Expand All @@ -86,8 +86,8 @@ const Alert = (($) => {
// private

_getRootElement(element) {
let selector = Util.getSelectorFromElement(element)
let parent = false
const selector = Util.getSelectorFromElement(element)
let parent = false

if (selector) {
parent = $(selector)[0]
Expand All @@ -101,7 +101,7 @@ const Alert = (($) => {
}

_triggerCloseEvent(element) {
let closeEvent = $.Event(Event.CLOSE)
const closeEvent = $.Event(Event.CLOSE)

$(element).trigger(closeEvent)
return closeEvent
Expand Down Expand Up @@ -133,8 +133,8 @@ const Alert = (($) => {

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)
Expand Down
8 changes: 4 additions & 4 deletions js/src/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ const Button = (($) => {

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') {
Expand All @@ -80,7 +80,7 @@ const Button = (($) => {
triggerChangeEvent = false

} else {
let activeElement = $(rootElement).find(Selector.ACTIVE)[0]
const activeElement = $(rootElement).find(Selector.ACTIVE)[0]

if (activeElement) {
$(activeElement).removeClass(ClassName.ACTIVE)
Expand Down Expand Up @@ -151,7 +151,7 @@ const Button = (($) => {
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))
})

Expand Down
55 changes: 28 additions & 27 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,18 @@ const Carousel = (($) => {

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
}

Expand All @@ -186,7 +187,7 @@ const Carousel = (($) => {
return
}

let direction = index > activeIndex ?
const direction = index > activeIndex ?
Direction.NEXT :
Direction.PREVIOUS

Expand Down Expand Up @@ -255,27 +256,27 @@ const Carousel = (($) => {
}

_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
})
Expand All @@ -291,7 +292,7 @@ const Carousel = (($) => {
.find(Selector.ACTIVE)
.removeClass(ClassName.ACTIVE)

let nextIndicator = this._indicatorsElement.children[
const nextIndicator = this._indicatorsElement.children[
this._getItemIndex(element)
]

Expand All @@ -302,13 +303,13 @@ const Carousel = (($) => {
}

_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

Expand All @@ -317,7 +318,7 @@ const Carousel = (($) => {
return
}

let slideEvent = this._triggerSlideEvent(nextElement, directionalClassName)
const slideEvent = this._triggerSlideEvent(nextElement, directionalClassName)
if (slideEvent.isDefaultPrevented()) {
return
}
Expand All @@ -335,7 +336,7 @@ const Carousel = (($) => {

this._setActiveIndicatorElement(nextElement)

let slidEvent = $.Event(Event.SLID, {
const slidEvent = $.Event(Event.SLID, {
relatedTarget: nextElement,
direction: directionalClassName
})
Expand Down Expand Up @@ -389,13 +390,13 @@ const Carousel = (($) => {
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)
Expand All @@ -417,20 +418,20 @@ const Carousel = (($) => {
}

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
Expand Down Expand Up @@ -459,7 +460,7 @@ const Carousel = (($) => {

$(window).on(Event.LOAD_DATA_API, () => {
$(Selector.DATA_RIDE).each(function () {
let $carousel = $(this)
const $carousel = $(this)
Carousel._jQueryInterface.call($carousel, $carousel.data())
})
})
Expand Down
40 changes: 20 additions & 20 deletions js/src/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const Collapse = (($) => {
}
}

let startEvent = $.Event(Event.SHOW)
const startEvent = $.Event(Event.SHOW)
$(this._element).trigger(startEvent)
if (startEvent.isDefaultPrevented()) {
return
Expand All @@ -147,7 +147,7 @@ const Collapse = (($) => {
}
}

let dimension = this._getDimension()
const dimension = this._getDimension()

$(this._element)
.removeClass(ClassName.COLLAPSE)
Expand All @@ -164,7 +164,7 @@ const Collapse = (($) => {

this.setTransitioning(true)

let complete = () => {
const complete = () => {
$(this._element)
.removeClass(ClassName.COLLAPSING)
.addClass(ClassName.COLLAPSE)
Expand All @@ -182,8 +182,8 @@ const 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)
Expand All @@ -198,14 +198,14 @@ const Collapse = (($) => {
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`
Expand All @@ -227,7 +227,7 @@ const Collapse = (($) => {

this.setTransitioning(true)

let complete = () => {
const complete = () => {
this.setTransitioning(false)
$(this._element)
.removeClass(ClassName.COLLAPSING)
Expand Down Expand Up @@ -272,13 +272,13 @@ const Collapse = (($) => {
}

_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) => {
Expand All @@ -293,7 +293,7 @@ const Collapse = (($) => {

_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) {
Expand All @@ -308,15 +308,15 @@ const Collapse = (($) => {
// 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(),
Expand Down Expand Up @@ -353,9 +353,9 @@ const Collapse = (($) => {
$(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)
})
Expand Down
Loading