9
import Tooltip from './tooltip'
16
const VERSION = '4.6.1'
17
const DATA_KEY = 'bs.popover'
18
const EVENT_KEY = `.${DATA_KEY}`
19
const JQUERY_NO_CONFLICT = $.fn[NAME]
20
const CLASS_PREFIX = 'bs-popover'
21
const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
23
const CLASS_NAME_FADE = 'fade'
24
const CLASS_NAME_SHOW = 'show'
26
const SELECTOR_TITLE = '.popover-header'
27
const SELECTOR_CONTENT = '.popover-body'
34
template: '<div class="popover" role="tooltip">' +
35
'<div class="arrow"></div>' +
36
'<h3 class="popover-header"></h3>' +
37
'<div class="popover-body"></div></div>'
41
...Tooltip.DefaultType,
42
content: '(string|element|function)'
46
HIDE: `hide${EVENT_KEY}`,
47
HIDDEN: `hidden${EVENT_KEY}`,
48
SHOW: `show${EVENT_KEY}`,
49
SHOWN: `shown${EVENT_KEY}`,
50
INSERTED: `inserted${EVENT_KEY}`,
51
CLICK: `click${EVENT_KEY}`,
52
FOCUSIN: `focusin${EVENT_KEY}`,
53
FOCUSOUT: `focusout${EVENT_KEY}`,
54
MOUSEENTER: `mouseenter${EVENT_KEY}`,
55
MOUSELEAVE: `mouseleave${EVENT_KEY}`
62
class Popover extends Tooltip {
64
static get VERSION() {
68
static get Default() {
76
static get DATA_KEY() {
84
static get EVENT_KEY() {
88
static get DefaultType() {
94
return this.getTitle() || this._getContent()
97
addAttachmentClass(attachment) {
98
$(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)
102
this.tip = this.tip || $(this.config.template)[0]
107
const $tip = $(this.getTipElement())
110
this.setElementContent($tip.find(SELECTOR_TITLE), this.getTitle())
111
let content = this._getContent()
112
if (typeof content === 'function') {
113
content = content.call(this.element)
116
this.setElementContent($tip.find(SELECTOR_CONTENT), content)
118
$tip.removeClass(`${CLASS_NAME_FADE} ${CLASS_NAME_SHOW}`)
123
return this.element.getAttribute('data-content') ||
128
const $tip = $(this.getTipElement())
129
const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)
130
if (tabClass !== null && tabClass.length > 0) {
131
$tip.removeClass(tabClass.join(''))
136
static _jQueryInterface(config) {
137
return this.each(function () {
138
let data = $(this).data(DATA_KEY)
139
const _config = typeof config === 'object' ? config : null
141
if (!data && /dispose|hide/.test(config)) {
146
data = new Popover(this, _config)
147
$(this).data(DATA_KEY, data)
150
if (typeof config === 'string') {
151
if (typeof data[config] === 'undefined') {
152
throw new TypeError(`No method named "${config}"`)
165
$.fn[NAME] = Popover._jQueryInterface
166
$.fn[NAME].Constructor = Popover
167
$.fn[NAME].noConflict = () => {
168
$.fn[NAME] = JQUERY_NO_CONFLICT
169
return Popover._jQueryInterface
172
export default Popover