]> git.ipfire.org Git - ipfire.org.git/blame - src/scss/bootstrap-4.0.0-alpha.6/js/src/popover.js
Introduce autotools
[ipfire.org.git] / src / scss / bootstrap-4.0.0-alpha.6 / js / src / popover.js
CommitLineData
91e44d91
S
1import Tooltip from './tooltip'
2
3
4/**
5 * --------------------------------------------------------------------------
6 * Bootstrap (v4.0.0-alpha.6): popover.js
7 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
8 * --------------------------------------------------------------------------
9 */
10
11const Popover = (($) => {
12
13
14 /**
15 * ------------------------------------------------------------------------
16 * Constants
17 * ------------------------------------------------------------------------
18 */
19
20 const NAME = 'popover'
21 const VERSION = '4.0.0-alpha.6'
22 const DATA_KEY = 'bs.popover'
23 const EVENT_KEY = `.${DATA_KEY}`
24 const JQUERY_NO_CONFLICT = $.fn[NAME]
25
26 const Default = $.extend({}, Tooltip.Default, {
27 placement : 'right',
28 trigger : 'click',
29 content : '',
30 template : '<div class="popover" role="tooltip">'
31 + '<h3 class="popover-title"></h3>'
32 + '<div class="popover-content"></div></div>'
33 })
34
35 const DefaultType = $.extend({}, Tooltip.DefaultType, {
36 content : '(string|element|function)'
37 })
38
39 const ClassName = {
40 FADE : 'fade',
41 SHOW : 'show'
42 }
43
44 const Selector = {
45 TITLE : '.popover-title',
46 CONTENT : '.popover-content'
47 }
48
49 const Event = {
50 HIDE : `hide${EVENT_KEY}`,
51 HIDDEN : `hidden${EVENT_KEY}`,
52 SHOW : `show${EVENT_KEY}`,
53 SHOWN : `shown${EVENT_KEY}`,
54 INSERTED : `inserted${EVENT_KEY}`,
55 CLICK : `click${EVENT_KEY}`,
56 FOCUSIN : `focusin${EVENT_KEY}`,
57 FOCUSOUT : `focusout${EVENT_KEY}`,
58 MOUSEENTER : `mouseenter${EVENT_KEY}`,
59 MOUSELEAVE : `mouseleave${EVENT_KEY}`
60 }
61
62
63 /**
64 * ------------------------------------------------------------------------
65 * Class Definition
66 * ------------------------------------------------------------------------
67 */
68
69 class Popover extends Tooltip {
70
71
72 // getters
73
74 static get VERSION() {
75 return VERSION
76 }
77
78 static get Default() {
79 return Default
80 }
81
82 static get NAME() {
83 return NAME
84 }
85
86 static get DATA_KEY() {
87 return DATA_KEY
88 }
89
90 static get Event() {
91 return Event
92 }
93
94 static get EVENT_KEY() {
95 return EVENT_KEY
96 }
97
98 static get DefaultType() {
99 return DefaultType
100 }
101
102
103 // overrides
104
105 isWithContent() {
106 return this.getTitle() || this._getContent()
107 }
108
109 getTipElement() {
110 return this.tip = this.tip || $(this.config.template)[0]
111 }
112
113 setContent() {
114 const $tip = $(this.getTipElement())
115
116 // we use append for html objects to maintain js events
117 this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
118 this.setElementContent($tip.find(Selector.CONTENT), this._getContent())
119
120 $tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
121
122 this.cleanupTether()
123 }
124
125 // private
126
127 _getContent() {
128 return this.element.getAttribute('data-content')
129 || (typeof this.config.content === 'function' ?
130 this.config.content.call(this.element) :
131 this.config.content)
132 }
133
134
135 // static
136
137 static _jQueryInterface(config) {
138 return this.each(function () {
139 let data = $(this).data(DATA_KEY)
140 const _config = typeof config === 'object' ? config : null
141
142 if (!data && /destroy|hide/.test(config)) {
143 return
144 }
145
146 if (!data) {
147 data = new Popover(this, _config)
148 $(this).data(DATA_KEY, data)
149 }
150
151 if (typeof config === 'string') {
152 if (data[config] === undefined) {
153 throw new Error(`No method named "${config}"`)
154 }
155 data[config]()
156 }
157 })
158 }
159 }
160
161
162 /**
163 * ------------------------------------------------------------------------
164 * jQuery
165 * ------------------------------------------------------------------------
166 */
167
168 $.fn[NAME] = Popover._jQueryInterface
169 $.fn[NAME].Constructor = Popover
170 $.fn[NAME].noConflict = function () {
171 $.fn[NAME] = JQUERY_NO_CONFLICT
172 return Popover._jQueryInterface
173 }
174
175 return Popover
176
177})(jQuery)
178
179export default Popover