mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-30 22:52:24 +01:00
Use on private method to set content & cleanup template
This commit is contained in:
parent
9c3ceaa25b
commit
da2db218ed
@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineJQueryPlugin } from './util/index'
|
import { defineJQueryPlugin } from './util/index'
|
||||||
import SelectorEngine from './dom/selector-engine'
|
|
||||||
import Tooltip from './tooltip'
|
import Tooltip from './tooltip'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,35 +84,11 @@ class Popover extends Tooltip {
|
|||||||
return this.getTitle() || this._getContent()
|
return this.getTitle() || this._getContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
getTipElement() {
|
|
||||||
if (this.tip) {
|
|
||||||
return this.tip
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tip = super.getTipElement()
|
|
||||||
|
|
||||||
if (!this.getTitle()) {
|
|
||||||
SelectorEngine.findOne(SELECTOR_TITLE, this.tip).remove()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this._getContent()) {
|
|
||||||
SelectorEngine.findOne(SELECTOR_CONTENT, this.tip).remove()
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.tip
|
|
||||||
}
|
|
||||||
|
|
||||||
setContent() {
|
setContent() {
|
||||||
const tip = this.getTipElement()
|
const tip = this.getTipElement()
|
||||||
|
|
||||||
// we use append for html objects to maintain js events
|
this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TITLE)
|
||||||
this.setElementContent(SelectorEngine.findOne(SELECTOR_TITLE, tip), this.getTitle())
|
this._sanitizeAndSetContent(tip, this._getContent(), SELECTOR_CONTENT)
|
||||||
let content = this._getContent()
|
|
||||||
if (typeof content === 'function') {
|
|
||||||
content = content.call(this._element)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setElementContent(SelectorEngine.findOne(SELECTOR_CONTENT, tip), content)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
@ -376,8 +376,18 @@ class Tooltip extends BaseComponent {
|
|||||||
|
|
||||||
setContent() {
|
setContent() {
|
||||||
const tip = this.getTipElement()
|
const tip = this.getTipElement()
|
||||||
this.setElementContent(SelectorEngine.findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle())
|
this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TOOLTIP_INNER)
|
||||||
tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW)
|
}
|
||||||
|
|
||||||
|
_sanitizeAndSetContent(template, content, selector) {
|
||||||
|
const templateElement = SelectorEngine.findOne(selector, template)
|
||||||
|
if (!content) {
|
||||||
|
templateElement.remove()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// we use append for html objects to maintain js events
|
||||||
|
this.setElementContent(templateElement, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
setElementContent(element, content) {
|
setElementContent(element, content) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user