@materializecss/materialize 1.2.2 → 2.0.1-alpha
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 +68 -313
- package/README.md +26 -14
- package/dist/css/materialize.css +1009 -1822
- package/dist/css/materialize.min.css +2 -8
- package/dist/js/materialize.js +8414 -12299
- package/dist/js/materialize.min.js +8968 -2
- package/dist/js/materialize.min.js.map +1 -0
- package/package.json +13 -9
- package/sass/components/_badges.scss +12 -2
- package/sass/components/_buttons.scss +16 -11
- package/sass/components/_cards.scss +14 -9
- package/sass/components/_carousel.scss +5 -2
- package/sass/components/_chips.scss +3 -3
- package/sass/components/_collapsible.scss +22 -8
- package/sass/components/_collection.scss +14 -6
- package/sass/components/_datepicker.scss +30 -11
- package/sass/components/_dropdown.scss +6 -4
- package/sass/components/_global.scss +132 -111
- package/sass/components/_grid.scss +119 -98
- package/sass/components/_modal.scss +3 -3
- package/sass/components/_navbar.scss +31 -17
- package/sass/components/_normalize.scss +26 -124
- package/sass/components/_sidenav.scss +21 -20
- package/sass/components/_slider.scss +27 -7
- package/sass/components/_table_of_contents.scss +12 -12
- package/sass/components/_tabs.scss +47 -16
- package/sass/components/_tapTarget.scss +6 -6
- package/sass/components/_theme_variables.scss +98 -0
- package/sass/components/_timepicker.scss +54 -46
- package/sass/components/_toast.scss +3 -3
- package/sass/components/_tooltip.scss +4 -5
- package/sass/components/_typography.scss +1 -1
- package/sass/components/_variables.scss +185 -120
- package/sass/components/forms/_checkboxes.scss +9 -9
- package/sass/components/forms/_file-input.scss +9 -7
- package/sass/components/forms/_input-fields.scss +173 -234
- package/sass/components/forms/_radio-buttons.scss +1 -1
- package/sass/components/forms/_range.scss +11 -11
- package/sass/components/forms/_select.scss +29 -19
- package/sass/components/forms/_switches.scss +22 -18
- package/sass/materialize.scss +1 -1
- package/src/autocomplete.ts +459 -0
- package/src/bounding.ts +6 -0
- package/{js/buttons.js → src/buttons.ts} +103 -162
- package/src/cards.ts +54 -0
- package/{js/carousel.js → src/carousel.ts} +137 -262
- package/src/characterCounter.ts +88 -0
- package/src/chips.ts +350 -0
- package/src/collapsible.ts +184 -0
- package/{js/component.js → src/component.ts} +6 -19
- package/{js/datepicker.js → src/datepicker.ts} +213 -299
- package/{js/dropdown.js → src/dropdown.ts} +140 -254
- package/src/edges.ts +6 -0
- package/src/forms.ts +120 -0
- package/src/global.ts +385 -0
- package/src/materialbox.ts +348 -0
- package/src/modal.ts +256 -0
- package/{js/parallax.js → src/parallax.ts} +47 -60
- package/{js/pushpin.js → src/pushpin.ts} +19 -47
- package/{js/range.js → src/range.ts} +58 -139
- package/{js/scrollspy.js → src/scrollspy.ts} +81 -153
- package/src/select.ts +448 -0
- package/{js/sidenav.js → src/sidenav.ts} +96 -202
- package/src/slider.ts +415 -0
- package/src/tabs.ts +293 -0
- package/src/tapTarget.ts +240 -0
- package/{js/timepicker.js → src/timepicker.ts} +268 -272
- package/{js/toasts.js → src/toasts.ts} +75 -134
- package/{js/tooltip.js → src/tooltip.ts} +59 -96
- package/src/waves.ts +70 -0
- package/extras/noUiSlider/nouislider.css +0 -404
- package/extras/noUiSlider/nouislider.js +0 -2147
- package/extras/noUiSlider/nouislider.min.js +0 -1
- package/js/anime.min.js +0 -34
- package/js/autocomplete.js +0 -479
- package/js/cards.js +0 -40
- package/js/cash.js +0 -960
- package/js/characterCounter.js +0 -136
- package/js/chips.js +0 -486
- package/js/collapsible.js +0 -275
- package/js/forms.js +0 -285
- package/js/global.js +0 -428
- package/js/materialbox.js +0 -453
- package/js/modal.js +0 -382
- package/js/select.js +0 -391
- package/js/slider.js +0 -497
- package/js/tabs.js +0 -402
- package/js/tapTarget.js +0 -315
- package/js/waves.js +0 -615
- package/sass/components/_waves.scss +0 -187
package/js/collapsible.js
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
(function($, anim) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
let _defaults = {
|
|
5
|
-
accordion: true,
|
|
6
|
-
onOpenStart: undefined,
|
|
7
|
-
onOpenEnd: undefined,
|
|
8
|
-
onCloseStart: undefined,
|
|
9
|
-
onCloseEnd: undefined,
|
|
10
|
-
inDuration: 300,
|
|
11
|
-
outDuration: 300
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @class
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
class Collapsible extends Component {
|
|
19
|
-
/**
|
|
20
|
-
* Construct Collapsible instance
|
|
21
|
-
* @constructor
|
|
22
|
-
* @param {Element} el
|
|
23
|
-
* @param {Object} options
|
|
24
|
-
*/
|
|
25
|
-
constructor(el, options) {
|
|
26
|
-
super(Collapsible, el, options);
|
|
27
|
-
|
|
28
|
-
this.el.M_Collapsible = this;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Options for the collapsible
|
|
32
|
-
* @member Collapsible#options
|
|
33
|
-
* @prop {Boolean} [accordion=false] - Type of the collapsible
|
|
34
|
-
* @prop {Function} onOpenStart - Callback function called before collapsible is opened
|
|
35
|
-
* @prop {Function} onOpenEnd - Callback function called after collapsible is opened
|
|
36
|
-
* @prop {Function} onCloseStart - Callback function called before collapsible is closed
|
|
37
|
-
* @prop {Function} onCloseEnd - Callback function called after collapsible is closed
|
|
38
|
-
* @prop {Number} inDuration - Transition in duration in milliseconds.
|
|
39
|
-
* @prop {Number} outDuration - Transition duration in milliseconds.
|
|
40
|
-
*/
|
|
41
|
-
this.options = $.extend({}, Collapsible.defaults, options);
|
|
42
|
-
|
|
43
|
-
// Setup tab indices
|
|
44
|
-
this.$headers = this.$el.children('li').children('.collapsible-header');
|
|
45
|
-
this.$headers.attr('tabindex', 0);
|
|
46
|
-
|
|
47
|
-
this._setupEventHandlers();
|
|
48
|
-
|
|
49
|
-
// Open first active
|
|
50
|
-
let $activeBodies = this.$el.children('li.active').children('.collapsible-body');
|
|
51
|
-
if (this.options.accordion) {
|
|
52
|
-
// Handle Accordion
|
|
53
|
-
$activeBodies.first().css('display', 'block');
|
|
54
|
-
} else {
|
|
55
|
-
// Handle Expandables
|
|
56
|
-
$activeBodies.css('display', 'block');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static get defaults() {
|
|
61
|
-
return _defaults;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static init(els, options) {
|
|
65
|
-
return super.init(this, els, options);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Get Instance
|
|
70
|
-
*/
|
|
71
|
-
static getInstance(el) {
|
|
72
|
-
let domElem = !!el.jquery ? el[0] : el;
|
|
73
|
-
return domElem.M_Collapsible;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Teardown component
|
|
78
|
-
*/
|
|
79
|
-
destroy() {
|
|
80
|
-
this._removeEventHandlers();
|
|
81
|
-
this.el.M_Collapsible = undefined;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Setup Event Handlers
|
|
86
|
-
*/
|
|
87
|
-
_setupEventHandlers() {
|
|
88
|
-
this._handleCollapsibleClickBound = this._handleCollapsibleClick.bind(this);
|
|
89
|
-
this._handleCollapsibleKeydownBound = this._handleCollapsibleKeydown.bind(this);
|
|
90
|
-
this.el.addEventListener('click', this._handleCollapsibleClickBound);
|
|
91
|
-
this.$headers.each((header) => {
|
|
92
|
-
header.addEventListener('keydown', this._handleCollapsibleKeydownBound);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Remove Event Handlers
|
|
98
|
-
*/
|
|
99
|
-
_removeEventHandlers() {
|
|
100
|
-
this.el.removeEventListener('click', this._handleCollapsibleClickBound);
|
|
101
|
-
this.$headers.each((header) => {
|
|
102
|
-
header.removeEventListener('keydown', this._handleCollapsibleKeydownBound);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Handle Collapsible Click
|
|
108
|
-
* @param {Event} e
|
|
109
|
-
*/
|
|
110
|
-
_handleCollapsibleClick(e) {
|
|
111
|
-
let $header = $(e.target).closest('.collapsible-header');
|
|
112
|
-
if (e.target && $header.length) {
|
|
113
|
-
let $collapsible = $header.closest('.collapsible');
|
|
114
|
-
if ($collapsible[0] === this.el) {
|
|
115
|
-
let $collapsibleLi = $header.closest('li');
|
|
116
|
-
let $collapsibleLis = $collapsible.children('li');
|
|
117
|
-
let isActive = $collapsibleLi[0].classList.contains('active');
|
|
118
|
-
let index = $collapsibleLis.index($collapsibleLi);
|
|
119
|
-
|
|
120
|
-
if (isActive) {
|
|
121
|
-
this.close(index);
|
|
122
|
-
} else {
|
|
123
|
-
this.open(index);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Handle Collapsible Keydown
|
|
131
|
-
* @param {Event} e
|
|
132
|
-
*/
|
|
133
|
-
_handleCollapsibleKeydown(e) {
|
|
134
|
-
if (e.keyCode === 13) {
|
|
135
|
-
this._handleCollapsibleClickBound(e);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Animate in collapsible slide
|
|
141
|
-
* @param {Number} index - 0th index of slide
|
|
142
|
-
*/
|
|
143
|
-
_animateIn(index) {
|
|
144
|
-
let $collapsibleLi = this.$el.children('li').eq(index);
|
|
145
|
-
if ($collapsibleLi.length) {
|
|
146
|
-
let $body = $collapsibleLi.children('.collapsible-body');
|
|
147
|
-
|
|
148
|
-
anim.remove($body[0]);
|
|
149
|
-
$body.css({
|
|
150
|
-
display: 'block',
|
|
151
|
-
overflow: 'hidden',
|
|
152
|
-
height: 0,
|
|
153
|
-
paddingTop: '',
|
|
154
|
-
paddingBottom: ''
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
let pTop = $body.css('padding-top');
|
|
158
|
-
let pBottom = $body.css('padding-bottom');
|
|
159
|
-
let finalHeight = $body[0].scrollHeight;
|
|
160
|
-
$body.css({
|
|
161
|
-
paddingTop: 0,
|
|
162
|
-
paddingBottom: 0
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
anim({
|
|
166
|
-
targets: $body[0],
|
|
167
|
-
height: finalHeight,
|
|
168
|
-
paddingTop: pTop,
|
|
169
|
-
paddingBottom: pBottom,
|
|
170
|
-
duration: this.options.inDuration,
|
|
171
|
-
easing: 'easeInOutCubic',
|
|
172
|
-
complete: (anim) => {
|
|
173
|
-
$body.css({
|
|
174
|
-
overflow: '',
|
|
175
|
-
paddingTop: '',
|
|
176
|
-
paddingBottom: '',
|
|
177
|
-
height: ''
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
// onOpenEnd callback
|
|
181
|
-
if (typeof this.options.onOpenEnd === 'function') {
|
|
182
|
-
this.options.onOpenEnd.call(this, $collapsibleLi[0]);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Animate out collapsible slide
|
|
191
|
-
* @param {Number} index - 0th index of slide to open
|
|
192
|
-
*/
|
|
193
|
-
_animateOut(index) {
|
|
194
|
-
let $collapsibleLi = this.$el.children('li').eq(index);
|
|
195
|
-
if ($collapsibleLi.length) {
|
|
196
|
-
let $body = $collapsibleLi.children('.collapsible-body');
|
|
197
|
-
anim.remove($body[0]);
|
|
198
|
-
$body.css('overflow', 'hidden');
|
|
199
|
-
anim({
|
|
200
|
-
targets: $body[0],
|
|
201
|
-
height: 0,
|
|
202
|
-
paddingTop: 0,
|
|
203
|
-
paddingBottom: 0,
|
|
204
|
-
duration: this.options.outDuration,
|
|
205
|
-
easing: 'easeInOutCubic',
|
|
206
|
-
complete: () => {
|
|
207
|
-
$body.css({
|
|
208
|
-
height: '',
|
|
209
|
-
overflow: '',
|
|
210
|
-
padding: '',
|
|
211
|
-
display: ''
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// onCloseEnd callback
|
|
215
|
-
if (typeof this.options.onCloseEnd === 'function') {
|
|
216
|
-
this.options.onCloseEnd.call(this, $collapsibleLi[0]);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Open Collapsible
|
|
225
|
-
* @param {Number} index - 0th index of slide
|
|
226
|
-
*/
|
|
227
|
-
open(index) {
|
|
228
|
-
let $collapsibleLi = this.$el.children('li').eq(index);
|
|
229
|
-
if ($collapsibleLi.length && !$collapsibleLi[0].classList.contains('active')) {
|
|
230
|
-
// onOpenStart callback
|
|
231
|
-
if (typeof this.options.onOpenStart === 'function') {
|
|
232
|
-
this.options.onOpenStart.call(this, $collapsibleLi[0]);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Handle accordion behavior
|
|
236
|
-
if (this.options.accordion) {
|
|
237
|
-
let $collapsibleLis = this.$el.children('li');
|
|
238
|
-
let $activeLis = this.$el.children('li.active');
|
|
239
|
-
$activeLis.each((el) => {
|
|
240
|
-
let index = $collapsibleLis.index($(el));
|
|
241
|
-
this.close(index);
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Animate in
|
|
246
|
-
$collapsibleLi[0].classList.add('active');
|
|
247
|
-
this._animateIn(index);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Close Collapsible
|
|
253
|
-
* @param {Number} index - 0th index of slide
|
|
254
|
-
*/
|
|
255
|
-
close(index) {
|
|
256
|
-
let $collapsibleLi = this.$el.children('li').eq(index);
|
|
257
|
-
if ($collapsibleLi.length && $collapsibleLi[0].classList.contains('active')) {
|
|
258
|
-
// onCloseStart callback
|
|
259
|
-
if (typeof this.options.onCloseStart === 'function') {
|
|
260
|
-
this.options.onCloseStart.call(this, $collapsibleLi[0]);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Animate out
|
|
264
|
-
$collapsibleLi[0].classList.remove('active');
|
|
265
|
-
this._animateOut(index);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
M.Collapsible = Collapsible;
|
|
271
|
-
|
|
272
|
-
if (M.jQueryLoaded) {
|
|
273
|
-
M.initializeJqueryWrapper(Collapsible, 'collapsible', 'M_Collapsible');
|
|
274
|
-
}
|
|
275
|
-
})(cash, M.anime);
|
package/js/forms.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
(function($) {
|
|
2
|
-
const TEXT_BASED_INPUT_SELECTOR = [
|
|
3
|
-
'input:not([type])',
|
|
4
|
-
'input[type=text]',
|
|
5
|
-
'input[type=password]',
|
|
6
|
-
'input[type=email]',
|
|
7
|
-
'input[type=url]',
|
|
8
|
-
'input[type=tel]',
|
|
9
|
-
'input[type=number]',
|
|
10
|
-
'input[type=search]',
|
|
11
|
-
'input[type=date]',
|
|
12
|
-
'input[type=time]',
|
|
13
|
-
'input[type=month]',
|
|
14
|
-
'input[type=datetime-local]',
|
|
15
|
-
'textarea'
|
|
16
|
-
].join(',');
|
|
17
|
-
|
|
18
|
-
// Function to update labels of text fields
|
|
19
|
-
M.updateTextFields = function() {
|
|
20
|
-
$(TEXT_BASED_INPUT_SELECTOR).each(function(element, index) {
|
|
21
|
-
let $this = $(this);
|
|
22
|
-
if (
|
|
23
|
-
element.value.length > 0 ||
|
|
24
|
-
$(element).is(':focus') ||
|
|
25
|
-
element.autofocus ||
|
|
26
|
-
$this.attr('placeholder') !== null
|
|
27
|
-
) {
|
|
28
|
-
$this.siblings('label').addClass('active');
|
|
29
|
-
} else if (element.validity) {
|
|
30
|
-
$this.siblings('label').toggleClass('active', element.validity.badInput === true);
|
|
31
|
-
} else {
|
|
32
|
-
$this.siblings('label').removeClass('active');
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
M.validate_field = function(object) {
|
|
38
|
-
let hasLength = object.attr('data-length') !== null;
|
|
39
|
-
let lenAttr = parseInt(object.attr('data-length'));
|
|
40
|
-
let len = object[0].value.length;
|
|
41
|
-
|
|
42
|
-
if (len === 0 && object[0].validity.badInput === false && !object.is(':required')) {
|
|
43
|
-
if (object.hasClass('validate')) {
|
|
44
|
-
object.removeClass('valid');
|
|
45
|
-
object.removeClass('invalid');
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
if (object.hasClass('validate')) {
|
|
49
|
-
// Check for character counter attributes
|
|
50
|
-
if (
|
|
51
|
-
(object.is(':valid') && hasLength && len <= lenAttr) ||
|
|
52
|
-
(object.is(':valid') && !hasLength)
|
|
53
|
-
) {
|
|
54
|
-
object.removeClass('invalid');
|
|
55
|
-
object.addClass('valid');
|
|
56
|
-
} else {
|
|
57
|
-
object.removeClass('valid');
|
|
58
|
-
object.addClass('invalid');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
M.textareaAutoResize = function($textarea) {
|
|
65
|
-
// Wrap if native element
|
|
66
|
-
if ($textarea instanceof Element) {
|
|
67
|
-
$textarea = $($textarea);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!$textarea.length) {
|
|
71
|
-
console.error('No textarea element found');
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Textarea Auto Resize
|
|
76
|
-
let hiddenDiv = $('.hiddendiv').first();
|
|
77
|
-
if (!hiddenDiv.length) {
|
|
78
|
-
hiddenDiv = $('<div class="hiddendiv common"></div>');
|
|
79
|
-
$('body').append(hiddenDiv);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Set font properties of hiddenDiv
|
|
83
|
-
let fontFamily = $textarea.css('font-family');
|
|
84
|
-
let fontSize = $textarea.css('font-size');
|
|
85
|
-
let lineHeight = $textarea.css('line-height');
|
|
86
|
-
|
|
87
|
-
// Firefox can't handle padding shorthand.
|
|
88
|
-
let paddingTop = $textarea.css('padding-top');
|
|
89
|
-
let paddingRight = $textarea.css('padding-right');
|
|
90
|
-
let paddingBottom = $textarea.css('padding-bottom');
|
|
91
|
-
let paddingLeft = $textarea.css('padding-left');
|
|
92
|
-
|
|
93
|
-
if (fontSize) {
|
|
94
|
-
hiddenDiv.css('font-size', fontSize);
|
|
95
|
-
}
|
|
96
|
-
if (fontFamily) {
|
|
97
|
-
hiddenDiv.css('font-family', fontFamily);
|
|
98
|
-
}
|
|
99
|
-
if (lineHeight) {
|
|
100
|
-
hiddenDiv.css('line-height', lineHeight);
|
|
101
|
-
}
|
|
102
|
-
if (paddingTop) {
|
|
103
|
-
hiddenDiv.css('padding-top', paddingTop);
|
|
104
|
-
}
|
|
105
|
-
if (paddingRight) {
|
|
106
|
-
hiddenDiv.css('padding-right', paddingRight);
|
|
107
|
-
}
|
|
108
|
-
if (paddingBottom) {
|
|
109
|
-
hiddenDiv.css('padding-bottom', paddingBottom);
|
|
110
|
-
}
|
|
111
|
-
if (paddingLeft) {
|
|
112
|
-
hiddenDiv.css('padding-left', paddingLeft);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Set original-height, if none
|
|
116
|
-
if (!$textarea.data('original-height')) {
|
|
117
|
-
$textarea.data('original-height', $textarea.height());
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if ($textarea.attr('wrap') === 'off') {
|
|
121
|
-
hiddenDiv.css('overflow-wrap', 'normal').css('white-space', 'pre');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
hiddenDiv.text($textarea[0].value + '\n');
|
|
125
|
-
let content = hiddenDiv.html().replace(/\n/g, '<br>');
|
|
126
|
-
hiddenDiv.html(content);
|
|
127
|
-
|
|
128
|
-
// When textarea is hidden, width goes crazy.
|
|
129
|
-
// Approximate with half of window size
|
|
130
|
-
|
|
131
|
-
if ($textarea[0].offsetWidth > 0 && $textarea[0].offsetHeight > 0) {
|
|
132
|
-
hiddenDiv.css('width', $textarea.width() + 'px');
|
|
133
|
-
} else {
|
|
134
|
-
hiddenDiv.css('width', window.innerWidth / 2 + 'px');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Resize if the new height is greater than the
|
|
139
|
-
* original height of the textarea
|
|
140
|
-
*/
|
|
141
|
-
if ($textarea.data('original-height') <= hiddenDiv.innerHeight()) {
|
|
142
|
-
$textarea.css('height', hiddenDiv.innerHeight() + 'px');
|
|
143
|
-
} else if ($textarea[0].value.length < $textarea.data('previous-length')) {
|
|
144
|
-
/**
|
|
145
|
-
* In case the new height is less than original height, it
|
|
146
|
-
* means the textarea has less text than before
|
|
147
|
-
* So we set the height to the original one
|
|
148
|
-
*/
|
|
149
|
-
$textarea.css('height', $textarea.data('original-height') + 'px');
|
|
150
|
-
}
|
|
151
|
-
$textarea.data('previous-length', $textarea[0].value.length);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
$(document).ready(function() {
|
|
155
|
-
// Add active if form auto complete
|
|
156
|
-
$(document).on('change', TEXT_BASED_INPUT_SELECTOR, function() {
|
|
157
|
-
if (this.value.length !== 0 || $(this).attr('placeholder') !== null) {
|
|
158
|
-
$(this)
|
|
159
|
-
.siblings('label')
|
|
160
|
-
.addClass('active');
|
|
161
|
-
}
|
|
162
|
-
M.validate_field($(this));
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// Add active if input element has been pre-populated on document ready
|
|
166
|
-
$(document).ready(function() {
|
|
167
|
-
M.updateTextFields();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// HTML DOM FORM RESET handling
|
|
171
|
-
$(document).on('reset', function(e) {
|
|
172
|
-
let formReset = $(e.target);
|
|
173
|
-
if (formReset.is('form')) {
|
|
174
|
-
formReset
|
|
175
|
-
.find(TEXT_BASED_INPUT_SELECTOR)
|
|
176
|
-
.removeClass('valid')
|
|
177
|
-
.removeClass('invalid');
|
|
178
|
-
formReset.find(TEXT_BASED_INPUT_SELECTOR).each(function(e) {
|
|
179
|
-
if (this.value.length) {
|
|
180
|
-
$(this)
|
|
181
|
-
.siblings('label')
|
|
182
|
-
.removeClass('active');
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Reset select (after native reset)
|
|
187
|
-
setTimeout(function() {
|
|
188
|
-
formReset.find('select').each(function() {
|
|
189
|
-
// check if initialized
|
|
190
|
-
if (this.M_FormSelect) {
|
|
191
|
-
$(this).trigger('change');
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}, 0);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Add active when element has focus
|
|
200
|
-
* @param {Event} e
|
|
201
|
-
*/
|
|
202
|
-
document.addEventListener(
|
|
203
|
-
'focus',
|
|
204
|
-
function(e) {
|
|
205
|
-
if ($(e.target).is(TEXT_BASED_INPUT_SELECTOR)) {
|
|
206
|
-
$(e.target)
|
|
207
|
-
.siblings('label, .prefix')
|
|
208
|
-
.addClass('active');
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
true
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Remove active when element is blurred
|
|
216
|
-
* @param {Event} e
|
|
217
|
-
*/
|
|
218
|
-
document.addEventListener(
|
|
219
|
-
'blur',
|
|
220
|
-
function(e) {
|
|
221
|
-
let $inputElement = $(e.target);
|
|
222
|
-
if ($inputElement.is(TEXT_BASED_INPUT_SELECTOR)) {
|
|
223
|
-
let selector = '.prefix';
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
$inputElement[0].value.length === 0 &&
|
|
227
|
-
$inputElement[0].validity.badInput !== true &&
|
|
228
|
-
$inputElement.attr('placeholder') === null
|
|
229
|
-
) {
|
|
230
|
-
selector += ', label';
|
|
231
|
-
}
|
|
232
|
-
$inputElement.siblings(selector).removeClass('active');
|
|
233
|
-
M.validate_field($inputElement);
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
true
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
// Radio and Checkbox focus class
|
|
240
|
-
let radio_checkbox = 'input[type=radio], input[type=checkbox]';
|
|
241
|
-
$(document).on('keyup', radio_checkbox, function(e) {
|
|
242
|
-
// TAB, check if tabbing to radio or checkbox.
|
|
243
|
-
if (e.which === M.keys.TAB) {
|
|
244
|
-
$(this).addClass('tabbed');
|
|
245
|
-
let $this = $(this);
|
|
246
|
-
$this.one('blur', function(e) {
|
|
247
|
-
$(this).removeClass('tabbed');
|
|
248
|
-
});
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
let text_area_selector = '.materialize-textarea';
|
|
254
|
-
$(text_area_selector).each(function() {
|
|
255
|
-
let $textarea = $(this);
|
|
256
|
-
/**
|
|
257
|
-
* Resize textarea on document load after storing
|
|
258
|
-
* the original height and the original length
|
|
259
|
-
*/
|
|
260
|
-
$textarea.data('original-height', $textarea.height());
|
|
261
|
-
$textarea.data('previous-length', this.value.length);
|
|
262
|
-
M.textareaAutoResize($textarea);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
$(document).on('keyup', text_area_selector, function() {
|
|
266
|
-
M.textareaAutoResize($(this));
|
|
267
|
-
});
|
|
268
|
-
$(document).on('keydown', text_area_selector, function() {
|
|
269
|
-
M.textareaAutoResize($(this));
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
// File Input Path
|
|
273
|
-
$(document).on('change', '.file-field input[type="file"]', function() {
|
|
274
|
-
let file_field = $(this).closest('.file-field');
|
|
275
|
-
let path_input = file_field.find('input.file-path');
|
|
276
|
-
let files = $(this)[0].files;
|
|
277
|
-
let file_names = [];
|
|
278
|
-
for (let i = 0; i < files.length; i++) {
|
|
279
|
-
file_names.push(files[i].name);
|
|
280
|
-
}
|
|
281
|
-
path_input[0].value = file_names.join(', ');
|
|
282
|
-
path_input.trigger('change');
|
|
283
|
-
});
|
|
284
|
-
}); // End of $(document).ready
|
|
285
|
-
})(cash);
|