mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-13 00:54:04 +02:00
Enable unicorn/no-array-for-each
rule
This commit is contained in:
@@ -51,7 +51,6 @@
|
|||||||
],
|
],
|
||||||
"unicorn/explicit-length-check": "off",
|
"unicorn/explicit-length-check": "off",
|
||||||
"unicorn/no-array-callback-reference": "off",
|
"unicorn/no-array-callback-reference": "off",
|
||||||
"unicorn/no-array-for-each": "off",
|
|
||||||
"unicorn/no-array-method-this-argument": "off",
|
"unicorn/no-array-method-this-argument": "off",
|
||||||
"unicorn/no-null": "off",
|
"unicorn/no-null": "off",
|
||||||
"unicorn/no-unused-properties": "error",
|
"unicorn/no-unused-properties": "error",
|
||||||
|
@@ -47,7 +47,7 @@ const files = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
files.forEach(file => {
|
for (const file of files) {
|
||||||
fs.readFile(file.file, 'utf8', (err, data) => {
|
fs.readFile(file.file, 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err
|
throw err
|
||||||
@@ -61,4 +61,4 @@ files.forEach(file => {
|
|||||||
|
|
||||||
sh.sed('-i', new RegExp(`^(\\s+${file.configPropertyName}:\\s+["'])\\S*(["'])`), `$1${integrity}$2`, configFile)
|
sh.sed('-i', new RegExp(`^(\\s+${file.configPropertyName}:\\s+["'])\\S*(["'])`), `$1${integrity}$2`, configFile)
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
@@ -57,22 +57,22 @@ sh.mkdir('-p', [
|
|||||||
|
|
||||||
sh.cp('-Rf', `${docsDir}/examples/*`, distFolder)
|
sh.cp('-Rf', `${docsDir}/examples/*`, distFolder)
|
||||||
|
|
||||||
cssFiles.forEach(file => {
|
for (const file of cssFiles) {
|
||||||
sh.cp('-f', `${docsDir}/dist/css/${file}`, `${distFolder}/assets/dist/css/`)
|
sh.cp('-f', `${docsDir}/dist/css/${file}`, `${distFolder}/assets/dist/css/`)
|
||||||
})
|
}
|
||||||
|
|
||||||
jsFiles.forEach(file => {
|
for (const file of jsFiles) {
|
||||||
sh.cp('-f', `${docsDir}/dist/js/${file}`, `${distFolder}/assets/dist/js/`)
|
sh.cp('-f', `${docsDir}/dist/js/${file}`, `${distFolder}/assets/dist/js/`)
|
||||||
})
|
}
|
||||||
|
|
||||||
imgFiles.forEach(file => {
|
for (const file of imgFiles) {
|
||||||
sh.cp('-f', `${docsDir}/assets/brand/${file}`, `${distFolder}/assets/brand/`)
|
sh.cp('-f', `${docsDir}/assets/brand/${file}`, `${distFolder}/assets/brand/`)
|
||||||
})
|
}
|
||||||
|
|
||||||
sh.rm(`${distFolder}/index.html`)
|
sh.rm(`${distFolder}/index.html`)
|
||||||
|
|
||||||
// get all examples' HTML files
|
// get all examples' HTML files
|
||||||
sh.find(`${distFolder}/**/*.html`).forEach(file => {
|
for (const file of sh.find(`${distFolder}/**/*.html`)) {
|
||||||
const fileContents = sh.cat(file)
|
const fileContents = sh.cat(file)
|
||||||
.toString()
|
.toString()
|
||||||
.replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
|
.replace(new RegExp(`"/docs/${versionShort}/`, 'g'), '"../')
|
||||||
@@ -81,7 +81,7 @@ sh.find(`${distFolder}/**/*.html`).forEach(file => {
|
|||||||
.replace(/(<script src="\.\.\/.*) integrity=".*>/g, '$1></script>')
|
.replace(/(<script src="\.\.\/.*) integrity=".*>/g, '$1></script>')
|
||||||
.replace(/( +)<!-- favicons(.|\n)+<style>/i, ' <style>')
|
.replace(/( +)<!-- favicons(.|\n)+<style>/i, ' <style>')
|
||||||
new sh.ShellString(fileContents).to(file)
|
new sh.ShellString(fileContents).to(file)
|
||||||
})
|
}
|
||||||
|
|
||||||
// create the zip file
|
// create the zip file
|
||||||
sh.exec(`zip -r9 "${distFolder}.zip" "${distFolder}"`)
|
sh.exec(`zip -r9 "${distFolder}.zip" "${distFolder}"`)
|
||||||
|
@@ -36,9 +36,9 @@ class BaseComponent {
|
|||||||
Data.remove(this._element, this.constructor.DATA_KEY)
|
Data.remove(this._element, this.constructor.DATA_KEY)
|
||||||
EventHandler.off(this._element, this.constructor.EVENT_KEY)
|
EventHandler.off(this._element, this.constructor.EVENT_KEY)
|
||||||
|
|
||||||
Object.getOwnPropertyNames(this).forEach(propertyName => {
|
for (const propertyName of Object.getOwnPropertyNames(this)) {
|
||||||
this[propertyName] = null
|
this[propertyName] = null
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_queueCallback(callback, element, isAnimated = true) {
|
_queueCallback(callback, element, isAnimated = true) {
|
||||||
|
@@ -304,9 +304,9 @@ class Carousel extends BaseComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectorEngine.find(SELECTOR_ITEM_IMG, this._element).forEach(itemImg => {
|
for (const itemImg of SelectorEngine.find(SELECTOR_ITEM_IMG, this._element)) {
|
||||||
EventHandler.on(itemImg, EVENT_DRAG_START, event => event.preventDefault())
|
EventHandler.on(itemImg, EVENT_DRAG_START, event => event.preventDefault())
|
||||||
})
|
}
|
||||||
|
|
||||||
if (this._pointerEvent) {
|
if (this._pointerEvent) {
|
||||||
EventHandler.on(this._element, EVENT_POINTERDOWN, event => start(event))
|
EventHandler.on(this._element, EVENT_POINTERDOWN, event => start(event))
|
||||||
|
@@ -127,7 +127,8 @@ class Collapse extends BaseComponent {
|
|||||||
|
|
||||||
if (this._config.parent) {
|
if (this._config.parent) {
|
||||||
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
||||||
actives = SelectorEngine.find(SELECTOR_ACTIVES, this._config.parent).filter(elem => !children.includes(elem)) // remove children if greater depth
|
// remove children if greater depth
|
||||||
|
actives = SelectorEngine.find(SELECTOR_ACTIVES, this._config.parent).filter(elem => !children.includes(elem))
|
||||||
}
|
}
|
||||||
|
|
||||||
const container = SelectorEngine.findOne(this._selector)
|
const container = SelectorEngine.findOne(this._selector)
|
||||||
@@ -145,7 +146,7 @@ class Collapse extends BaseComponent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
actives.forEach(elemActive => {
|
for (const elemActive of actives) {
|
||||||
if (container !== elemActive) {
|
if (container !== elemActive) {
|
||||||
Collapse.getOrCreateInstance(elemActive, { toggle: false }).hide()
|
Collapse.getOrCreateInstance(elemActive, { toggle: false }).hide()
|
||||||
}
|
}
|
||||||
@@ -153,7 +154,7 @@ class Collapse extends BaseComponent {
|
|||||||
if (!activesData) {
|
if (!activesData) {
|
||||||
Data.set(elemActive, DATA_KEY, null)
|
Data.set(elemActive, DATA_KEY, null)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
const dimension = this._getDimension()
|
const dimension = this._getDimension()
|
||||||
|
|
||||||
@@ -252,14 +253,15 @@ class Collapse extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
||||||
SelectorEngine.find(SELECTOR_DATA_TOGGLE, this._config.parent).filter(elem => !children.includes(elem))
|
const elements = SelectorEngine.find(SELECTOR_DATA_TOGGLE, this._config.parent).filter(elem => !children.includes(elem))
|
||||||
.forEach(element => {
|
|
||||||
const selected = getElementFromSelector(element)
|
|
||||||
|
|
||||||
if (selected) {
|
for (const element of elements) {
|
||||||
this._addAriaAndCollapsedClass([element], this._isShown(selected))
|
const selected = getElementFromSelector(element)
|
||||||
}
|
|
||||||
})
|
if (selected) {
|
||||||
|
this._addAriaAndCollapsedClass([element], this._isShown(selected))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_addAriaAndCollapsedClass(triggerArray, isOpen) {
|
_addAriaAndCollapsedClass(triggerArray, isOpen) {
|
||||||
@@ -267,7 +269,7 @@ class Collapse extends BaseComponent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerArray.forEach(elem => {
|
for (const elem of triggerArray) {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
elem.classList.remove(CLASS_NAME_COLLAPSED)
|
elem.classList.remove(CLASS_NAME_COLLAPSED)
|
||||||
} else {
|
} else {
|
||||||
@@ -275,7 +277,7 @@ class Collapse extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elem.setAttribute('aria-expanded', isOpen)
|
elem.setAttribute('aria-expanded', isOpen)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static
|
// Static
|
||||||
@@ -315,9 +317,9 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (
|
|||||||
const selector = getSelectorFromElement(this)
|
const selector = getSelectorFromElement(this)
|
||||||
const selectorElements = SelectorEngine.find(selector)
|
const selectorElements = SelectorEngine.find(selector)
|
||||||
|
|
||||||
selectorElements.forEach(element => {
|
for (const element of selectorElements) {
|
||||||
Collapse.getOrCreateInstance(element, { toggle: false }).toggle()
|
Collapse.getOrCreateInstance(element, { toggle: false }).toggle()
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -221,13 +221,13 @@ function removeHandler(element, events, typeEvent, handler, delegationSelector)
|
|||||||
function removeNamespacedHandlers(element, events, typeEvent, namespace) {
|
function removeNamespacedHandlers(element, events, typeEvent, namespace) {
|
||||||
const storeElementEvent = events[typeEvent] || {}
|
const storeElementEvent = events[typeEvent] || {}
|
||||||
|
|
||||||
Object.keys(storeElementEvent).forEach(handlerKey => {
|
for (const handlerKey of Object.keys(storeElementEvent)) {
|
||||||
if (handlerKey.includes(namespace)) {
|
if (handlerKey.includes(namespace)) {
|
||||||
const event = storeElementEvent[handlerKey]
|
const event = storeElementEvent[handlerKey]
|
||||||
|
|
||||||
removeHandler(element, events, typeEvent, event.originalHandler, event.delegationSelector)
|
removeHandler(element, events, typeEvent, event.originalHandler, event.delegationSelector)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTypeEvent(event) {
|
function getTypeEvent(event) {
|
||||||
@@ -266,13 +266,13 @@ const EventHandler = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isNamespace) {
|
if (isNamespace) {
|
||||||
Object.keys(events).forEach(elementEvent => {
|
for (const elementEvent of Object.keys(events)) {
|
||||||
removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.slice(1))
|
removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.slice(1))
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const storeElementEvent = events[typeEvent] || {}
|
const storeElementEvent = events[typeEvent] || {}
|
||||||
Object.keys(storeElementEvent).forEach(keyHandlers => {
|
for (const keyHandlers of Object.keys(storeElementEvent)) {
|
||||||
const handlerKey = keyHandlers.replace(stripUidRegex, '')
|
const handlerKey = keyHandlers.replace(stripUidRegex, '')
|
||||||
|
|
||||||
if (!inNamespace || originalTypeEvent.includes(handlerKey)) {
|
if (!inNamespace || originalTypeEvent.includes(handlerKey)) {
|
||||||
@@ -280,7 +280,7 @@ const EventHandler = {
|
|||||||
|
|
||||||
removeHandler(element, events, typeEvent, event.originalHandler, event.delegationSelector)
|
removeHandler(element, events, typeEvent, event.originalHandler, event.delegationSelector)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
trigger(element, event, args) {
|
trigger(element, event, args) {
|
||||||
@@ -320,13 +320,13 @@ const EventHandler = {
|
|||||||
|
|
||||||
// merge custom information in our event
|
// merge custom information in our event
|
||||||
if (typeof args !== 'undefined') {
|
if (typeof args !== 'undefined') {
|
||||||
Object.keys(args).forEach(key => {
|
for (const key of Object.keys(args)) {
|
||||||
Object.defineProperty(evt, key, {
|
Object.defineProperty(evt, key, {
|
||||||
get() {
|
get() {
|
||||||
return args[key]
|
return args[key]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaultPrevented) {
|
if (defaultPrevented) {
|
||||||
|
@@ -44,14 +44,13 @@ const Manipulator = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const attributes = {}
|
const attributes = {}
|
||||||
|
const bsKeys = Object.keys(element.dataset).filter(key => key.startsWith('bs'))
|
||||||
|
|
||||||
Object.keys(element.dataset)
|
for (const key of bsKeys) {
|
||||||
.filter(key => key.startsWith('bs'))
|
let pureKey = key.replace(/^bs/, '')
|
||||||
.forEach(key => {
|
pureKey = pureKey.charAt(0).toLowerCase() + pureKey.slice(1, pureKey.length)
|
||||||
let pureKey = key.replace(/^bs/, '')
|
attributes[pureKey] = normalizeData(element.dataset[key])
|
||||||
pureKey = pureKey.charAt(0).toLowerCase() + pureKey.slice(1, pureKey.length)
|
}
|
||||||
attributes[pureKey] = normalizeData(element.dataset[key])
|
|
||||||
})
|
|
||||||
|
|
||||||
return attributes
|
return attributes
|
||||||
},
|
},
|
||||||
|
@@ -151,10 +151,10 @@ class Dropdown extends BaseComponent {
|
|||||||
// empty mouseover listeners to the body's immediate children;
|
// empty mouseover listeners to the body's immediate children;
|
||||||
// only needed because of broken event delegation on iOS
|
// only needed because of broken event delegation on iOS
|
||||||
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
|
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
|
||||||
if ('ontouchstart' in document.documentElement &&
|
if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) {
|
||||||
!parent.closest(SELECTOR_NAVBAR_NAV)) {
|
for (const elem of [].concat(...document.body.children)) {
|
||||||
[].concat(...document.body.children)
|
EventHandler.on(elem, 'mouseover', noop)
|
||||||
.forEach(elem => EventHandler.on(elem, 'mouseover', noop))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._element.focus()
|
this._element.focus()
|
||||||
@@ -203,8 +203,9 @@ class Dropdown extends BaseComponent {
|
|||||||
// If this is a touch-enabled device we remove the extra
|
// If this is a touch-enabled device we remove the extra
|
||||||
// empty mouseover listeners we added for iOS support
|
// empty mouseover listeners we added for iOS support
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if ('ontouchstart' in document.documentElement) {
|
||||||
[].concat(...document.body.children)
|
for (const elem of [].concat(...document.body.children)) {
|
||||||
.forEach(elem => EventHandler.off(elem, 'mouseover', noop))
|
EventHandler.off(elem, 'mouseover', noop)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._popper) {
|
if (this._popper) {
|
||||||
|
@@ -175,8 +175,9 @@ class Modal extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
[window, this._dialog]
|
for (const htmlElement of [window, this._dialog]) {
|
||||||
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
|
EventHandler.off(htmlElement, EVENT_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
this._backdrop.dispose()
|
this._backdrop.dispose()
|
||||||
this._focustrap.deactivate()
|
this._focustrap.deactivate()
|
||||||
|
@@ -256,9 +256,11 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (
|
|||||||
data.toggle(this)
|
data.toggle(this)
|
||||||
})
|
})
|
||||||
|
|
||||||
EventHandler.on(window, EVENT_LOAD_DATA_API, () =>
|
EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
|
||||||
SelectorEngine.find(OPEN_SELECTOR).forEach(el => Offcanvas.getOrCreateInstance(el).show())
|
for (const el of SelectorEngine.find(OPEN_SELECTOR)) {
|
||||||
)
|
Offcanvas.getOrCreateInstance(el).show()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
enableDismissTrigger(Offcanvas)
|
enableDismissTrigger(Offcanvas)
|
||||||
/**
|
/**
|
||||||
|
@@ -111,7 +111,7 @@ class ScrollSpy extends BaseComponent {
|
|||||||
|
|
||||||
const targets = SelectorEngine.find(SELECTOR_LINK_ITEMS, this._config.target)
|
const targets = SelectorEngine.find(SELECTOR_LINK_ITEMS, this._config.target)
|
||||||
|
|
||||||
targets.map(element => {
|
for (const item of targets.map(element => {
|
||||||
const targetSelector = getSelectorFromElement(element)
|
const targetSelector = getSelectorFromElement(element)
|
||||||
const target = targetSelector ? SelectorEngine.findOne(targetSelector) : null
|
const target = targetSelector ? SelectorEngine.findOne(targetSelector) : null
|
||||||
|
|
||||||
@@ -128,11 +128,10 @@ class ScrollSpy extends BaseComponent {
|
|||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
.filter(item => item)
|
.filter(item => item)
|
||||||
.sort((a, b) => a[0] - b[0])
|
.sort((a, b) => a[0] - b[0])) {
|
||||||
.forEach(item => {
|
this._offsets.push(item[0])
|
||||||
this._offsets.push(item[0])
|
this._targets.push(item[1])
|
||||||
this._targets.push(item[1])
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
@@ -226,20 +225,20 @@ class ScrollSpy extends BaseComponent {
|
|||||||
SelectorEngine.findOne(SELECTOR_DROPDOWN_TOGGLE, link.closest(SELECTOR_DROPDOWN))
|
SelectorEngine.findOne(SELECTOR_DROPDOWN_TOGGLE, link.closest(SELECTOR_DROPDOWN))
|
||||||
.classList.add(CLASS_NAME_ACTIVE)
|
.classList.add(CLASS_NAME_ACTIVE)
|
||||||
} else {
|
} else {
|
||||||
SelectorEngine.parents(link, SELECTOR_NAV_LIST_GROUP)
|
for (const listGroup of SelectorEngine.parents(link, SELECTOR_NAV_LIST_GROUP)) {
|
||||||
.forEach(listGroup => {
|
// Set triggered links parents as active
|
||||||
// Set triggered links parents as active
|
// With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor
|
||||||
// With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor
|
for (const item of SelectorEngine.prev(listGroup, `${SELECTOR_NAV_LINKS}, ${SELECTOR_LIST_ITEMS}`)) {
|
||||||
SelectorEngine.prev(listGroup, `${SELECTOR_NAV_LINKS}, ${SELECTOR_LIST_ITEMS}`)
|
item.classList.add(CLASS_NAME_ACTIVE)
|
||||||
.forEach(item => item.classList.add(CLASS_NAME_ACTIVE))
|
}
|
||||||
|
|
||||||
// Handle special case when .nav-link is inside .nav-item
|
// Handle special case when .nav-link is inside .nav-item
|
||||||
SelectorEngine.prev(listGroup, SELECTOR_NAV_ITEMS)
|
for (const navItem of SelectorEngine.prev(listGroup, SELECTOR_NAV_ITEMS)) {
|
||||||
.forEach(navItem => {
|
for (const item of SelectorEngine.children(navItem, SELECTOR_NAV_LINKS)) {
|
||||||
SelectorEngine.children(navItem, SELECTOR_NAV_LINKS)
|
item.classList.add(CLASS_NAME_ACTIVE)
|
||||||
.forEach(item => item.classList.add(CLASS_NAME_ACTIVE))
|
}
|
||||||
})
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandler.trigger(this._scrollElement, EVENT_ACTIVATE, {
|
EventHandler.trigger(this._scrollElement, EVENT_ACTIVATE, {
|
||||||
@@ -248,9 +247,12 @@ class ScrollSpy extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_clear() {
|
_clear() {
|
||||||
SelectorEngine.find(SELECTOR_LINK_ITEMS, this._config.target)
|
const activeNodes = SelectorEngine.find(SELECTOR_LINK_ITEMS, this._config.target)
|
||||||
.filter(node => node.classList.contains(CLASS_NAME_ACTIVE))
|
.filter(node => node.classList.contains(CLASS_NAME_ACTIVE))
|
||||||
.forEach(node => node.classList.remove(CLASS_NAME_ACTIVE))
|
|
||||||
|
for (const node of activeNodes) {
|
||||||
|
node.classList.remove(CLASS_NAME_ACTIVE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static
|
// Static
|
||||||
@@ -279,8 +281,9 @@ class ScrollSpy extends BaseComponent {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
|
EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
|
||||||
SelectorEngine.find(SELECTOR_DATA_SPY)
|
for (const spy of SelectorEngine.find(SELECTOR_DATA_SPY)) {
|
||||||
.forEach(spy => new ScrollSpy(spy))
|
new ScrollSpy(spy) // eslint-disable-line no-new
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -164,8 +164,9 @@ class Tab extends BaseComponent {
|
|||||||
const dropdownElement = element.closest(SELECTOR_DROPDOWN)
|
const dropdownElement = element.closest(SELECTOR_DROPDOWN)
|
||||||
|
|
||||||
if (dropdownElement) {
|
if (dropdownElement) {
|
||||||
SelectorEngine.find(SELECTOR_DROPDOWN_TOGGLE, dropdownElement)
|
for (const dropdown of SelectorEngine.find(SELECTOR_DROPDOWN_TOGGLE, dropdownElement)) {
|
||||||
.forEach(dropdown => dropdown.classList.add(CLASS_NAME_ACTIVE))
|
dropdown.classList.add(CLASS_NAME_ACTIVE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element.setAttribute('aria-expanded', true)
|
element.setAttribute('aria-expanded', true)
|
||||||
|
@@ -285,9 +285,9 @@ class Tooltip extends BaseComponent {
|
|||||||
// only needed because of broken event delegation on iOS
|
// only needed because of broken event delegation on iOS
|
||||||
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
|
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if ('ontouchstart' in document.documentElement) {
|
||||||
[].concat(...document.body.children).forEach(element => {
|
for (const element of [].concat(...document.body.children)) {
|
||||||
EventHandler.on(element, 'mouseover', noop)
|
EventHandler.on(element, 'mouseover', noop)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const complete = () => {
|
const complete = () => {
|
||||||
@@ -337,8 +337,9 @@ class Tooltip extends BaseComponent {
|
|||||||
// If this is a touch-enabled device we remove the extra
|
// If this is a touch-enabled device we remove the extra
|
||||||
// empty mouseover listeners we added for iOS support
|
// empty mouseover listeners we added for iOS support
|
||||||
if ('ontouchstart' in document.documentElement) {
|
if ('ontouchstart' in document.documentElement) {
|
||||||
[].concat(...document.body.children)
|
for (const element of [].concat(...document.body.children)) {
|
||||||
.forEach(element => EventHandler.off(element, 'mouseover', noop))
|
EventHandler.off(element, 'mouseover', noop)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._activeTrigger[TRIGGER_CLICK] = false
|
this._activeTrigger[TRIGGER_CLICK] = false
|
||||||
@@ -527,7 +528,7 @@ class Tooltip extends BaseComponent {
|
|||||||
_setListeners() {
|
_setListeners() {
|
||||||
const triggers = this._config.trigger.split(' ')
|
const triggers = this._config.trigger.split(' ')
|
||||||
|
|
||||||
triggers.forEach(trigger => {
|
for (const trigger of triggers) {
|
||||||
if (trigger === 'click') {
|
if (trigger === 'click') {
|
||||||
EventHandler.on(this._element, this.constructor.Event.CLICK, this._config.selector, event => this.toggle(event))
|
EventHandler.on(this._element, this.constructor.Event.CLICK, this._config.selector, event => this.toggle(event))
|
||||||
} else if (trigger !== TRIGGER_MANUAL) {
|
} else if (trigger !== TRIGGER_MANUAL) {
|
||||||
@@ -541,7 +542,7 @@ class Tooltip extends BaseComponent {
|
|||||||
EventHandler.on(this._element, eventIn, this._config.selector, event => this._enter(event))
|
EventHandler.on(this._element, eventIn, this._config.selector, event => this._enter(event))
|
||||||
EventHandler.on(this._element, eventOut, this._config.selector, event => this._leave(event))
|
EventHandler.on(this._element, eventOut, this._config.selector, event => this._leave(event))
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
this._hideModalHandler = () => {
|
this._hideModalHandler = () => {
|
||||||
if (this._element) {
|
if (this._element) {
|
||||||
@@ -648,11 +649,11 @@ class Tooltip extends BaseComponent {
|
|||||||
_getConfig(config) {
|
_getConfig(config) {
|
||||||
const dataAttributes = Manipulator.getDataAttributes(this._element)
|
const dataAttributes = Manipulator.getDataAttributes(this._element)
|
||||||
|
|
||||||
Object.keys(dataAttributes).forEach(dataAttr => {
|
for (const dataAttr of Object.keys(dataAttributes)) {
|
||||||
if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
|
if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
|
||||||
delete dataAttributes[dataAttr]
|
delete dataAttributes[dataAttr]
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
...this.constructor.Default,
|
...this.constructor.Default,
|
||||||
@@ -706,8 +707,9 @@ class Tooltip extends BaseComponent {
|
|||||||
const basicClassPrefixRegex = new RegExp(`(^|\\s)${this._getBasicClassPrefix()}\\S+`, 'g')
|
const basicClassPrefixRegex = new RegExp(`(^|\\s)${this._getBasicClassPrefix()}\\S+`, 'g')
|
||||||
const tabClass = tip.getAttribute('class').match(basicClassPrefixRegex)
|
const tabClass = tip.getAttribute('class').match(basicClassPrefixRegex)
|
||||||
if (tabClass !== null && tabClass.length > 0) {
|
if (tabClass !== null && tabClass.length > 0) {
|
||||||
tabClass.map(token => token.trim())
|
for (const tClass of tabClass.map(token => token.trim())) {
|
||||||
.forEach(tClass => tip.classList.remove(tClass))
|
tip.classList.remove(tClass)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -125,7 +125,7 @@ const getElement = obj => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const typeCheckConfig = (componentName, config, configTypes) => {
|
const typeCheckConfig = (componentName, config, configTypes) => {
|
||||||
Object.keys(configTypes).forEach(property => {
|
for (const property of Object.keys(configTypes)) {
|
||||||
const expectedTypes = configTypes[property]
|
const expectedTypes = configTypes[property]
|
||||||
const value = config[property]
|
const value = config[property]
|
||||||
const valueType = value && isElement(value) ? 'element' : toType(value)
|
const valueType = value && isElement(value) ? 'element' : toType(value)
|
||||||
@@ -135,7 +135,7 @@ const typeCheckConfig = (componentName, config, configTypes) => {
|
|||||||
`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`
|
`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isVisible = element => {
|
const isVisible = element => {
|
||||||
@@ -217,7 +217,9 @@ const onDOMContentLoaded = callback => {
|
|||||||
// add listener on the first call when the document is in loading state
|
// add listener on the first call when the document is in loading state
|
||||||
if (!DOMContentLoadedCallbacks.length) {
|
if (!DOMContentLoadedCallbacks.length) {
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
DOMContentLoadedCallbacks.forEach(callback => callback())
|
for (const callback of DOMContentLoadedCallbacks) {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -114,11 +114,11 @@ export function sanitizeHtml(unsafeHtml, allowList, sanitizeFn) {
|
|||||||
const attributeList = [].concat(...element.attributes)
|
const attributeList = [].concat(...element.attributes)
|
||||||
const allowedAttributes = [].concat(allowList['*'] || [], allowList[elementName] || [])
|
const allowedAttributes = [].concat(allowList['*'] || [], allowList[elementName] || [])
|
||||||
|
|
||||||
attributeList.forEach(attribute => {
|
for (const attribute of attributeList) {
|
||||||
if (!allowedAttribute(attribute, allowedAttributes)) {
|
if (!allowedAttribute(attribute, allowedAttributes)) {
|
||||||
element.removeAttribute(attribute.nodeName)
|
element.removeAttribute(attribute.nodeName)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return createdDocument.body.innerHTML
|
return createdDocument.body.innerHTML
|
||||||
|
@@ -85,7 +85,9 @@ class ScrollBarHelper {
|
|||||||
if (isElement(selector)) {
|
if (isElement(selector)) {
|
||||||
callBack(selector)
|
callBack(selector)
|
||||||
} else {
|
} else {
|
||||||
SelectorEngine.find(selector, this._element).forEach(callBack)
|
for (const sel of SelectorEngine.find(selector, this._element)) {
|
||||||
|
callBack(sel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,17 +34,17 @@ export const jQueryMock = {
|
|||||||
elements: undefined,
|
elements: undefined,
|
||||||
fn: {},
|
fn: {},
|
||||||
each(fn) {
|
each(fn) {
|
||||||
this.elements.forEach(el => {
|
for (const el of this.elements) {
|
||||||
fn.call(el)
|
fn.call(el)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const clearBodyAndDocument = () => {
|
export const clearBodyAndDocument = () => {
|
||||||
const attributes = ['data-bs-padding-right', 'style']
|
const attributes = ['data-bs-padding-right', 'style']
|
||||||
|
|
||||||
attributes.forEach(attr => {
|
for (const attr of attributes) {
|
||||||
document.documentElement.removeAttribute(attr)
|
document.documentElement.removeAttribute(attr)
|
||||||
document.body.removeAttribute(attr)
|
document.body.removeAttribute(attr)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
@@ -211,14 +211,14 @@ describe('Carousel', () => {
|
|||||||
|
|
||||||
spyOn(carousel, '_triggerSlideEvent')
|
spyOn(carousel, '_triggerSlideEvent')
|
||||||
|
|
||||||
carousel._isSliding = true;
|
carousel._isSliding = true
|
||||||
|
|
||||||
['ArrowLeft', 'ArrowRight'].forEach(key => {
|
for (const key of ['ArrowLeft', 'ArrowRight']) {
|
||||||
const keydown = createEvent('keydown')
|
const keydown = createEvent('keydown')
|
||||||
keydown.key = key
|
keydown.key = key
|
||||||
|
|
||||||
carouselEl.dispatchEvent(keydown)
|
carouselEl.dispatchEvent(keydown)
|
||||||
})
|
}
|
||||||
|
|
||||||
expect(carousel._triggerSlideEvent).not.toHaveBeenCalled()
|
expect(carousel._triggerSlideEvent).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
@@ -17,10 +17,9 @@ describe('Modal', () => {
|
|||||||
clearBodyAndDocument()
|
clearBodyAndDocument()
|
||||||
document.body.classList.remove('modal-open')
|
document.body.classList.remove('modal-open')
|
||||||
|
|
||||||
document.querySelectorAll('.modal-backdrop')
|
for (const backdrop of document.querySelectorAll('.modal-backdrop')) {
|
||||||
.forEach(backdrop => {
|
backdrop.remove()
|
||||||
backdrop.remove()
|
}
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -15,9 +15,9 @@ describe('Popover', () => {
|
|||||||
|
|
||||||
const popoverList = document.querySelectorAll('.popover')
|
const popoverList = document.querySelectorAll('.popover')
|
||||||
|
|
||||||
popoverList.forEach(popoverEl => {
|
for (const popoverEl of popoverList) {
|
||||||
popoverEl.remove()
|
popoverEl.remove()
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('VERSION', () => {
|
describe('VERSION', () => {
|
||||||
|
@@ -15,9 +15,9 @@ describe('Tooltip', () => {
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
clearFixture()
|
clearFixture()
|
||||||
|
|
||||||
document.querySelectorAll('.tooltip').forEach(tooltipEl => {
|
for (const tooltipEl of document.querySelectorAll('.tooltip')) {
|
||||||
tooltipEl.remove()
|
tooltipEl.remove()
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('VERSION', () => {
|
describe('VERSION', () => {
|
||||||
|
@@ -17,9 +17,9 @@ describe('Backdrop', () => {
|
|||||||
clearFixture()
|
clearFixture()
|
||||||
const list = document.querySelectorAll(CLASS_BACKDROP)
|
const list = document.querySelectorAll(CLASS_BACKDROP)
|
||||||
|
|
||||||
list.forEach(el => {
|
for (const el of list) {
|
||||||
el.remove()
|
el.remove()
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('show', () => {
|
describe('show', () => {
|
||||||
@@ -35,9 +35,10 @@ describe('Backdrop', () => {
|
|||||||
instance.show()
|
instance.show()
|
||||||
instance.show(() => {
|
instance.show(() => {
|
||||||
expect(getElements().length).toEqual(1)
|
expect(getElements().length).toEqual(1)
|
||||||
getElements().forEach(el => {
|
for (const el of getElements()) {
|
||||||
expect(el.classList.contains(CLASS_NAME_SHOW)).toEqual(true)
|
expect(el.classList.contains(CLASS_NAME_SHOW)).toEqual(true)
|
||||||
})
|
}
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -67,9 +68,10 @@ describe('Backdrop', () => {
|
|||||||
|
|
||||||
instance.show(() => {
|
instance.show(() => {
|
||||||
expect(getElements().length).toEqual(1)
|
expect(getElements().length).toEqual(1)
|
||||||
getElements().forEach(el => {
|
for (const el of getElements()) {
|
||||||
expect(el.classList.contains(CLASS_NAME_FADE)).toEqual(true)
|
expect(el.classList.contains(CLASS_NAME_FADE)).toEqual(true)
|
||||||
})
|
}
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user