Skip to content

Commit

Permalink
Revert "Switch to Node#append() / Node#remove()"
Browse files Browse the repository at this point in the history
Edge 16 does not support these.
  • Loading branch information
XhmikosR committed May 8, 2020
1 parent 83e33df commit 46e815f
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Expand Up @@ -49,6 +49,8 @@
"unicorn/no-null": "off",
"unicorn/no-unused-properties": "error",
"unicorn/prefer-dataset": "off",
"unicorn/prefer-node-append": "off",
"unicorn/prefer-node-remove": "off",
"unicorn/prefer-query-selector": "off",
"unicorn/prevent-abbreviations": "off"
}
Expand Down
2 changes: 1 addition & 1 deletion js/src/alert.js
Expand Up @@ -107,7 +107,7 @@ class Alert {

_destroyElement(element) {
if (element.parentNode) {
element.remove()
element.parentNode.removeChild(element)
}

EventHandler.trigger(element, EVENT_CLOSED)
Expand Down
10 changes: 5 additions & 5 deletions js/src/modal.js
Expand Up @@ -242,7 +242,7 @@ class Modal {
if (!this._element.parentNode ||
this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
// Don't move modal's DOM position
document.body.append(this._element)
document.body.appendChild(this._element)
}

this._element.style.display = 'block'
Expand Down Expand Up @@ -333,7 +333,7 @@ class Modal {
}

_removeBackdrop() {
this._backdrop.remove()
this._backdrop.parentNode.removeChild(this._backdrop)
this._backdrop = null
}

Expand All @@ -350,7 +350,7 @@ class Modal {
this._backdrop.classList.add(animate)
}

document.body.append(this._backdrop)
document.body.appendChild(this._backdrop)

EventHandler.on(this._element, EVENT_CLICK_DISMISS, event => {
if (this._ignoreBackdropClick) {
Expand Down Expand Up @@ -515,9 +515,9 @@ class Modal {
_getScrollbarWidth() { // thx d.walsh
const scrollDiv = document.createElement('div')
scrollDiv.className = CLASS_NAME_SCROLLBAR_MEASURER
document.body.append(scrollDiv)
document.body.appendChild(scrollDiv)
const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth
scrollDiv.remove()
document.body.removeChild(scrollDiv)
return scrollbarWidth
}

Expand Down
8 changes: 4 additions & 4 deletions js/src/tooltip.js
Expand Up @@ -230,7 +230,7 @@ class Tooltip {
EventHandler.off(this.element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)

if (this.tip) {
this.tip.remove()
this.tip.parentNode.removeChild(this.tip)
}

this._isEnabled = null
Expand Down Expand Up @@ -286,7 +286,7 @@ class Tooltip {
Data.setData(tip, this.constructor.DATA_KEY, this)

if (!this.element.ownerDocument.documentElement.contains(this.tip)) {
container.append(tip)
container.appendChild(tip)
}

EventHandler.trigger(this.element, this.constructor.Event.INSERTED)
Expand Down Expand Up @@ -334,7 +334,7 @@ class Tooltip {
const tip = this.getTipElement()
const complete = () => {
if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
tip.remove()
tip.parentNode.removeChild(tip)
}

this._cleanTipClass()
Expand Down Expand Up @@ -417,7 +417,7 @@ class Tooltip {
if (this.config.html) {
if (content.parentNode !== element) {
element.innerHTML = ''
element.append(content)
element.appendChild(content)
}
} else {
element.textContent = content.textContent
Expand Down
2 changes: 1 addition & 1 deletion js/src/util/sanitizer.js
Expand Up @@ -108,7 +108,7 @@ export function sanitizeHtml(unsafeHtml, whiteList, sanitizeFn) {
const elName = el.nodeName.toLowerCase()

if (!whitelistKeys.includes(elName)) {
el.remove()
el.parentNode.removeChild(el)

continue
}
Expand Down
2 changes: 1 addition & 1 deletion js/tests/helpers/fixture.js
Expand Up @@ -11,7 +11,7 @@ export const getFixture = () => {
fixtureEl.style.left = '-10000px'
fixtureEl.style.width = '10000px'
fixtureEl.style.height = '10000px'
document.body.append(fixtureEl)
document.body.appendChild(fixtureEl)
}

return fixtureEl
Expand Down
10 changes: 5 additions & 5 deletions js/tests/unit/carousel.spec.js
Expand Up @@ -13,7 +13,7 @@ describe('Carousel', () => {

const stylesCarousel = document.createElement('style')
stylesCarousel.type = 'text/css'
stylesCarousel.append(document.createTextNode(cssStyleCarousel))
stylesCarousel.appendChild(document.createTextNode(cssStyleCarousel))

const clearPointerEvents = () => {
window.PointerEvent = null
Expand Down Expand Up @@ -309,7 +309,7 @@ describe('Carousel', () => {
}

document.documentElement.ontouchstart = () => {}
document.head.append(stylesCarousel)
document.head.appendChild(stylesCarousel)
Simulator.setType('pointer')

fixtureEl.innerHTML = [
Expand All @@ -334,7 +334,7 @@ describe('Carousel', () => {
carouselEl.addEventListener('slid.bs.carousel', () => {
expect(item.classList.contains('active')).toEqual(true)
expect(carousel.prev).toHaveBeenCalled()
stylesCarousel.remove()
document.head.removeChild(stylesCarousel)
delete document.documentElement.ontouchstart
done()
})
Expand All @@ -353,7 +353,7 @@ describe('Carousel', () => {
}

document.documentElement.ontouchstart = () => {}
document.head.append(stylesCarousel)
document.head.appendChild(stylesCarousel)
Simulator.setType('pointer')

fixtureEl.innerHTML = [
Expand All @@ -378,7 +378,7 @@ describe('Carousel', () => {
carouselEl.addEventListener('slid.bs.carousel', () => {
expect(item.classList.contains('active')).toEqual(false)
expect(carousel.next).toHaveBeenCalled()
stylesCarousel.remove()
document.head.removeChild(stylesCarousel)
delete document.documentElement.ontouchstart
done()
})
Expand Down
6 changes: 3 additions & 3 deletions js/tests/unit/dom/event-handler.spec.js
Expand Up @@ -278,10 +278,10 @@ describe('EventHandler', () => {
it('should remove the correct delegated event listener', () => {
const element = document.createElement('div')
const subelement = document.createElement('span')
element.append(subelement)
element.appendChild(subelement)

const anchor = document.createElement('a')
element.append(anchor)
element.appendChild(anchor)

let i = 0
const handler = () => {
Expand All @@ -291,7 +291,7 @@ describe('EventHandler', () => {
EventHandler.on(element, 'click', 'a', handler)
EventHandler.on(element, 'click', 'span', handler)

fixtureEl.append(element)
fixtureEl.appendChild(element)

EventHandler.trigger(anchor, 'click')
EventHandler.trigger(subelement, 'click')
Expand Down
22 changes: 11 additions & 11 deletions js/tests/unit/modal.spec.js
Expand Up @@ -16,9 +16,9 @@ describe('Modal', () => {

style = document.createElement('style')
style.type = 'text/css'
style.append(document.createTextNode(css))
style.appendChild(document.createTextNode(css))

document.head.append(style)
document.head.appendChild(style)

// Simulate scrollbars
document.documentElement.style.paddingRight = '16px'
Expand All @@ -33,14 +33,14 @@ describe('Modal', () => {

document.querySelectorAll('.modal-backdrop')
.forEach(backdrop => {
backdrop.remove()
document.body.removeChild(backdrop)
})

document.body.style.paddingRight = '0px'
})

afterAll(() => {
style.remove()
document.head.removeChild(style)
document.documentElement.style.paddingRight = '0px'
})

Expand Down Expand Up @@ -147,8 +147,8 @@ describe('Modal', () => {
const styleTest = document.createElement('style')

styleTest.type = 'text/css'
styleTest.append(document.createTextNode('body { padding-right: 7px; }'))
document.head.append(styleTest)
styleTest.appendChild(document.createTextNode('body { padding-right: 7px; }'))
document.head.appendChild(styleTest)

const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
Expand All @@ -159,7 +159,7 @@ describe('Modal', () => {

modalEl.addEventListener('hidden.bs.modal', () => {
expect(window.getComputedStyle(document.body).paddingLeft).toEqual('0px', 'body does not have inline padding set')
styleTest.remove()
document.head.removeChild(styleTest)
done()
})

Expand All @@ -171,9 +171,9 @@ describe('Modal', () => {
const styleTest = document.createElement('style')

styleTest.type = 'text/css'
styleTest.append(document.createTextNode('body { padding-right: 7px; }'))
styleTest.appendChild(document.createTextNode('body { padding-right: 7px; }'))

document.head.append(styleTest)
document.head.appendChild(styleTest)
document.body.style.color = 'red'

const modalEl = fixtureEl.querySelector('.modal')
Expand All @@ -188,7 +188,7 @@ describe('Modal', () => {

expect(bodyPaddingRight === '0px' || bodyPaddingRight === '').toEqual(true, 'body does not have inline padding set')
expect(document.body.style.color).toEqual('red', 'body still has other inline styles set')
styleTest.remove()
document.head.removeChild(styleTest)
document.body.removeAttribute('style')
done()
})
Expand Down Expand Up @@ -276,7 +276,7 @@ describe('Modal', () => {
modalEl.addEventListener('shown.bs.modal', () => {
const dynamicModal = document.getElementById(id)
expect(dynamicModal).toBeDefined()
dynamicModal.remove()
dynamicModal.parentNode.removeChild(dynamicModal)
done()
})

Expand Down
2 changes: 1 addition & 1 deletion js/tests/unit/popover.spec.js
Expand Up @@ -16,7 +16,7 @@ describe('Popover', () => {
const popoverList = document.querySelectorAll('.popover')

popoverList.forEach(popoverEl => {
popoverEl.remove()
document.body.removeChild(popoverEl)
})
})

Expand Down
4 changes: 2 additions & 2 deletions js/tests/unit/tab.spec.js
Expand Up @@ -319,8 +319,8 @@ describe('Tab', () => {
const tabId = linkEl.getAttribute('href')
const tabIdEl = fixtureEl.querySelector(tabId)

liEl.remove()
tabIdEl.remove()
liEl.parentNode.removeChild(liEl)
tabIdEl.parentNode.removeChild(tabIdEl)
secondNavTab.show()
})

Expand Down
6 changes: 3 additions & 3 deletions js/tests/unit/tooltip.spec.js
Expand Up @@ -16,7 +16,7 @@ describe('Tooltip', () => {
clearFixture()

document.querySelectorAll('.tooltip').forEach(tooltipEl => {
tooltipEl.remove()
document.body.removeChild(tooltipEl)
})
})

Expand Down Expand Up @@ -375,7 +375,7 @@ describe('Tooltip', () => {
tooltipEl.removeEventListener('shown.bs.tooltip', firstCallback)
let tooltipShown = document.querySelector('.tooltip')

tooltipShown.remove()
tooltipShown.parentNode.removeChild(tooltipShown)

tooltipEl.addEventListener('shown.bs.tooltip', () => {
tooltipShown = document.querySelector('.tooltip')
Expand Down Expand Up @@ -835,7 +835,7 @@ describe('Tooltip', () => {
html: true
})

tooltip.getTipElement().append(childContent)
tooltip.getTipElement().appendChild(childContent)
tooltip.setElementContent(tooltip.getTipElement(), childContent)

expect().nothing()
Expand Down
1 change: 1 addition & 0 deletions site/.eslintrc.json
Expand Up @@ -36,6 +36,7 @@
"unicorn/no-for-loop": "off",
"unicorn/no-null": "off",
"unicorn/prefer-dataset": "off",
"unicorn/prefer-node-append": "off",
"unicorn/prefer-query-selector": "off",
"unicorn/prevent-abbreviations": "off"
}
Expand Down

0 comments on commit 46e815f

Please sign in to comment.