@finqu/cool 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/build/.eslintrc.json +10 -0
- package/build/banner.js +14 -0
- package/build/build-plugins.js +92 -0
- package/build/rollup.config.js +78 -0
- package/dist/css/cool-grid.css +3672 -0
- package/dist/css/cool-grid.css.map +30 -0
- package/dist/css/cool-grid.min.css +7 -0
- package/dist/css/cool-grid.min.css.map +1 -0
- package/dist/css/cool-reboot.css +281 -0
- package/dist/css/cool-reboot.css.map +58 -0
- package/dist/css/cool-reboot.min.css +7 -0
- package/dist/css/cool-reboot.min.css.map +1 -0
- package/dist/css/cool.css +14841 -0
- package/dist/css/cool.css.map +144 -0
- package/dist/css/cool.min.css +7 -0
- package/dist/css/cool.min.css.map +1 -0
- package/dist/js/cool.bundle.js +15304 -0
- package/dist/js/cool.bundle.js.map +1 -0
- package/dist/js/cool.bundle.min.js +45 -0
- package/dist/js/cool.bundle.min.js.map +1 -0
- package/dist/js/cool.esm.js +4766 -0
- package/dist/js/cool.esm.js.map +1 -0
- package/dist/js/cool.esm.min.js +7 -0
- package/dist/js/cool.esm.min.js.map +1 -0
- package/dist/js/cool.js +4948 -0
- package/dist/js/cool.js.map +1 -0
- package/dist/js/cool.min.js +7 -0
- package/dist/js/cool.min.js.map +1 -0
- package/html/index.html +892 -0
- package/js/dist/collapse.js +321 -0
- package/js/dist/collapse.js.map +1 -0
- package/js/dist/common.js +1474 -0
- package/js/dist/common.js.map +1 -0
- package/js/dist/cooldropdown.js +467 -0
- package/js/dist/cooldropdown.js.map +1 -0
- package/js/dist/coolpopover.js +391 -0
- package/js/dist/coolpopover.js.map +1 -0
- package/js/dist/coolsectiontabs.js +256 -0
- package/js/dist/coolsectiontabs.js.map +1 -0
- package/js/dist/coolselect.js +796 -0
- package/js/dist/coolselect.js.map +1 -0
- package/js/dist/cooltooltip.js +360 -0
- package/js/dist/cooltooltip.js.map +1 -0
- package/js/dist/coolui.js +73 -0
- package/js/dist/coolui.js.map +1 -0
- package/js/dist/dropdown.js +1716 -0
- package/js/dist/dropdown.js.map +1 -0
- package/js/dist/popover.js +587 -0
- package/js/dist/popover.js.map +1 -0
- package/js/dist/sectiontabs.js +263 -0
- package/js/dist/sectiontabs.js.map +1 -0
- package/js/dist/select.js +2029 -0
- package/js/dist/select.js.map +1 -0
- package/js/dist/tooltip.js +555 -0
- package/js/dist/tooltip.js.map +1 -0
- package/js/index.esm.js +21 -0
- package/js/index.umd.js +21 -0
- package/js/src/abstract-ui-component.js +70 -0
- package/js/src/collapse.js +258 -0
- package/js/src/common.js +280 -0
- package/js/src/dialog.js +570 -0
- package/js/src/dropdown.js +443 -0
- package/js/src/popover.js +615 -0
- package/js/src/section-tabs.js +204 -0
- package/js/src/select.js +832 -0
- package/js/src/toast.js +581 -0
- package/js/src/tooltip.js +575 -0
- package/js/src/util/animate-css.js +22 -0
- package/js/src/util/index.js +112 -0
- package/js/src/util/perfect-scrollbar.js +1316 -0
- package/less/alert.less +345 -0
- package/less/badge.less +38 -0
- package/less/bootstrap-noconflict.less +23 -0
- package/less/bootstrap.less +23 -0
- package/less/button-group.less +153 -0
- package/less/buttons.less +287 -0
- package/less/dialog-noconflict.less +174 -0
- package/less/dialog.less +203 -0
- package/less/dropdown.less +209 -0
- package/less/forms.less +770 -0
- package/less/images.less +242 -0
- package/less/input-group.less +163 -0
- package/less/list-group.less +73 -0
- package/less/mixins/aspect-ratio.less +23 -0
- package/less/mixins/border-radius.less +24 -0
- package/less/mixins/box-shadow.less +4 -0
- package/less/mixins/buttons.less +17 -0
- package/less/mixins/caret.less +51 -0
- package/less/mixins/clearfix.less +10 -0
- package/less/mixins/gradients.less +34 -0
- package/less/mixins/nav-divider.less +7 -0
- package/less/mixins/object-fit.less +13 -0
- package/less/mixins/reset-text.less +16 -0
- package/less/mixins.less +11 -0
- package/less/package.json +11 -0
- package/less/pagination.less +69 -0
- package/less/popover.less +143 -0
- package/less/project.sublime-workspace +774 -0
- package/less/reboot.less +235 -0
- package/less/section.less +793 -0
- package/less/select.less +150 -0
- package/less/tables.less +737 -0
- package/less/tabs.less +162 -0
- package/less/tooltip.less +87 -0
- package/less/type.less +71 -0
- package/less/utilities/align.less +27 -0
- package/less/utilities/animate.less +3512 -0
- package/less/utilities/background.less +70 -0
- package/less/utilities/borders.less +16 -0
- package/less/utilities/color.less +70 -0
- package/less/utilities/cursor.less +8 -0
- package/less/utilities/display.less +38 -0
- package/less/utilities/embed.less +61 -0
- package/less/utilities/flex.less +76 -0
- package/less/utilities/jquery-ui.less +116 -0
- package/less/utilities/lazyload.less +29 -0
- package/less/utilities/overflow.less +11 -0
- package/less/utilities/pace.less +25 -0
- package/less/utilities/placeholder.less +60 -0
- package/less/utilities/position.less +42 -0
- package/less/utilities/scrollbar.less +152 -0
- package/less/utilities/spacing.less +197 -0
- package/less/utilities/text.less +68 -0
- package/less/utilities/transform.less +7 -0
- package/less/utilities.less +21 -0
- package/less/variables.less +343 -0
- package/package.json +71 -0
- package/scss/LISENCE +15 -0
- package/scss/_alert.scss +125 -0
- package/scss/_badge.scss +58 -0
- package/scss/_button-group.scss +124 -0
- package/scss/_buttons.scss +206 -0
- package/scss/_custom-forms.scss +423 -0
- package/scss/_dialog.scss +149 -0
- package/scss/_dropdown.scss +234 -0
- package/scss/_forms.scss +257 -0
- package/scss/_frame.scss +523 -0
- package/scss/_functions.scss +114 -0
- package/scss/_grid.scss +35 -0
- package/scss/_images.scss +312 -0
- package/scss/_input-group.scss +245 -0
- package/scss/_list-group.scss +82 -0
- package/scss/_mixins.scss +32 -0
- package/scss/_navbar.scss +214 -0
- package/scss/_pagination.scss +79 -0
- package/scss/_popover.scss +165 -0
- package/scss/_reboot.scss +279 -0
- package/scss/_root.scss +15 -0
- package/scss/_section.scss +851 -0
- package/scss/_select.scss +166 -0
- package/scss/_tables.scss +707 -0
- package/scss/_tabs.scss +175 -0
- package/scss/_toast.scss +182 -0
- package/scss/_tooltip.scss +101 -0
- package/scss/_type.scss +90 -0
- package/scss/_utilities.scss +21 -0
- package/scss/_variables.scss +697 -0
- package/scss/cool-grid.scss +29 -0
- package/scss/cool-reboot.scss +11 -0
- package/scss/cool.scss +36 -0
- package/scss/mixins/_alert-variant.scss +40 -0
- package/scss/mixins/_aspect-ratio.scss +29 -0
- package/scss/mixins/_background-variant.scss +25 -0
- package/scss/mixins/_badge-variant.scss +13 -0
- package/scss/mixins/_breakpoints.scss +102 -0
- package/scss/mixins/_buttons.scss +104 -0
- package/scss/mixins/_caret.scss +80 -0
- package/scss/mixins/_clearfix.scss +10 -0
- package/scss/mixins/_float.scss +14 -0
- package/scss/mixins/_forms.scss +51 -0
- package/scss/mixins/_gradients.scss +40 -0
- package/scss/mixins/_grid-framework.scss +72 -0
- package/scss/mixins/_grid.scss +60 -0
- package/scss/mixins/_nav-divider.scss +9 -0
- package/scss/mixins/_object-fit.scss +16 -0
- package/scss/mixins/_reset-text.scss +19 -0
- package/scss/mixins/_text-emphasis.scss +21 -0
- package/scss/mixins/_text-hide.scss +10 -0
- package/scss/mixins/_text-truncate.scss +8 -0
- package/scss/project.sublime-workspace +491 -0
- package/scss/utilities/_align.scss +41 -0
- package/scss/utilities/_animate.scss +3512 -0
- package/scss/utilities/_background.scss +14 -0
- package/scss/utilities/_borders.scss +146 -0
- package/scss/utilities/_clearfix.scss +6 -0
- package/scss/utilities/_collapse.scss +33 -0
- package/scss/utilities/_cursor.scss +10 -0
- package/scss/utilities/_display.scss +16 -0
- package/scss/utilities/_embed.scss +78 -0
- package/scss/utilities/_flex.scss +50 -0
- package/scss/utilities/_lazyload.scss +31 -0
- package/scss/utilities/_overflow.scss +6 -0
- package/scss/utilities/_perfect-scrollbar.scss +154 -0
- package/scss/utilities/_placeholder.scss +76 -0
- package/scss/utilities/_position.scss +30 -0
- package/scss/utilities/_sizing.scss +32 -0
- package/scss/utilities/_spacing.scss +92 -0
- package/scss/utilities/_text.scss +97 -0
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
import 'jquery';
|
|
2
|
+
import { debounce } from './util/index';
|
|
3
|
+
import AbstractUIComponent from './abstract-ui-component';
|
|
4
|
+
|
|
5
|
+
const NAME = 'coolPopover';
|
|
6
|
+
const DATA_KEY = 'plugin_coolPopover';
|
|
7
|
+
|
|
8
|
+
class Popover extends AbstractUIComponent {
|
|
9
|
+
|
|
10
|
+
constructor(el, opts) {
|
|
11
|
+
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
this.opts = {};
|
|
15
|
+
|
|
16
|
+
if (window.Cool.settings.popover) {
|
|
17
|
+
|
|
18
|
+
$.extend(true, this.opts, $.fn[NAME].defaults, window.Cool.settings.popover, opts);
|
|
19
|
+
|
|
20
|
+
} else {
|
|
21
|
+
|
|
22
|
+
$.extend(true, this.opts, $.fn[NAME].defaults, opts);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.el = el;
|
|
26
|
+
this.debug = this.opts.debug;
|
|
27
|
+
this.init();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Init plugin
|
|
31
|
+
init() {
|
|
32
|
+
|
|
33
|
+
this.buildCache();
|
|
34
|
+
this.bindEvents();
|
|
35
|
+
this.onInit();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Remove plugin instance completely
|
|
39
|
+
destroy() {
|
|
40
|
+
|
|
41
|
+
this.unbindEvents();
|
|
42
|
+
this.$el.removeData(DATA_KEY);
|
|
43
|
+
this.onDestroy();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Update plugin data
|
|
47
|
+
update() {
|
|
48
|
+
|
|
49
|
+
this.buildCache();
|
|
50
|
+
this.onUpdate();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Cache DOM nodes for performance
|
|
54
|
+
buildCache() {
|
|
55
|
+
|
|
56
|
+
this.$el = $(this.el);
|
|
57
|
+
this.$container = this.$el.data('container') ? $(this.$el.data('container')) : $(this.opts.container);
|
|
58
|
+
this.id = 'popover-'+this.generateUUID();
|
|
59
|
+
this.animation = this.$el.data('animation') ? this.$el.data('animation') : this.opts.animation;
|
|
60
|
+
this.animationIn = this.$el.data('animationIn') ? this.$el.data('animationIn') : this.opts.animationIn;
|
|
61
|
+
this.animationOut = this.$el.data('animationOut') ? this.$el.data('animationOut') : this.opts.animationOut;
|
|
62
|
+
this.animationSpeed = this.$el.data('animationSpeed') ? this.$el.data('animationSpeed') : this.opts.animationSpeed;
|
|
63
|
+
this.trigger = this.$el.data('trigger') ? this.$el.data('trigger') : this.opts.trigger;
|
|
64
|
+
this.placement = this.$el.data('placement') ? this.$el.data('placement') : this.opts.placement;
|
|
65
|
+
this.placementChanged = false;
|
|
66
|
+
this.title = this.$el.data('title') ? this.$el.data('title') : this.opts.title;
|
|
67
|
+
this.content = this.$el.data('content') ? this.$el.data('content') : this.opts.content;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Bind events that trigger methods
|
|
71
|
+
bindEvents() {
|
|
72
|
+
|
|
73
|
+
if (this.trigger === 'click') {
|
|
74
|
+
|
|
75
|
+
this.$el.on('click'+'.'+NAME, () => {
|
|
76
|
+
|
|
77
|
+
if (this.$popover) {
|
|
78
|
+
this.close();
|
|
79
|
+
} else {
|
|
80
|
+
this.show();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
} else if (this.trigger === 'hover') {
|
|
85
|
+
|
|
86
|
+
this.$el.on('mouseenter'+'.'+NAME, () => {
|
|
87
|
+
|
|
88
|
+
this.show();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
this.$el.on('mouseleave'+'.'+NAME, () => {
|
|
92
|
+
|
|
93
|
+
this.close();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
} else if (this.trigger === 'focus') {
|
|
97
|
+
|
|
98
|
+
this.$el.on('focusin'+'.'+NAME, () => {
|
|
99
|
+
|
|
100
|
+
this.show();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
this.$el.on('focusout'+'.'+NAME, () => {
|
|
104
|
+
|
|
105
|
+
this.close();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
$(window).on('resize', debounce(() => {
|
|
110
|
+
|
|
111
|
+
if (this.$popover) {
|
|
112
|
+
this.setPosition();
|
|
113
|
+
this.onUpdate();
|
|
114
|
+
}
|
|
115
|
+
}, 250));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Unbind events that trigger methods
|
|
119
|
+
unbindEvents() {
|
|
120
|
+
|
|
121
|
+
this.$el.off('.'+NAME);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Generate UUID
|
|
125
|
+
generateUUID() {
|
|
126
|
+
|
|
127
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
128
|
+
let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
129
|
+
return v.toString(16);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Build popover
|
|
134
|
+
buildPopover() {
|
|
135
|
+
|
|
136
|
+
let content;
|
|
137
|
+
|
|
138
|
+
if (typeof this.content === 'function') {
|
|
139
|
+
content = this.content();
|
|
140
|
+
} else {
|
|
141
|
+
content = this.content;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this.$popover = $(`
|
|
145
|
+
<div class="popover" role="tooltip" id="${this.id}">
|
|
146
|
+
|
|
147
|
+
<div class="arrow"></div>
|
|
148
|
+
|
|
149
|
+
<h3 class="popover-header">${this.title}</h3>
|
|
150
|
+
|
|
151
|
+
<div class="popover-body">${content}</div>
|
|
152
|
+
|
|
153
|
+
</div>
|
|
154
|
+
`);
|
|
155
|
+
|
|
156
|
+
this.$container.append(this.$popover);
|
|
157
|
+
this.$arrow = this.$popover.find('.arrow') ? this.$popover.find('.arrow') : false;
|
|
158
|
+
|
|
159
|
+
this.log(this.$el);
|
|
160
|
+
this.log(this.$container);
|
|
161
|
+
this.log(this.$popover);
|
|
162
|
+
this.log(this.$arrow);
|
|
163
|
+
this.log('Id: '+this.id);
|
|
164
|
+
this.log('Trigger: '+this.trigger);
|
|
165
|
+
this.log('Placement: '+this.placement);
|
|
166
|
+
this.log('Animation: '+this.animation);
|
|
167
|
+
this.log('Animation in: '+this.animationIn);
|
|
168
|
+
this.log('Animation out: '+this.animationOut);
|
|
169
|
+
this.log('Animation speed: '+this.animationSpeed);
|
|
170
|
+
this.log('Title: '+this.title);
|
|
171
|
+
this.log('Content: '+this.content);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Set positions
|
|
175
|
+
setPosition(placement) {
|
|
176
|
+
|
|
177
|
+
if (typeof placement === 'undefined' || placement === null) {
|
|
178
|
+
placement = this.placement;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.$popover.addClass('popover-'+placement);
|
|
182
|
+
|
|
183
|
+
let containerInnerWidth = this.$container.innerWidth();
|
|
184
|
+
let containerInnerHeight = this.$container.innerHeight();
|
|
185
|
+
let popoverWidth = this.$popover.outerWidth(true);
|
|
186
|
+
let popoverHeight = this.$popover.outerHeight(true);
|
|
187
|
+
let popoverTriggerWidth = this.$el.outerWidth();
|
|
188
|
+
let popoverTriggerHeight = this.$el.outerHeight();
|
|
189
|
+
let popoverTriggerPosX = this.$el.position().left;
|
|
190
|
+
let popoverTriggerPosY = this.$el.position().top;
|
|
191
|
+
let arrowWidth = this.$arrow.outerWidth(true);
|
|
192
|
+
let arrowHeight = this.$arrow.outerHeight(true);
|
|
193
|
+
let arrowPos;
|
|
194
|
+
let popoverPosX;
|
|
195
|
+
let popoverPosY;
|
|
196
|
+
|
|
197
|
+
if (placement === 'top') {
|
|
198
|
+
|
|
199
|
+
popoverPosX = Math.round(popoverTriggerPosX - (popoverWidth - popoverTriggerWidth) / 2);
|
|
200
|
+
popoverPosY = Math.round(popoverTriggerPosY - popoverHeight);
|
|
201
|
+
arrowPos = Math.round(popoverWidth / 2 - arrowWidth / 2);
|
|
202
|
+
|
|
203
|
+
this.$arrow.css({
|
|
204
|
+
left: arrowPos+'px'
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
} else if (placement === 'right') {
|
|
208
|
+
|
|
209
|
+
popoverPosX = Math.round(popoverTriggerPosX + popoverTriggerWidth);
|
|
210
|
+
popoverPosY = Math.round(popoverTriggerPosY - (popoverHeight - popoverTriggerHeight) / 2);
|
|
211
|
+
arrowPos = Math.round(popoverHeight / 2 - arrowHeight / 2);
|
|
212
|
+
|
|
213
|
+
this.$arrow.css({
|
|
214
|
+
top: arrowPos+'px'
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
} else if (placement === 'bottom') {
|
|
218
|
+
|
|
219
|
+
popoverPosX = Math.round(popoverTriggerPosX - (popoverWidth - popoverTriggerWidth) / 2);
|
|
220
|
+
popoverPosY = Math.round(popoverTriggerPosY + popoverTriggerHeight);
|
|
221
|
+
arrowPos = Math.round(popoverWidth / 2 - arrowWidth / 2);
|
|
222
|
+
|
|
223
|
+
this.$arrow.css({
|
|
224
|
+
left: arrowPos+'px'
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
} else if (placement === 'left') {
|
|
228
|
+
|
|
229
|
+
popoverPosX = Math.round(popoverTriggerPosX - popoverWidth);
|
|
230
|
+
popoverPosY = Math.round(popoverTriggerPosY - (popoverHeight - popoverTriggerHeight) / 2);
|
|
231
|
+
arrowPos = Math.round(popoverHeight / 2 - arrowHeight / 2);
|
|
232
|
+
|
|
233
|
+
this.$arrow.css({
|
|
234
|
+
top: arrowPos+'px'
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
this.$popover.css({
|
|
239
|
+
position: 'absolute',
|
|
240
|
+
top: '0px',
|
|
241
|
+
left: '0px',
|
|
242
|
+
transform: 'translate3d('+popoverPosX+'px, '+popoverPosY+'px, 0px)',
|
|
243
|
+
'will-change': 'transform'
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Correct placement if popover goes outside of container
|
|
247
|
+
let popoverOverflowCount = 0;
|
|
248
|
+
let popoverPosition = {
|
|
249
|
+
left: this.$popover.position().left,
|
|
250
|
+
top: this.$popover.position().top,
|
|
251
|
+
right: containerInnerWidth - (this.$popover.position().left + popoverWidth),
|
|
252
|
+
bottom: containerInnerHeight - (this.$popover.position().top + popoverHeight),
|
|
253
|
+
};
|
|
254
|
+
let popoverOverflow = {
|
|
255
|
+
left: false,
|
|
256
|
+
top: false,
|
|
257
|
+
right: false,
|
|
258
|
+
bottom: false
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
if (popoverPosition.right < 0) {
|
|
262
|
+
|
|
263
|
+
popoverOverflow.right = true;
|
|
264
|
+
popoverOverflowCount++;
|
|
265
|
+
|
|
266
|
+
this.log('Popover overflowing from right');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (popoverPosition.left < 0) {
|
|
270
|
+
|
|
271
|
+
popoverOverflow.left = true;
|
|
272
|
+
popoverOverflowCount++;
|
|
273
|
+
|
|
274
|
+
this.log('Popover overflowing from left');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (popoverPosition.bottom < 0) {
|
|
278
|
+
|
|
279
|
+
popoverOverflow.bottom = true;
|
|
280
|
+
popoverOverflowCount++;
|
|
281
|
+
|
|
282
|
+
this.log('Popover overflowing from bottom');
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (popoverPosition.top < 0) {
|
|
286
|
+
|
|
287
|
+
popoverOverflow.top = true;
|
|
288
|
+
popoverOverflowCount++;
|
|
289
|
+
|
|
290
|
+
this.log('Popover overflowing from top');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (popoverOverflowCount > 0) {
|
|
294
|
+
|
|
295
|
+
if (!this.placementChanged && popoverOverflow.left && popoverPosition.right > popoverWidth) {
|
|
296
|
+
|
|
297
|
+
this.log('Changing popover placement to right');
|
|
298
|
+
|
|
299
|
+
this.placementChanged = true;
|
|
300
|
+
this.$popover.removeClass('popover-'+placement);
|
|
301
|
+
this.$arrow.removeAttr('style');
|
|
302
|
+
this.setPosition('right');
|
|
303
|
+
|
|
304
|
+
} else if (!this.placementChanged && popoverOverflow.top && popoverPosition.top > popoverHeight) {
|
|
305
|
+
|
|
306
|
+
this.log('Changing popover placement to bottom');
|
|
307
|
+
|
|
308
|
+
this.placementChanged = true;
|
|
309
|
+
this.$popover.removeClass('popover-'+placement);
|
|
310
|
+
this.$arrow.removeAttr('style');
|
|
311
|
+
this.setPosition('bottom');
|
|
312
|
+
|
|
313
|
+
} else if (!this.placementChanged && popoverOverflow.right && popoverPosition.left > popoverWidth) {
|
|
314
|
+
|
|
315
|
+
this.log('Changing popover placement to left');
|
|
316
|
+
|
|
317
|
+
this.placementChanged = true;
|
|
318
|
+
this.$popover.removeClass('popover-'+placement);
|
|
319
|
+
this.$arrow.removeAttr('style');
|
|
320
|
+
this.setPosition('left');
|
|
321
|
+
|
|
322
|
+
} else if (!this.placementChanged && popoverOverflow.bottom && popoverPosition.top > popoverHeight) {
|
|
323
|
+
|
|
324
|
+
this.log('Changing popover placement to top');
|
|
325
|
+
|
|
326
|
+
this.placementChanged = true;
|
|
327
|
+
this.$popover.removeClass('popover-'+placement);
|
|
328
|
+
this.$arrow.removeAttr('style');
|
|
329
|
+
this.setPosition('top');
|
|
330
|
+
|
|
331
|
+
} else if (!this.placementChanged && (placement !== 'top' || placement !== 'bottom') && (popoverOverflow.left || popoverOverflow.right)) {
|
|
332
|
+
|
|
333
|
+
if (popoverPosition.top > popoverPosition.bottom) {
|
|
334
|
+
|
|
335
|
+
this.log('Changing popover placement to top');
|
|
336
|
+
|
|
337
|
+
this.placementChanged = true;
|
|
338
|
+
this.$popover.removeClass('popover-'+placement);
|
|
339
|
+
this.$arrow.removeAttr('style');
|
|
340
|
+
this.setPosition('top');
|
|
341
|
+
|
|
342
|
+
} else {
|
|
343
|
+
|
|
344
|
+
this.log('Changing popover placement to bottom');
|
|
345
|
+
|
|
346
|
+
this.placementChanged = true;
|
|
347
|
+
this.$popover.removeClass('popover-'+placement);
|
|
348
|
+
this.$arrow.removeAttr('style');
|
|
349
|
+
this.setPosition('bottom');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
} else {
|
|
353
|
+
|
|
354
|
+
this.fixPopoverPosition = true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (this.fixPopoverPosition) {
|
|
358
|
+
|
|
359
|
+
this.log('Adjusting popover size or position in order to popover fit in the container');
|
|
360
|
+
|
|
361
|
+
if (popoverOverflow.left) {
|
|
362
|
+
|
|
363
|
+
this.log('Popover overflowing from left');
|
|
364
|
+
|
|
365
|
+
let overflowAmount = Math.abs(popoverPosition.left);
|
|
366
|
+
let excludePlacements = ['top', 'bottom'];
|
|
367
|
+
|
|
368
|
+
if ((popoverTriggerPosX >= popoverPosX + overflowAmount) && excludePlacements.indexOf(placement) < 0) {
|
|
369
|
+
|
|
370
|
+
this.log('Popover adjusting width');
|
|
371
|
+
|
|
372
|
+
popoverWidth -= overflowAmount;
|
|
373
|
+
popoverPosX += overflowAmount;
|
|
374
|
+
|
|
375
|
+
} else {
|
|
376
|
+
|
|
377
|
+
this.log('Popover adjusting position x');
|
|
378
|
+
|
|
379
|
+
popoverPosX += overflowAmount;
|
|
380
|
+
arrowPos -= overflowAmount;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (popoverOverflow.top) {
|
|
385
|
+
|
|
386
|
+
this.log('Popover overflowing from top');
|
|
387
|
+
|
|
388
|
+
let overflowAmount = Math.abs(popoverPosition.top);
|
|
389
|
+
|
|
390
|
+
this.log('Popover adjusting position y');
|
|
391
|
+
|
|
392
|
+
popoverPosY += overflowAmount;
|
|
393
|
+
arrowPos -= overflowAmount;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (popoverOverflow.right) {
|
|
397
|
+
|
|
398
|
+
this.log('Popover overflowing from right');
|
|
399
|
+
|
|
400
|
+
let overflowAmount = Math.abs(popoverPosition.right);
|
|
401
|
+
let excludePlacements = ['top', 'bottom'];
|
|
402
|
+
|
|
403
|
+
if ((popoverTriggerPosX <= popoverPosX - overflowAmount) && excludePlacements.indexOf(placement) < 0) {
|
|
404
|
+
|
|
405
|
+
this.log('Popover adjusting width');
|
|
406
|
+
|
|
407
|
+
popoverWidth -= overflowAmount;
|
|
408
|
+
|
|
409
|
+
} else {
|
|
410
|
+
|
|
411
|
+
this.log('Popover adjusting position x');
|
|
412
|
+
|
|
413
|
+
popoverPosX -= overflowAmount;
|
|
414
|
+
arrowPos += overflowAmount;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (popoverOverflow.bottom) {
|
|
419
|
+
|
|
420
|
+
this.log('Popover overflowing from bottom');
|
|
421
|
+
|
|
422
|
+
let overflowAmount = Math.abs(popoverPosition.bottom);
|
|
423
|
+
|
|
424
|
+
this.log('Popover adjusting position y');
|
|
425
|
+
|
|
426
|
+
popoverPosY -= overflowAmount;
|
|
427
|
+
arrowPos += overflowAmount;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (placement === 'top') {
|
|
431
|
+
|
|
432
|
+
this.$arrow.css({
|
|
433
|
+
left: arrowPos+'px'
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
} else if (placement === 'right') {
|
|
437
|
+
|
|
438
|
+
this.$arrow.css({
|
|
439
|
+
top: arrowPos+'px'
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
} else if (placement === 'bottom') {
|
|
443
|
+
|
|
444
|
+
this.$arrow.css({
|
|
445
|
+
left: arrowPos+'px'
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
} else if (placement === 'left') {
|
|
449
|
+
|
|
450
|
+
this.$arrow.css({
|
|
451
|
+
top: arrowPos+'px'
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
this.$popover.css({
|
|
456
|
+
width: popoverWidth,
|
|
457
|
+
transform: 'translate3d('+popoverPosX+'px, '+popoverPosY+'px, 0px)'
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
this.fixPopoverPosition = false;
|
|
461
|
+
|
|
462
|
+
this.log('Popover placement changed: '+this.placementChanged);
|
|
463
|
+
this.log('Popover container inner width: '+containerInnerWidth+'px');
|
|
464
|
+
this.log('Popover container inner height: '+containerInnerHeight+'px');
|
|
465
|
+
this.log('Popover trigger width: '+popoverTriggerWidth+'px');
|
|
466
|
+
this.log('Popover trigger height: '+popoverTriggerHeight+'px');
|
|
467
|
+
this.log('popover trigger position x: '+popoverTriggerPosX+'px');
|
|
468
|
+
this.log('Popover trigger position Y: '+popoverTriggerPosY+'px');
|
|
469
|
+
this.log('Popover width: '+popoverWidth+'px');
|
|
470
|
+
this.log('Popover height: '+popoverHeight+'px');
|
|
471
|
+
this.log('Popover position x: '+popoverPosX+'px');
|
|
472
|
+
this.log('Popover position y: '+popoverPosY+'px');
|
|
473
|
+
this.log('Popover position left: '+popoverPosition.left+'px');
|
|
474
|
+
this.log('Popover position top: '+popoverPosition.top+'px');
|
|
475
|
+
this.log('Popover position right: '+popoverPosition.right+'px');
|
|
476
|
+
this.log('Popover position bottom: '+popoverPosition.bottom+'px');
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
} else {
|
|
480
|
+
|
|
481
|
+
this.log('Popover placement changed: '+this.placementChanged);
|
|
482
|
+
this.log('Popover container inner width: '+containerInnerWidth+'px');
|
|
483
|
+
this.log('Popover container inner height: '+containerInnerHeight+'px');
|
|
484
|
+
this.log('Popover trigger width: '+popoverTriggerWidth+'px');
|
|
485
|
+
this.log('Popover trigger height: '+popoverTriggerHeight+'px');
|
|
486
|
+
this.log('popover trigger position x: '+popoverTriggerPosX+'px');
|
|
487
|
+
this.log('Popover trigger position Y: '+popoverTriggerPosY+'px');
|
|
488
|
+
this.log('Popover width: '+popoverWidth+'px');
|
|
489
|
+
this.log('Popover height: '+popoverHeight+'px');
|
|
490
|
+
this.log('Popover position x: '+popoverPosX+'px');
|
|
491
|
+
this.log('Popover position y: '+popoverPosY+'px');
|
|
492
|
+
this.log('Popover position left: '+popoverPosition.left+'px');
|
|
493
|
+
this.log('Popover position top: '+popoverPosition.top+'px');
|
|
494
|
+
this.log('Popover position right: '+popoverPosition.right+'px');
|
|
495
|
+
this.log('Popover position bottom: '+popoverPosition.bottom+'px');
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Show
|
|
500
|
+
show() {
|
|
501
|
+
|
|
502
|
+
if (this.$popover) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
this.buildPopover();
|
|
507
|
+
this.setPosition();
|
|
508
|
+
|
|
509
|
+
if (this.animation) {
|
|
510
|
+
|
|
511
|
+
this.$popover.addClass(this.animationSpeed);
|
|
512
|
+
this.$popover.animateCss(this.animationIn);
|
|
513
|
+
this.$popover.addClass('show');
|
|
514
|
+
this.$popover.attr('id', this.id);
|
|
515
|
+
this.$el.attr('data-popover', this.id);
|
|
516
|
+
|
|
517
|
+
} else {
|
|
518
|
+
|
|
519
|
+
this.$popover.addClass('show');
|
|
520
|
+
this.$popover.attr('id', this.id);
|
|
521
|
+
this.$el.attr('data-popover', this.id);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
this.onShow();
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// Close
|
|
528
|
+
close() {
|
|
529
|
+
|
|
530
|
+
if (!this.$popover) {
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (this.animation && !this.$popover.hasClass('animated')) {
|
|
535
|
+
|
|
536
|
+
this.$popover.animateCss(this.animationOut, () => {
|
|
537
|
+
|
|
538
|
+
this.$popover.remove();
|
|
539
|
+
this.$el.removeAttr('data-popover');
|
|
540
|
+
this.$popover = null;
|
|
541
|
+
this.placementChanged = false;
|
|
542
|
+
|
|
543
|
+
this.onClose();
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
} else {
|
|
547
|
+
|
|
548
|
+
this.$popover.remove();
|
|
549
|
+
this.$el.removeAttr('data-popover');
|
|
550
|
+
this.$popover = null;
|
|
551
|
+
this.placementChanged = false;
|
|
552
|
+
|
|
553
|
+
this.onClose();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
static _jQueryInterface(config) {
|
|
558
|
+
|
|
559
|
+
return this.each(function() {
|
|
560
|
+
|
|
561
|
+
let data = $(this).data(DATA_KEY);
|
|
562
|
+
const _config = typeof config === 'object' && config;
|
|
563
|
+
|
|
564
|
+
if (!data) {
|
|
565
|
+
data = new Popover(this, _config);
|
|
566
|
+
$(this).data(DATA_KEY, data);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (typeof config === 'string') {
|
|
570
|
+
|
|
571
|
+
if (typeof data[config] === 'undefined') {
|
|
572
|
+
throw new TypeError(`No method named "${config}"`)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
data[config]()
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (typeof $ !== 'undefined') {
|
|
582
|
+
|
|
583
|
+
// jQuery
|
|
584
|
+
const JQUERY_NO_CONFLICT = $.fn[NAME];
|
|
585
|
+
|
|
586
|
+
$.fn[NAME] = Popover._jQueryInterface;
|
|
587
|
+
$.fn[NAME].Constructor = Popover;
|
|
588
|
+
|
|
589
|
+
$.fn[NAME].noConflict = () => {
|
|
590
|
+
|
|
591
|
+
$.fn[NAME] = JQUERY_NO_CONFLICT
|
|
592
|
+
|
|
593
|
+
return Popover._jQueryInterface
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
$.fn[NAME].defaults = {
|
|
597
|
+
container: '.content-inner',
|
|
598
|
+
trigger: 'focus',
|
|
599
|
+
placement: 'bottom',
|
|
600
|
+
animation: true,
|
|
601
|
+
animationIn: 'fadeIn',
|
|
602
|
+
animationOut: 'fadeOut',
|
|
603
|
+
animationSpeed: 'fastest',
|
|
604
|
+
title: '',
|
|
605
|
+
content: '',
|
|
606
|
+
onInit: null,
|
|
607
|
+
onUpdate: null,
|
|
608
|
+
onDestroy: null,
|
|
609
|
+
onShow: null,
|
|
610
|
+
onClose: null,
|
|
611
|
+
debug: false
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export default Popover;
|