twbs--bootstrap/js/src/popover.js

117 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-05-12 17:28:11 -04:00
/**
* --------------------------------------------------------------------------
2021-10-09 02:33:12 -04:00
* Bootstrap (v5.1.3): popover.js
2020-06-16 14:41:47 -04:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2015-05-12 17:28:11 -04:00
* --------------------------------------------------------------------------
*/
import { defineJQueryPlugin } from './util/index'
import Tooltip from './tooltip'
2018-09-26 04:39:01 -04:00
/**
* Constants
*/
2019-02-26 06:20:34 -05:00
const NAME = 'popover'
const DATA_KEY = 'bs.popover'
const EVENT_KEY = `.${DATA_KEY}`
2018-09-26 04:39:01 -04:00
const SELECTOR_TITLE = '.popover-header'
const SELECTOR_CONTENT = '.popover-body'
2018-09-26 04:39:01 -04:00
const Default = {
...Tooltip.Default,
2019-02-26 06:20:34 -05:00
placement: 'right',
offset: [0, 8],
2019-02-26 06:20:34 -05:00
trigger: 'click',
content: '',
template: '<div class="popover" role="tooltip">' +
2019-02-11 05:27:14 -05:00
'<div class="popover-arrow"></div>' +
'<h3 class="popover-header"></h3>' +
2020-12-01 23:45:15 -05:00
'<div class="popover-body"></div>' +
'</div>'
2018-09-26 04:39:01 -04:00
}
const DefaultType = {
...Tooltip.DefaultType,
content: '(null|string|element|function)'
2018-09-26 04:39:01 -04:00
}
const Event = {
2019-02-26 06:20:34 -05: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 04:39:01 -04:00
}
/**
* Class definition
2018-09-26 04:39:01 -04:00
*/
class Popover extends Tooltip {
// Getters
static get Default() {
return Default
}
2015-05-13 17:46:50 -04:00
static get DefaultType() {
return DefaultType
}
2018-09-26 04:39:01 -04:00
static get NAME() {
return NAME
2015-05-12 17:28:11 -04:00
}
2018-09-26 04:39:01 -04:00
static get Event() {
return Event
2015-05-12 17:28:11 -04:00
}
2018-09-26 04:39:01 -04:00
// Overrides
_isWithContent() {
return this._getTitle() || this._getContent()
2018-09-26 04:39:01 -04:00
}
2015-05-12 17:28:11 -04:00
// Private
_getContentForTemplate() {
return {
[SELECTOR_TITLE]: this._getTitle(),
[SELECTOR_CONTENT]: this._getContent()
}
2018-09-26 04:39:01 -04:00
}
2015-05-13 17:46:50 -04:00
2018-09-26 04:39:01 -04:00
_getContent() {
return this._resolvePossibleFunction(this._config.content)
2018-09-26 04:39:01 -04:00
}
2015-05-12 17:28:11 -04:00
2018-09-26 04:39:01 -04:00
// Static
2019-07-28 09:24:46 -04:00
static jQueryInterface(config) {
2018-09-26 04:39:01 -04:00
return this.each(function () {
const data = Popover.getOrCreateInstance(this, config)
2015-05-12 17:28:11 -04:00
2021-11-25 13:33:42 -05:00
if (typeof config !== 'string') {
return
}
2019-02-26 06:20:34 -05:00
2021-11-25 13:33:42 -05:00
if (typeof data[config] === 'undefined') {
throw new TypeError(`No method named "${config}"`)
2018-09-26 04:39:01 -04:00
}
2021-11-25 13:33:42 -05:00
data[config]()
2018-09-26 04:39:01 -04:00
})
2015-05-12 17:28:11 -04:00
}
2018-09-26 04:39:01 -04:00
}
2015-05-12 17:28:11 -04:00
2018-09-26 04:39:01 -04:00
/**
* jQuery
*/
defineJQueryPlugin(Popover)
2015-05-12 17:28:11 -04:00
export default Popover