1 | /**
|
---|
2 | * --------------------------------------------------------------------------
|
---|
3 | * Bootstrap (v5.1.3): popover.js
|
---|
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
5 | * --------------------------------------------------------------------------
|
---|
6 | */
|
---|
7 |
|
---|
8 | import { defineJQueryPlugin } from './util/index'
|
---|
9 | import Tooltip from './tooltip'
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * ------------------------------------------------------------------------
|
---|
13 | * Constants
|
---|
14 | * ------------------------------------------------------------------------
|
---|
15 | */
|
---|
16 |
|
---|
17 | const NAME = 'popover'
|
---|
18 | const DATA_KEY = 'bs.popover'
|
---|
19 | const EVENT_KEY = `.${DATA_KEY}`
|
---|
20 | const CLASS_PREFIX = 'bs-popover'
|
---|
21 |
|
---|
22 | const Default = {
|
---|
23 | ...Tooltip.Default,
|
---|
24 | placement: 'right',
|
---|
25 | offset: [0, 8],
|
---|
26 | trigger: 'click',
|
---|
27 | content: '',
|
---|
28 | template: '<div class="popover" role="tooltip">' +
|
---|
29 | '<div class="popover-arrow"></div>' +
|
---|
30 | '<h3 class="popover-header"></h3>' +
|
---|
31 | '<div class="popover-body"></div>' +
|
---|
32 | '</div>'
|
---|
33 | }
|
---|
34 |
|
---|
35 | const DefaultType = {
|
---|
36 | ...Tooltip.DefaultType,
|
---|
37 | content: '(string|element|function)'
|
---|
38 | }
|
---|
39 |
|
---|
40 | const Event = {
|
---|
41 | HIDE: `hide${EVENT_KEY}`,
|
---|
42 | HIDDEN: `hidden${EVENT_KEY}`,
|
---|
43 | SHOW: `show${EVENT_KEY}`,
|
---|
44 | SHOWN: `shown${EVENT_KEY}`,
|
---|
45 | INSERTED: `inserted${EVENT_KEY}`,
|
---|
46 | CLICK: `click${EVENT_KEY}`,
|
---|
47 | FOCUSIN: `focusin${EVENT_KEY}`,
|
---|
48 | FOCUSOUT: `focusout${EVENT_KEY}`,
|
---|
49 | MOUSEENTER: `mouseenter${EVENT_KEY}`,
|
---|
50 | MOUSELEAVE: `mouseleave${EVENT_KEY}`
|
---|
51 | }
|
---|
52 |
|
---|
53 | const SELECTOR_TITLE = '.popover-header'
|
---|
54 | const SELECTOR_CONTENT = '.popover-body'
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * ------------------------------------------------------------------------
|
---|
58 | * Class Definition
|
---|
59 | * ------------------------------------------------------------------------
|
---|
60 | */
|
---|
61 |
|
---|
62 | class Popover extends Tooltip {
|
---|
63 | // Getters
|
---|
64 |
|
---|
65 | static get Default() {
|
---|
66 | return Default
|
---|
67 | }
|
---|
68 |
|
---|
69 | static get NAME() {
|
---|
70 | return NAME
|
---|
71 | }
|
---|
72 |
|
---|
73 | static get Event() {
|
---|
74 | return Event
|
---|
75 | }
|
---|
76 |
|
---|
77 | static get DefaultType() {
|
---|
78 | return DefaultType
|
---|
79 | }
|
---|
80 |
|
---|
81 | // Overrides
|
---|
82 |
|
---|
83 | isWithContent() {
|
---|
84 | return this.getTitle() || this._getContent()
|
---|
85 | }
|
---|
86 |
|
---|
87 | setContent(tip) {
|
---|
88 | this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TITLE)
|
---|
89 | this._sanitizeAndSetContent(tip, this._getContent(), SELECTOR_CONTENT)
|
---|
90 | }
|
---|
91 |
|
---|
92 | // Private
|
---|
93 |
|
---|
94 | _getContent() {
|
---|
95 | return this._resolvePossibleFunction(this._config.content)
|
---|
96 | }
|
---|
97 |
|
---|
98 | _getBasicClassPrefix() {
|
---|
99 | return CLASS_PREFIX
|
---|
100 | }
|
---|
101 |
|
---|
102 | // Static
|
---|
103 |
|
---|
104 | static jQueryInterface(config) {
|
---|
105 | return this.each(function () {
|
---|
106 | const data = Popover.getOrCreateInstance(this, config)
|
---|
107 |
|
---|
108 | if (typeof config === 'string') {
|
---|
109 | if (typeof data[config] === 'undefined') {
|
---|
110 | throw new TypeError(`No method named "${config}"`)
|
---|
111 | }
|
---|
112 |
|
---|
113 | data[config]()
|
---|
114 | }
|
---|
115 | })
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * ------------------------------------------------------------------------
|
---|
121 | * jQuery
|
---|
122 | * ------------------------------------------------------------------------
|
---|
123 | * add .Popover to jQuery only if jQuery is present
|
---|
124 | */
|
---|
125 |
|
---|
126 | defineJQueryPlugin(Popover)
|
---|
127 |
|
---|
128 | export default Popover
|
---|