2015-05-12 14:28:11 -07:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2023-03-22 09:12:33 +02:00
|
|
|
* Bootstrap 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
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2022-10-26 08:26:51 +03:00
|
|
|
import Tooltip from './tooltip.js'
|
2023-03-29 20:49:30 +03:00
|
|
|
import { defineJQueryPlugin } from './util/index.js'
|
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'
|
2018-09-26 10:39:01 +02:00
|
|
|
|
2021-10-13 15:19:28 +03:00
|
|
|
const SELECTOR_TITLE = '.popover-header'
|
|
|
|
const SELECTOR_CONTENT = '.popover-body'
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
const Default = {
|
|
|
|
...Tooltip.Default,
|
2019-02-26 13:20:34 +02:00
|
|
|
content: '',
|
2022-05-19 15:35:44 +02:00
|
|
|
offset: [0, 8],
|
|
|
|
placement: 'right',
|
2019-02-26 13:20:34 +02:00
|
|
|
template: '<div class="popover" role="tooltip">' +
|
2022-05-19 15:35:44 +02:00
|
|
|
'<div class="popover-arrow"></div>' +
|
|
|
|
'<h3 class="popover-header"></h3>' +
|
|
|
|
'<div class="popover-body"></div>' +
|
|
|
|
'</div>',
|
|
|
|
trigger: 'click'
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const DefaultType = {
|
|
|
|
...Tooltip.DefaultType,
|
2021-12-15 10:41:31 +02:00
|
|
|
content: '(null|string|element|function)'
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-13 15:19:28 +03:00
|
|
|
* Class definition
|
2018-09-26 10:39:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-12-10 18:18:18 +02:00
|
|
|
static get DefaultType() {
|
|
|
|
return DefaultType
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Overrides
|
2021-11-29 16:25:12 +02:00
|
|
|
_isWithContent() {
|
|
|
|
return this._getTitle() || this._getContent()
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 14:28:11 -07:00
|
|
|
|
2021-11-25 19:14:02 +02:00
|
|
|
// Private
|
|
|
|
_getContentForTemplate() {
|
|
|
|
return {
|
2021-11-29 16:25:12 +02:00
|
|
|
[SELECTOR_TITLE]: this._getTitle(),
|
2021-11-25 19:14:02 +02:00
|
|
|
[SELECTOR_CONTENT]: this._getContent()
|
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-13 14:46:50 -07:00
|
|
|
|
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
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Static
|
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
|
|
|
|
2021-11-25 20:33:42 +02:00
|
|
|
if (typeof config !== 'string') {
|
|
|
|
return
|
|
|
|
}
|
2019-02-26 13:20:34 +02:00
|
|
|
|
2021-11-25 20:33:42 +02:00
|
|
|
if (typeof data[config] === 'undefined') {
|
|
|
|
throw new TypeError(`No method named "${config}"`)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2021-11-25 20:33:42 +02:00
|
|
|
|
|
|
|
data[config]()
|
2018-09-26 10:39:01 +02:00
|
|
|
})
|
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 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
|