2015-05-12 14:28:11 -07:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2021-09-07 18:37:44 +03:00
|
|
|
* Bootstrap (v5.1.1): popover.js
|
2020-06-16 21:41:47 +03:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
2015-05-12 14:28:11 -07:00
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2020-12-08 07:16:50 +01:00
|
|
|
import { defineJQueryPlugin } from './util/index'
|
2019-10-02 11:43:54 +02:00
|
|
|
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 DATA_KEY = 'bs.popover'
|
|
|
|
const EVENT_KEY = `.${DATA_KEY}`
|
|
|
|
const CLASS_PREFIX = 'bs-popover'
|
2018-09-26 10:39:01 +02:00
|
|
|
|
|
|
|
const Default = {
|
|
|
|
...Tooltip.Default,
|
2019-02-26 13:20:34 +02:00
|
|
|
placement: 'right',
|
2021-02-04 01:07:25 +05:30
|
|
|
offset: [0, 8],
|
2019-02-26 13:20:34 +02:00
|
|
|
trigger: 'click',
|
|
|
|
content: '',
|
|
|
|
template: '<div class="popover" role="tooltip">' +
|
2019-02-11 11:27:14 +01:00
|
|
|
'<div class="popover-arrow"></div>' +
|
2021-05-18 11:32:39 +05:30
|
|
|
'<h3 class="popover-header"></h3>' +
|
2020-12-02 06:45:15 +02:00
|
|
|
'<div class="popover-body"></div>' +
|
|
|
|
'</div>'
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 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 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 Event() {
|
|
|
|
return Event
|
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
|
|
|
|
2021-08-03 11:59:33 +03:00
|
|
|
setContent(tip) {
|
2021-06-10 11:00:05 +03:00
|
|
|
this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TITLE)
|
|
|
|
this._sanitizeAndSetContent(tip, this._getContent(), SELECTOR_CONTENT)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-13 14:46:50 -07:00
|
|
|
|
2020-06-26 18:40:54 +03:00
|
|
|
// Private
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_getContent() {
|
2021-06-10 10:55:34 +03:00
|
|
|
return this._resolvePossibleFunction(this._config.content)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2021-06-10 10:48:35 +03:00
|
|
|
_getBasicClassPrefix() {
|
|
|
|
return CLASS_PREFIX
|
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 () {
|
2021-06-03 18:53:27 +03:00
|
|
|
const data = Popover.getOrCreateInstance(this, config)
|
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-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* jQuery
|
|
|
|
* ------------------------------------------------------------------------
|
2020-11-01 15:49:51 +02:00
|
|
|
* add .Popover to jQuery only if jQuery is present
|
2018-09-26 10:39:01 +02:00
|
|
|
*/
|
2020-11-01 14:32:36 +01:00
|
|
|
|
2021-05-11 10:49:30 +03:00
|
|
|
defineJQueryPlugin(Popover)
|
2015-05-12 14:28:11 -07:00
|
|
|
|
|
|
|
export default Popover
|