2015-05-12 14:28:11 -07:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2019-02-13 18:01:40 +02:00
|
|
|
* Bootstrap (v4.3.1): popover.js
|
2015-05-12 14:28:11 -07:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2019-10-02 11:43:54 +02:00
|
|
|
import { getjQuery } from './util/index'
|
|
|
|
import Data from './dom/data'
|
|
|
|
import SelectorEngine from './dom/selector-engine'
|
|
|
|
import Tooltip from './tooltip'
|
2018-11-14 10:16:56 +01:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Constants
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2019-02-26 13:20:34 +02:00
|
|
|
const NAME = 'popover'
|
|
|
|
const VERSION = '4.3.1'
|
|
|
|
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')
|
2018-09-26 10:39:01 +02:00
|
|
|
|
|
|
|
const Default = {
|
|
|
|
...Tooltip.Default,
|
2019-02-26 13:20:34 +02:00
|
|
|
placement: 'right',
|
|
|
|
trigger: 'click',
|
|
|
|
content: '',
|
|
|
|
template: '<div class="popover" role="tooltip">' +
|
2019-02-11 11:27:14 +01:00
|
|
|
'<div class="popover-arrow"></div>' +
|
2018-09-26 10:39:01 +02:00
|
|
|
'<h3 class="popover-header"></h3>' +
|
|
|
|
'<div class="popover-body"></div></div>'
|
|
|
|
}
|
|
|
|
|
|
|
|
const DefaultType = {
|
|
|
|
...Tooltip.DefaultType,
|
2019-02-26 13:20:34 +02:00
|
|
|
content: '(string|element|function)'
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const Event = {
|
2019-02-26 13:20:34 +02:00
|
|
|
HIDE: `hide${EVENT_KEY}`,
|
|
|
|
HIDDEN: `hidden${EVENT_KEY}`,
|
|
|
|
SHOW: `show${EVENT_KEY}`,
|
|
|
|
SHOWN: `shown${EVENT_KEY}`,
|
|
|
|
INSERTED: `inserted${EVENT_KEY}`,
|
|
|
|
CLICK: `click${EVENT_KEY}`,
|
|
|
|
FOCUSIN: `focusin${EVENT_KEY}`,
|
|
|
|
FOCUSOUT: `focusout${EVENT_KEY}`,
|
|
|
|
MOUSEENTER: `mouseenter${EVENT_KEY}`,
|
|
|
|
MOUSELEAVE: `mouseleave${EVENT_KEY}`
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
2020-03-07 11:31:42 +02:00
|
|
|
const CLASS_NAME_FADE = 'fade'
|
|
|
|
const CLASS_NAME_SHOW = 'show'
|
|
|
|
|
|
|
|
const SELECTOR_TITLE = '.popover-header'
|
|
|
|
const SELECTOR_CONTENT = '.popover-body'
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Class Definition
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Popover extends Tooltip {
|
|
|
|
// Getters
|
|
|
|
|
|
|
|
static get VERSION() {
|
|
|
|
return VERSION
|
2017-11-13 11:25:36 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get Default() {
|
|
|
|
return Default
|
2017-11-13 11:25:36 +01:00
|
|
|
}
|
2015-05-13 14:46:50 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get NAME() {
|
|
|
|
return NAME
|
2015-05-12 14:28:11 -07:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get DATA_KEY() {
|
|
|
|
return DATA_KEY
|
2015-05-12 14:28:11 -07:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get Event() {
|
|
|
|
return Event
|
2015-05-12 14:28:11 -07:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get EVENT_KEY() {
|
|
|
|
return EVENT_KEY
|
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get DefaultType() {
|
|
|
|
return DefaultType
|
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Overrides
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
isWithContent() {
|
|
|
|
return this.getTitle() || this._getContent()
|
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
setContent() {
|
2017-09-21 18:04:47 +02:00
|
|
|
const tip = this.getTipElement()
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2017-09-21 18:04:47 +02:00
|
|
|
// we use append for html objects to maintain js events
|
2020-03-07 11:31:42 +02:00
|
|
|
this.setElementContent(SelectorEngine.findOne(SELECTOR_TITLE, tip), this.getTitle())
|
2018-09-26 10:39:01 +02:00
|
|
|
let content = this._getContent()
|
|
|
|
if (typeof content === 'function') {
|
|
|
|
content = content.call(this.element)
|
2015-05-13 12:48:34 -07:00
|
|
|
}
|
2019-02-26 13:20:34 +02:00
|
|
|
|
2020-03-07 11:31:42 +02:00
|
|
|
this.setElementContent(SelectorEngine.findOne(SELECTOR_CONTENT, tip), content)
|
2015-05-13 12:48:34 -07:00
|
|
|
|
2020-03-07 11:31:42 +02:00
|
|
|
tip.classList.remove(CLASS_NAME_FADE)
|
|
|
|
tip.classList.remove(CLASS_NAME_SHOW)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-13 14:46:50 -07:00
|
|
|
|
2019-07-24 09:53:58 +02:00
|
|
|
_addAttachmentClass(attachment) {
|
|
|
|
this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
|
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Private
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_getContent() {
|
|
|
|
return this.element.getAttribute('data-content') ||
|
|
|
|
this.config.content
|
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_cleanTipClass() {
|
2017-09-21 18:04:47 +02:00
|
|
|
const tip = this.getTipElement()
|
|
|
|
const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
|
2018-09-26 10:39:01 +02:00
|
|
|
if (tabClass !== null && tabClass.length > 0) {
|
2019-02-26 13:20:34 +02:00
|
|
|
tabClass.map(token => token.trim())
|
|
|
|
.forEach(tClass => tip.classList.remove(tClass))
|
2017-04-07 13:20:34 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2017-04-07 13:20:34 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Static
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2019-07-28 15:24:46 +02:00
|
|
|
static jQueryInterface(config) {
|
2018-09-26 10:39:01 +02:00
|
|
|
return this.each(function () {
|
2019-02-26 13:20:34 +02:00
|
|
|
let data = Data.getData(this, DATA_KEY)
|
2018-09-26 10:39:01 +02:00
|
|
|
const _config = typeof config === 'object' ? config : null
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (!data && /dispose|hide/.test(config)) {
|
|
|
|
return
|
2017-11-07 08:18:52 +01:00
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (!data) {
|
|
|
|
data = new Popover(this, _config)
|
2017-09-21 18:04:47 +02:00
|
|
|
Data.setData(this, DATA_KEY, data)
|
2017-04-07 13:20:34 +02:00
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (typeof config === 'string') {
|
|
|
|
if (typeof data[config] === 'undefined') {
|
|
|
|
throw new TypeError(`No method named "${config}"`)
|
2015-05-12 14:28:11 -07:00
|
|
|
}
|
2019-02-26 13:20:34 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
data[config]()
|
|
|
|
}
|
|
|
|
})
|
2015-05-12 14:28:11 -07:00
|
|
|
}
|
2018-06-07 21:43:04 +02:00
|
|
|
|
2019-07-28 15:24:46 +02:00
|
|
|
static getInstance(element) {
|
2018-06-07 21:43:04 +02:00
|
|
|
return Data.getData(element, DATA_KEY)
|
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2019-08-02 15:51:05 +02:00
|
|
|
const $ = getjQuery()
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* jQuery
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2019-05-08 21:32:50 +02:00
|
|
|
/* istanbul ignore if */
|
2019-08-02 15:51:05 +02:00
|
|
|
if ($) {
|
2017-09-21 18:04:47 +02:00
|
|
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
2019-07-28 15:24:46 +02:00
|
|
|
$.fn[NAME] = Popover.jQueryInterface
|
2019-02-26 13:20:34 +02:00
|
|
|
$.fn[NAME].Constructor = Popover
|
|
|
|
$.fn[NAME].noConflict = () => {
|
2017-09-21 18:04:47 +02:00
|
|
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
2019-07-28 15:24:46 +02:00
|
|
|
return Popover.jQueryInterface
|
2017-09-21 18:04:47 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
|
|
|
export default Popover
|