kmaterialize 2.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/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/css/materialize.css +9067 -0
- package/dist/css/materialize.min.css +13 -0
- package/dist/js/materialize.js +12374 -0
- package/dist/js/materialize.min.js +6 -0
- package/extras/noUiSlider/nouislider.css +406 -0
- package/extras/noUiSlider/nouislider.js +2147 -0
- package/extras/noUiSlider/nouislider.min.js +1 -0
- package/js/anime.min.js +34 -0
- package/js/autocomplete.js +448 -0
- package/js/buttons.js +354 -0
- package/js/cards.js +40 -0
- package/js/carousel.js +717 -0
- package/js/cash.js +960 -0
- package/js/characterCounter.js +136 -0
- package/js/chips.js +481 -0
- package/js/collapsible.js +275 -0
- package/js/component.js +44 -0
- package/js/datepicker.js +975 -0
- package/js/dropdown.js +635 -0
- package/js/forms.js +275 -0
- package/js/global.js +444 -0
- package/js/materialbox.js +453 -0
- package/js/modal.js +382 -0
- package/js/parallax.js +138 -0
- package/js/pushpin.js +148 -0
- package/js/range.js +263 -0
- package/js/scrollspy.js +295 -0
- package/js/select.js +450 -0
- package/js/sidenav.js +580 -0
- package/js/slider.js +359 -0
- package/js/tabs.js +402 -0
- package/js/tapTarget.js +314 -0
- package/js/timepicker.js +647 -0
- package/js/toasts.js +310 -0
- package/js/tooltip.js +303 -0
- package/js/waves.js +335 -0
- package/package.json +62 -0
package/js/toasts.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
(function($, anim) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
let _defaults = {
|
|
5
|
+
html: '',
|
|
6
|
+
displayLength: 4000,
|
|
7
|
+
inDuration: 300,
|
|
8
|
+
outDuration: 375,
|
|
9
|
+
classes: '',
|
|
10
|
+
completeCallback: null,
|
|
11
|
+
activationPercent: 0.8
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class Toast {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
/**
|
|
17
|
+
* Options for the toast
|
|
18
|
+
* @member Toast#options
|
|
19
|
+
*/
|
|
20
|
+
this.options = $.extend({}, Toast.defaults, options);
|
|
21
|
+
this.message = this.options.html;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Describes current pan state toast
|
|
25
|
+
* @type {Boolean}
|
|
26
|
+
*/
|
|
27
|
+
this.panning = false;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Time remaining until toast is removed
|
|
31
|
+
*/
|
|
32
|
+
this.timeRemaining = this.options.displayLength;
|
|
33
|
+
|
|
34
|
+
if (Toast._toasts.length === 0) {
|
|
35
|
+
Toast._createContainer();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Create new toast
|
|
39
|
+
Toast._toasts.push(this);
|
|
40
|
+
let toastElement = this._createToast();
|
|
41
|
+
toastElement.M_Toast = this;
|
|
42
|
+
this.el = toastElement;
|
|
43
|
+
this.$el = $(toastElement);
|
|
44
|
+
this._animateIn();
|
|
45
|
+
this._setTimer();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static get defaults() {
|
|
49
|
+
return _defaults;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get Instance
|
|
54
|
+
*/
|
|
55
|
+
static getInstance(el) {
|
|
56
|
+
let domElem = !!el.jquery ? el[0] : el;
|
|
57
|
+
return domElem.M_Toast;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Append toast container and add event handlers
|
|
62
|
+
*/
|
|
63
|
+
static _createContainer() {
|
|
64
|
+
let container = document.createElement('div');
|
|
65
|
+
container.setAttribute('id', 'toast-container');
|
|
66
|
+
|
|
67
|
+
// Add event handler
|
|
68
|
+
container.addEventListener('touchstart', Toast._onDragStart);
|
|
69
|
+
container.addEventListener('touchmove', Toast._onDragMove);
|
|
70
|
+
container.addEventListener('touchend', Toast._onDragEnd);
|
|
71
|
+
|
|
72
|
+
container.addEventListener('mousedown', Toast._onDragStart);
|
|
73
|
+
document.addEventListener('mousemove', Toast._onDragMove);
|
|
74
|
+
document.addEventListener('mouseup', Toast._onDragEnd);
|
|
75
|
+
|
|
76
|
+
document.body.appendChild(container);
|
|
77
|
+
Toast._container = container;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Remove toast container and event handlers
|
|
82
|
+
*/
|
|
83
|
+
static _removeContainer() {
|
|
84
|
+
// Add event handler
|
|
85
|
+
document.removeEventListener('mousemove', Toast._onDragMove);
|
|
86
|
+
document.removeEventListener('mouseup', Toast._onDragEnd);
|
|
87
|
+
|
|
88
|
+
$(Toast._container).remove();
|
|
89
|
+
Toast._container = null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Begin drag handler
|
|
94
|
+
* @param {Event} e
|
|
95
|
+
*/
|
|
96
|
+
static _onDragStart(e) {
|
|
97
|
+
if (e.target && $(e.target).closest('.toast').length) {
|
|
98
|
+
let $toast = $(e.target).closest('.toast');
|
|
99
|
+
let toast = $toast[0].M_Toast;
|
|
100
|
+
toast.panning = true;
|
|
101
|
+
Toast._draggedToast = toast;
|
|
102
|
+
toast.el.classList.add('panning');
|
|
103
|
+
toast.el.style.transition = '';
|
|
104
|
+
toast.startingXPos = Toast._xPos(e);
|
|
105
|
+
toast.time = Date.now();
|
|
106
|
+
toast.xPos = Toast._xPos(e);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Drag move handler
|
|
112
|
+
* @param {Event} e
|
|
113
|
+
*/
|
|
114
|
+
static _onDragMove(e) {
|
|
115
|
+
if (!!Toast._draggedToast) {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
let toast = Toast._draggedToast;
|
|
118
|
+
toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e));
|
|
119
|
+
toast.xPos = Toast._xPos(e);
|
|
120
|
+
toast.velocityX = toast.deltaX / (Date.now() - toast.time);
|
|
121
|
+
toast.time = Date.now();
|
|
122
|
+
|
|
123
|
+
let totalDeltaX = toast.xPos - toast.startingXPos;
|
|
124
|
+
let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
125
|
+
toast.el.style.transform = `translateX(${totalDeltaX}px)`;
|
|
126
|
+
toast.el.style.opacity = 1 - Math.abs(totalDeltaX / activationDistance);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* End drag handler
|
|
132
|
+
*/
|
|
133
|
+
static _onDragEnd() {
|
|
134
|
+
if (!!Toast._draggedToast) {
|
|
135
|
+
let toast = Toast._draggedToast;
|
|
136
|
+
toast.panning = false;
|
|
137
|
+
toast.el.classList.remove('panning');
|
|
138
|
+
|
|
139
|
+
let totalDeltaX = toast.xPos - toast.startingXPos;
|
|
140
|
+
let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
|
141
|
+
let shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1;
|
|
142
|
+
|
|
143
|
+
// Remove toast
|
|
144
|
+
if (shouldBeDismissed) {
|
|
145
|
+
toast.wasSwiped = true;
|
|
146
|
+
toast.dismiss();
|
|
147
|
+
|
|
148
|
+
// Animate toast back to original position
|
|
149
|
+
} else {
|
|
150
|
+
toast.el.style.transition = 'transform .2s, opacity .2s';
|
|
151
|
+
toast.el.style.transform = '';
|
|
152
|
+
toast.el.style.opacity = '';
|
|
153
|
+
}
|
|
154
|
+
Toast._draggedToast = null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Get x position of mouse or touch event
|
|
160
|
+
* @param {Event} e
|
|
161
|
+
*/
|
|
162
|
+
static _xPos(e) {
|
|
163
|
+
if (e.targetTouches && e.targetTouches.length >= 1) {
|
|
164
|
+
return e.targetTouches[0].clientX;
|
|
165
|
+
}
|
|
166
|
+
// mouse event
|
|
167
|
+
return e.clientX;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Remove all toasts
|
|
172
|
+
*/
|
|
173
|
+
static dismissAll() {
|
|
174
|
+
for (let toastIndex in Toast._toasts) {
|
|
175
|
+
Toast._toasts[toastIndex].dismiss();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Create toast and append it to toast container
|
|
181
|
+
*/
|
|
182
|
+
_createToast() {
|
|
183
|
+
let toast = document.createElement('div');
|
|
184
|
+
toast.classList.add('toast');
|
|
185
|
+
|
|
186
|
+
// Add custom classes onto toast
|
|
187
|
+
if (!!this.options.classes.length) {
|
|
188
|
+
$(toast).addClass(this.options.classes);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Set content
|
|
192
|
+
if (
|
|
193
|
+
typeof HTMLElement === 'object'
|
|
194
|
+
? this.message instanceof HTMLElement
|
|
195
|
+
: this.message &&
|
|
196
|
+
typeof this.message === 'object' &&
|
|
197
|
+
this.message !== null &&
|
|
198
|
+
this.message.nodeType === 1 &&
|
|
199
|
+
typeof this.message.nodeName === 'string'
|
|
200
|
+
) {
|
|
201
|
+
toast.appendChild(this.message);
|
|
202
|
+
|
|
203
|
+
// Check if it is jQuery object
|
|
204
|
+
} else if (!!this.message.jquery) {
|
|
205
|
+
$(toast).append(this.message[0]);
|
|
206
|
+
|
|
207
|
+
// Insert as html;
|
|
208
|
+
} else {
|
|
209
|
+
toast.innerHTML = this.message;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Append toasft
|
|
213
|
+
Toast._container.appendChild(toast);
|
|
214
|
+
return toast;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Animate in toast
|
|
219
|
+
*/
|
|
220
|
+
_animateIn() {
|
|
221
|
+
// Animate toast in
|
|
222
|
+
anim({
|
|
223
|
+
targets: this.el,
|
|
224
|
+
top: 0,
|
|
225
|
+
opacity: 1,
|
|
226
|
+
duration: this.options.inDuration,
|
|
227
|
+
easing: 'easeOutCubic'
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Create setInterval which automatically removes toast when timeRemaining >= 0
|
|
233
|
+
* has been reached
|
|
234
|
+
*/
|
|
235
|
+
_setTimer() {
|
|
236
|
+
if (this.timeRemaining !== Infinity) {
|
|
237
|
+
this.counterInterval = setInterval(() => {
|
|
238
|
+
// If toast is not being dragged, decrease its time remaining
|
|
239
|
+
if (!this.panning) {
|
|
240
|
+
this.timeRemaining -= 20;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Animate toast out
|
|
244
|
+
if (this.timeRemaining <= 0) {
|
|
245
|
+
this.dismiss();
|
|
246
|
+
}
|
|
247
|
+
}, 20);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Dismiss toast with animation
|
|
253
|
+
*/
|
|
254
|
+
dismiss() {
|
|
255
|
+
window.clearInterval(this.counterInterval);
|
|
256
|
+
let activationDistance = this.el.offsetWidth * this.options.activationPercent;
|
|
257
|
+
|
|
258
|
+
if (this.wasSwiped) {
|
|
259
|
+
this.el.style.transition = 'transform .05s, opacity .05s';
|
|
260
|
+
this.el.style.transform = `translateX(${activationDistance}px)`;
|
|
261
|
+
this.el.style.opacity = 0;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
anim({
|
|
265
|
+
targets: this.el,
|
|
266
|
+
opacity: 0,
|
|
267
|
+
marginTop: -40,
|
|
268
|
+
duration: this.options.outDuration,
|
|
269
|
+
easing: 'easeOutExpo',
|
|
270
|
+
complete: () => {
|
|
271
|
+
// Call the optional callback
|
|
272
|
+
if (typeof this.options.completeCallback === 'function') {
|
|
273
|
+
this.options.completeCallback();
|
|
274
|
+
}
|
|
275
|
+
// Remove toast from DOM
|
|
276
|
+
this.$el.remove();
|
|
277
|
+
Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
|
|
278
|
+
if (Toast._toasts.length === 0) {
|
|
279
|
+
Toast._removeContainer();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @static
|
|
288
|
+
* @memberof Toast
|
|
289
|
+
* @type {Array.<Toast>}
|
|
290
|
+
*/
|
|
291
|
+
Toast._toasts = [];
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @static
|
|
295
|
+
* @memberof Toast
|
|
296
|
+
*/
|
|
297
|
+
Toast._container = null;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @static
|
|
301
|
+
* @memberof Toast
|
|
302
|
+
* @type {Toast}
|
|
303
|
+
*/
|
|
304
|
+
Toast._draggedToast = null;
|
|
305
|
+
|
|
306
|
+
M.Toast = Toast;
|
|
307
|
+
M.toast = function(options) {
|
|
308
|
+
return new Toast(options);
|
|
309
|
+
};
|
|
310
|
+
})(cash, M.anime);
|
package/js/tooltip.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
(function($, anim) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
let _defaults = {
|
|
5
|
+
exitDelay: 200,
|
|
6
|
+
enterDelay: 0,
|
|
7
|
+
html: null,
|
|
8
|
+
margin: 5,
|
|
9
|
+
inDuration: 250,
|
|
10
|
+
outDuration: 200,
|
|
11
|
+
position: 'bottom',
|
|
12
|
+
transitionMovement: 10
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @class
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
class Tooltip extends Component {
|
|
20
|
+
/**
|
|
21
|
+
* Construct Tooltip instance
|
|
22
|
+
* @constructor
|
|
23
|
+
* @param {Element} el
|
|
24
|
+
* @param {Object} options
|
|
25
|
+
*/
|
|
26
|
+
constructor(el, options) {
|
|
27
|
+
super(Tooltip, el, options);
|
|
28
|
+
|
|
29
|
+
this.el.M_Tooltip = this;
|
|
30
|
+
this.options = $.extend({}, Tooltip.defaults, options);
|
|
31
|
+
|
|
32
|
+
this.isOpen = false;
|
|
33
|
+
this.isHovered = false;
|
|
34
|
+
this.isFocused = false;
|
|
35
|
+
this._appendTooltipEl();
|
|
36
|
+
this._setupEventHandlers();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static get defaults() {
|
|
40
|
+
return _defaults;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static init(els, options) {
|
|
44
|
+
return super.init(this, els, options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get Instance
|
|
49
|
+
*/
|
|
50
|
+
static getInstance(el) {
|
|
51
|
+
let domElem = !!el.jquery ? el[0] : el;
|
|
52
|
+
return domElem.M_Tooltip;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Teardown component
|
|
57
|
+
*/
|
|
58
|
+
destroy() {
|
|
59
|
+
$(this.tooltipEl).remove();
|
|
60
|
+
this._removeEventHandlers();
|
|
61
|
+
this.el.M_Tooltip = undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_appendTooltipEl() {
|
|
65
|
+
let tooltipEl = document.createElement('div');
|
|
66
|
+
tooltipEl.classList.add('material-tooltip');
|
|
67
|
+
this.tooltipEl = tooltipEl;
|
|
68
|
+
|
|
69
|
+
let tooltipContentEl = document.createElement('div');
|
|
70
|
+
tooltipContentEl.classList.add('tooltip-content');
|
|
71
|
+
tooltipContentEl.innerHTML = this.options.html;
|
|
72
|
+
tooltipEl.appendChild(tooltipContentEl);
|
|
73
|
+
document.body.appendChild(tooltipEl);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_updateTooltipContent() {
|
|
77
|
+
this.tooltipEl.querySelector('.tooltip-content').innerHTML = this.options.html;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_setupEventHandlers() {
|
|
81
|
+
this._handleMouseEnterBound = this._handleMouseEnter.bind(this);
|
|
82
|
+
this._handleMouseLeaveBound = this._handleMouseLeave.bind(this);
|
|
83
|
+
this._handleFocusBound = this._handleFocus.bind(this);
|
|
84
|
+
this._handleBlurBound = this._handleBlur.bind(this);
|
|
85
|
+
this.el.addEventListener('mouseenter', this._handleMouseEnterBound);
|
|
86
|
+
this.el.addEventListener('mouseleave', this._handleMouseLeaveBound);
|
|
87
|
+
this.el.addEventListener('focus', this._handleFocusBound, true);
|
|
88
|
+
this.el.addEventListener('blur', this._handleBlurBound, true);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
_removeEventHandlers() {
|
|
92
|
+
this.el.removeEventListener('mouseenter', this._handleMouseEnterBound);
|
|
93
|
+
this.el.removeEventListener('mouseleave', this._handleMouseLeaveBound);
|
|
94
|
+
this.el.removeEventListener('focus', this._handleFocusBound, true);
|
|
95
|
+
this.el.removeEventListener('blur', this._handleBlurBound, true);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
open(isManual) {
|
|
99
|
+
if (this.isOpen) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
isManual = isManual === undefined ? true : undefined; // Default value true
|
|
103
|
+
this.isOpen = true;
|
|
104
|
+
// Update tooltip content with HTML attribute options
|
|
105
|
+
this.options = $.extend({}, this.options, this._getAttributeOptions());
|
|
106
|
+
this._updateTooltipContent();
|
|
107
|
+
this._setEnterDelayTimeout(isManual);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
close() {
|
|
111
|
+
if (!this.isOpen) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.isHovered = false;
|
|
116
|
+
this.isFocused = false;
|
|
117
|
+
this.isOpen = false;
|
|
118
|
+
this._setExitDelayTimeout();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Create timeout which delays when the tooltip closes
|
|
123
|
+
*/
|
|
124
|
+
_setExitDelayTimeout() {
|
|
125
|
+
clearTimeout(this._exitDelayTimeout);
|
|
126
|
+
|
|
127
|
+
this._exitDelayTimeout = setTimeout(() => {
|
|
128
|
+
if (this.isHovered || this.isFocused) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this._animateOut();
|
|
133
|
+
}, this.options.exitDelay);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Create timeout which delays when the toast closes
|
|
138
|
+
*/
|
|
139
|
+
_setEnterDelayTimeout(isManual) {
|
|
140
|
+
clearTimeout(this._enterDelayTimeout);
|
|
141
|
+
|
|
142
|
+
this._enterDelayTimeout = setTimeout(() => {
|
|
143
|
+
if (!this.isHovered && !this.isFocused && !isManual) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
this._animateIn();
|
|
148
|
+
}, this.options.enterDelay);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_positionTooltip() {
|
|
152
|
+
let origin = this.el,
|
|
153
|
+
tooltip = this.tooltipEl,
|
|
154
|
+
originHeight = origin.offsetHeight,
|
|
155
|
+
originWidth = origin.offsetWidth,
|
|
156
|
+
tooltipHeight = tooltip.offsetHeight,
|
|
157
|
+
tooltipWidth = tooltip.offsetWidth,
|
|
158
|
+
newCoordinates,
|
|
159
|
+
margin = this.options.margin,
|
|
160
|
+
targetTop,
|
|
161
|
+
targetLeft;
|
|
162
|
+
|
|
163
|
+
(this.xMovement = 0), (this.yMovement = 0);
|
|
164
|
+
|
|
165
|
+
targetTop = origin.getBoundingClientRect().top + M.getDocumentScrollTop();
|
|
166
|
+
targetLeft = origin.getBoundingClientRect().left + M.getDocumentScrollLeft();
|
|
167
|
+
|
|
168
|
+
if (this.options.position === 'top') {
|
|
169
|
+
targetTop += -tooltipHeight - margin;
|
|
170
|
+
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
|
171
|
+
this.yMovement = -this.options.transitionMovement;
|
|
172
|
+
} else if (this.options.position === 'right') {
|
|
173
|
+
targetTop += originHeight / 2 - tooltipHeight / 2;
|
|
174
|
+
targetLeft += originWidth + margin;
|
|
175
|
+
this.xMovement = this.options.transitionMovement;
|
|
176
|
+
} else if (this.options.position === 'left') {
|
|
177
|
+
targetTop += originHeight / 2 - tooltipHeight / 2;
|
|
178
|
+
targetLeft += -tooltipWidth - margin;
|
|
179
|
+
this.xMovement = -this.options.transitionMovement;
|
|
180
|
+
} else {
|
|
181
|
+
targetTop += originHeight + margin;
|
|
182
|
+
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
|
183
|
+
this.yMovement = this.options.transitionMovement;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
newCoordinates = this._repositionWithinScreen(
|
|
187
|
+
targetLeft,
|
|
188
|
+
targetTop,
|
|
189
|
+
tooltipWidth,
|
|
190
|
+
tooltipHeight
|
|
191
|
+
);
|
|
192
|
+
$(tooltip).css({
|
|
193
|
+
top: newCoordinates.y + 'px',
|
|
194
|
+
left: newCoordinates.x + 'px'
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
_repositionWithinScreen(x, y, width, height) {
|
|
199
|
+
let scrollLeft = M.getDocumentScrollLeft();
|
|
200
|
+
let scrollTop = M.getDocumentScrollTop();
|
|
201
|
+
let newX = x - scrollLeft;
|
|
202
|
+
let newY = y - scrollTop;
|
|
203
|
+
|
|
204
|
+
let bounding = {
|
|
205
|
+
left: newX,
|
|
206
|
+
top: newY,
|
|
207
|
+
width: width,
|
|
208
|
+
height: height
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
let offset = this.options.margin + this.options.transitionMovement;
|
|
212
|
+
let edges = M.checkWithinContainer(document.body, bounding, offset);
|
|
213
|
+
|
|
214
|
+
if (edges.left) {
|
|
215
|
+
newX = offset;
|
|
216
|
+
} else if (edges.right) {
|
|
217
|
+
newX -= newX + width - window.innerWidth;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (edges.top) {
|
|
221
|
+
newY = offset;
|
|
222
|
+
} else if (edges.bottom) {
|
|
223
|
+
newY -= newY + height - window.innerHeight;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
x: newX + scrollLeft,
|
|
228
|
+
y: newY + scrollTop
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
_animateIn() {
|
|
233
|
+
this._positionTooltip();
|
|
234
|
+
this.tooltipEl.style.visibility = 'visible';
|
|
235
|
+
anim.remove(this.tooltipEl);
|
|
236
|
+
anim({
|
|
237
|
+
targets: this.tooltipEl,
|
|
238
|
+
opacity: 1,
|
|
239
|
+
translateX: this.xMovement,
|
|
240
|
+
translateY: this.yMovement,
|
|
241
|
+
duration: this.options.inDuration,
|
|
242
|
+
easing: 'easeOutCubic'
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
_animateOut() {
|
|
247
|
+
anim.remove(this.tooltipEl);
|
|
248
|
+
anim({
|
|
249
|
+
targets: this.tooltipEl,
|
|
250
|
+
opacity: 0,
|
|
251
|
+
translateX: 0,
|
|
252
|
+
translateY: 0,
|
|
253
|
+
duration: this.options.outDuration,
|
|
254
|
+
easing: 'easeOutCubic'
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
_handleMouseEnter() {
|
|
259
|
+
this.isHovered = true;
|
|
260
|
+
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
|
261
|
+
this.open(false);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
_handleMouseLeave() {
|
|
265
|
+
this.isHovered = false;
|
|
266
|
+
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
|
267
|
+
this.close();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
_handleFocus() {
|
|
271
|
+
if (M.tabPressed) {
|
|
272
|
+
this.isFocused = true;
|
|
273
|
+
this.open(false);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
_handleBlur() {
|
|
278
|
+
this.isFocused = false;
|
|
279
|
+
this.close();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
_getAttributeOptions() {
|
|
283
|
+
let attributeOptions = {};
|
|
284
|
+
let tooltipTextOption = this.el.getAttribute('data-tooltip');
|
|
285
|
+
let positionOption = this.el.getAttribute('data-position');
|
|
286
|
+
|
|
287
|
+
if (tooltipTextOption) {
|
|
288
|
+
attributeOptions.html = tooltipTextOption;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (positionOption) {
|
|
292
|
+
attributeOptions.position = positionOption;
|
|
293
|
+
}
|
|
294
|
+
return attributeOptions;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
M.Tooltip = Tooltip;
|
|
299
|
+
|
|
300
|
+
if (M.jQueryLoaded) {
|
|
301
|
+
M.initializeJqueryWrapper(Tooltip, 'tooltip', 'M_Tooltip');
|
|
302
|
+
}
|
|
303
|
+
})(cash, M.anime);
|