materialize-sass 0.100.2.1 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +18 -42
  3. data/Rakefile +17 -17
  4. data/{app/assets → assets}/javascripts/materialize-sprockets.js +8 -12
  5. data/assets/javascripts/materialize.js +11877 -0
  6. data/assets/javascripts/materialize/autocomplete.js +420 -0
  7. data/assets/javascripts/materialize/buttons.js +388 -0
  8. data/assets/javascripts/materialize/cards.js +28 -0
  9. data/assets/javascripts/materialize/carousel.js +791 -0
  10. data/assets/javascripts/materialize/cash.js +992 -0
  11. data/assets/javascripts/materialize/characterCounter.js +180 -0
  12. data/assets/javascripts/materialize/chips.js +555 -0
  13. data/assets/javascripts/materialize/collapsible.js +275 -0
  14. data/assets/javascripts/materialize/datepicker.js +898 -0
  15. data/assets/javascripts/materialize/dropdown.js +530 -0
  16. data/{app/assets → assets}/javascripts/materialize/extras/nouislider.js +1 -1
  17. data/{app/assets → assets}/javascripts/materialize/extras/nouislider.min.js +1 -1
  18. data/assets/javascripts/materialize/forms.js +223 -0
  19. data/assets/javascripts/materialize/global.js +353 -0
  20. data/assets/javascripts/materialize/materialbox.js +432 -0
  21. data/{app/assets → assets}/javascripts/materialize/modal.js +82 -113
  22. data/assets/javascripts/materialize/parallax.js +135 -0
  23. data/assets/javascripts/materialize/pushpin.js +158 -0
  24. data/assets/javascripts/materialize/range.js +305 -0
  25. data/assets/javascripts/materialize/scrollspy.js +322 -0
  26. data/assets/javascripts/materialize/select.js +426 -0
  27. data/assets/javascripts/materialize/sidenav.js +584 -0
  28. data/assets/javascripts/materialize/slider.js +383 -0
  29. data/assets/javascripts/materialize/tabs.js +460 -0
  30. data/assets/javascripts/materialize/tapTarget.js +347 -0
  31. data/assets/javascripts/materialize/timepicker.js +616 -0
  32. data/{app/assets → assets}/javascripts/materialize/toasts.js +42 -46
  33. data/assets/javascripts/materialize/tooltip.js +325 -0
  34. data/assets/javascripts/materialize/velocity.min.js +782 -0
  35. data/{app/assets → assets}/javascripts/materialize/waves.js +0 -0
  36. data/{app/assets → assets}/stylesheets/materialize.scss +5 -6
  37. data/{app/assets → assets}/stylesheets/materialize/components/_badges.scss +1 -1
  38. data/{app/assets → assets}/stylesheets/materialize/components/_buttons.scss +34 -2
  39. data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +0 -0
  40. data/{app/assets → assets}/stylesheets/materialize/components/_carousel.scss +1 -1
  41. data/{app/assets → assets}/stylesheets/materialize/components/_chips.scss +6 -5
  42. data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +3 -3
  43. data/{app/assets → assets}/stylesheets/materialize/components/_color.scss +0 -0
  44. data/assets/stylesheets/materialize/components/_datepicker.scss +180 -0
  45. data/{app/assets → assets}/stylesheets/materialize/components/_dropdown.scss +16 -15
  46. data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +49 -14
  47. data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +1 -1
  48. data/{app/assets → assets}/stylesheets/materialize/components/_icons-material-design.scss +0 -0
  49. data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +0 -0
  50. data/assets/stylesheets/materialize/components/_mixins.scss +5 -0
  51. data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +1 -1
  52. data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +0 -0
  53. data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
  54. data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +0 -0
  55. data/{app/assets → assets}/stylesheets/materialize/components/_pulse.scss +0 -0
  56. data/{app/assets/stylesheets/materialize/components/_sideNav.scss → assets/stylesheets/materialize/components/_sidenav.scss} +23 -21
  57. data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +0 -0
  58. data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +3 -3
  59. data/{app/assets → assets}/stylesheets/materialize/components/_tabs.scss +2 -2
  60. data/{app/assets → assets}/stylesheets/materialize/components/_tapTarget.scss +0 -0
  61. data/assets/stylesheets/materialize/components/_timepicker.scss +182 -0
  62. data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +0 -0
  63. data/{app/assets → assets}/stylesheets/materialize/components/_tooltip.scss +1 -0
  64. data/{app/assets → assets}/stylesheets/materialize/components/_transitions.scss +0 -0
  65. data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +8 -8
  66. data/{app/assets → assets}/stylesheets/materialize/components/_variables.scss +42 -44
  67. data/{app/assets → assets}/stylesheets/materialize/components/_waves.scss +0 -0
  68. data/{app/assets → assets}/stylesheets/materialize/components/forms/_checkboxes.scss +24 -24
  69. data/{app/assets → assets}/stylesheets/materialize/components/forms/_file-input.scss +0 -0
  70. data/{app/assets → assets}/stylesheets/materialize/components/forms/_forms.scss +0 -0
  71. data/{app/assets → assets}/stylesheets/materialize/components/forms/_input-fields.scss +49 -35
  72. data/{app/assets → assets}/stylesheets/materialize/components/forms/_radio-buttons.scss +29 -29
  73. data/{app/assets → assets}/stylesheets/materialize/components/forms/_range.scss +32 -31
  74. data/{app/assets → assets}/stylesheets/materialize/components/forms/_select.scss +20 -11
  75. data/{app/assets → assets}/stylesheets/materialize/components/forms/_switches.scss +0 -0
  76. data/{app/assets → assets}/stylesheets/materialize/extras/nouislider.css +1 -1
  77. data/lib/materialize-sass.rb +13 -23
  78. data/lib/materialize-sass/engine.rb +6 -9
  79. data/lib/materialize-sass/version.rb +1 -1
  80. data/materialize-sass.gemspec +2 -1
  81. metadata +97 -97
  82. data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
  83. data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
  84. data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
  85. data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
  86. data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
  87. data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
  88. data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
  89. data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
  90. data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
  91. data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
  92. data/app/assets/javascripts/materialize.js +0 -10021
  93. data/app/assets/javascripts/materialize/animation.js +0 -7
  94. data/app/assets/javascripts/materialize/buttons.js +0 -253
  95. data/app/assets/javascripts/materialize/cards.js +0 -28
  96. data/app/assets/javascripts/materialize/carousel.js +0 -543
  97. data/app/assets/javascripts/materialize/character_counter.js +0 -64
  98. data/app/assets/javascripts/materialize/chips.js +0 -315
  99. data/app/assets/javascripts/materialize/collapsible.js +0 -178
  100. data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1399
  101. data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1196
  102. data/app/assets/javascripts/materialize/date_picker/picker.time.js +0 -646
  103. data/app/assets/javascripts/materialize/dropdown.js +0 -257
  104. data/app/assets/javascripts/materialize/forms.js +0 -806
  105. data/app/assets/javascripts/materialize/global.js +0 -170
  106. data/app/assets/javascripts/materialize/hammer.min.js +0 -424
  107. data/app/assets/javascripts/materialize/initial.js +0 -10
  108. data/app/assets/javascripts/materialize/jquery.easing.1.4.js +0 -144
  109. data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
  110. data/app/assets/javascripts/materialize/materialbox.js +0 -263
  111. data/app/assets/javascripts/materialize/parallax.js +0 -54
  112. data/app/assets/javascripts/materialize/pushpin.js +0 -68
  113. data/app/assets/javascripts/materialize/scrollFire.js +0 -49
  114. data/app/assets/javascripts/materialize/scrollspy.js +0 -230
  115. data/app/assets/javascripts/materialize/sideNav.js +0 -395
  116. data/app/assets/javascripts/materialize/slider.js +0 -295
  117. data/app/assets/javascripts/materialize/tabs.js +0 -244
  118. data/app/assets/javascripts/materialize/tapTarget.js +0 -184
  119. data/app/assets/javascripts/materialize/tooltip.js +0 -227
  120. data/app/assets/javascripts/materialize/transitions.js +0 -163
  121. data/app/assets/javascripts/materialize/velocity.min.js +0 -626
  122. data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -424
  123. data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -39
  124. data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -469
  125. data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -216
  126. data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -267
@@ -1,257 +0,0 @@
1
- (function ($) {
2
-
3
- // Add posibility to scroll to selected option
4
- // usefull for select for example
5
- $.fn.scrollTo = function (elem) {
6
- $(this).scrollTop($(this).scrollTop() - $(this).offset().top + $(elem).offset().top);
7
- return this;
8
- };
9
-
10
- $.fn.dropdown = function (options) {
11
- var defaults = {
12
- inDuration: 300,
13
- outDuration: 225,
14
- constrainWidth: true, // Constrains width of dropdown to the activator
15
- hover: false,
16
- gutter: 0, // Spacing from edge
17
- belowOrigin: false,
18
- alignment: 'left',
19
- stopPropagation: false
20
- };
21
-
22
- // Open dropdown.
23
- if (options === "open") {
24
- this.each(function () {
25
- $(this).trigger('open');
26
- });
27
- return false;
28
- }
29
-
30
- // Close dropdown.
31
- if (options === "close") {
32
- this.each(function () {
33
- $(this).trigger('close');
34
- });
35
- return false;
36
- }
37
-
38
- this.each(function () {
39
- var origin = $(this);
40
- var curr_options = $.extend({}, defaults, options);
41
- var isFocused = false;
42
-
43
- // Dropdown menu
44
- var activates = $("#" + origin.attr('data-activates'));
45
-
46
- function updateOptions() {
47
- if (origin.data('induration') !== undefined) curr_options.inDuration = origin.data('induration');
48
- if (origin.data('outduration') !== undefined) curr_options.outDuration = origin.data('outduration');
49
- if (origin.data('constrainwidth') !== undefined) curr_options.constrainWidth = origin.data('constrainwidth');
50
- if (origin.data('hover') !== undefined) curr_options.hover = origin.data('hover');
51
- if (origin.data('gutter') !== undefined) curr_options.gutter = origin.data('gutter');
52
- if (origin.data('beloworigin') !== undefined) curr_options.belowOrigin = origin.data('beloworigin');
53
- if (origin.data('alignment') !== undefined) curr_options.alignment = origin.data('alignment');
54
- if (origin.data('stoppropagation') !== undefined) curr_options.stopPropagation = origin.data('stoppropagation');
55
- }
56
-
57
- updateOptions();
58
-
59
- // Attach dropdown to its activator
60
- origin.after(activates);
61
-
62
- /*
63
- Helper function to position and resize dropdown.
64
- Used in hover and click handler.
65
- */
66
- function placeDropdown(eventType) {
67
- // Check for simultaneous focus and click events.
68
- if (eventType === 'focus') {
69
- isFocused = true;
70
- }
71
-
72
- // Check html data attributes
73
- updateOptions();
74
-
75
- // Set Dropdown state
76
- activates.addClass('active');
77
- origin.addClass('active');
78
-
79
- var originWidth = origin[0].getBoundingClientRect().width;
80
-
81
- // Constrain width
82
- if (curr_options.constrainWidth === true) {
83
- activates.css('width', originWidth);
84
- } else {
85
- activates.css('white-space', 'nowrap');
86
- }
87
-
88
- // Offscreen detection
89
- var windowHeight = window.innerHeight;
90
- var originHeight = origin.innerHeight();
91
- var offsetLeft = origin.offset().left;
92
- var offsetTop = origin.offset().top - $(window).scrollTop();
93
- var currAlignment = curr_options.alignment;
94
- var gutterSpacing = 0;
95
- var leftPosition = 0;
96
-
97
- // Below Origin
98
- var verticalOffset = 0;
99
- if (curr_options.belowOrigin === true) {
100
- verticalOffset = originHeight;
101
- }
102
-
103
- // Check for scrolling positioned container.
104
- var scrollYOffset = 0;
105
- var scrollXOffset = 0;
106
- var wrapper = origin.parent();
107
- if (!wrapper.is('body')) {
108
- if (wrapper[0].scrollHeight > wrapper[0].clientHeight) {
109
- scrollYOffset = wrapper[0].scrollTop;
110
- }
111
- if (wrapper[0].scrollWidth > wrapper[0].clientWidth) {
112
- scrollXOffset = wrapper[0].scrollLeft;
113
- }
114
- }
115
-
116
- if (offsetLeft + activates.innerWidth() > $(window).width()) {
117
- // Dropdown goes past screen on right, force right alignment
118
- currAlignment = 'right';
119
- } else if (offsetLeft - activates.innerWidth() + origin.innerWidth() < 0) {
120
- // Dropdown goes past screen on left, force left alignment
121
- currAlignment = 'left';
122
- }
123
- // Vertical bottom offscreen detection
124
- if (offsetTop + activates.innerHeight() > windowHeight) {
125
- // If going upwards still goes offscreen, just crop height of dropdown.
126
- if (offsetTop + originHeight - activates.innerHeight() < 0) {
127
- var adjustedHeight = windowHeight - offsetTop - verticalOffset;
128
- activates.css('max-height', adjustedHeight);
129
- } else {
130
- // Flow upwards.
131
- if (!verticalOffset) {
132
- verticalOffset += originHeight;
133
- }
134
- verticalOffset -= activates.innerHeight();
135
- }
136
- }
137
-
138
- // Handle edge alignment
139
- if (currAlignment === 'left') {
140
- gutterSpacing = curr_options.gutter;
141
- leftPosition = origin.position().left + gutterSpacing;
142
- } else if (currAlignment === 'right') {
143
- // Material icons fix
144
- activates.stop(true, true).css({
145
- opacity: 0,
146
- left: 0
147
- });
148
-
149
- var offsetRight = origin.position().left + originWidth - activates.width();
150
- gutterSpacing = -curr_options.gutter;
151
- leftPosition = offsetRight + gutterSpacing;
152
- }
153
-
154
- // Position dropdown
155
- activates.css({
156
- position: 'absolute',
157
- top: origin.position().top + verticalOffset + scrollYOffset,
158
- left: leftPosition + scrollXOffset
159
- });
160
-
161
- // Show dropdown
162
- activates.slideDown({
163
- queue: false,
164
- duration: curr_options.inDuration,
165
- easing: 'easeOutCubic',
166
- complete: function () {
167
- $(this).css('height', '');
168
- }
169
- }).animate({ opacity: 1 }, { queue: false, duration: curr_options.inDuration, easing: 'easeOutSine' });
170
-
171
- // Add click close handler to document
172
- setTimeout(function () {
173
- $(document).on('click.' + activates.attr('id'), function (e) {
174
- hideDropdown();
175
- $(document).off('click.' + activates.attr('id'));
176
- });
177
- }, 0);
178
- }
179
-
180
- function hideDropdown() {
181
- // Check for simultaneous focus and click events.
182
- isFocused = false;
183
- activates.fadeOut(curr_options.outDuration);
184
- activates.removeClass('active');
185
- origin.removeClass('active');
186
- $(document).off('click.' + activates.attr('id'));
187
- setTimeout(function () {
188
- activates.css('max-height', '');
189
- }, curr_options.outDuration);
190
- }
191
-
192
- // Hover
193
- if (curr_options.hover) {
194
- var open = false;
195
- origin.off('click.' + origin.attr('id'));
196
- // Hover handler to show dropdown
197
- origin.on('mouseenter', function (e) {
198
- // Mouse over
199
- if (open === false) {
200
- placeDropdown();
201
- open = true;
202
- }
203
- });
204
- origin.on('mouseleave', function (e) {
205
- // If hover on origin then to something other than dropdown content, then close
206
- var toEl = e.toElement || e.relatedTarget; // added browser compatibility for target element
207
- if (!$(toEl).closest('.dropdown-content').is(activates)) {
208
- activates.stop(true, true);
209
- hideDropdown();
210
- open = false;
211
- }
212
- });
213
-
214
- activates.on('mouseleave', function (e) {
215
- // Mouse out
216
- var toEl = e.toElement || e.relatedTarget;
217
- if (!$(toEl).closest('.dropdown-button').is(origin)) {
218
- activates.stop(true, true);
219
- hideDropdown();
220
- open = false;
221
- }
222
- });
223
-
224
- // Click
225
- } else {
226
- // Click handler to show dropdown
227
- origin.off('click.' + origin.attr('id'));
228
- origin.on('click.' + origin.attr('id'), function (e) {
229
- if (!isFocused) {
230
- if (origin[0] == e.currentTarget && !origin.hasClass('active') && $(e.target).closest('.dropdown-content').length === 0) {
231
- e.preventDefault(); // Prevents button click from moving window
232
- if (curr_options.stopPropagation) {
233
- e.stopPropagation();
234
- }
235
- placeDropdown('click');
236
- }
237
- // If origin is clicked and menu is open, close menu
238
- else if (origin.hasClass('active')) {
239
- hideDropdown();
240
- $(document).off('click.' + activates.attr('id'));
241
- }
242
- }
243
- });
244
- } // End else
245
-
246
- // Listen to open and close event - useful for select component
247
- origin.on('open', function (e, eventType) {
248
- placeDropdown(eventType);
249
- });
250
- origin.on('close', hideDropdown);
251
- });
252
- }; // End dropdown plugin
253
-
254
- $(document).on('ready turbolinks:load', function () {
255
- $('.dropdown-button').dropdown();
256
- });
257
- })(jQuery);
@@ -1,806 +0,0 @@
1
- (function ($) {
2
- $(document).on('ready turbolinks:load', function () {
3
-
4
- // Function to update labels of text fields
5
- Materialize.updateTextFields = function () {
6
- var input_selector = 'input[type=text], input[type=password], input[type=email], input[type=url], input[type=tel], input[type=number], input[type=search], textarea';
7
- $(input_selector).each(function (index, element) {
8
- var $this = $(this);
9
- if ($(element).val().length > 0 || $(element).is(':focus') || element.autofocus || $this.attr('placeholder') !== undefined) {
10
- $this.siblings('label').addClass('active');
11
- } else if ($(element)[0].validity) {
12
- $this.siblings('label').toggleClass('active', $(element)[0].validity.badInput === true);
13
- } else {
14
- $this.siblings('label').removeClass('active');
15
- }
16
- });
17
- };
18
-
19
- // Text based inputs
20
- var input_selector = 'input[type=text], input[type=password], input[type=email], input[type=url], input[type=tel], input[type=number], input[type=search], textarea';
21
-
22
- // Add active if form auto complete
23
- $(document).on('change', input_selector, function () {
24
- if ($(this).val().length !== 0 || $(this).attr('placeholder') !== undefined) {
25
- $(this).siblings('label').addClass('active');
26
- }
27
- validate_field($(this));
28
- });
29
-
30
- // Add active if input element has been pre-populated on document ready
31
- $(document).on('ready turbolinks:load', function () {
32
- Materialize.updateTextFields();
33
- });
34
-
35
- // HTML DOM FORM RESET handling
36
- $(document).on('reset', function (e) {
37
- var formReset = $(e.target);
38
- if (formReset.is('form')) {
39
- formReset.find(input_selector).removeClass('valid').removeClass('invalid');
40
- formReset.find(input_selector).each(function () {
41
- if ($(this).attr('value') === '') {
42
- $(this).siblings('label').removeClass('active');
43
- }
44
- });
45
-
46
- // Reset select
47
- formReset.find('select.initialized').each(function () {
48
- var reset_text = formReset.find('option[selected]').text();
49
- formReset.siblings('input.select-dropdown').val(reset_text);
50
- });
51
- }
52
- });
53
-
54
- // Add active when element has focus
55
- $(document).on('focus', input_selector, function () {
56
- $(this).siblings('label, .prefix').addClass('active');
57
- });
58
-
59
- $(document).on('blur', input_selector, function () {
60
- var $inputElement = $(this);
61
- var selector = ".prefix";
62
-
63
- if ($inputElement.val().length === 0 && $inputElement[0].validity.badInput !== true && $inputElement.attr('placeholder') === undefined) {
64
- selector += ", label";
65
- }
66
-
67
- $inputElement.siblings(selector).removeClass('active');
68
-
69
- validate_field($inputElement);
70
- });
71
-
72
- window.validate_field = function (object) {
73
- var hasLength = object.attr('data-length') !== undefined;
74
- var lenAttr = parseInt(object.attr('data-length'));
75
- var len = object.val().length;
76
-
77
- if (object.val().length === 0 && object[0].validity.badInput === false && !object.is(':required')) {
78
- if (object.hasClass('validate')) {
79
- object.removeClass('valid');
80
- object.removeClass('invalid');
81
- }
82
- } else {
83
- if (object.hasClass('validate')) {
84
- // Check for character counter attributes
85
- if (object.is(':valid') && hasLength && len <= lenAttr || object.is(':valid') && !hasLength) {
86
- object.removeClass('invalid');
87
- object.addClass('valid');
88
- } else {
89
- object.removeClass('valid');
90
- object.addClass('invalid');
91
- }
92
- }
93
- }
94
- };
95
-
96
- // Radio and Checkbox focus class
97
- var radio_checkbox = 'input[type=radio], input[type=checkbox]';
98
- $(document).on('keyup.radio', radio_checkbox, function (e) {
99
- // TAB, check if tabbing to radio or checkbox.
100
- if (e.which === 9) {
101
- $(this).addClass('tabbed');
102
- var $this = $(this);
103
- $this.one('blur', function (e) {
104
-
105
- $(this).removeClass('tabbed');
106
- });
107
- return;
108
- }
109
- });
110
-
111
- // Textarea Auto Resize
112
- var hiddenDiv = $('.hiddendiv').first();
113
- if (!hiddenDiv.length) {
114
- hiddenDiv = $('<div class="hiddendiv common"></div>');
115
- $('body').append(hiddenDiv);
116
- }
117
- var text_area_selector = '.materialize-textarea';
118
-
119
- function textareaAutoResize($textarea) {
120
- // Set font properties of hiddenDiv
121
-
122
- var fontFamily = $textarea.css('font-family');
123
- var fontSize = $textarea.css('font-size');
124
- var lineHeight = $textarea.css('line-height');
125
- var padding = $textarea.css('padding');
126
-
127
- if (fontSize) {
128
- hiddenDiv.css('font-size', fontSize);
129
- }
130
- if (fontFamily) {
131
- hiddenDiv.css('font-family', fontFamily);
132
- }
133
- if (lineHeight) {
134
- hiddenDiv.css('line-height', lineHeight);
135
- }
136
- if (padding) {
137
- hiddenDiv.css('padding', padding);
138
- }
139
-
140
- // Set original-height, if none
141
- if (!$textarea.data('original-height')) {
142
- $textarea.data('original-height', $textarea.height());
143
- }
144
-
145
- if ($textarea.attr('wrap') === 'off') {
146
- hiddenDiv.css('overflow-wrap', 'normal').css('white-space', 'pre');
147
- }
148
-
149
- hiddenDiv.text($textarea.val() + '\n');
150
- var content = hiddenDiv.html().replace(/\n/g, '<br>');
151
- hiddenDiv.html(content);
152
-
153
- // When textarea is hidden, width goes crazy.
154
- // Approximate with half of window size
155
-
156
- if ($textarea.is(':visible')) {
157
- hiddenDiv.css('width', $textarea.width());
158
- } else {
159
- hiddenDiv.css('width', $(window).width() / 2);
160
- }
161
-
162
- /**
163
- * Resize if the new height is greater than the
164
- * original height of the textarea
165
- */
166
- if ($textarea.data('original-height') <= hiddenDiv.height()) {
167
- $textarea.css('height', hiddenDiv.height());
168
- } else if ($textarea.val().length < $textarea.data('previous-length')) {
169
- /**
170
- * In case the new height is less than original height, it
171
- * means the textarea has less text than before
172
- * So we set the height to the original one
173
- */
174
- $textarea.css('height', $textarea.data('original-height'));
175
- }
176
- $textarea.data('previous-length', $textarea.val().length);
177
- }
178
-
179
- $(text_area_selector).each(function () {
180
- var $textarea = $(this);
181
- /**
182
- * Instead of resizing textarea on document load,
183
- * store the original height and the original length
184
- */
185
- $textarea.data('original-height', $textarea.height());
186
- $textarea.data('previous-length', $textarea.val().length);
187
- });
188
-
189
- $('body').on('keyup keydown autoresize', text_area_selector, function () {
190
- textareaAutoResize($(this));
191
- });
192
-
193
- // File Input Path
194
- $(document).on('change', '.file-field input[type="file"]', function () {
195
- var file_field = $(this).closest('.file-field');
196
- var path_input = file_field.find('input.file-path');
197
- var files = $(this)[0].files;
198
- var file_names = [];
199
- for (var i = 0; i < files.length; i++) {
200
- file_names.push(files[i].name);
201
- }
202
- path_input.val(file_names.join(", "));
203
- path_input.trigger('change');
204
- });
205
-
206
- /****************
207
- * Range Input *
208
- ****************/
209
-
210
- var range_type = 'input[type=range]';
211
- var range_mousedown = false;
212
- var left;
213
-
214
- $(range_type).each(function () {
215
- var thumb = $('<span class="thumb"><span class="value"></span></span>');
216
- $(this).after(thumb);
217
- });
218
-
219
- var showRangeBubble = function (thumb) {
220
- var paddingLeft = parseInt(thumb.parent().css('padding-left'));
221
- var marginLeft = -7 + paddingLeft + 'px';
222
- thumb.velocity({ height: "30px", width: "30px", top: "-30px", marginLeft: marginLeft }, { duration: 300, easing: 'easeOutExpo' });
223
- };
224
-
225
- var calcRangeOffset = function (range) {
226
- var width = range.width() - 15;
227
- var max = parseFloat(range.attr('max'));
228
- var min = parseFloat(range.attr('min'));
229
- var percent = (parseFloat(range.val()) - min) / (max - min);
230
- return percent * width;
231
- };
232
-
233
- var range_wrapper = '.range-field';
234
- $(document).on('change', range_type, function (e) {
235
- var thumb = $(this).siblings('.thumb');
236
- thumb.find('.value').html($(this).val());
237
-
238
- if (!thumb.hasClass('active')) {
239
- showRangeBubble(thumb);
240
- }
241
-
242
- var offsetLeft = calcRangeOffset($(this));
243
- thumb.addClass('active').css('left', offsetLeft);
244
- });
245
-
246
- $(document).on('mousedown touchstart', range_type, function (e) {
247
- var thumb = $(this).siblings('.thumb');
248
-
249
- // If thumb indicator does not exist yet, create it
250
- if (thumb.length <= 0) {
251
- thumb = $('<span class="thumb"><span class="value"></span></span>');
252
- $(this).after(thumb);
253
- }
254
-
255
- // Set indicator value
256
- thumb.find('.value').html($(this).val());
257
-
258
- range_mousedown = true;
259
- $(this).addClass('active');
260
-
261
- if (!thumb.hasClass('active')) {
262
- showRangeBubble(thumb);
263
- }
264
-
265
- if (e.type !== 'input') {
266
- var offsetLeft = calcRangeOffset($(this));
267
- thumb.addClass('active').css('left', offsetLeft);
268
- }
269
- });
270
-
271
- $(document).on('mouseup touchend', range_wrapper, function () {
272
- range_mousedown = false;
273
- $(this).removeClass('active');
274
- });
275
-
276
- $(document).on('input mousemove touchmove', range_wrapper, function (e) {
277
- var thumb = $(this).children('.thumb');
278
- var left;
279
- var input = $(this).find(range_type);
280
-
281
- if (range_mousedown) {
282
- if (!thumb.hasClass('active')) {
283
- showRangeBubble(thumb);
284
- }
285
-
286
- var offsetLeft = calcRangeOffset(input);
287
- thumb.addClass('active').css('left', offsetLeft);
288
- thumb.find('.value').html(thumb.siblings(range_type).val());
289
- }
290
- });
291
-
292
- $(document).on('mouseout touchleave', range_wrapper, function () {
293
- if (!range_mousedown) {
294
-
295
- var thumb = $(this).children('.thumb');
296
- var paddingLeft = parseInt($(this).css('padding-left'));
297
- var marginLeft = 7 + paddingLeft + 'px';
298
-
299
- if (thumb.hasClass('active')) {
300
- thumb.velocity({ height: '0', width: '0', top: '10px', marginLeft: marginLeft }, { duration: 100 });
301
- }
302
- thumb.removeClass('active');
303
- }
304
- });
305
-
306
- /**************************
307
- * Auto complete plugin *
308
- *************************/
309
- $.fn.autocomplete = function (options) {
310
- // Defaults
311
- var defaults = {
312
- data: {},
313
- limit: Infinity,
314
- onAutocomplete: null,
315
- minLength: 1
316
- };
317
-
318
- options = $.extend(defaults, options);
319
-
320
- return this.each(function () {
321
- var $input = $(this);
322
- var data = options.data,
323
- count = 0,
324
- activeIndex = -1,
325
- oldVal,
326
- $inputDiv = $input.closest('.input-field'); // Div to append on
327
-
328
- // Check if data isn't empty
329
- if (!$.isEmptyObject(data)) {
330
- var $autocomplete = $('<ul class="autocomplete-content dropdown-content"></ul>');
331
- var $oldAutocomplete;
332
-
333
- // Append autocomplete element.
334
- // Prevent double structure init.
335
- if ($inputDiv.length) {
336
- $oldAutocomplete = $inputDiv.children('.autocomplete-content.dropdown-content').first();
337
- if (!$oldAutocomplete.length) {
338
- $inputDiv.append($autocomplete); // Set ul in body
339
- }
340
- } else {
341
- $oldAutocomplete = $input.next('.autocomplete-content.dropdown-content');
342
- if (!$oldAutocomplete.length) {
343
- $input.after($autocomplete);
344
- }
345
- }
346
- if ($oldAutocomplete.length) {
347
- $autocomplete = $oldAutocomplete;
348
- }
349
-
350
- // Highlight partial match.
351
- var highlight = function (string, $el) {
352
- var img = $el.find('img');
353
- var matchStart = $el.text().toLowerCase().indexOf("" + string.toLowerCase() + ""),
354
- matchEnd = matchStart + string.length - 1,
355
- beforeMatch = $el.text().slice(0, matchStart),
356
- matchText = $el.text().slice(matchStart, matchEnd + 1),
357
- afterMatch = $el.text().slice(matchEnd + 1);
358
- $el.html("<span>" + beforeMatch + "<span class='highlight'>" + matchText + "</span>" + afterMatch + "</span>");
359
- if (img.length) {
360
- $el.prepend(img);
361
- }
362
- };
363
-
364
- // Reset current element position
365
- var resetCurrentElement = function () {
366
- activeIndex = -1;
367
- $autocomplete.find('.active').removeClass('active');
368
- };
369
-
370
- // Remove autocomplete elements
371
- var removeAutocomplete = function () {
372
- $autocomplete.empty();
373
- resetCurrentElement();
374
- oldVal = undefined;
375
- };
376
-
377
- $input.off('blur.autocomplete').on('blur.autocomplete', function () {
378
- removeAutocomplete();
379
- });
380
-
381
- // Perform search
382
- $input.off('keyup.autocomplete focus.autocomplete').on('keyup.autocomplete focus.autocomplete', function (e) {
383
- // Reset count.
384
- count = 0;
385
- var val = $input.val().toLowerCase();
386
-
387
- // Don't capture enter or arrow key usage.
388
- if (e.which === 13 || e.which === 38 || e.which === 40) {
389
- return;
390
- }
391
-
392
- // Check if the input isn't empty
393
- if (oldVal !== val) {
394
- removeAutocomplete();
395
-
396
- if (val.length >= options.minLength) {
397
- for (var key in data) {
398
- if (data.hasOwnProperty(key) && key.toLowerCase().indexOf(val) !== -1) {
399
- // Break if past limit
400
- if (count >= options.limit) {
401
- break;
402
- }
403
-
404
- var autocompleteOption = $('<li></li>');
405
- if (!!data[key]) {
406
- autocompleteOption.append('<img src="' + data[key] + '" class="right circle"><span>' + key + '</span>');
407
- } else {
408
- autocompleteOption.append('<span>' + key + '</span>');
409
- }
410
-
411
- $autocomplete.append(autocompleteOption);
412
- highlight(val, autocompleteOption);
413
- count++;
414
- }
415
- }
416
- }
417
- }
418
-
419
- // Update oldVal
420
- oldVal = val;
421
- });
422
-
423
- $input.off('keydown.autocomplete').on('keydown.autocomplete', function (e) {
424
- // Arrow keys and enter key usage
425
- var keyCode = e.which,
426
- liElement,
427
- numItems = $autocomplete.children('li').length,
428
- $active = $autocomplete.children('.active').first();
429
-
430
- // select element on Enter
431
- if (keyCode === 13 && activeIndex >= 0) {
432
- liElement = $autocomplete.children('li').eq(activeIndex);
433
- if (liElement.length) {
434
- liElement.trigger('mousedown.autocomplete');
435
- e.preventDefault();
436
- }
437
- return;
438
- }
439
-
440
- // Capture up and down key
441
- if (keyCode === 38 || keyCode === 40) {
442
- e.preventDefault();
443
-
444
- if (keyCode === 38 && activeIndex > 0) {
445
- activeIndex--;
446
- }
447
-
448
- if (keyCode === 40 && activeIndex < numItems - 1) {
449
- activeIndex++;
450
- }
451
-
452
- $active.removeClass('active');
453
- if (activeIndex >= 0) {
454
- $autocomplete.children('li').eq(activeIndex).addClass('active');
455
- }
456
- }
457
- });
458
-
459
- // Set input value
460
- $autocomplete.off('mousedown.autocomplete touchstart.autocomplete').on('mousedown.autocomplete touchstart.autocomplete', 'li', function () {
461
- var text = $(this).text().trim();
462
- $input.val(text);
463
- $input.trigger('change');
464
- removeAutocomplete();
465
-
466
- // Handle onAutocomplete callback.
467
- if (typeof options.onAutocomplete === "function") {
468
- options.onAutocomplete.call(this, text);
469
- }
470
- });
471
-
472
- // Empty data
473
- } else {
474
- $input.off('keyup.autocomplete focus.autocomplete');
475
- }
476
- });
477
- };
478
- }); // End of $(document).ready
479
-
480
- /*******************
481
- * Select Plugin *
482
- ******************/
483
- $.fn.material_select = function (callback) {
484
- $(this).each(function () {
485
- var $select = $(this);
486
-
487
- if ($select.hasClass('browser-default')) {
488
- return; // Continue to next (return false breaks out of entire loop)
489
- }
490
-
491
- var multiple = $select.attr('multiple') ? true : false,
492
- lastID = $select.attr('data-select-id'); // Tear down structure if Select needs to be rebuilt
493
-
494
- if (lastID) {
495
- $select.parent().find('span.caret').remove();
496
- $select.parent().find('input').remove();
497
-
498
- $select.unwrap();
499
- $('ul#select-options-' + lastID).remove();
500
- }
501
-
502
- // If destroying the select, remove the selelct-id and reset it to it's uninitialized state.
503
- if (callback === 'destroy') {
504
- $select.removeAttr('data-select-id').removeClass('initialized');
505
- $(window).off('click.select');
506
- return;
507
- }
508
-
509
- var uniqueID = Materialize.guid();
510
- $select.attr('data-select-id', uniqueID);
511
- var wrapper = $('<div class="select-wrapper"></div>');
512
- wrapper.addClass($select.attr('class'));
513
- if ($select.is(':disabled')) wrapper.addClass('disabled');
514
- var options = $('<ul id="select-options-' + uniqueID + '" class="dropdown-content select-dropdown ' + (multiple ? 'multiple-select-dropdown' : '') + '"></ul>'),
515
- selectChildren = $select.children('option, optgroup'),
516
- valuesSelected = [],
517
- optionsHover = false;
518
-
519
- var label = $select.find('option:selected').html() || $select.find('option:first').html() || "";
520
-
521
- // Function that renders and appends the option taking into
522
- // account type and possible image icon.
523
- var appendOptionWithIcon = function (select, option, type) {
524
- // Add disabled attr if disabled
525
- var disabledClass = option.is(':disabled') ? 'disabled ' : '';
526
- var optgroupClass = type === 'optgroup-option' ? 'optgroup-option ' : '';
527
- var multipleCheckbox = multiple ? '<input type="checkbox"' + disabledClass + '/><label></label>' : '';
528
-
529
- // add icons
530
- var icon_url = option.data('icon');
531
- var classes = option.attr('class');
532
- if (!!icon_url) {
533
- var classString = '';
534
- if (!!classes) classString = ' class="' + classes + '"';
535
-
536
- // Check for multiple type.
537
- options.append($('<li class="' + disabledClass + optgroupClass + '"><img alt="" src="' + icon_url + '"' + classString + '><span>' + multipleCheckbox + option.html() + '</span></li>'));
538
- return true;
539
- }
540
-
541
- // Check for multiple type.
542
- options.append($('<li class="' + disabledClass + optgroupClass + '"><span>' + multipleCheckbox + option.html() + '</span></li>'));
543
- };
544
-
545
- /* Create dropdown structure. */
546
- if (selectChildren.length) {
547
- selectChildren.each(function () {
548
- if ($(this).is('option')) {
549
- // Direct descendant option.
550
- if (multiple) {
551
- appendOptionWithIcon($select, $(this), 'multiple');
552
- } else {
553
- appendOptionWithIcon($select, $(this));
554
- }
555
- } else if ($(this).is('optgroup')) {
556
- // Optgroup.
557
- var selectOptions = $(this).children('option');
558
- options.append($('<li class="optgroup"><span>' + $(this).attr('label') + '</span></li>'));
559
-
560
- selectOptions.each(function () {
561
- appendOptionWithIcon($select, $(this), 'optgroup-option');
562
- });
563
- }
564
- });
565
- }
566
-
567
- options.find('li:not(.optgroup)').each(function (i) {
568
- $(this).click(function (e) {
569
- // Check if option element is disabled
570
- if (!$(this).hasClass('disabled') && !$(this).hasClass('optgroup')) {
571
- var selected = true;
572
-
573
- if (multiple) {
574
- $('input[type="checkbox"]', this).prop('checked', function (i, v) {
575
- return !v;
576
- });
577
- selected = toggleEntryFromArray(valuesSelected, i, $select);
578
- $newSelect.trigger('focus');
579
- } else {
580
- options.find('li').removeClass('active');
581
- $(this).toggleClass('active');
582
- $newSelect.val($(this).text());
583
- }
584
-
585
- activateOption(options, $(this));
586
- $select.find('option').eq(i).prop('selected', selected);
587
- // Trigger onchange() event
588
- $select.trigger('change');
589
- if (typeof callback !== 'undefined') callback();
590
- }
591
-
592
- e.stopPropagation();
593
- });
594
- });
595
-
596
- // Wrap Elements
597
- $select.wrap(wrapper);
598
- // Add Select Display Element
599
- var dropdownIcon = $('<span class="caret">&#9660;</span>');
600
-
601
- // escape double quotes
602
- var sanitizedLabelHtml = label.replace(/"/g, '&quot;');
603
-
604
- var $newSelect = $('<input type="text" class="select-dropdown" readonly="true" ' + ($select.is(':disabled') ? 'disabled' : '') + ' data-activates="select-options-' + uniqueID + '" value="' + sanitizedLabelHtml + '"/>');
605
- $select.before($newSelect);
606
- $newSelect.before(dropdownIcon);
607
-
608
- $newSelect.after(options);
609
- // Check if section element is disabled
610
- if (!$select.is(':disabled')) {
611
- $newSelect.dropdown({ 'hover': false });
612
- }
613
-
614
- // Copy tabindex
615
- if ($select.attr('tabindex')) {
616
- $($newSelect[0]).attr('tabindex', $select.attr('tabindex'));
617
- }
618
-
619
- $select.addClass('initialized');
620
-
621
- $newSelect.on({
622
- 'focus': function () {
623
- if ($('ul.select-dropdown').not(options[0]).is(':visible')) {
624
- $('input.select-dropdown').trigger('close');
625
- $(window).off('click.select');
626
- }
627
- if (!options.is(':visible')) {
628
- $(this).trigger('open', ['focus']);
629
- var label = $(this).val();
630
- if (multiple && label.indexOf(',') >= 0) {
631
- label = label.split(',')[0];
632
- }
633
-
634
- var selectedOption = options.find('li').filter(function () {
635
- return $(this).text().toLowerCase() === label.toLowerCase();
636
- })[0];
637
- activateOption(options, selectedOption, true);
638
-
639
- $(window).off('click.select').on('click.select', function () {
640
- multiple && (optionsHover || $newSelect.trigger('close'));
641
- $(window).off('click.select');
642
- });
643
- }
644
- },
645
- 'click': function (e) {
646
- e.stopPropagation();
647
- }
648
- });
649
-
650
- $newSelect.on('blur', function () {
651
- if (!multiple) {
652
- $(this).trigger('close');
653
- $(window).off('click.select');
654
- }
655
- options.find('li.selected').removeClass('selected');
656
- });
657
-
658
- options.hover(function () {
659
- optionsHover = true;
660
- }, function () {
661
- optionsHover = false;
662
- });
663
-
664
- // Add initial multiple selections.
665
- if (multiple) {
666
- $select.find("option:selected:not(:disabled)").each(function () {
667
- var index = this.index;
668
-
669
- toggleEntryFromArray(valuesSelected, index, $select);
670
- options.find("li:not(.optgroup)").eq(index).find(":checkbox").prop("checked", true);
671
- });
672
- }
673
-
674
- /**
675
- * Make option as selected and scroll to selected position
676
- * @param {jQuery} collection Select options jQuery element
677
- * @param {Element} newOption element of the new option
678
- * @param {Boolean} firstActivation If on first activation of select
679
- */
680
- var activateOption = function (collection, newOption, firstActivation) {
681
- if (newOption) {
682
- collection.find('li.selected').removeClass('selected');
683
- var option = $(newOption);
684
- option.addClass('selected');
685
- if (!multiple || !!firstActivation) {
686
- options.scrollTo(option);
687
- }
688
- }
689
- };
690
-
691
- // Allow user to search by typing
692
- // this array is cleared after 1 second
693
- var filterQuery = [],
694
- onKeyDown = function (e) {
695
- // TAB - switch to another input
696
- if (e.which == 9) {
697
- $newSelect.trigger('close');
698
- return;
699
- }
700
-
701
- // ARROW DOWN WHEN SELECT IS CLOSED - open select options
702
- if (e.which == 40 && !options.is(':visible')) {
703
- $newSelect.trigger('open');
704
- return;
705
- }
706
-
707
- // ENTER WHEN SELECT IS CLOSED - submit form
708
- if (e.which == 13 && !options.is(':visible')) {
709
- return;
710
- }
711
-
712
- e.preventDefault();
713
-
714
- // CASE WHEN USER TYPE LETTERS
715
- var letter = String.fromCharCode(e.which).toLowerCase(),
716
- nonLetters = [9, 13, 27, 38, 40];
717
- if (letter && nonLetters.indexOf(e.which) === -1) {
718
- filterQuery.push(letter);
719
-
720
- var string = filterQuery.join(''),
721
- newOption = options.find('li').filter(function () {
722
- return $(this).text().toLowerCase().indexOf(string) === 0;
723
- })[0];
724
-
725
- if (newOption) {
726
- activateOption(options, newOption);
727
- }
728
- }
729
-
730
- // ENTER - select option and close when select options are opened
731
- if (e.which == 13) {
732
- var activeOption = options.find('li.selected:not(.disabled)')[0];
733
- if (activeOption) {
734
- $(activeOption).trigger('click');
735
- if (!multiple) {
736
- $newSelect.trigger('close');
737
- }
738
- }
739
- }
740
-
741
- // ARROW DOWN - move to next not disabled option
742
- if (e.which == 40) {
743
- if (options.find('li.selected').length) {
744
- newOption = options.find('li.selected').next('li:not(.disabled)')[0];
745
- } else {
746
- newOption = options.find('li:not(.disabled)')[0];
747
- }
748
- activateOption(options, newOption);
749
- }
750
-
751
- // ESC - close options
752
- if (e.which == 27) {
753
- $newSelect.trigger('close');
754
- }
755
-
756
- // ARROW UP - move to previous not disabled option
757
- if (e.which == 38) {
758
- newOption = options.find('li.selected').prev('li:not(.disabled)')[0];
759
- if (newOption) activateOption(options, newOption);
760
- }
761
-
762
- // Automaticaly clean filter query so user can search again by starting letters
763
- setTimeout(function () {
764
- filterQuery = [];
765
- }, 1000);
766
- };
767
-
768
- $newSelect.on('keydown', onKeyDown);
769
- });
770
-
771
- function toggleEntryFromArray(entriesArray, entryIndex, select) {
772
- var index = entriesArray.indexOf(entryIndex),
773
- notAdded = index === -1;
774
-
775
- if (notAdded) {
776
- entriesArray.push(entryIndex);
777
- } else {
778
- entriesArray.splice(index, 1);
779
- }
780
-
781
- select.siblings('ul.dropdown-content').find('li:not(.optgroup)').eq(entryIndex).toggleClass('active');
782
-
783
- // use notAdded instead of true (to detect if the option is selected or not)
784
- select.find('option').eq(entryIndex).prop('selected', notAdded);
785
- setValueToInput(entriesArray, select);
786
-
787
- return notAdded;
788
- }
789
-
790
- function setValueToInput(entriesArray, select) {
791
- var value = '';
792
-
793
- for (var i = 0, count = entriesArray.length; i < count; i++) {
794
- var text = select.find('option').eq(entriesArray[i]).text();
795
-
796
- i === 0 ? value += text : value += ', ' + text;
797
- }
798
-
799
- if (value === '') {
800
- value = select.find('option:disabled').eq(0).text();
801
- }
802
-
803
- select.siblings('input.select-dropdown').val(value);
804
- }
805
- };
806
- })(jQuery);