@materializecss/materialize 1.2.0 → 1.2.2
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/Gruntfile.js +722 -712
- package/LICENSE +21 -21
- package/README.md +91 -91
- package/dist/css/materialize.css +78 -137
- package/dist/css/materialize.min.css +12 -12
- package/dist/js/materialize.js +1502 -1378
- package/dist/js/materialize.min.js +6 -6
- package/extras/noUiSlider/nouislider.css +403 -403
- package/extras/noUiSlider/nouislider.js +2147 -2147
- package/js/anime.min.js +34 -34
- package/js/autocomplete.js +479 -479
- package/js/buttons.js +354 -354
- package/js/cards.js +40 -40
- package/js/carousel.js +732 -732
- package/js/cash.js +960 -960
- package/js/characterCounter.js +136 -136
- package/js/chips.js +486 -486
- package/js/collapsible.js +275 -275
- package/js/component.js +44 -44
- package/js/datepicker.js +983 -983
- package/js/dropdown.js +669 -669
- package/js/forms.js +285 -285
- package/js/global.js +428 -428
- package/js/materialbox.js +453 -453
- package/js/modal.js +382 -382
- package/js/parallax.js +138 -138
- package/js/pushpin.js +148 -148
- package/js/range.js +263 -263
- package/js/scrollspy.js +295 -295
- package/js/select.js +391 -391
- package/js/sidenav.js +583 -583
- package/js/slider.js +497 -359
- package/js/tabs.js +402 -402
- package/js/tapTarget.js +315 -315
- package/js/timepicker.js +712 -712
- package/js/toasts.js +325 -325
- package/js/tooltip.js +320 -320
- package/js/waves.js +614 -614
- package/package.json +87 -84
- package/sass/components/_badges.scss +55 -55
- package/sass/components/_buttons.scss +322 -322
- package/sass/components/_cards.scss +195 -195
- package/sass/components/_carousel.scss +90 -90
- package/sass/components/_chips.scss +96 -96
- package/sass/components/_collapsible.scss +91 -91
- package/sass/components/_collection.scss +106 -106
- package/sass/components/_color-classes.scss +32 -32
- package/sass/components/_color-variables.scss +370 -370
- package/sass/components/_datepicker.scss +191 -191
- package/sass/components/_dropdown.scss +84 -84
- package/sass/components/_global.scss +646 -646
- package/sass/components/_grid.scss +158 -158
- package/sass/components/_icons-material-design.scss +5 -5
- package/sass/components/_materialbox.scss +42 -42
- package/sass/components/_modal.scss +97 -97
- package/sass/components/_navbar.scss +208 -208
- package/sass/components/_normalize.scss +447 -447
- package/sass/components/_preloader.scss +334 -334
- package/sass/components/_pulse.scss +34 -34
- package/sass/components/_sidenav.scss +214 -214
- package/sass/components/_slider.scss +100 -91
- package/sass/components/_table_of_contents.scss +33 -33
- package/sass/components/_tabs.scss +99 -99
- package/sass/components/_tapTarget.scss +103 -103
- package/sass/components/_timepicker.scss +199 -199
- package/sass/components/_toast.scss +58 -58
- package/sass/components/_tooltip.scss +32 -32
- package/sass/components/_transitions.scss +12 -12
- package/sass/components/_typography.scss +62 -62
- package/sass/components/_variables.scss +352 -352
- package/sass/components/_waves.scss +187 -187
- package/sass/components/forms/_checkboxes.scss +200 -200
- package/sass/components/forms/_file-input.scss +44 -44
- package/sass/components/forms/_forms.scss +22 -22
- package/sass/components/forms/_input-fields.scss +388 -388
- package/sass/components/forms/_radio-buttons.scss +115 -115
- package/sass/components/forms/_range.scss +161 -161
- package/sass/components/forms/_select.scss +199 -199
- package/sass/components/forms/_switches.scss +91 -91
- package/sass/materialize.scss +42 -42
- package/sass/_style.scss +0 -929
- package/sass/ghpages-materialize.scss +0 -7
package/js/tooltip.js
CHANGED
|
@@ -1,320 +1,320 @@
|
|
|
1
|
-
(function($, anim) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
let _defaults = {
|
|
5
|
-
exitDelay: 200,
|
|
6
|
-
enterDelay: 0,
|
|
7
|
-
html: null,
|
|
8
|
-
text: '',
|
|
9
|
-
unsafeHTML: null,
|
|
10
|
-
margin: 5,
|
|
11
|
-
inDuration: 250,
|
|
12
|
-
outDuration: 200,
|
|
13
|
-
position: 'bottom',
|
|
14
|
-
transitionMovement: 10
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @class
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
class Tooltip extends Component {
|
|
22
|
-
/**
|
|
23
|
-
* Construct Tooltip instance
|
|
24
|
-
* @constructor
|
|
25
|
-
* @param {Element} el
|
|
26
|
-
* @param {Object} options
|
|
27
|
-
*/
|
|
28
|
-
constructor(el, options) {
|
|
29
|
-
super(Tooltip, el, options);
|
|
30
|
-
|
|
31
|
-
this.el.M_Tooltip = this;
|
|
32
|
-
this.options = $.extend({}, Tooltip.defaults, options);
|
|
33
|
-
|
|
34
|
-
this.isOpen = false;
|
|
35
|
-
this.isHovered = false;
|
|
36
|
-
this.isFocused = false;
|
|
37
|
-
this._appendTooltipEl();
|
|
38
|
-
this._setupEventHandlers();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static get defaults() {
|
|
42
|
-
return _defaults;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static init(els, options) {
|
|
46
|
-
return super.init(this, els, options);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Get Instance
|
|
51
|
-
*/
|
|
52
|
-
static getInstance(el) {
|
|
53
|
-
let domElem = !!el.jquery ? el[0] : el;
|
|
54
|
-
return domElem.M_Tooltip;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Teardown component
|
|
59
|
-
*/
|
|
60
|
-
destroy() {
|
|
61
|
-
$(this.tooltipEl).remove();
|
|
62
|
-
this._removeEventHandlers();
|
|
63
|
-
this.el.M_Tooltip = undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
_appendTooltipEl() {
|
|
67
|
-
let tooltipEl = document.createElement('div');
|
|
68
|
-
tooltipEl.classList.add('material-tooltip');
|
|
69
|
-
this.tooltipEl = tooltipEl;
|
|
70
|
-
|
|
71
|
-
let tooltipContentEl = document.createElement('div');
|
|
72
|
-
tooltipContentEl.classList.add('tooltip-content');
|
|
73
|
-
this._setTooltipContent(tooltipContentEl);
|
|
74
|
-
|
|
75
|
-
tooltipEl.appendChild(tooltipContentEl);
|
|
76
|
-
document.body.appendChild(tooltipEl);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
_setTooltipContent(tooltipContentEl) {
|
|
80
|
-
tooltipContentEl.textContent = this.options.text;
|
|
81
|
-
if (!!this.options.html) {
|
|
82
|
-
// Warn when using html
|
|
83
|
-
console.warn(
|
|
84
|
-
'The html option is deprecated and will be removed in the future. See https://github.com/materializecss/materialize/pull/49'
|
|
85
|
-
);
|
|
86
|
-
$(tooltipContentEl).append(this.options.html);
|
|
87
|
-
}
|
|
88
|
-
if (!!this.options.unsafeHTML) {
|
|
89
|
-
$(tooltipContentEl).append(this.options.unsafeHTML);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
_updateTooltipContent() {
|
|
94
|
-
this._setTooltipContent(this.tooltipEl.querySelector('.tooltip-content'));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_setupEventHandlers() {
|
|
98
|
-
this._handleMouseEnterBound = this._handleMouseEnter.bind(this);
|
|
99
|
-
this._handleMouseLeaveBound = this._handleMouseLeave.bind(this);
|
|
100
|
-
this._handleFocusBound = this._handleFocus.bind(this);
|
|
101
|
-
this._handleBlurBound = this._handleBlur.bind(this);
|
|
102
|
-
this.el.addEventListener('mouseenter', this._handleMouseEnterBound);
|
|
103
|
-
this.el.addEventListener('mouseleave', this._handleMouseLeaveBound);
|
|
104
|
-
this.el.addEventListener('focus', this._handleFocusBound, true);
|
|
105
|
-
this.el.addEventListener('blur', this._handleBlurBound, true);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
_removeEventHandlers() {
|
|
109
|
-
this.el.removeEventListener('mouseenter', this._handleMouseEnterBound);
|
|
110
|
-
this.el.removeEventListener('mouseleave', this._handleMouseLeaveBound);
|
|
111
|
-
this.el.removeEventListener('focus', this._handleFocusBound, true);
|
|
112
|
-
this.el.removeEventListener('blur', this._handleBlurBound, true);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
open(isManual) {
|
|
116
|
-
if (this.isOpen) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
isManual = isManual === undefined ? true : undefined; // Default value true
|
|
120
|
-
this.isOpen = true;
|
|
121
|
-
// Update tooltip content with HTML attribute options
|
|
122
|
-
this.options = $.extend({}, this.options, this._getAttributeOptions());
|
|
123
|
-
this._updateTooltipContent();
|
|
124
|
-
this._setEnterDelayTimeout(isManual);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
close() {
|
|
128
|
-
if (!this.isOpen) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this.isHovered = false;
|
|
133
|
-
this.isFocused = false;
|
|
134
|
-
this.isOpen = false;
|
|
135
|
-
this._setExitDelayTimeout();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Create timeout which delays when the tooltip closes
|
|
140
|
-
*/
|
|
141
|
-
_setExitDelayTimeout() {
|
|
142
|
-
clearTimeout(this._exitDelayTimeout);
|
|
143
|
-
|
|
144
|
-
this._exitDelayTimeout = setTimeout(() => {
|
|
145
|
-
if (this.isHovered || this.isFocused) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
this._animateOut();
|
|
150
|
-
}, this.options.exitDelay);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Create timeout which delays when the toast closes
|
|
155
|
-
*/
|
|
156
|
-
_setEnterDelayTimeout(isManual) {
|
|
157
|
-
clearTimeout(this._enterDelayTimeout);
|
|
158
|
-
|
|
159
|
-
this._enterDelayTimeout = setTimeout(() => {
|
|
160
|
-
if (!this.isHovered && !this.isFocused && !isManual) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
this._animateIn();
|
|
165
|
-
}, this.options.enterDelay);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
_positionTooltip() {
|
|
169
|
-
let origin = this.el,
|
|
170
|
-
tooltip = this.tooltipEl,
|
|
171
|
-
originHeight = origin.offsetHeight,
|
|
172
|
-
originWidth = origin.offsetWidth,
|
|
173
|
-
tooltipHeight = tooltip.offsetHeight,
|
|
174
|
-
tooltipWidth = tooltip.offsetWidth,
|
|
175
|
-
newCoordinates,
|
|
176
|
-
margin = this.options.margin,
|
|
177
|
-
targetTop,
|
|
178
|
-
targetLeft;
|
|
179
|
-
|
|
180
|
-
(this.xMovement = 0), (this.yMovement = 0);
|
|
181
|
-
|
|
182
|
-
targetTop = origin.getBoundingClientRect().top + M.getDocumentScrollTop();
|
|
183
|
-
targetLeft = origin.getBoundingClientRect().left + M.getDocumentScrollLeft();
|
|
184
|
-
|
|
185
|
-
if (this.options.position === 'top') {
|
|
186
|
-
targetTop += -tooltipHeight - margin;
|
|
187
|
-
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
|
188
|
-
this.yMovement = -this.options.transitionMovement;
|
|
189
|
-
} else if (this.options.position === 'right') {
|
|
190
|
-
targetTop += originHeight / 2 - tooltipHeight / 2;
|
|
191
|
-
targetLeft += originWidth + margin;
|
|
192
|
-
this.xMovement = this.options.transitionMovement;
|
|
193
|
-
} else if (this.options.position === 'left') {
|
|
194
|
-
targetTop += originHeight / 2 - tooltipHeight / 2;
|
|
195
|
-
targetLeft += -tooltipWidth - margin;
|
|
196
|
-
this.xMovement = -this.options.transitionMovement;
|
|
197
|
-
} else {
|
|
198
|
-
targetTop += originHeight + margin;
|
|
199
|
-
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
|
200
|
-
this.yMovement = this.options.transitionMovement;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
newCoordinates = this._repositionWithinScreen(
|
|
204
|
-
targetLeft,
|
|
205
|
-
targetTop,
|
|
206
|
-
tooltipWidth,
|
|
207
|
-
tooltipHeight
|
|
208
|
-
);
|
|
209
|
-
$(tooltip).css({
|
|
210
|
-
top: newCoordinates.y + 'px',
|
|
211
|
-
left: newCoordinates.x + 'px'
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
_repositionWithinScreen(x, y, width, height) {
|
|
216
|
-
let scrollLeft = M.getDocumentScrollLeft();
|
|
217
|
-
let scrollTop = M.getDocumentScrollTop();
|
|
218
|
-
let newX = x - scrollLeft;
|
|
219
|
-
let newY = y - scrollTop;
|
|
220
|
-
|
|
221
|
-
let bounding = {
|
|
222
|
-
left: newX,
|
|
223
|
-
top: newY,
|
|
224
|
-
width: width,
|
|
225
|
-
height: height
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
let offset = this.options.margin + this.options.transitionMovement;
|
|
229
|
-
let edges = M.checkWithinContainer(document.body, bounding, offset);
|
|
230
|
-
|
|
231
|
-
if (edges.left) {
|
|
232
|
-
newX = offset;
|
|
233
|
-
} else if (edges.right) {
|
|
234
|
-
newX -= newX + width - window.innerWidth;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (edges.top) {
|
|
238
|
-
newY = offset;
|
|
239
|
-
} else if (edges.bottom) {
|
|
240
|
-
newY -= newY + height - window.innerHeight;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
x: newX + scrollLeft,
|
|
245
|
-
y: newY + scrollTop
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
_animateIn() {
|
|
250
|
-
this._positionTooltip();
|
|
251
|
-
this.tooltipEl.style.visibility = 'visible';
|
|
252
|
-
anim.remove(this.tooltipEl);
|
|
253
|
-
anim({
|
|
254
|
-
targets: this.tooltipEl,
|
|
255
|
-
opacity: this.options.opacity || 1,
|
|
256
|
-
translateX: this.xMovement,
|
|
257
|
-
translateY: this.yMovement,
|
|
258
|
-
duration: this.options.inDuration,
|
|
259
|
-
easing: 'easeOutCubic'
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
_animateOut() {
|
|
264
|
-
anim.remove(this.tooltipEl);
|
|
265
|
-
anim({
|
|
266
|
-
targets: this.tooltipEl,
|
|
267
|
-
opacity: 0,
|
|
268
|
-
translateX: 0,
|
|
269
|
-
translateY: 0,
|
|
270
|
-
duration: this.options.outDuration,
|
|
271
|
-
easing: 'easeOutCubic'
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
_handleMouseEnter() {
|
|
276
|
-
this.isHovered = true;
|
|
277
|
-
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
|
278
|
-
this.open(false);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
_handleMouseLeave() {
|
|
282
|
-
this.isHovered = false;
|
|
283
|
-
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
|
284
|
-
this.close();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
_handleFocus() {
|
|
288
|
-
if (M.tabPressed) {
|
|
289
|
-
this.isFocused = true;
|
|
290
|
-
this.open(false);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
_handleBlur() {
|
|
295
|
-
this.isFocused = false;
|
|
296
|
-
this.close();
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
_getAttributeOptions() {
|
|
300
|
-
let attributeOptions = {};
|
|
301
|
-
let tooltipTextOption = this.el.getAttribute('data-tooltip');
|
|
302
|
-
let positionOption = this.el.getAttribute('data-position');
|
|
303
|
-
|
|
304
|
-
if (tooltipTextOption) {
|
|
305
|
-
attributeOptions.text = tooltipTextOption;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (positionOption) {
|
|
309
|
-
attributeOptions.position = positionOption;
|
|
310
|
-
}
|
|
311
|
-
return attributeOptions;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
M.Tooltip = Tooltip;
|
|
316
|
-
|
|
317
|
-
if (M.jQueryLoaded) {
|
|
318
|
-
M.initializeJqueryWrapper(Tooltip, 'tooltip', 'M_Tooltip');
|
|
319
|
-
}
|
|
320
|
-
})(cash, M.anime);
|
|
1
|
+
(function($, anim) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
let _defaults = {
|
|
5
|
+
exitDelay: 200,
|
|
6
|
+
enterDelay: 0,
|
|
7
|
+
html: null,
|
|
8
|
+
text: '',
|
|
9
|
+
unsafeHTML: null,
|
|
10
|
+
margin: 5,
|
|
11
|
+
inDuration: 250,
|
|
12
|
+
outDuration: 200,
|
|
13
|
+
position: 'bottom',
|
|
14
|
+
transitionMovement: 10
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @class
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
class Tooltip extends Component {
|
|
22
|
+
/**
|
|
23
|
+
* Construct Tooltip instance
|
|
24
|
+
* @constructor
|
|
25
|
+
* @param {Element} el
|
|
26
|
+
* @param {Object} options
|
|
27
|
+
*/
|
|
28
|
+
constructor(el, options) {
|
|
29
|
+
super(Tooltip, el, options);
|
|
30
|
+
|
|
31
|
+
this.el.M_Tooltip = this;
|
|
32
|
+
this.options = $.extend({}, Tooltip.defaults, options);
|
|
33
|
+
|
|
34
|
+
this.isOpen = false;
|
|
35
|
+
this.isHovered = false;
|
|
36
|
+
this.isFocused = false;
|
|
37
|
+
this._appendTooltipEl();
|
|
38
|
+
this._setupEventHandlers();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static get defaults() {
|
|
42
|
+
return _defaults;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static init(els, options) {
|
|
46
|
+
return super.init(this, els, options);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get Instance
|
|
51
|
+
*/
|
|
52
|
+
static getInstance(el) {
|
|
53
|
+
let domElem = !!el.jquery ? el[0] : el;
|
|
54
|
+
return domElem.M_Tooltip;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Teardown component
|
|
59
|
+
*/
|
|
60
|
+
destroy() {
|
|
61
|
+
$(this.tooltipEl).remove();
|
|
62
|
+
this._removeEventHandlers();
|
|
63
|
+
this.el.M_Tooltip = undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_appendTooltipEl() {
|
|
67
|
+
let tooltipEl = document.createElement('div');
|
|
68
|
+
tooltipEl.classList.add('material-tooltip');
|
|
69
|
+
this.tooltipEl = tooltipEl;
|
|
70
|
+
|
|
71
|
+
let tooltipContentEl = document.createElement('div');
|
|
72
|
+
tooltipContentEl.classList.add('tooltip-content');
|
|
73
|
+
this._setTooltipContent(tooltipContentEl);
|
|
74
|
+
|
|
75
|
+
tooltipEl.appendChild(tooltipContentEl);
|
|
76
|
+
document.body.appendChild(tooltipEl);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_setTooltipContent(tooltipContentEl) {
|
|
80
|
+
tooltipContentEl.textContent = this.options.text;
|
|
81
|
+
if (!!this.options.html) {
|
|
82
|
+
// Warn when using html
|
|
83
|
+
console.warn(
|
|
84
|
+
'The html option is deprecated and will be removed in the future. See https://github.com/materializecss/materialize/pull/49'
|
|
85
|
+
);
|
|
86
|
+
$(tooltipContentEl).append(this.options.html);
|
|
87
|
+
}
|
|
88
|
+
if (!!this.options.unsafeHTML) {
|
|
89
|
+
$(tooltipContentEl).append(this.options.unsafeHTML);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
_updateTooltipContent() {
|
|
94
|
+
this._setTooltipContent(this.tooltipEl.querySelector('.tooltip-content'));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_setupEventHandlers() {
|
|
98
|
+
this._handleMouseEnterBound = this._handleMouseEnter.bind(this);
|
|
99
|
+
this._handleMouseLeaveBound = this._handleMouseLeave.bind(this);
|
|
100
|
+
this._handleFocusBound = this._handleFocus.bind(this);
|
|
101
|
+
this._handleBlurBound = this._handleBlur.bind(this);
|
|
102
|
+
this.el.addEventListener('mouseenter', this._handleMouseEnterBound);
|
|
103
|
+
this.el.addEventListener('mouseleave', this._handleMouseLeaveBound);
|
|
104
|
+
this.el.addEventListener('focus', this._handleFocusBound, true);
|
|
105
|
+
this.el.addEventListener('blur', this._handleBlurBound, true);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_removeEventHandlers() {
|
|
109
|
+
this.el.removeEventListener('mouseenter', this._handleMouseEnterBound);
|
|
110
|
+
this.el.removeEventListener('mouseleave', this._handleMouseLeaveBound);
|
|
111
|
+
this.el.removeEventListener('focus', this._handleFocusBound, true);
|
|
112
|
+
this.el.removeEventListener('blur', this._handleBlurBound, true);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
open(isManual) {
|
|
116
|
+
if (this.isOpen) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
isManual = isManual === undefined ? true : undefined; // Default value true
|
|
120
|
+
this.isOpen = true;
|
|
121
|
+
// Update tooltip content with HTML attribute options
|
|
122
|
+
this.options = $.extend({}, this.options, this._getAttributeOptions());
|
|
123
|
+
this._updateTooltipContent();
|
|
124
|
+
this._setEnterDelayTimeout(isManual);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
close() {
|
|
128
|
+
if (!this.isOpen) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this.isHovered = false;
|
|
133
|
+
this.isFocused = false;
|
|
134
|
+
this.isOpen = false;
|
|
135
|
+
this._setExitDelayTimeout();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Create timeout which delays when the tooltip closes
|
|
140
|
+
*/
|
|
141
|
+
_setExitDelayTimeout() {
|
|
142
|
+
clearTimeout(this._exitDelayTimeout);
|
|
143
|
+
|
|
144
|
+
this._exitDelayTimeout = setTimeout(() => {
|
|
145
|
+
if (this.isHovered || this.isFocused) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this._animateOut();
|
|
150
|
+
}, this.options.exitDelay);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Create timeout which delays when the toast closes
|
|
155
|
+
*/
|
|
156
|
+
_setEnterDelayTimeout(isManual) {
|
|
157
|
+
clearTimeout(this._enterDelayTimeout);
|
|
158
|
+
|
|
159
|
+
this._enterDelayTimeout = setTimeout(() => {
|
|
160
|
+
if (!this.isHovered && !this.isFocused && !isManual) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
this._animateIn();
|
|
165
|
+
}, this.options.enterDelay);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
_positionTooltip() {
|
|
169
|
+
let origin = this.el,
|
|
170
|
+
tooltip = this.tooltipEl,
|
|
171
|
+
originHeight = origin.offsetHeight,
|
|
172
|
+
originWidth = origin.offsetWidth,
|
|
173
|
+
tooltipHeight = tooltip.offsetHeight,
|
|
174
|
+
tooltipWidth = tooltip.offsetWidth,
|
|
175
|
+
newCoordinates,
|
|
176
|
+
margin = this.options.margin,
|
|
177
|
+
targetTop,
|
|
178
|
+
targetLeft;
|
|
179
|
+
|
|
180
|
+
(this.xMovement = 0), (this.yMovement = 0);
|
|
181
|
+
|
|
182
|
+
targetTop = origin.getBoundingClientRect().top + M.getDocumentScrollTop();
|
|
183
|
+
targetLeft = origin.getBoundingClientRect().left + M.getDocumentScrollLeft();
|
|
184
|
+
|
|
185
|
+
if (this.options.position === 'top') {
|
|
186
|
+
targetTop += -tooltipHeight - margin;
|
|
187
|
+
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
|
188
|
+
this.yMovement = -this.options.transitionMovement;
|
|
189
|
+
} else if (this.options.position === 'right') {
|
|
190
|
+
targetTop += originHeight / 2 - tooltipHeight / 2;
|
|
191
|
+
targetLeft += originWidth + margin;
|
|
192
|
+
this.xMovement = this.options.transitionMovement;
|
|
193
|
+
} else if (this.options.position === 'left') {
|
|
194
|
+
targetTop += originHeight / 2 - tooltipHeight / 2;
|
|
195
|
+
targetLeft += -tooltipWidth - margin;
|
|
196
|
+
this.xMovement = -this.options.transitionMovement;
|
|
197
|
+
} else {
|
|
198
|
+
targetTop += originHeight + margin;
|
|
199
|
+
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
|
200
|
+
this.yMovement = this.options.transitionMovement;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
newCoordinates = this._repositionWithinScreen(
|
|
204
|
+
targetLeft,
|
|
205
|
+
targetTop,
|
|
206
|
+
tooltipWidth,
|
|
207
|
+
tooltipHeight
|
|
208
|
+
);
|
|
209
|
+
$(tooltip).css({
|
|
210
|
+
top: newCoordinates.y + 'px',
|
|
211
|
+
left: newCoordinates.x + 'px'
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
_repositionWithinScreen(x, y, width, height) {
|
|
216
|
+
let scrollLeft = M.getDocumentScrollLeft();
|
|
217
|
+
let scrollTop = M.getDocumentScrollTop();
|
|
218
|
+
let newX = x - scrollLeft;
|
|
219
|
+
let newY = y - scrollTop;
|
|
220
|
+
|
|
221
|
+
let bounding = {
|
|
222
|
+
left: newX,
|
|
223
|
+
top: newY,
|
|
224
|
+
width: width,
|
|
225
|
+
height: height
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
let offset = this.options.margin + this.options.transitionMovement;
|
|
229
|
+
let edges = M.checkWithinContainer(document.body, bounding, offset);
|
|
230
|
+
|
|
231
|
+
if (edges.left) {
|
|
232
|
+
newX = offset;
|
|
233
|
+
} else if (edges.right) {
|
|
234
|
+
newX -= newX + width - window.innerWidth;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (edges.top) {
|
|
238
|
+
newY = offset;
|
|
239
|
+
} else if (edges.bottom) {
|
|
240
|
+
newY -= newY + height - window.innerHeight;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
x: newX + scrollLeft,
|
|
245
|
+
y: newY + scrollTop
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
_animateIn() {
|
|
250
|
+
this._positionTooltip();
|
|
251
|
+
this.tooltipEl.style.visibility = 'visible';
|
|
252
|
+
anim.remove(this.tooltipEl);
|
|
253
|
+
anim({
|
|
254
|
+
targets: this.tooltipEl,
|
|
255
|
+
opacity: this.options.opacity || 1,
|
|
256
|
+
translateX: this.xMovement,
|
|
257
|
+
translateY: this.yMovement,
|
|
258
|
+
duration: this.options.inDuration,
|
|
259
|
+
easing: 'easeOutCubic'
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
_animateOut() {
|
|
264
|
+
anim.remove(this.tooltipEl);
|
|
265
|
+
anim({
|
|
266
|
+
targets: this.tooltipEl,
|
|
267
|
+
opacity: 0,
|
|
268
|
+
translateX: 0,
|
|
269
|
+
translateY: 0,
|
|
270
|
+
duration: this.options.outDuration,
|
|
271
|
+
easing: 'easeOutCubic'
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
_handleMouseEnter() {
|
|
276
|
+
this.isHovered = true;
|
|
277
|
+
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
|
278
|
+
this.open(false);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
_handleMouseLeave() {
|
|
282
|
+
this.isHovered = false;
|
|
283
|
+
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
|
284
|
+
this.close();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
_handleFocus() {
|
|
288
|
+
if (M.tabPressed) {
|
|
289
|
+
this.isFocused = true;
|
|
290
|
+
this.open(false);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
_handleBlur() {
|
|
295
|
+
this.isFocused = false;
|
|
296
|
+
this.close();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
_getAttributeOptions() {
|
|
300
|
+
let attributeOptions = {};
|
|
301
|
+
let tooltipTextOption = this.el.getAttribute('data-tooltip');
|
|
302
|
+
let positionOption = this.el.getAttribute('data-position');
|
|
303
|
+
|
|
304
|
+
if (tooltipTextOption) {
|
|
305
|
+
attributeOptions.text = tooltipTextOption;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (positionOption) {
|
|
309
|
+
attributeOptions.position = positionOption;
|
|
310
|
+
}
|
|
311
|
+
return attributeOptions;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
M.Tooltip = Tooltip;
|
|
316
|
+
|
|
317
|
+
if (M.jQueryLoaded) {
|
|
318
|
+
M.initializeJqueryWrapper(Tooltip, 'tooltip', 'M_Tooltip');
|
|
319
|
+
}
|
|
320
|
+
})(cash, M.anime);
|