diff options
Diffstat (limited to 'js/src/popover.js')
| -rw-r--r-- | js/src/popover.js | 63 |
1 files changed, 10 insertions, 53 deletions
diff --git a/js/src/popover.js b/js/src/popover.js index 0677dafa0..a01e2d294 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -1,13 +1,11 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-beta2): popover.js + * Bootstrap (v5.1.0): popover.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ import { defineJQueryPlugin } from './util/index' -import Data from './dom/data' -import SelectorEngine from './dom/selector-engine' import Tooltip from './tooltip' /** @@ -20,7 +18,6 @@ const NAME = 'popover' const DATA_KEY = 'bs.popover' const EVENT_KEY = `.${DATA_KEY}` const CLASS_PREFIX = 'bs-popover' -const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g') const Default = { ...Tooltip.Default, @@ -30,7 +27,7 @@ const Default = { content: '', template: '<div class="popover" role="tooltip">' + '<div class="popover-arrow"></div>' + - '<h3 class="popover-header"></h3>' + + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div>' + '</div>' } @@ -53,9 +50,6 @@ const Event = { MOUSELEAVE: `mouseleave${EVENT_KEY}` } -const CLASS_NAME_FADE = 'fade' -const CLASS_NAME_SHOW = 'show' - const SELECTOR_TITLE = '.popover-header' const SELECTOR_CONTENT = '.popover-body' @@ -76,18 +70,10 @@ class Popover extends Tooltip { return NAME } - static get DATA_KEY() { - return DATA_KEY - } - static get Event() { return Event } - static get EVENT_KEY() { - return EVENT_KEY - } - static get DefaultType() { return DefaultType } @@ -98,55 +84,26 @@ class Popover extends Tooltip { return this.getTitle() || this._getContent() } - setContent() { - const tip = this.getTipElement() - - // we use append for html objects to maintain js events - this.setElementContent(SelectorEngine.findOne(SELECTOR_TITLE, tip), this.getTitle()) - let content = this._getContent() - if (typeof content === 'function') { - content = content.call(this._element) - } - - this.setElementContent(SelectorEngine.findOne(SELECTOR_CONTENT, tip), content) - - tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW) + setContent(tip) { + this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TITLE) + this._sanitizeAndSetContent(tip, this._getContent(), SELECTOR_CONTENT) } // Private - _addAttachmentClass(attachment) { - this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`) - } - _getContent() { - return this._element.getAttribute('data-bs-content') || this.config.content + return this._resolvePossibleFunction(this._config.content) } - _cleanTipClass() { - const tip = this.getTipElement() - const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX) - if (tabClass !== null && tabClass.length > 0) { - tabClass.map(token => token.trim()) - .forEach(tClass => tip.classList.remove(tClass)) - } + _getBasicClassPrefix() { + return CLASS_PREFIX } // Static static jQueryInterface(config) { return this.each(function () { - let data = Data.getData(this, DATA_KEY) - const _config = typeof config === 'object' ? config : null - - if (!data && /dispose|hide/.test(config)) { - return - } - - if (!data) { - data = new Popover(this, _config) - Data.setData(this, DATA_KEY, data) - } + const data = Popover.getOrCreateInstance(this, config) if (typeof config === 'string') { if (typeof data[config] === 'undefined') { @@ -166,6 +123,6 @@ class Popover extends Tooltip { * add .Popover to jQuery only if jQuery is present */ -defineJQueryPlugin(NAME, Popover) +defineJQueryPlugin(Popover) export default Popover |
