mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-05 17:24:20 +01:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
const fixtureId = 'fixture'
|
|
|
|
export const getFixture = () => {
|
|
let fixtureElement = document.getElementById(fixtureId)
|
|
|
|
if (!fixtureElement) {
|
|
fixtureElement = document.createElement('div')
|
|
fixtureElement.setAttribute('id', fixtureId)
|
|
fixtureElement.style.position = 'absolute'
|
|
fixtureElement.style.top = '-10000px'
|
|
fixtureElement.style.left = '-10000px'
|
|
fixtureElement.style.width = '10000px'
|
|
fixtureElement.style.height = '10000px'
|
|
document.body.append(fixtureElement)
|
|
}
|
|
|
|
return fixtureElement
|
|
}
|
|
|
|
export const clearFixture = () => {
|
|
const fixtureElement = getFixture()
|
|
|
|
fixtureElement.innerHTML = ''
|
|
}
|
|
|
|
export const createEvent = (eventName, parameters = {}) => {
|
|
const event = document.createEvent('Event')
|
|
|
|
event.initEvent(eventName, Boolean(parameters.bubbles), Boolean(parameters.cancelable))
|
|
return event
|
|
}
|
|
|
|
export const jQueryMock = {
|
|
elements: undefined,
|
|
fn: {},
|
|
each(fn) {
|
|
for (const element of this.elements) {
|
|
fn.call(element)
|
|
}
|
|
}
|
|
}
|
|
|
|
export const clearBodyAndDocument = () => {
|
|
const attributes = ['data-bs-padding-right', 'style']
|
|
|
|
for (const attribute of attributes) {
|
|
document.documentElement.removeAttribute(attribute)
|
|
document.body.removeAttribute(attribute)
|
|
}
|
|
}
|