Skip to content

Commit 5a12f06

Browse files
committed
refactor: Join template literals. Add parentheses around multiple spread conditions.
1 parent 252d229 commit 5a12f06

File tree

9 files changed

+100
-135
lines changed

9 files changed

+100
-135
lines changed

js/src/alert.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ class Alert {
6565
// Public
6666

6767
close(element) {
68-
let rootElement = this._element
69-
if (element) {
70-
rootElement = this._getRootElement(element)
71-
}
68+
const rootElement = element ? this._getRootElement(element) : this._element
7269

7370
const customEvent = this._triggerCloseEvent(rootElement)
7471

@@ -104,8 +101,7 @@ class Alert {
104101

105102
const transitionDuration = getTransitionDurationFromElement(element)
106103

107-
EventHandler
108-
.one(element, TRANSITION_END, () => this._destroyElement(element))
104+
EventHandler.one(element, TRANSITION_END, () => this._destroyElement(element))
109105
emulateTransitionEnd(element, transitionDuration)
110106
}
111107

@@ -153,8 +149,7 @@ class Alert {
153149
* Data Api implementation
154150
* ------------------------------------------------------------------------
155151
*/
156-
EventHandler
157-
.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert()))
152+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert()))
158153

159154
const $ = getjQuery()
160155

js/src/carousel.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,12 @@ class Carousel {
267267

268268
_addEventListeners() {
269269
if (this._config.keyboard) {
270-
EventHandler
271-
.on(this._element, EVENT_KEYDOWN, event => this._keydown(event))
270+
EventHandler.on(this._element, EVENT_KEYDOWN, event => this._keydown(event))
272271
}
273272

274273
if (this._config.pause === 'hover') {
275-
EventHandler
276-
.on(this._element, EVENT_MOUSEENTER, event => this.pause(event))
277-
EventHandler
278-
.on(this._element, EVENT_MOUSELEAVE, event => this.cycle(event))
274+
EventHandler.on(this._element, EVENT_MOUSEENTER, event => this.pause(event))
275+
EventHandler.on(this._element, EVENT_MOUSELEAVE, event => this.cycle(event))
279276
}
280277

281278
if (this._config.touch && this._touchSupported) {
@@ -480,24 +477,23 @@ class Carousel {
480477

481478
const transitionDuration = getTransitionDurationFromElement(activeElement)
482479

483-
EventHandler
484-
.one(activeElement, TRANSITION_END, () => {
485-
nextElement.classList.remove(directionalClassName, orderClassName)
486-
nextElement.classList.add(CLASS_NAME_ACTIVE)
480+
EventHandler.one(activeElement, TRANSITION_END, () => {
481+
nextElement.classList.remove(directionalClassName, orderClassName)
482+
nextElement.classList.add(CLASS_NAME_ACTIVE)
487483

488-
activeElement.classList.remove(CLASS_NAME_ACTIVE, orderClassName, directionalClassName)
484+
activeElement.classList.remove(CLASS_NAME_ACTIVE, orderClassName, directionalClassName)
489485

490-
this._isSliding = false
486+
this._isSliding = false
491487

492-
setTimeout(() => {
493-
EventHandler.trigger(this._element, EVENT_SLID, {
494-
relatedTarget: nextElement,
495-
direction: eventDirectionName,
496-
from: activeElementIndex,
497-
to: nextElementIndex
498-
})
499-
}, 0)
500-
})
488+
setTimeout(() => {
489+
EventHandler.trigger(this._element, EVENT_SLID, {
490+
relatedTarget: nextElement,
491+
direction: eventDirectionName,
492+
from: activeElementIndex,
493+
to: nextElementIndex
494+
})
495+
}, 0)
496+
})
501497

502498
emulateTransitionEnd(activeElement, transitionDuration)
503499
} else {
@@ -597,8 +593,7 @@ class Carousel {
597593
* ------------------------------------------------------------------------
598594
*/
599595

600-
EventHandler
601-
.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler)
596+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler)
602597

603598
EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
604599
const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE)

js/src/collapse.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ class Collapse {
291291
}
292292

293293
_getDimension() {
294-
const hasWidth = this._element.classList.contains(WIDTH)
295-
return hasWidth ? WIDTH : HEIGHT
294+
return this._element.classList.contains(WIDTH) ? WIDTH : HEIGHT
296295
}
297296

298297
_getParent() {
@@ -323,21 +322,21 @@ class Collapse {
323322
}
324323

325324
_addAriaAndCollapsedClass(element, triggerArray) {
326-
if (element) {
327-
const isOpen = element.classList.contains(CLASS_NAME_SHOW)
328-
329-
if (triggerArray.length) {
330-
triggerArray.forEach(elem => {
331-
if (isOpen) {
332-
elem.classList.remove(CLASS_NAME_COLLAPSED)
333-
} else {
334-
elem.classList.add(CLASS_NAME_COLLAPSED)
335-
}
325+
if (!element || !triggerArray.length) {
326+
return
327+
}
336328

337-
elem.setAttribute('aria-expanded', isOpen)
338-
})
329+
const isOpen = element.classList.contains(CLASS_NAME_SHOW)
330+
331+
triggerArray.forEach(elem => {
332+
if (isOpen) {
333+
elem.classList.remove(CLASS_NAME_COLLAPSED)
334+
} else {
335+
elem.classList.add(CLASS_NAME_COLLAPSED)
339336
}
340-
}
337+
338+
elem.setAttribute('aria-expanded', isOpen)
339+
})
341340
}
342341

343342
// Static
@@ -347,7 +346,7 @@ class Collapse {
347346
const _config = {
348347
...Default,
349348
...Manipulator.getDataAttributes(element),
350-
...typeof config === 'object' && config ? config : {}
349+
...(typeof config === 'object' && config ? config : {})
351350
}
352351

353352
if (!data && _config.toggle && typeof config === 'string' && /show|hide/.test(config)) {

js/src/dropdown.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -320,25 +320,6 @@ class Dropdown {
320320
return Boolean(this._element.closest(`.${CLASS_NAME_HEADER}`))
321321
}
322322

323-
// _getOffset() {
324-
// const offset = {}
325-
326-
// if (typeof this._config.offset === 'function') {
327-
// offset.fn = data => {
328-
// data.offsets = {
329-
// ...data.offsets,
330-
// ...this._config.offset(data.offsets, this._element) || {}
331-
// }
332-
333-
// return data
334-
// }
335-
// } else {
336-
// offset.offset = this._config.offset
337-
// }
338-
339-
// return offset
340-
// }
341-
342323
_getOffset() {
343324
let offset = []
344325

@@ -514,8 +495,7 @@ class Dropdown {
514495
return
515496
}
516497

517-
const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, parent)
518-
.filter(isVisible)
498+
const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, parent).filter(isVisible)
519499

520500
if (!items.length) {
521501
return
@@ -557,8 +537,7 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (
557537
event.stopPropagation()
558538
Dropdown.dropdownInterface(this, 'toggle')
559539
})
560-
EventHandler
561-
.on(document, EVENT_CLICK_DATA_API, SELECTOR_FORM_CHILD, e => e.stopPropagation())
540+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_FORM_CHILD, e => e.stopPropagation())
562541

563542
const $ = getjQuery()
564543

js/src/modal.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,23 @@ class Modal {
413413
return
414414
}
415415

416+
const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
417+
418+
if (!isModalOverflowing) {
419+
this._element.style.overflowY = 'hidden'
420+
}
421+
416422
this._element.classList.add(CLASS_NAME_STATIC)
417-
const modalTransitionDuration = getTransitionDurationFromElement(this._element)
423+
const modalTransitionDuration = getTransitionDurationFromElement(this._dialog)
424+
EventHandler.off(this._element, TRANSITION_END)
418425
EventHandler.one(this._element, TRANSITION_END, () => {
419426
this._element.classList.remove(CLASS_NAME_STATIC)
427+
if (!isModalOverflowing) {
428+
EventHandler.one(this._element, TRANSITION_END, () => {
429+
this._element.style.overflowY = ''
430+
})
431+
emulateTransitionEnd(this._element, modalTransitionDuration)
432+
}
420433
})
421434
emulateTransitionEnd(this._element, modalTransitionDuration)
422435
this._element.focus()
@@ -535,7 +548,7 @@ class Modal {
535548
const _config = {
536549
...Default,
537550
...Manipulator.getDataAttributes(this),
538-
...typeof config === 'object' && config ? config : {}
551+
...(typeof config === 'object' && config ? config : {})
539552
}
540553

541554
if (!data) {

js/src/popover.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ class Popover extends Tooltip {
120120
tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW)
121121
}
122122

123+
// Private
124+
123125
_addAttachmentClass(attachment) {
124126
this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
125127
}
126128

127-
// Private
128-
129129
_getContent() {
130130
return this.element.getAttribute('data-content') ||
131131
this.config.content

js/src/scrollspy.js

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ class ScrollSpy {
7474
this._element = element
7575
this._scrollElement = element.tagName === 'BODY' ? window : element
7676
this._config = this._getConfig(config)
77-
this._selector = `${this._config.target} ${SELECTOR_NAV_LINKS},` +
78-
`${this._config.target} ${SELECTOR_LIST_ITEMS},` +
79-
`${this._config.target} .${CLASS_NAME_DROPDOWN_ITEM}`
77+
this._selector = `${this._config.target} ${SELECTOR_NAV_LINKS}, ${this._config.target} ${SELECTOR_LIST_ITEMS}, ${this._config.target} .${CLASS_NAME_DROPDOWN_ITEM}`
8078
this._offsets = []
8179
this._targets = []
8280
this._activeTarget = null
@@ -117,32 +115,26 @@ class ScrollSpy {
117115

118116
this._offsets = []
119117
this._targets = []
120-
121118
this._scrollHeight = this._getScrollHeight()
122119

123120
const targets = SelectorEngine.find(this._selector)
124121

125-
targets
126-
.map(element => {
127-
let target
128-
const targetSelector = getSelectorFromElement(element)
129-
130-
if (targetSelector) {
131-
target = SelectorEngine.findOne(targetSelector)
132-
}
133-
134-
if (target) {
135-
const targetBCR = target.getBoundingClientRect()
136-
if (targetBCR.width || targetBCR.height) {
137-
return [
138-
Manipulator[offsetMethod](target).top + offsetBase,
139-
targetSelector
140-
]
141-
}
122+
targets.map(element => {
123+
const targetSelector = getSelectorFromElement(element)
124+
const target = targetSelector ? SelectorEngine.findOne(targetSelector) : null
125+
126+
if (target) {
127+
const targetBCR = target.getBoundingClientRect()
128+
if (targetBCR.width || targetBCR.height) {
129+
return [
130+
Manipulator[offsetMethod](target).top + offsetBase,
131+
targetSelector
132+
]
142133
}
134+
}
143135

144-
return null
145-
})
136+
return null
137+
})
146138
.filter(item => item)
147139
.sort((a, b) => a[0] - b[0])
148140
.forEach(item => {
@@ -170,7 +162,7 @@ class ScrollSpy {
170162
_getConfig(config) {
171163
config = {
172164
...Default,
173-
...typeof config === 'object' && config ? config : {}
165+
...(typeof config === 'object' && config ? config : {})
174166
}
175167

176168
if (typeof config.target !== 'string' && isElement(config.target)) {
@@ -257,17 +249,15 @@ class ScrollSpy {
257249
const link = SelectorEngine.findOne(queries.join(','))
258250

259251
if (link.classList.contains(CLASS_NAME_DROPDOWN_ITEM)) {
260-
SelectorEngine
261-
.findOne(SELECTOR_DROPDOWN_TOGGLE, link.closest(SELECTOR_DROPDOWN))
252+
SelectorEngine.findOne(SELECTOR_DROPDOWN_TOGGLE, link.closest(SELECTOR_DROPDOWN))
262253
.classList.add(CLASS_NAME_ACTIVE)
263254

264255
link.classList.add(CLASS_NAME_ACTIVE)
265256
} else {
266257
// Set triggered link as active
267258
link.classList.add(CLASS_NAME_ACTIVE)
268259

269-
SelectorEngine
270-
.parents(link, SELECTOR_NAV_LIST_GROUP)
260+
SelectorEngine.parents(link, SELECTOR_NAV_LIST_GROUP)
271261
.forEach(listGroup => {
272262
// Set triggered links parents as active
273263
// With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor

js/src/toast.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const DefaultType = {
5252
const Default = {
5353
animation: true,
5454
autohide: true,
55-
delay: 500
55+
delay: 5000
5656
}
5757

5858
const SELECTOR_DATA_DISMISS = '[data-dismiss="toast"]'
@@ -95,6 +95,8 @@ class Toast {
9595
return
9696
}
9797

98+
this._clearTimeout()
99+
98100
if (this._config.animation) {
99101
this._element.classList.add(CLASS_NAME_FADE)
100102
}
@@ -153,8 +155,7 @@ class Toast {
153155
}
154156

155157
dispose() {
156-
clearTimeout(this._timeout)
157-
this._timeout = null
158+
this._clearTimeout()
158159

159160
if (this._element.classList.contains(CLASS_NAME_SHOW)) {
160161
this._element.classList.remove(CLASS_NAME_SHOW)
@@ -173,7 +174,7 @@ class Toast {
173174
config = {
174175
...Default,
175176
...Manipulator.getDataAttributes(this._element),
176-
...typeof config === 'object' && config ? config : {}
177+
...(typeof config === 'object' && config ? config : {})
177178
}
178179

179180
typeCheckConfig(
@@ -186,12 +187,12 @@ class Toast {
186187
}
187188

188189
_setListeners() {
189-
EventHandler.on(
190-
this._element,
191-
EVENT_CLICK_DISMISS,
192-
SELECTOR_DATA_DISMISS,
193-
() => this.hide()
194-
)
190+
EventHandler.on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, () => this.hide())
191+
}
192+
193+
_clearTimeout() {
194+
clearTimeout(this._timeout)
195+
this._timeout = null
195196
}
196197

197198
// Static

0 commit comments

Comments
 (0)