@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/forms.js
CHANGED
|
@@ -1,285 +1,285 @@
|
|
|
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);
|
|
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);
|