0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Tooltip/Popover: add underscore prefix to protected functions

This commit is contained in:
GeoSot 2021-11-29 16:25:12 +02:00 committed by XhmikosR
parent bd79d69a73
commit 385fea49e8
4 changed files with 48 additions and 48 deletions

View File

@ -73,14 +73,14 @@ class Popover extends Tooltip {
}
// Overrides
isWithContent() {
return this.getTitle() || this._getContent()
_isWithContent() {
return this._getTitle() || this._getContent()
}
// Private
_getContentForTemplate() {
return {
[SELECTOR_TITLE]: this.getTitle(),
[SELECTOR_TITLE]: this._getTitle(),
[SELECTOR_CONTENT]: this._getContent()
}
}

View File

@ -181,7 +181,7 @@ class Tooltip extends BaseComponent {
context._leave()
}
} else {
if (this.getTipElement().classList.contains(CLASS_NAME_SHOW)) {
if (this._getTipElement().classList.contains(CLASS_NAME_SHOW)) {
this._leave()
return
}
@ -208,7 +208,7 @@ class Tooltip extends BaseComponent {
throw new Error('Please use show on visible elements')
}
if (!(this.isWithContent() && this._isEnabled)) {
if (!(this._isWithContent() && this._isEnabled)) {
return
}
@ -222,7 +222,7 @@ class Tooltip extends BaseComponent {
return
}
const tip = this.getTipElement()
const tip = this._getTipElement()
this._element.setAttribute('aria-describedby', tip.getAttribute('id'))
@ -279,7 +279,7 @@ class Tooltip extends BaseComponent {
return
}
const tip = this.getTipElement()
const tip = this._getTipElement()
tip.classList.remove(CLASS_NAME_SHOW)
// If this is a touch-enabled device we remove the extra
@ -320,11 +320,11 @@ class Tooltip extends BaseComponent {
}
// Protected
isWithContent() {
return Boolean(this.getTitle())
_isWithContent() {
return Boolean(this._getTitle())
}
getTipElement() {
_getTipElement() {
if (!this.tip) {
this.tip = this._createTipElement(this._getContentForTemplate())
}
@ -389,11 +389,11 @@ class Tooltip extends BaseComponent {
_getContentForTemplate() {
return {
[SELECTOR_TOOLTIP_INNER]: this.getTitle()
[SELECTOR_TOOLTIP_INNER]: this._getTitle()
}
}
getTitle() {
_getTitle() {
return this._resolvePossibleFunction(this._config.title) || this._element.getAttribute('title')
}
@ -518,7 +518,7 @@ class Tooltip extends BaseComponent {
}
_enter() {
if (this.getTipElement().classList.contains(CLASS_NAME_SHOW) || this._isHovered) {
if (this._getTipElement().classList.contains(CLASS_NAME_SHOW) || this._isHovered) {
this._isHovered = true
return
}

View File

@ -162,7 +162,7 @@ describe('Popover', () => {
const popover = new Popover(popoverEl)
popover.setContent({ '.tooltip-inner': 'foo' })
const tip = popover.getTipElement()
const tip = popover._getTipElement()
expect(tip).toHaveClass('popover')
expect(tip).toHaveClass('bs-popover-auto')

View File

@ -466,12 +466,12 @@ describe('Tooltip', () => {
})
tooltipEl.addEventListener('inserted.bs.tooltip', () => {
expect(tooltip.getTipElement()).toHaveClass('bs-tooltip-auto')
expect(tooltip._getTipElement()).toHaveClass('bs-tooltip-auto')
})
tooltipEl.addEventListener('shown.bs.tooltip', () => {
expect(tooltip.getTipElement()).toHaveClass('bs-tooltip-auto')
expect(tooltip.getTipElement().getAttribute('data-popper-placement')).toEqual('bottom')
expect(tooltip._getTipElement()).toHaveClass('bs-tooltip-auto')
expect(tooltip._getTipElement().getAttribute('data-popper-placement')).toEqual('bottom')
done()
})
@ -689,20 +689,20 @@ describe('Tooltip', () => {
})
setTimeout(() => {
expect(tooltip.getTipElement()).toHaveClass('show')
expect(tooltip._getTipElement()).toHaveClass('show')
tooltipEl.dispatchEvent(createEvent('mouseout'))
setTimeout(() => {
expect(tooltip.getTipElement()).toHaveClass('show')
expect(tooltip._getTipElement()).toHaveClass('show')
tooltipEl.dispatchEvent(createEvent('mouseover'))
}, 100)
setTimeout(() => {
expect(tooltip.getTipElement()).toHaveClass('show')
expect(tooltip._getTipElement()).toHaveClass('show')
expect(document.querySelectorAll('.tooltip')).toHaveSize(1)
done()
}, 200)
}, 3)
}, 10)
tooltipEl.dispatchEvent(createEvent('mouseover'))
})
@ -752,20 +752,20 @@ describe('Tooltip', () => {
setTimeout(() => {
expect(tooltip._popper).not.toBeNull()
expect(tooltip.getTipElement().getAttribute('data-popper-placement')).toEqual('top')
expect(tooltip._getTipElement().getAttribute('data-popper-placement')).toEqual('top')
tooltipEl.dispatchEvent(createEvent('mouseout'))
setTimeout(() => {
expect(tooltip.getTipElement()).not.toHaveClass('show')
expect(tooltip._getTipElement()).not.toHaveClass('show')
tooltipEl.dispatchEvent(createEvent('mouseover'))
}, 100)
setTimeout(() => {
expect(tooltip._popper).not.toBeNull()
expect(tooltip.getTipElement().getAttribute('data-popper-placement')).toEqual('top')
expect(tooltip._getTipElement().getAttribute('data-popper-placement')).toEqual('top')
done()
}, 200)
}, 3)
}, 10)
tooltipEl.dispatchEvent(createEvent('mouseover'))
})
@ -986,14 +986,14 @@ describe('Tooltip', () => {
})
})
describe('isWithContent', () => {
describe('_isWithContent', () => {
it('should return true if there is content', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip">'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
expect(tooltip.isWithContent()).toBeTrue()
expect(tooltip._isWithContent()).toBeTrue()
})
it('should return false if there is no content', () => {
@ -1002,11 +1002,11 @@ describe('Tooltip', () => {
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
expect(tooltip.isWithContent()).toBeFalse()
expect(tooltip._isWithContent()).toBeFalse()
})
})
describe('getTipElement', () => {
describe('_getTipElement', () => {
it('should create the tip element and return it', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip">'
@ -1015,7 +1015,7 @@ describe('Tooltip', () => {
spyOn(document, 'createElement').and.callThrough()
expect(tooltip.getTipElement()).toBeDefined()
expect(tooltip._getTipElement()).toBeDefined()
expect(document.createElement).toHaveBeenCalled()
})
@ -1027,12 +1027,12 @@ describe('Tooltip', () => {
const spy = spyOn(document, 'createElement').and.callThrough()
expect(tooltip.getTipElement()).toBeDefined()
expect(tooltip._getTipElement()).toBeDefined()
expect(spy).toHaveBeenCalled()
spy.calls.reset()
expect(tooltip.getTipElement()).toBeDefined()
expect(tooltip._getTipElement()).toBeDefined()
expect(spy).not.toHaveBeenCalled()
})
})
@ -1044,7 +1044,7 @@ describe('Tooltip', () => {
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl, { animation: false })
const tip = tooltip.getTipElement()
const tip = tooltip._getTipElement()
tooltip.setContent(tip)
@ -1059,7 +1059,7 @@ describe('Tooltip', () => {
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
tooltip.show()
const tip = () => tooltip.getTipElement()
const tip = () => tooltip._getTipElement()
expect(tip()).toHaveClass('show')
tooltip.setContent({ '.tooltip-inner': 'foo' })
@ -1073,7 +1073,7 @@ describe('Tooltip', () => {
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
const tip = () => tooltip.getTipElement()
const tip = () => tooltip._getTipElement()
expect(tip()).not.toHaveClass('show')
tooltip.setContent({ '.tooltip-inner': 'foo' })
@ -1089,7 +1089,7 @@ describe('Tooltip', () => {
const tooltip = new Tooltip(tooltipEl)
tooltip.setContent({ '.tooltip-inner': 'foo' })
const tip = tooltip.getTipElement()
const tip = tooltip._getTipElement()
expect(tip).toHaveClass('tooltip')
expect(tip).toHaveClass('bs-tooltip-auto')
@ -1121,7 +1121,7 @@ describe('Tooltip', () => {
html: true
})
tooltip.getTipElement().append(childContent)
tooltip._getTipElement().append(childContent)
tooltip.setContent({ '.tooltip': childContent })
expect().nothing()
@ -1141,7 +1141,7 @@ describe('Tooltip', () => {
tooltip.setContent({ '.tooltip': { 0: childContent, jquery: 'jQuery' } })
expect(childContent.parentNode).toEqual(tooltip.getTipElement())
expect(childContent.parentNode).toEqual(tooltip._getTipElement())
})
it('should add the child text content in the element', () => {
@ -1156,7 +1156,7 @@ describe('Tooltip', () => {
tooltip.setContent({ '.tooltip': childContent })
expect(childContent.textContent).toEqual(tooltip.getTipElement().textContent)
expect(childContent.textContent).toEqual(tooltip._getTipElement().textContent)
})
it('should add html without sanitize it', () => {
@ -1170,7 +1170,7 @@ describe('Tooltip', () => {
tooltip.setContent({ '.tooltip': '<div id="childContent">Tooltip</div>' })
expect(tooltip.getTipElement().querySelector('div').id).toEqual('childContent')
expect(tooltip._getTipElement().querySelector('div').id).toEqual('childContent')
})
it('should add html sanitized', () => {
@ -1188,8 +1188,8 @@ describe('Tooltip', () => {
].join('')
tooltip.setContent({ '.tooltip': content })
expect(tooltip.getTipElement().querySelector('div').id).toEqual('childContent')
expect(tooltip.getTipElement().querySelector('button')).toBeNull()
expect(tooltip._getTipElement().querySelector('div').id).toEqual('childContent')
expect(tooltip._getTipElement().querySelector('button')).toBeNull()
})
it('should add text content', () => {
@ -1200,18 +1200,18 @@ describe('Tooltip', () => {
tooltip.setContent({ '.tooltip': 'test' })
expect(tooltip.getTipElement().textContent).toEqual('test')
expect(tooltip._getTipElement().textContent).toEqual('test')
})
})
describe('getTitle', () => {
describe('_getTitle', () => {
it('should return the title', () => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip">'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
expect(tooltip.getTitle()).toEqual('Another tooltip')
expect(tooltip._getTitle()).toEqual('Another tooltip')
})
it('should call title function', () => {
@ -1222,7 +1222,7 @@ describe('Tooltip', () => {
title: () => 'test'
})
expect(tooltip.getTitle()).toEqual('test')
expect(tooltip._getTitle()).toEqual('test')
})
})
@ -1331,7 +1331,7 @@ describe('Tooltip', () => {
})
expect(tooltip).toBeInstanceOf(Tooltip)
expect(tooltip.getTitle()).toEqual('test')
expect(tooltip._getTitle()).toEqual('test')
})
it('should return the instance when exists without given configuration', () => {
@ -1349,7 +1349,7 @@ describe('Tooltip', () => {
expect(tooltip).toBeInstanceOf(Tooltip)
expect(tooltip2).toEqual(tooltip)
expect(tooltip2.getTitle()).toEqual('nothing')
expect(tooltip2._getTitle()).toEqual('nothing')
})
})