materialize-sass 0.97.0 → 1.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitattributes +1 -0
- data/.gitignore +3 -0
- data/README.md +48 -10
- data/Rakefile +129 -1
- data/assets/javascripts/materialize/anime.min.js +417 -0
- data/assets/javascripts/materialize/autocomplete.js +504 -0
- data/assets/javascripts/materialize/buttons.js +409 -0
- data/assets/javascripts/materialize/cards.js +34 -0
- data/assets/javascripts/materialize/carousel.js +797 -0
- data/assets/javascripts/materialize/cash.js +990 -0
- data/assets/javascripts/materialize/characterCounter.js +180 -0
- data/assets/javascripts/materialize/chips.js +564 -0
- data/assets/javascripts/materialize/collapsible.js +337 -0
- data/assets/javascripts/materialize/component.js +57 -0
- data/assets/javascripts/materialize/datepicker.js +935 -0
- data/assets/javascripts/materialize/dropdown.js +659 -0
- data/assets/javascripts/materialize/extras/nouislider.js +2147 -0
- data/assets/javascripts/materialize/extras/nouislider.min.js +1 -0
- data/assets/javascripts/materialize/forms.js +244 -0
- data/assets/javascripts/materialize/global.js +408 -0
- data/assets/javascripts/materialize/materialbox.js +513 -0
- data/assets/javascripts/materialize/modal.js +449 -0
- data/assets/javascripts/materialize/parallax.js +173 -0
- data/assets/javascripts/materialize/pushpin.js +179 -0
- data/assets/javascripts/materialize/range.js +310 -0
- data/assets/javascripts/materialize/scrollspy.js +328 -0
- data/assets/javascripts/materialize/select.js +497 -0
- data/assets/javascripts/materialize/sidenav.js +655 -0
- data/assets/javascripts/materialize/slider.js +424 -0
- data/assets/javascripts/materialize/tabs.js +476 -0
- data/assets/javascripts/materialize/tapTarget.js +364 -0
- data/assets/javascripts/materialize/timepicker.js +647 -0
- data/assets/javascripts/materialize/toasts.js +355 -0
- data/assets/javascripts/materialize/tooltip.js +351 -0
- data/{app/assets → assets}/javascripts/materialize/waves.js +42 -47
- data/assets/javascripts/materialize-sprockets.js +29 -0
- data/assets/javascripts/materialize.js +12374 -0
- data/assets/stylesheets/materialize/components/_badges.scss +55 -0
- data/assets/stylesheets/materialize/components/_buttons.scss +322 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +72 -29
- data/assets/stylesheets/materialize/components/_carousel.scss +90 -0
- data/assets/stylesheets/materialize/components/_chips.scss +90 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +23 -17
- data/assets/stylesheets/materialize/components/_color-classes.scss +32 -0
- data/{app/assets/stylesheets/materialize/components/_color.scss → assets/stylesheets/materialize/components/_color-variables.scss} +22 -64
- data/assets/stylesheets/materialize/components/_datepicker.scss +191 -0
- data/assets/stylesheets/materialize/components/_dropdown.scss +85 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +197 -144
- data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +57 -18
- data/assets/stylesheets/materialize/components/_icons-material-design.scss +5 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +15 -13
- data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +18 -14
- data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +89 -25
- data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +5 -3
- data/assets/stylesheets/materialize/components/_pulse.scss +34 -0
- data/assets/stylesheets/materialize/components/_sidenav.scss +208 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +2 -2
- data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +5 -5
- data/assets/stylesheets/materialize/components/_tabs.scss +99 -0
- data/assets/stylesheets/materialize/components/_tapTarget.scss +103 -0
- data/assets/stylesheets/materialize/components/_timepicker.scss +183 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +17 -22
- data/assets/stylesheets/materialize/components/_tooltip.scss +32 -0
- data/assets/stylesheets/materialize/components/_transitions.scss +13 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +11 -9
- data/assets/stylesheets/materialize/components/_variables.scss +349 -0
- data/assets/stylesheets/materialize/components/_waves.scss +114 -0
- data/assets/stylesheets/materialize/components/forms/_checkboxes.scss +200 -0
- data/assets/stylesheets/materialize/components/forms/_file-input.scss +44 -0
- data/assets/stylesheets/materialize/components/forms/_forms.scss +22 -0
- data/assets/stylesheets/materialize/components/forms/_input-fields.scss +354 -0
- data/assets/stylesheets/materialize/components/forms/_radio-buttons.scss +115 -0
- data/assets/stylesheets/materialize/components/forms/_range.scss +161 -0
- data/assets/stylesheets/materialize/components/forms/_select.scss +190 -0
- data/assets/stylesheets/materialize/components/forms/_switches.scss +89 -0
- data/assets/stylesheets/materialize/extras/nouislider.css +406 -0
- data/{app/assets → assets}/stylesheets/materialize.scss +13 -10
- data/lib/materialize-sass/engine.rb +11 -6
- data/lib/materialize-sass/helpers.rb +38 -0
- data/lib/materialize-sass/version.rb +1 -1
- data/lib/materialize-sass.rb +13 -28
- data/materialize-sass.gemspec +5 -5
- metadata +97 -105
- data/app/assets/fonts/material-design-icons/LICENSE.txt +0 -428
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.eot +0 -0
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.svg +0 -769
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.ttf +0 -0
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.woff +0 -0
- data/app/assets/fonts/material-design-icons/Material-Design-Icons.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
- data/app/assets/javascripts/materialize/animation.js +0 -9
- data/app/assets/javascripts/materialize/buttons.js +0 -61
- data/app/assets/javascripts/materialize/cards.js +0 -27
- data/app/assets/javascripts/materialize/character_counter.js +0 -59
- data/app/assets/javascripts/materialize/collapsible.js +0 -139
- data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1430
- data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1123
- data/app/assets/javascripts/materialize/dropdown.js +0 -178
- data/app/assets/javascripts/materialize/forms.js +0 -456
- data/app/assets/javascripts/materialize/global.js +0 -36
- data/app/assets/javascripts/materialize/hammer.min.js +0 -1
- data/app/assets/javascripts/materialize/init.js +0 -136
- data/app/assets/javascripts/materialize/jquery.easing.1.3.js +0 -205
- data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
- data/app/assets/javascripts/materialize/jquery.timeago.min.js +0 -1
- data/app/assets/javascripts/materialize/leanModal.js +0 -178
- data/app/assets/javascripts/materialize/materialbox.js +0 -249
- data/app/assets/javascripts/materialize/parallax.js +0 -58
- data/app/assets/javascripts/materialize/prism.js +0 -8
- data/app/assets/javascripts/materialize/pushpin.js +0 -62
- data/app/assets/javascripts/materialize/scrollFire.js +0 -44
- data/app/assets/javascripts/materialize/scrollspy.js +0 -284
- data/app/assets/javascripts/materialize/sideNav.js +0 -312
- data/app/assets/javascripts/materialize/slider.js +0 -301
- data/app/assets/javascripts/materialize/tabs.js +0 -136
- data/app/assets/javascripts/materialize/toasts.js +0 -125
- data/app/assets/javascripts/materialize/tooltip.js +0 -166
- data/app/assets/javascripts/materialize/transitions.js +0 -154
- data/app/assets/javascripts/materialize/velocity.min.js +0 -4
- data/app/assets/javascripts/materialize-sprockets.js +0 -27
- data/app/assets/javascripts/materialize.js +0 -6159
- data/app/assets/stylesheets/materialize/components/_buttons.scss +0 -157
- data/app/assets/stylesheets/materialize/components/_dropdown.scss +0 -40
- data/app/assets/stylesheets/materialize/components/_form.scss +0 -886
- data/app/assets/stylesheets/materialize/components/_icons-material-design.scss +0 -3257
- data/app/assets/stylesheets/materialize/components/_mixins.scss +0 -5
- data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -427
- data/app/assets/stylesheets/materialize/components/_prefixer.scss +0 -376
- data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -38
- data/app/assets/stylesheets/materialize/components/_sideNav.scss +0 -111
- data/app/assets/stylesheets/materialize/components/_tabs.scss +0 -47
- data/app/assets/stylesheets/materialize/components/_tooltip.scss +0 -34
- data/app/assets/stylesheets/materialize/components/_variables.scss +0 -152
- data/app/assets/stylesheets/materialize/components/_waves.scss +0 -167
- data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -435
- data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -201
- data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -125
@@ -0,0 +1,355 @@
|
|
1
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
2
|
+
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4
|
+
|
5
|
+
(function ($, anim) {
|
6
|
+
'use strict';
|
7
|
+
|
8
|
+
var _defaults = {
|
9
|
+
html: '',
|
10
|
+
displayLength: 4000,
|
11
|
+
inDuration: 300,
|
12
|
+
outDuration: 375,
|
13
|
+
classes: '',
|
14
|
+
completeCallback: null,
|
15
|
+
activationPercent: 0.8
|
16
|
+
};
|
17
|
+
|
18
|
+
var Toast = function () {
|
19
|
+
function Toast(options) {
|
20
|
+
_classCallCheck(this, Toast);
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Options for the toast
|
24
|
+
* @member Toast#options
|
25
|
+
*/
|
26
|
+
this.options = $.extend({}, Toast.defaults, options);
|
27
|
+
this.message = this.options.html;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Describes current pan state toast
|
31
|
+
* @type {Boolean}
|
32
|
+
*/
|
33
|
+
this.panning = false;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Time remaining until toast is removed
|
37
|
+
*/
|
38
|
+
this.timeRemaining = this.options.displayLength;
|
39
|
+
|
40
|
+
if (Toast._toasts.length === 0) {
|
41
|
+
Toast._createContainer();
|
42
|
+
}
|
43
|
+
|
44
|
+
// Create new toast
|
45
|
+
Toast._toasts.push(this);
|
46
|
+
var toastElement = this._createToast();
|
47
|
+
toastElement.M_Toast = this;
|
48
|
+
this.el = toastElement;
|
49
|
+
this.$el = $(toastElement);
|
50
|
+
this._animateIn();
|
51
|
+
this._setTimer();
|
52
|
+
}
|
53
|
+
|
54
|
+
_createClass(Toast, [{
|
55
|
+
key: '_createToast',
|
56
|
+
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Create toast and append it to toast container
|
60
|
+
*/
|
61
|
+
value: function _createToast() {
|
62
|
+
var toast = document.createElement('div');
|
63
|
+
toast.classList.add('toast');
|
64
|
+
|
65
|
+
// Add custom classes onto toast
|
66
|
+
if (!!this.options.classes.length) {
|
67
|
+
$(toast).addClass(this.options.classes);
|
68
|
+
}
|
69
|
+
|
70
|
+
// Set content
|
71
|
+
if (typeof HTMLElement === 'object' ? this.message instanceof HTMLElement : this.message && typeof this.message === 'object' && this.message !== null && this.message.nodeType === 1 && typeof this.message.nodeName === 'string') {
|
72
|
+
toast.appendChild(this.message);
|
73
|
+
|
74
|
+
// Check if it is jQuery object
|
75
|
+
} else if (!!this.message.jquery) {
|
76
|
+
$(toast).append(this.message[0]);
|
77
|
+
|
78
|
+
// Insert as html;
|
79
|
+
} else {
|
80
|
+
toast.innerHTML = this.message;
|
81
|
+
}
|
82
|
+
|
83
|
+
// Append toasft
|
84
|
+
Toast._container.appendChild(toast);
|
85
|
+
return toast;
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Animate in toast
|
90
|
+
*/
|
91
|
+
|
92
|
+
}, {
|
93
|
+
key: '_animateIn',
|
94
|
+
value: function _animateIn() {
|
95
|
+
// Animate toast in
|
96
|
+
anim({
|
97
|
+
targets: this.el,
|
98
|
+
top: 0,
|
99
|
+
opacity: 1,
|
100
|
+
duration: this.options.inDuration,
|
101
|
+
easing: 'easeOutCubic'
|
102
|
+
});
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Create setInterval which automatically removes toast when timeRemaining >= 0
|
107
|
+
* has been reached
|
108
|
+
*/
|
109
|
+
|
110
|
+
}, {
|
111
|
+
key: '_setTimer',
|
112
|
+
value: function _setTimer() {
|
113
|
+
var _this = this;
|
114
|
+
|
115
|
+
if (this.timeRemaining !== Infinity) {
|
116
|
+
this.counterInterval = setInterval(function () {
|
117
|
+
// If toast is not being dragged, decrease its time remaining
|
118
|
+
if (!_this.panning) {
|
119
|
+
_this.timeRemaining -= 20;
|
120
|
+
}
|
121
|
+
|
122
|
+
// Animate toast out
|
123
|
+
if (_this.timeRemaining <= 0) {
|
124
|
+
_this.dismiss();
|
125
|
+
}
|
126
|
+
}, 20);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Dismiss toast with animation
|
132
|
+
*/
|
133
|
+
|
134
|
+
}, {
|
135
|
+
key: 'dismiss',
|
136
|
+
value: function dismiss() {
|
137
|
+
var _this2 = this;
|
138
|
+
|
139
|
+
window.clearInterval(this.counterInterval);
|
140
|
+
var activationDistance = this.el.offsetWidth * this.options.activationPercent;
|
141
|
+
|
142
|
+
if (this.wasSwiped) {
|
143
|
+
this.el.style.transition = 'transform .05s, opacity .05s';
|
144
|
+
this.el.style.transform = 'translateX(' + activationDistance + 'px)';
|
145
|
+
this.el.style.opacity = 0;
|
146
|
+
}
|
147
|
+
|
148
|
+
anim({
|
149
|
+
targets: this.el,
|
150
|
+
opacity: 0,
|
151
|
+
marginTop: -40,
|
152
|
+
duration: this.options.outDuration,
|
153
|
+
easing: 'easeOutExpo',
|
154
|
+
complete: function () {
|
155
|
+
// Call the optional callback
|
156
|
+
if (typeof _this2.options.completeCallback === 'function') {
|
157
|
+
_this2.options.completeCallback();
|
158
|
+
}
|
159
|
+
// Remove toast from DOM
|
160
|
+
_this2.$el.remove();
|
161
|
+
Toast._toasts.splice(Toast._toasts.indexOf(_this2), 1);
|
162
|
+
if (Toast._toasts.length === 0) {
|
163
|
+
Toast._removeContainer();
|
164
|
+
}
|
165
|
+
}
|
166
|
+
});
|
167
|
+
}
|
168
|
+
}], [{
|
169
|
+
key: 'getInstance',
|
170
|
+
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Get Instance
|
174
|
+
*/
|
175
|
+
value: function getInstance(el) {
|
176
|
+
var domElem = !!el.jquery ? el[0] : el;
|
177
|
+
return domElem.M_Toast;
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Append toast container and add event handlers
|
182
|
+
*/
|
183
|
+
|
184
|
+
}, {
|
185
|
+
key: '_createContainer',
|
186
|
+
value: function _createContainer() {
|
187
|
+
var container = document.createElement('div');
|
188
|
+
container.setAttribute('id', 'toast-container');
|
189
|
+
|
190
|
+
// Add event handler
|
191
|
+
container.addEventListener('touchstart', Toast._onDragStart);
|
192
|
+
container.addEventListener('touchmove', Toast._onDragMove);
|
193
|
+
container.addEventListener('touchend', Toast._onDragEnd);
|
194
|
+
|
195
|
+
container.addEventListener('mousedown', Toast._onDragStart);
|
196
|
+
document.addEventListener('mousemove', Toast._onDragMove);
|
197
|
+
document.addEventListener('mouseup', Toast._onDragEnd);
|
198
|
+
|
199
|
+
document.body.appendChild(container);
|
200
|
+
Toast._container = container;
|
201
|
+
}
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Remove toast container and event handlers
|
205
|
+
*/
|
206
|
+
|
207
|
+
}, {
|
208
|
+
key: '_removeContainer',
|
209
|
+
value: function _removeContainer() {
|
210
|
+
// Add event handler
|
211
|
+
document.removeEventListener('mousemove', Toast._onDragMove);
|
212
|
+
document.removeEventListener('mouseup', Toast._onDragEnd);
|
213
|
+
|
214
|
+
$(Toast._container).remove();
|
215
|
+
Toast._container = null;
|
216
|
+
}
|
217
|
+
|
218
|
+
/**
|
219
|
+
* Begin drag handler
|
220
|
+
* @param {Event} e
|
221
|
+
*/
|
222
|
+
|
223
|
+
}, {
|
224
|
+
key: '_onDragStart',
|
225
|
+
value: function _onDragStart(e) {
|
226
|
+
if (e.target && $(e.target).closest('.toast').length) {
|
227
|
+
var $toast = $(e.target).closest('.toast');
|
228
|
+
var toast = $toast[0].M_Toast;
|
229
|
+
toast.panning = true;
|
230
|
+
Toast._draggedToast = toast;
|
231
|
+
toast.el.classList.add('panning');
|
232
|
+
toast.el.style.transition = '';
|
233
|
+
toast.startingXPos = Toast._xPos(e);
|
234
|
+
toast.time = Date.now();
|
235
|
+
toast.xPos = Toast._xPos(e);
|
236
|
+
}
|
237
|
+
}
|
238
|
+
|
239
|
+
/**
|
240
|
+
* Drag move handler
|
241
|
+
* @param {Event} e
|
242
|
+
*/
|
243
|
+
|
244
|
+
}, {
|
245
|
+
key: '_onDragMove',
|
246
|
+
value: function _onDragMove(e) {
|
247
|
+
if (!!Toast._draggedToast) {
|
248
|
+
e.preventDefault();
|
249
|
+
var toast = Toast._draggedToast;
|
250
|
+
toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e));
|
251
|
+
toast.xPos = Toast._xPos(e);
|
252
|
+
toast.velocityX = toast.deltaX / (Date.now() - toast.time);
|
253
|
+
toast.time = Date.now();
|
254
|
+
|
255
|
+
var totalDeltaX = toast.xPos - toast.startingXPos;
|
256
|
+
var activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
257
|
+
toast.el.style.transform = 'translateX(' + totalDeltaX + 'px)';
|
258
|
+
toast.el.style.opacity = 1 - Math.abs(totalDeltaX / activationDistance);
|
259
|
+
}
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* End drag handler
|
264
|
+
*/
|
265
|
+
|
266
|
+
}, {
|
267
|
+
key: '_onDragEnd',
|
268
|
+
value: function _onDragEnd() {
|
269
|
+
if (!!Toast._draggedToast) {
|
270
|
+
var toast = Toast._draggedToast;
|
271
|
+
toast.panning = false;
|
272
|
+
toast.el.classList.remove('panning');
|
273
|
+
|
274
|
+
var totalDeltaX = toast.xPos - toast.startingXPos;
|
275
|
+
var activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
|
276
|
+
var shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1;
|
277
|
+
|
278
|
+
// Remove toast
|
279
|
+
if (shouldBeDismissed) {
|
280
|
+
toast.wasSwiped = true;
|
281
|
+
toast.dismiss();
|
282
|
+
|
283
|
+
// Animate toast back to original position
|
284
|
+
} else {
|
285
|
+
toast.el.style.transition = 'transform .2s, opacity .2s';
|
286
|
+
toast.el.style.transform = '';
|
287
|
+
toast.el.style.opacity = '';
|
288
|
+
}
|
289
|
+
Toast._draggedToast = null;
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
/**
|
294
|
+
* Get x position of mouse or touch event
|
295
|
+
* @param {Event} e
|
296
|
+
*/
|
297
|
+
|
298
|
+
}, {
|
299
|
+
key: '_xPos',
|
300
|
+
value: function _xPos(e) {
|
301
|
+
if (e.targetTouches && e.targetTouches.length >= 1) {
|
302
|
+
return e.targetTouches[0].clientX;
|
303
|
+
}
|
304
|
+
// mouse event
|
305
|
+
return e.clientX;
|
306
|
+
}
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Remove all toasts
|
310
|
+
*/
|
311
|
+
|
312
|
+
}, {
|
313
|
+
key: 'dismissAll',
|
314
|
+
value: function dismissAll() {
|
315
|
+
for (var toastIndex in Toast._toasts) {
|
316
|
+
Toast._toasts[toastIndex].dismiss();
|
317
|
+
}
|
318
|
+
}
|
319
|
+
}, {
|
320
|
+
key: 'defaults',
|
321
|
+
get: function () {
|
322
|
+
return _defaults;
|
323
|
+
}
|
324
|
+
}]);
|
325
|
+
|
326
|
+
return Toast;
|
327
|
+
}();
|
328
|
+
|
329
|
+
/**
|
330
|
+
* @static
|
331
|
+
* @memberof Toast
|
332
|
+
* @type {Array.<Toast>}
|
333
|
+
*/
|
334
|
+
|
335
|
+
|
336
|
+
Toast._toasts = [];
|
337
|
+
|
338
|
+
/**
|
339
|
+
* @static
|
340
|
+
* @memberof Toast
|
341
|
+
*/
|
342
|
+
Toast._container = null;
|
343
|
+
|
344
|
+
/**
|
345
|
+
* @static
|
346
|
+
* @memberof Toast
|
347
|
+
* @type {Toast}
|
348
|
+
*/
|
349
|
+
Toast._draggedToast = null;
|
350
|
+
|
351
|
+
M.Toast = Toast;
|
352
|
+
M.toast = function (options) {
|
353
|
+
return new Toast(options);
|
354
|
+
};
|
355
|
+
})(cash, M.anime);
|
@@ -0,0 +1,351 @@
|
|
1
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
2
|
+
|
3
|
+
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
4
|
+
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6
|
+
|
7
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
8
|
+
|
9
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
10
|
+
|
11
|
+
(function ($, anim) {
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _defaults = {
|
15
|
+
exitDelay: 200,
|
16
|
+
enterDelay: 0,
|
17
|
+
html: null,
|
18
|
+
margin: 5,
|
19
|
+
inDuration: 250,
|
20
|
+
outDuration: 200,
|
21
|
+
position: 'bottom',
|
22
|
+
transitionMovement: 10
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* @class
|
27
|
+
*
|
28
|
+
*/
|
29
|
+
|
30
|
+
var Tooltip = function (_Component) {
|
31
|
+
_inherits(Tooltip, _Component);
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Construct Tooltip instance
|
35
|
+
* @constructor
|
36
|
+
* @param {Element} el
|
37
|
+
* @param {Object} options
|
38
|
+
*/
|
39
|
+
function Tooltip(el, options) {
|
40
|
+
_classCallCheck(this, Tooltip);
|
41
|
+
|
42
|
+
var _this = _possibleConstructorReturn(this, (Tooltip.__proto__ || Object.getPrototypeOf(Tooltip)).call(this, Tooltip, el, options));
|
43
|
+
|
44
|
+
_this.el.M_Tooltip = _this;
|
45
|
+
_this.options = $.extend({}, Tooltip.defaults, options);
|
46
|
+
|
47
|
+
_this.isOpen = false;
|
48
|
+
_this.isHovered = false;
|
49
|
+
_this.isFocused = false;
|
50
|
+
_this._appendTooltipEl();
|
51
|
+
_this._setupEventHandlers();
|
52
|
+
return _this;
|
53
|
+
}
|
54
|
+
|
55
|
+
_createClass(Tooltip, [{
|
56
|
+
key: 'destroy',
|
57
|
+
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Teardown component
|
61
|
+
*/
|
62
|
+
value: function destroy() {
|
63
|
+
$(this.tooltipEl).remove();
|
64
|
+
this._removeEventHandlers();
|
65
|
+
this.el.M_Tooltip = undefined;
|
66
|
+
}
|
67
|
+
}, {
|
68
|
+
key: '_appendTooltipEl',
|
69
|
+
value: function _appendTooltipEl() {
|
70
|
+
var tooltipEl = document.createElement('div');
|
71
|
+
tooltipEl.classList.add('material-tooltip');
|
72
|
+
this.tooltipEl = tooltipEl;
|
73
|
+
|
74
|
+
var tooltipContentEl = document.createElement('div');
|
75
|
+
tooltipContentEl.classList.add('tooltip-content');
|
76
|
+
tooltipContentEl.innerHTML = this.options.html;
|
77
|
+
tooltipEl.appendChild(tooltipContentEl);
|
78
|
+
document.body.appendChild(tooltipEl);
|
79
|
+
}
|
80
|
+
}, {
|
81
|
+
key: '_updateTooltipContent',
|
82
|
+
value: function _updateTooltipContent() {
|
83
|
+
this.tooltipEl.querySelector('.tooltip-content').innerHTML = this.options.html;
|
84
|
+
}
|
85
|
+
}, {
|
86
|
+
key: '_setupEventHandlers',
|
87
|
+
value: function _setupEventHandlers() {
|
88
|
+
this._handleMouseEnterBound = this._handleMouseEnter.bind(this);
|
89
|
+
this._handleMouseLeaveBound = this._handleMouseLeave.bind(this);
|
90
|
+
this._handleFocusBound = this._handleFocus.bind(this);
|
91
|
+
this._handleBlurBound = this._handleBlur.bind(this);
|
92
|
+
this.el.addEventListener('mouseenter', this._handleMouseEnterBound);
|
93
|
+
this.el.addEventListener('mouseleave', this._handleMouseLeaveBound);
|
94
|
+
this.el.addEventListener('focus', this._handleFocusBound, true);
|
95
|
+
this.el.addEventListener('blur', this._handleBlurBound, true);
|
96
|
+
}
|
97
|
+
}, {
|
98
|
+
key: '_removeEventHandlers',
|
99
|
+
value: function _removeEventHandlers() {
|
100
|
+
this.el.removeEventListener('mouseenter', this._handleMouseEnterBound);
|
101
|
+
this.el.removeEventListener('mouseleave', this._handleMouseLeaveBound);
|
102
|
+
this.el.removeEventListener('focus', this._handleFocusBound, true);
|
103
|
+
this.el.removeEventListener('blur', this._handleBlurBound, true);
|
104
|
+
}
|
105
|
+
}, {
|
106
|
+
key: 'open',
|
107
|
+
value: function open(isManual) {
|
108
|
+
if (this.isOpen) {
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
isManual = isManual === undefined ? true : undefined; // Default value true
|
112
|
+
this.isOpen = true;
|
113
|
+
// Update tooltip content with HTML attribute options
|
114
|
+
this.options = $.extend({}, this.options, this._getAttributeOptions());
|
115
|
+
this._updateTooltipContent();
|
116
|
+
this._setEnterDelayTimeout(isManual);
|
117
|
+
}
|
118
|
+
}, {
|
119
|
+
key: 'close',
|
120
|
+
value: function close() {
|
121
|
+
if (!this.isOpen) {
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
|
125
|
+
this.isHovered = false;
|
126
|
+
this.isFocused = false;
|
127
|
+
this.isOpen = false;
|
128
|
+
this._setExitDelayTimeout();
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Create timeout which delays when the tooltip closes
|
133
|
+
*/
|
134
|
+
|
135
|
+
}, {
|
136
|
+
key: '_setExitDelayTimeout',
|
137
|
+
value: function _setExitDelayTimeout() {
|
138
|
+
var _this2 = this;
|
139
|
+
|
140
|
+
clearTimeout(this._exitDelayTimeout);
|
141
|
+
|
142
|
+
this._exitDelayTimeout = setTimeout(function () {
|
143
|
+
if (_this2.isHovered || _this2.isFocused) {
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
|
147
|
+
_this2._animateOut();
|
148
|
+
}, this.options.exitDelay);
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Create timeout which delays when the toast closes
|
153
|
+
*/
|
154
|
+
|
155
|
+
}, {
|
156
|
+
key: '_setEnterDelayTimeout',
|
157
|
+
value: function _setEnterDelayTimeout(isManual) {
|
158
|
+
var _this3 = this;
|
159
|
+
|
160
|
+
clearTimeout(this._enterDelayTimeout);
|
161
|
+
|
162
|
+
this._enterDelayTimeout = setTimeout(function () {
|
163
|
+
if (!_this3.isHovered && !_this3.isFocused && !isManual) {
|
164
|
+
return;
|
165
|
+
}
|
166
|
+
|
167
|
+
_this3._animateIn();
|
168
|
+
}, this.options.enterDelay);
|
169
|
+
}
|
170
|
+
}, {
|
171
|
+
key: '_positionTooltip',
|
172
|
+
value: function _positionTooltip() {
|
173
|
+
var origin = this.el,
|
174
|
+
tooltip = this.tooltipEl,
|
175
|
+
originHeight = origin.offsetHeight,
|
176
|
+
originWidth = origin.offsetWidth,
|
177
|
+
tooltipHeight = tooltip.offsetHeight,
|
178
|
+
tooltipWidth = tooltip.offsetWidth,
|
179
|
+
newCoordinates = void 0,
|
180
|
+
margin = this.options.margin,
|
181
|
+
targetTop = void 0,
|
182
|
+
targetLeft = void 0;
|
183
|
+
|
184
|
+
this.xMovement = 0, this.yMovement = 0;
|
185
|
+
|
186
|
+
targetTop = origin.getBoundingClientRect().top + M.getDocumentScrollTop();
|
187
|
+
targetLeft = origin.getBoundingClientRect().left + M.getDocumentScrollLeft();
|
188
|
+
|
189
|
+
if (this.options.position === 'top') {
|
190
|
+
targetTop += -tooltipHeight - margin;
|
191
|
+
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
192
|
+
this.yMovement = -this.options.transitionMovement;
|
193
|
+
} else if (this.options.position === 'right') {
|
194
|
+
targetTop += originHeight / 2 - tooltipHeight / 2;
|
195
|
+
targetLeft += originWidth + margin;
|
196
|
+
this.xMovement = this.options.transitionMovement;
|
197
|
+
} else if (this.options.position === 'left') {
|
198
|
+
targetTop += originHeight / 2 - tooltipHeight / 2;
|
199
|
+
targetLeft += -tooltipWidth - margin;
|
200
|
+
this.xMovement = -this.options.transitionMovement;
|
201
|
+
} else {
|
202
|
+
targetTop += originHeight + margin;
|
203
|
+
targetLeft += originWidth / 2 - tooltipWidth / 2;
|
204
|
+
this.yMovement = this.options.transitionMovement;
|
205
|
+
}
|
206
|
+
|
207
|
+
newCoordinates = this._repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight);
|
208
|
+
$(tooltip).css({
|
209
|
+
top: newCoordinates.y + 'px',
|
210
|
+
left: newCoordinates.x + 'px'
|
211
|
+
});
|
212
|
+
}
|
213
|
+
}, {
|
214
|
+
key: '_repositionWithinScreen',
|
215
|
+
value: function _repositionWithinScreen(x, y, width, height) {
|
216
|
+
var scrollLeft = M.getDocumentScrollLeft();
|
217
|
+
var scrollTop = M.getDocumentScrollTop();
|
218
|
+
var newX = x - scrollLeft;
|
219
|
+
var newY = y - scrollTop;
|
220
|
+
|
221
|
+
var bounding = {
|
222
|
+
left: newX,
|
223
|
+
top: newY,
|
224
|
+
width: width,
|
225
|
+
height: height
|
226
|
+
};
|
227
|
+
|
228
|
+
var offset = this.options.margin + this.options.transitionMovement;
|
229
|
+
var 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
|
+
key: '_animateIn',
|
250
|
+
value: function _animateIn() {
|
251
|
+
this._positionTooltip();
|
252
|
+
this.tooltipEl.style.visibility = 'visible';
|
253
|
+
anim.remove(this.tooltipEl);
|
254
|
+
anim({
|
255
|
+
targets: this.tooltipEl,
|
256
|
+
opacity: 1,
|
257
|
+
translateX: this.xMovement,
|
258
|
+
translateY: this.yMovement,
|
259
|
+
duration: this.options.inDuration,
|
260
|
+
easing: 'easeOutCubic'
|
261
|
+
});
|
262
|
+
}
|
263
|
+
}, {
|
264
|
+
key: '_animateOut',
|
265
|
+
value: function _animateOut() {
|
266
|
+
anim.remove(this.tooltipEl);
|
267
|
+
anim({
|
268
|
+
targets: this.tooltipEl,
|
269
|
+
opacity: 0,
|
270
|
+
translateX: 0,
|
271
|
+
translateY: 0,
|
272
|
+
duration: this.options.outDuration,
|
273
|
+
easing: 'easeOutCubic'
|
274
|
+
});
|
275
|
+
}
|
276
|
+
}, {
|
277
|
+
key: '_handleMouseEnter',
|
278
|
+
value: function _handleMouseEnter() {
|
279
|
+
this.isHovered = true;
|
280
|
+
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
281
|
+
this.open(false);
|
282
|
+
}
|
283
|
+
}, {
|
284
|
+
key: '_handleMouseLeave',
|
285
|
+
value: function _handleMouseLeave() {
|
286
|
+
this.isHovered = false;
|
287
|
+
this.isFocused = false; // Allows close of tooltip when opened by focus.
|
288
|
+
this.close();
|
289
|
+
}
|
290
|
+
}, {
|
291
|
+
key: '_handleFocus',
|
292
|
+
value: function _handleFocus() {
|
293
|
+
if (M.tabPressed) {
|
294
|
+
this.isFocused = true;
|
295
|
+
this.open(false);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
}, {
|
299
|
+
key: '_handleBlur',
|
300
|
+
value: function _handleBlur() {
|
301
|
+
this.isFocused = false;
|
302
|
+
this.close();
|
303
|
+
}
|
304
|
+
}, {
|
305
|
+
key: '_getAttributeOptions',
|
306
|
+
value: function _getAttributeOptions() {
|
307
|
+
var attributeOptions = {};
|
308
|
+
var tooltipTextOption = this.el.getAttribute('data-tooltip');
|
309
|
+
var positionOption = this.el.getAttribute('data-position');
|
310
|
+
|
311
|
+
if (tooltipTextOption) {
|
312
|
+
attributeOptions.html = tooltipTextOption;
|
313
|
+
}
|
314
|
+
|
315
|
+
if (positionOption) {
|
316
|
+
attributeOptions.position = positionOption;
|
317
|
+
}
|
318
|
+
return attributeOptions;
|
319
|
+
}
|
320
|
+
}], [{
|
321
|
+
key: 'init',
|
322
|
+
value: function init(els, options) {
|
323
|
+
return _get(Tooltip.__proto__ || Object.getPrototypeOf(Tooltip), 'init', this).call(this, this, els, options);
|
324
|
+
}
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Get Instance
|
328
|
+
*/
|
329
|
+
|
330
|
+
}, {
|
331
|
+
key: 'getInstance',
|
332
|
+
value: function getInstance(el) {
|
333
|
+
var domElem = !!el.jquery ? el[0] : el;
|
334
|
+
return domElem.M_Tooltip;
|
335
|
+
}
|
336
|
+
}, {
|
337
|
+
key: 'defaults',
|
338
|
+
get: function () {
|
339
|
+
return _defaults;
|
340
|
+
}
|
341
|
+
}]);
|
342
|
+
|
343
|
+
return Tooltip;
|
344
|
+
}(Component);
|
345
|
+
|
346
|
+
M.Tooltip = Tooltip;
|
347
|
+
|
348
|
+
if (M.jQueryLoaded) {
|
349
|
+
M.initializeJqueryWrapper(Tooltip, 'tooltip', 'M_Tooltip');
|
350
|
+
}
|
351
|
+
})(cash, M.anime);
|