corrade-http-templates – Blame information for rev 61

Subversion Repositories:
Rev:
Rev Author Line No. Line
61 office 1 import $ from 'jquery'
2 import Tooltip from './tooltip'
3  
4 /**
5 * --------------------------------------------------------------------------
6 * Bootstrap (v4.1.3): popover.js
7 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
8 * --------------------------------------------------------------------------
9 */
10  
11 const Popover = (($) => {
12 /**
13 * ------------------------------------------------------------------------
14 * Constants
15 * ------------------------------------------------------------------------
16 */
17  
18 const NAME = 'popover'
19 const VERSION = '4.1.3'
20 const DATA_KEY = 'bs.popover'
21 const EVENT_KEY = `.${DATA_KEY}`
22 const JQUERY_NO_CONFLICT = $.fn[NAME]
23 const CLASS_PREFIX = 'bs-popover'
24 const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
25  
26 const Default = {
27 ...Tooltip.Default,
28 placement : 'right',
29 trigger : 'click',
30 content : '',
31 template : '<div class="popover" role="tooltip">' +
32 '<div class="arrow"></div>' +
33 '<h3 class="popover-header"></h3>' +
34 '<div class="popover-body"></div></div>'
35 }
36  
37 const DefaultType = {
38 ...Tooltip.DefaultType,
39 content : '(string|element|function)'
40 }
41  
42 const ClassName = {
43 FADE : 'fade',
44 SHOW : 'show'
45 }
46  
47 const Selector = {
48 TITLE : '.popover-header',
49 CONTENT : '.popover-body'
50 }
51  
52 const Event = {
53 HIDE : `hide${EVENT_KEY}`,
54 HIDDEN : `hidden${EVENT_KEY}`,
55 SHOW : `show${EVENT_KEY}`,
56 SHOWN : `shown${EVENT_KEY}`,
57 INSERTED : `inserted${EVENT_KEY}`,
58 CLICK : `click${EVENT_KEY}`,
59 FOCUSIN : `focusin${EVENT_KEY}`,
60 FOCUSOUT : `focusout${EVENT_KEY}`,
61 MOUSEENTER : `mouseenter${EVENT_KEY}`,
62 MOUSELEAVE : `mouseleave${EVENT_KEY}`
63 }
64  
65 /**
66 * ------------------------------------------------------------------------
67 * Class Definition
68 * ------------------------------------------------------------------------
69 */
70  
71 class Popover extends Tooltip {
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 // Overrides
103  
104 isWithContent() {
105 return this.getTitle() || this._getContent()
106 }
107  
108 addAttachmentClass(attachment) {
109 $(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)
110 }
111  
112 getTipElement() {
113 this.tip = this.tip || $(this.config.template)[0]
114 return this.tip
115 }
116  
117 setContent() {
118 const $tip = $(this.getTipElement())
119  
120 // We use append for html objects to maintain js events
121 this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
122 let content = this._getContent()
123 if (typeof content === 'function') {
124 content = content.call(this.element)
125 }
126 this.setElementContent($tip.find(Selector.CONTENT), content)
127  
128 $tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`)
129 }
130  
131 // Private
132  
133 _getContent() {
134 return this.element.getAttribute('data-content') ||
135 this.config.content
136 }
137  
138 _cleanTipClass() {
139 const $tip = $(this.getTipElement())
140 const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)
141 if (tabClass !== null && tabClass.length > 0) {
142 $tip.removeClass(tabClass.join(''))
143 }
144 }
145  
146 // Static
147  
148 static _jQueryInterface(config) {
149 return this.each(function () {
150 let data = $(this).data(DATA_KEY)
151 const _config = typeof config === 'object' ? config : null
152  
153 if (!data && /destroy|hide/.test(config)) {
154 return
155 }
156  
157 if (!data) {
158 data = new Popover(this, _config)
159 $(this).data(DATA_KEY, data)
160 }
161  
162 if (typeof config === 'string') {
163 if (typeof data[config] === 'undefined') {
164 throw new TypeError(`No method named "${config}"`)
165 }
166 data[config]()
167 }
168 })
169 }
170 }
171  
172 /**
173 * ------------------------------------------------------------------------
174 * jQuery
175 * ------------------------------------------------------------------------
176 */
177  
178 $.fn[NAME] = Popover._jQueryInterface
179 $.fn[NAME].Constructor = Popover
180 $.fn[NAME].noConflict = function () {
181 $.fn[NAME] = JQUERY_NO_CONFLICT
182 return Popover._jQueryInterface
183 }
184  
185 return Popover
186 })($)
187  
188 export default Popover