2 import Tooltip from './tooltip'
5 * --------------------------------------------------------------------------
6 * Bootstrap (v4.1.3): popover.js
7 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
8 * --------------------------------------------------------------------------
11 const Popover = (($) => {
13 * ------------------------------------------------------------------------
15 * ------------------------------------------------------------------------
18 const NAME = 'popover'
19 const VERSION = '4.1.3'
20 const DATA_KEY = 'bs.popover'
21 const EVENT_KEY = `.${DATA_KEY}`
22 const JQUERY_NO_CONFLICT = $.fn[NAME]
23 const CLASS_PREFIX = 'bs-popover'
24 const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
31 template : '<div class="popover" role="tooltip">' +
32 '<div class="arrow"></div>' +
33 '<h3 class="popover-header"></h3>' +
34 '<div class="popover-body"></div></div>'
38 ...Tooltip.DefaultType,
39 content : '(string|element|function)'
48 TITLE : '.popover-header',
49 CONTENT : '.popover-body'
53 HIDE : `hide${EVENT_KEY}`,
54 HIDDEN : `hidden${EVENT_KEY}`,
55 SHOW : `show${EVENT_KEY}`,
56 SHOWN : `shown${EVENT_KEY}`,
57 INSERTED : `inserted${EVENT_KEY}`,
58 CLICK : `click${EVENT_KEY}`,
59 FOCUSIN : `focusin${EVENT_KEY}`,
60 FOCUSOUT : `focusout${EVENT_KEY}`,
61 MOUSEENTER : `mouseenter${EVENT_KEY}`,
62 MOUSELEAVE : `mouseleave${EVENT_KEY}`
66 * ------------------------------------------------------------------------
68 * ------------------------------------------------------------------------
71 class Popover extends Tooltip {
74 static get VERSION() {
78 static get Default() {
86 static get DATA_KEY() {
94 static get EVENT_KEY() {
98 static get DefaultType() {
105 return this.getTitle() || this._getContent()
108 addAttachmentClass(attachment) {
109 $(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)
113 this.tip = this.tip || $(this.config.template)[0]
118 const $tip = $(this.getTipElement())
120 // We use append for html objects to maintain js events
121 this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
122 let content = this._getContent()
123 if (typeof content === 'function') {
124 content = content.call(this.element)
126 this.setElementContent($tip.find(Selector.CONTENT), content)
128 $tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
134 return this.element.getAttribute('data-content') ||
139 const $tip = $(this.getTipElement())
140 const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)
141 if (tabClass !== null && tabClass.length > 0) {
142 $tip.removeClass(tabClass.join(''))
148 static _jQueryInterface(config) {
149 return this.each(function () {
150 let data = $(this).data(DATA_KEY)
151 const _config = typeof config === 'object' ? config : null
153 if (!data && /destroy|hide/.test(config)) {
158 data = new Popover(this, _config)
159 $(this).data(DATA_KEY, data)
162 if (typeof config === 'string') {
163 if (typeof data[config] === 'undefined') {
164 throw new TypeError(`No method named "${config}"`)
173 * ------------------------------------------------------------------------
175 * ------------------------------------------------------------------------
178 $.fn[NAME] = Popover._jQueryInterface
179 $.fn[NAME].Constructor = Popover
180 $.fn[NAME].noConflict = function () {
181 $.fn[NAME] = JQUERY_NO_CONFLICT
182 return Popover._jQueryInterface
188 export default Popover