.forEach(element => {
const actualPadding = element.style.paddingRight
const calculatedPadding = window.getComputedStyle(element)['padding-right']
- Manipulator.setDataAttribute(element, 'bs-padding-right', actualPadding)
+ Manipulator.setDataAttribute(element, 'padding-right', actualPadding)
element.style.paddingRight = `${Number.parseFloat(calculatedPadding) + this._scrollbarWidth}px`
})
.forEach(element => {
const actualMargin = element.style.marginRight
const calculatedMargin = window.getComputedStyle(element)['margin-right']
- Manipulator.setDataAttribute(element, 'bs-margin-right', actualMargin)
+ Manipulator.setDataAttribute(element, 'margin-right', actualMargin)
element.style.marginRight = `${Number.parseFloat(calculatedMargin) - this._scrollbarWidth}px`
})
const actualPadding = document.body.style.paddingRight
const calculatedPadding = window.getComputedStyle(document.body)['padding-right']
- Manipulator.setDataAttribute(document.body, 'bs-padding-right', actualPadding)
+ Manipulator.setDataAttribute(document.body, 'padding-right', actualPadding)
document.body.style.paddingRight = `${Number.parseFloat(calculatedPadding) + this._scrollbarWidth}px`
}
// Restore fixed content padding
SelectorEngine.find(SELECTOR_FIXED_CONTENT)
.forEach(element => {
- const padding = Manipulator.getDataAttribute(element, 'bs-padding-right')
+ const padding = Manipulator.getDataAttribute(element, 'padding-right')
if (typeof padding !== 'undefined') {
- Manipulator.removeDataAttribute(element, 'bs-padding-right')
+ Manipulator.removeDataAttribute(element, 'padding-right')
element.style.paddingRight = padding
}
})
// Restore sticky content and navbar-toggler margin
SelectorEngine.find(`${SELECTOR_STICKY_CONTENT}`)
.forEach(element => {
- const margin = Manipulator.getDataAttribute(element, 'bs-margin-right')
+ const margin = Manipulator.getDataAttribute(element, 'margin-right')
if (typeof margin !== 'undefined') {
- Manipulator.removeDataAttribute(element, 'bs-margin-right')
+ Manipulator.removeDataAttribute(element, 'margin-right')
element.style.marginRight = margin
}
})
// Restore body padding
- const padding = Manipulator.getDataAttribute(document.body, 'bs-padding-right')
+ const padding = Manipulator.getDataAttribute(document.body, 'padding-right')
if (typeof padding === 'undefined') {
document.body.style.paddingRight = ''
} else {
- Manipulator.removeDataAttribute(document.body, 'bs-padding-right')
+ Manipulator.removeDataAttribute(document.body, 'padding-right')
document.body.style.paddingRight = padding
}
}
})
describe('setDataAttribute', () => {
- it('should set data attribute', () => {
+ it('should set data attribute prefixed with bs', () => {
fixtureEl.innerHTML = '<div></div>'
const div = fixtureEl.querySelector('div')
Manipulator.setDataAttribute(div, 'key', 'value')
- expect(div.getAttribute('data-key')).toEqual('value')
+ expect(div.getAttribute('data-bs-key')).toEqual('value')
})
it('should set data attribute in kebab case', () => {
const div = fixtureEl.querySelector('div')
Manipulator.setDataAttribute(div, 'testKey', 'value')
- expect(div.getAttribute('data-test-key')).toEqual('value')
+ expect(div.getAttribute('data-bs-test-key')).toEqual('value')
})
})
describe('removeDataAttribute', () => {
- it('should remove data attribute', () => {
- fixtureEl.innerHTML = '<div data-key="value"></div>'
+ it('should only remove bs-prefixed data attribute', () => {
+ fixtureEl.innerHTML = '<div data-bs-key="value" data-key-bs="postfixed" data-key="value"></div>'
const div = fixtureEl.querySelector('div')
Manipulator.removeDataAttribute(div, 'key')
- expect(div.getAttribute('data-key')).toBeNull()
+ expect(div.getAttribute('data-bs-key')).toBeNull()
+ expect(div.getAttribute('data-key-bs')).toEqual('postfixed')
+ expect(div.getAttribute('data-key')).toEqual('value')
})
it('should remove data attribute in kebab case', () => {
- fixtureEl.innerHTML = '<div data-test-key="value"></div>'
+ fixtureEl.innerHTML = '<div data-bs-test-key="value"></div>'
const div = fixtureEl.querySelector('div')
Manipulator.removeDataAttribute(div, 'testKey')
- expect(div.getAttribute('data-test-key')).toBeNull()
+ expect(div.getAttribute('data-bs-test-key')).toBeNull()
})
})
describe('getDataAttributes', () => {
- it('should return empty object for null', () => {
+ it('should return an empty object for null', () => {
expect(Manipulator.getDataAttributes(null)).toEqual({})
expect().nothing()
})
- it('should get only bs prefixed data attributes without bs namespace', () => {
+ it('should get only bs-prefixed data attributes without bs namespace', () => {
fixtureEl.innerHTML = '<div data-bs-toggle="tabs" data-bs-target="#element" data-another="value" data-target-bs="#element" data-in-bs-out="in-between"></div>'
const div = fixtureEl.querySelector('div')
})
describe('getDataAttribute', () => {
- it('should get data attribute', () => {
- fixtureEl.innerHTML = '<div data-test="null" ></div>'
+ it('should only get bs-prefixed data attribute', () => {
+ fixtureEl.innerHTML = '<div data-bs-key="value" data-test-bs="postFixed" data-toggle="tab"></div>'
const div = fixtureEl.querySelector('div')
+ expect(Manipulator.getDataAttribute(div, 'key')).toEqual('value')
expect(Manipulator.getDataAttribute(div, 'test')).toBeNull()
+ expect(Manipulator.getDataAttribute(div, 'toggle')).toBeNull()
})
it('should get data attribute in kebab case', () => {
- fixtureEl.innerHTML = '<div data-test-key="value" ></div>'
+ fixtureEl.innerHTML = '<div data-bs-test-key="value" ></div>'
const div = fixtureEl.querySelector('div')
})
it('should normalize data', () => {
- fixtureEl.innerHTML = '<div data-test="false" ></div>'
+ fixtureEl.innerHTML = '<div data-bs-test="false" ></div>'
const div = fixtureEl.querySelector('div')
expect(Manipulator.getDataAttribute(div, 'test')).toEqual(false)
- div.setAttribute('data-test', 'true')
+ div.setAttribute('data-bs-test', 'true')
expect(Manipulator.getDataAttribute(div, 'test')).toEqual(true)
- div.setAttribute('data-test', '1')
+ div.setAttribute('data-bs-test', '1')
expect(Manipulator.getDataAttribute(div, 'test')).toEqual(1)
})
})
describe('offset', () => {
- it('should return object with two properties top and left, both numbers', () => {
+ it('should return an object with two properties top and left, both numbers', () => {
fixtureEl.innerHTML = '<div></div>'
const div = fixtureEl.querySelector('div')
})
describe('position', () => {
- it('should return object with two properties top and left, both numbers', () => {
+ it('should return an object with two properties top and left, both numbers', () => {
fixtureEl.innerHTML = '<div></div>'
const div = fixtureEl.querySelector('div')