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