materialize-sass 0.97.8 → 1.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +5 -5
  2. data/.gitattributes +1 -0
  3. data/.gitignore +1 -0
  4. data/README.md +34 -32
  5. data/Rakefile +38 -21
  6. data/assets/javascripts/materialize/anime.min.js +417 -0
  7. data/assets/javascripts/materialize/autocomplete.js +504 -0
  8. data/assets/javascripts/materialize/buttons.js +409 -0
  9. data/assets/javascripts/materialize/cards.js +34 -0
  10. data/assets/javascripts/materialize/carousel.js +797 -0
  11. data/assets/javascripts/materialize/cash.js +990 -0
  12. data/assets/javascripts/materialize/characterCounter.js +180 -0
  13. data/assets/javascripts/materialize/chips.js +564 -0
  14. data/assets/javascripts/materialize/collapsible.js +337 -0
  15. data/assets/javascripts/materialize/component.js +57 -0
  16. data/assets/javascripts/materialize/datepicker.js +935 -0
  17. data/assets/javascripts/materialize/dropdown.js +659 -0
  18. data/assets/javascripts/materialize/extras/nouislider.js +2147 -0
  19. data/assets/javascripts/materialize/extras/nouislider.min.js +1 -0
  20. data/assets/javascripts/materialize/forms.js +244 -0
  21. data/assets/javascripts/materialize/global.js +408 -0
  22. data/assets/javascripts/materialize/materialbox.js +513 -0
  23. data/assets/javascripts/materialize/modal.js +449 -0
  24. data/assets/javascripts/materialize/parallax.js +173 -0
  25. data/assets/javascripts/materialize/pushpin.js +179 -0
  26. data/assets/javascripts/materialize/range.js +310 -0
  27. data/assets/javascripts/materialize/scrollspy.js +328 -0
  28. data/assets/javascripts/materialize/select.js +497 -0
  29. data/assets/javascripts/materialize/sidenav.js +655 -0
  30. data/assets/javascripts/materialize/slider.js +424 -0
  31. data/assets/javascripts/materialize/tabs.js +476 -0
  32. data/assets/javascripts/materialize/tapTarget.js +364 -0
  33. data/assets/javascripts/materialize/timepicker.js +647 -0
  34. data/assets/javascripts/materialize/toasts.js +355 -0
  35. data/assets/javascripts/materialize/tooltip.js +351 -0
  36. data/{app/assets → assets}/javascripts/materialize/waves.js +42 -47
  37. data/{app/assets → assets}/javascripts/materialize-sprockets.js +12 -13
  38. data/assets/javascripts/materialize.js +12374 -0
  39. data/assets/stylesheets/materialize/components/_badges.scss +55 -0
  40. data/{app/assets → assets}/stylesheets/materialize/components/_buttons.scss +99 -58
  41. data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +14 -6
  42. data/{app/assets → assets}/stylesheets/materialize/components/_carousel.scss +12 -7
  43. data/{app/assets → assets}/stylesheets/materialize/components/_chips.scss +13 -6
  44. data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +16 -15
  45. data/assets/stylesheets/materialize/components/_color-classes.scss +32 -0
  46. data/{app/assets/stylesheets/materialize/components/_color.scss → assets/stylesheets/materialize/components/_color-variables.scss} +2 -44
  47. data/assets/stylesheets/materialize/components/_datepicker.scss +191 -0
  48. data/{app/assets → assets}/stylesheets/materialize/components/_dropdown.scss +35 -15
  49. data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +96 -125
  50. data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +45 -36
  51. data/{app/assets → assets}/stylesheets/materialize/components/_icons-material-design.scss +0 -0
  52. data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +13 -12
  53. data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +7 -3
  54. data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +29 -11
  55. data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
  56. data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +2 -2
  57. data/assets/stylesheets/materialize/components/_pulse.scss +34 -0
  58. data/{app/assets/stylesheets/materialize/components/_sideNav.scss → assets/stylesheets/materialize/components/_sidenav.scss} +47 -47
  59. data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +0 -0
  60. data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +5 -5
  61. data/{app/assets → assets}/stylesheets/materialize/components/_tabs.scss +10 -10
  62. data/assets/stylesheets/materialize/components/_tapTarget.scss +103 -0
  63. data/assets/stylesheets/materialize/components/_timepicker.scss +183 -0
  64. data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +7 -14
  65. data/{app/assets → assets}/stylesheets/materialize/components/_tooltip.scss +3 -3
  66. data/assets/stylesheets/materialize/components/_transitions.scss +13 -0
  67. data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +8 -9
  68. data/{app/assets → assets}/stylesheets/materialize/components/_variables.scss +65 -29
  69. data/assets/stylesheets/materialize/components/_waves.scss +114 -0
  70. data/{app/assets → assets}/stylesheets/materialize/components/forms/_checkboxes.scss +26 -46
  71. data/{app/assets → assets}/stylesheets/materialize/components/forms/_file-input.scss +6 -0
  72. data/{app/assets → assets}/stylesheets/materialize/components/forms/_forms.scss +0 -0
  73. data/{app/assets → assets}/stylesheets/materialize/components/forms/_input-fields.scss +131 -63
  74. data/assets/stylesheets/materialize/components/forms/_radio-buttons.scss +115 -0
  75. data/{app/assets → assets}/stylesheets/materialize/components/forms/_range.scss +35 -33
  76. data/{app/assets → assets}/stylesheets/materialize/components/forms/_select.scss +88 -19
  77. data/{app/assets → assets}/stylesheets/materialize/components/forms/_switches.scss +32 -21
  78. data/assets/stylesheets/materialize/extras/nouislider.css +406 -0
  79. data/{app/assets → assets}/stylesheets/materialize.scss +10 -9
  80. data/lib/materialize-sass/engine.rb +9 -7
  81. data/lib/materialize-sass/helpers.rb +38 -0
  82. data/lib/materialize-sass/version.rb +1 -1
  83. data/lib/materialize-sass.rb +13 -28
  84. data/materialize-sass.gemspec +5 -5
  85. metadata +97 -119
  86. data/app/assets/fonts/roboto/Roboto-Bold.eot +0 -0
  87. data/app/assets/fonts/roboto/Roboto-Bold.ttf +0 -0
  88. data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
  89. data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
  90. data/app/assets/fonts/roboto/Roboto-Light.eot +0 -0
  91. data/app/assets/fonts/roboto/Roboto-Light.ttf +0 -0
  92. data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
  93. data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
  94. data/app/assets/fonts/roboto/Roboto-Medium.eot +0 -0
  95. data/app/assets/fonts/roboto/Roboto-Medium.ttf +0 -0
  96. data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
  97. data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
  98. data/app/assets/fonts/roboto/Roboto-Regular.eot +0 -0
  99. data/app/assets/fonts/roboto/Roboto-Regular.ttf +0 -0
  100. data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
  101. data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
  102. data/app/assets/fonts/roboto/Roboto-Thin.eot +0 -0
  103. data/app/assets/fonts/roboto/Roboto-Thin.ttf +0 -0
  104. data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
  105. data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
  106. data/app/assets/javascripts/materialize/animation.js +0 -9
  107. data/app/assets/javascripts/materialize/buttons.js +0 -267
  108. data/app/assets/javascripts/materialize/cards.js +0 -26
  109. data/app/assets/javascripts/materialize/carousel.js +0 -454
  110. data/app/assets/javascripts/materialize/character_counter.js +0 -72
  111. data/app/assets/javascripts/materialize/chips.js +0 -289
  112. data/app/assets/javascripts/materialize/collapsible.js +0 -160
  113. data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1430
  114. data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1123
  115. data/app/assets/javascripts/materialize/dropdown.js +0 -265
  116. data/app/assets/javascripts/materialize/extras/nouislider.js +0 -1666
  117. data/app/assets/javascripts/materialize/extras/nouislider.min.js +0 -1
  118. data/app/assets/javascripts/materialize/forms.js +0 -682
  119. data/app/assets/javascripts/materialize/global.js +0 -98
  120. data/app/assets/javascripts/materialize/hammer.min.js +0 -1
  121. data/app/assets/javascripts/materialize/init.js +0 -174
  122. data/app/assets/javascripts/materialize/initial.js +0 -11
  123. data/app/assets/javascripts/materialize/jquery.easing.1.3.js +0 -205
  124. data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
  125. data/app/assets/javascripts/materialize/jquery.timeago.min.js +0 -1
  126. data/app/assets/javascripts/materialize/materialbox.js +0 -269
  127. data/app/assets/javascripts/materialize/modal.js +0 -184
  128. data/app/assets/javascripts/materialize/parallax.js +0 -58
  129. data/app/assets/javascripts/materialize/prism.js +0 -8
  130. data/app/assets/javascripts/materialize/pushpin.js +0 -71
  131. data/app/assets/javascripts/materialize/scrollFire.js +0 -48
  132. data/app/assets/javascripts/materialize/scrollspy.js +0 -284
  133. data/app/assets/javascripts/materialize/sideNav.js +0 -370
  134. data/app/assets/javascripts/materialize/slider.js +0 -321
  135. data/app/assets/javascripts/materialize/tabs.js +0 -164
  136. data/app/assets/javascripts/materialize/toasts.js +0 -137
  137. data/app/assets/javascripts/materialize/tooltip.js +0 -236
  138. data/app/assets/javascripts/materialize/transitions.js +0 -169
  139. data/app/assets/javascripts/materialize/velocity.min.js +0 -5
  140. data/app/assets/javascripts/materialize.js +0 -5
  141. data/app/assets/stylesheets/materialize/components/_mixins.scss +0 -5
  142. data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -424
  143. data/app/assets/stylesheets/materialize/components/_prefixer.scss +0 -384
  144. data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -49
  145. data/app/assets/stylesheets/materialize/components/_waves.scss +0 -177
  146. data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -435
  147. data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -201
  148. data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -125
  149. data/app/assets/stylesheets/materialize/components/forms/_radio-buttons.scss +0 -117
  150. data/app/assets/stylesheets/materialize/extras/nouislider.css +0 -259
@@ -0,0 +1,504 @@
1
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2
+
3
+ var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
4
+
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+
7
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8
+
9
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
10
+
11
+ (function ($) {
12
+ 'use strict';
13
+
14
+ var _defaults = {
15
+ data: {}, // Autocomplete data set
16
+ limit: Infinity, // Limit of results the autocomplete shows
17
+ onAutocomplete: null, // Callback for when autocompleted
18
+ minLength: 1, // Min characters before autocomplete starts
19
+ sortFunction: function (a, b, inputString) {
20
+ // Sort function for sorting autocomplete results
21
+ return a.indexOf(inputString) - b.indexOf(inputString);
22
+ }
23
+ };
24
+
25
+ /**
26
+ * @class
27
+ *
28
+ */
29
+
30
+ var Autocomplete = function (_Component) {
31
+ _inherits(Autocomplete, _Component);
32
+
33
+ /**
34
+ * Construct Autocomplete instance
35
+ * @constructor
36
+ * @param {Element} el
37
+ * @param {Object} options
38
+ */
39
+ function Autocomplete(el, options) {
40
+ _classCallCheck(this, Autocomplete);
41
+
42
+ var _this = _possibleConstructorReturn(this, (Autocomplete.__proto__ || Object.getPrototypeOf(Autocomplete)).call(this, Autocomplete, el, options));
43
+
44
+ _this.el.M_Autocomplete = _this;
45
+
46
+ /**
47
+ * Options for the autocomplete
48
+ * @member Autocomplete#options
49
+ * @prop {Number} duration
50
+ * @prop {Number} dist
51
+ * @prop {number} shift
52
+ * @prop {number} padding
53
+ * @prop {Boolean} fullWidth
54
+ * @prop {Boolean} indicators
55
+ * @prop {Boolean} noWrap
56
+ * @prop {Function} onCycleTo
57
+ */
58
+ _this.options = $.extend({}, Autocomplete.defaults, options);
59
+
60
+ // Setup
61
+ _this.isOpen = false;
62
+ _this.count = 0;
63
+ _this.activeIndex = -1;
64
+ _this.oldVal;
65
+ _this.$inputField = _this.$el.closest('.input-field');
66
+ _this.$active = $();
67
+ _this._mousedown = false;
68
+ _this._setupDropdown();
69
+
70
+ _this._setupEventHandlers();
71
+ return _this;
72
+ }
73
+
74
+ _createClass(Autocomplete, [{
75
+ key: 'destroy',
76
+
77
+
78
+ /**
79
+ * Teardown component
80
+ */
81
+ value: function destroy() {
82
+ this._removeEventHandlers();
83
+ this._removeDropdown();
84
+ this.el.M_Autocomplete = undefined;
85
+ }
86
+
87
+ /**
88
+ * Setup Event Handlers
89
+ */
90
+
91
+ }, {
92
+ key: '_setupEventHandlers',
93
+ value: function _setupEventHandlers() {
94
+ this._handleInputBlurBound = this._handleInputBlur.bind(this);
95
+ this._handleInputKeyupAndFocusBound = this._handleInputKeyupAndFocus.bind(this);
96
+ this._handleInputKeydownBound = this._handleInputKeydown.bind(this);
97
+ this._handleInputClickBound = this._handleInputClick.bind(this);
98
+ this._handleContainerMousedownAndTouchstartBound = this._handleContainerMousedownAndTouchstart.bind(this);
99
+ this._handleContainerMouseupAndTouchendBound = this._handleContainerMouseupAndTouchend.bind(this);
100
+
101
+ this.el.addEventListener('blur', this._handleInputBlurBound);
102
+ this.el.addEventListener('keyup', this._handleInputKeyupAndFocusBound);
103
+ this.el.addEventListener('focus', this._handleInputKeyupAndFocusBound);
104
+ this.el.addEventListener('keydown', this._handleInputKeydownBound);
105
+ this.el.addEventListener('click', this._handleInputClickBound);
106
+ this.container.addEventListener('mousedown', this._handleContainerMousedownAndTouchstartBound);
107
+ this.container.addEventListener('mouseup', this._handleContainerMouseupAndTouchendBound);
108
+
109
+ if (typeof window.ontouchstart !== 'undefined') {
110
+ this.container.addEventListener('touchstart', this._handleContainerMousedownAndTouchstartBound);
111
+ this.container.addEventListener('touchend', this._handleContainerMouseupAndTouchendBound);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Remove Event Handlers
117
+ */
118
+
119
+ }, {
120
+ key: '_removeEventHandlers',
121
+ value: function _removeEventHandlers() {
122
+ this.el.removeEventListener('blur', this._handleInputBlurBound);
123
+ this.el.removeEventListener('keyup', this._handleInputKeyupAndFocusBound);
124
+ this.el.removeEventListener('focus', this._handleInputKeyupAndFocusBound);
125
+ this.el.removeEventListener('keydown', this._handleInputKeydownBound);
126
+ this.el.removeEventListener('click', this._handleInputClickBound);
127
+ this.container.removeEventListener('mousedown', this._handleContainerMousedownAndTouchstartBound);
128
+ this.container.removeEventListener('mouseup', this._handleContainerMouseupAndTouchendBound);
129
+
130
+ if (typeof window.ontouchstart !== 'undefined') {
131
+ this.container.removeEventListener('touchstart', this._handleContainerMousedownAndTouchstartBound);
132
+ this.container.removeEventListener('touchend', this._handleContainerMouseupAndTouchendBound);
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Setup dropdown
138
+ */
139
+
140
+ }, {
141
+ key: '_setupDropdown',
142
+ value: function _setupDropdown() {
143
+ var _this2 = this;
144
+
145
+ this.container = document.createElement('ul');
146
+ this.container.id = 'autocomplete-options-' + M.guid();
147
+ $(this.container).addClass('autocomplete-content dropdown-content');
148
+ this.$inputField.append(this.container);
149
+ this.el.setAttribute('data-target', this.container.id);
150
+
151
+ this.dropdown = M.Dropdown.init(this.el, {
152
+ autoFocus: false,
153
+ closeOnClick: false,
154
+ coverTrigger: false,
155
+ onItemClick: function (itemEl) {
156
+ _this2.selectOption($(itemEl));
157
+ }
158
+ });
159
+
160
+ // Sketchy removal of dropdown click handler
161
+ this.el.removeEventListener('click', this.dropdown._handleClickBound);
162
+ }
163
+
164
+ /**
165
+ * Remove dropdown
166
+ */
167
+
168
+ }, {
169
+ key: '_removeDropdown',
170
+ value: function _removeDropdown() {
171
+ this.container.parentNode.removeChild(this.container);
172
+ }
173
+
174
+ /**
175
+ * Handle Input Blur
176
+ */
177
+
178
+ }, {
179
+ key: '_handleInputBlur',
180
+ value: function _handleInputBlur() {
181
+ if (!this._mousedown) {
182
+ this.close();
183
+ this._resetAutocomplete();
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Handle Input Keyup and Focus
189
+ * @param {Event} e
190
+ */
191
+
192
+ }, {
193
+ key: '_handleInputKeyupAndFocus',
194
+ value: function _handleInputKeyupAndFocus(e) {
195
+ if (e.type === 'keyup') {
196
+ Autocomplete._keydown = false;
197
+ }
198
+
199
+ this.count = 0;
200
+ var val = this.el.value.toLowerCase();
201
+
202
+ // Don't capture enter or arrow key usage.
203
+ if (e.keyCode === 13 || e.keyCode === 38 || e.keyCode === 40) {
204
+ return;
205
+ }
206
+
207
+ // Check if the input isn't empty
208
+ // Check if focus triggered by tab
209
+ if (this.oldVal !== val && (M.tabPressed || e.type !== 'focus')) {
210
+ this.open();
211
+ }
212
+
213
+ // Update oldVal
214
+ this.oldVal = val;
215
+ }
216
+
217
+ /**
218
+ * Handle Input Keydown
219
+ * @param {Event} e
220
+ */
221
+
222
+ }, {
223
+ key: '_handleInputKeydown',
224
+ value: function _handleInputKeydown(e) {
225
+ Autocomplete._keydown = true;
226
+
227
+ // Arrow keys and enter key usage
228
+ var keyCode = e.keyCode,
229
+ liElement = void 0,
230
+ numItems = $(this.container).children('li').length;
231
+
232
+ // select element on Enter
233
+ if (keyCode === M.keys.ENTER && this.activeIndex >= 0) {
234
+ liElement = $(this.container).children('li').eq(this.activeIndex);
235
+ if (liElement.length) {
236
+ this.selectOption(liElement);
237
+ e.preventDefault();
238
+ }
239
+ return;
240
+ }
241
+
242
+ // Capture up and down key
243
+ if (keyCode === M.keys.ARROW_UP || keyCode === M.keys.ARROW_DOWN) {
244
+ e.preventDefault();
245
+
246
+ if (keyCode === M.keys.ARROW_UP && this.activeIndex > 0) {
247
+ this.activeIndex--;
248
+ }
249
+
250
+ if (keyCode === M.keys.ARROW_DOWN && this.activeIndex < numItems - 1) {
251
+ this.activeIndex++;
252
+ }
253
+
254
+ this.$active.removeClass('active');
255
+ if (this.activeIndex >= 0) {
256
+ this.$active = $(this.container).children('li').eq(this.activeIndex);
257
+ this.$active.addClass('active');
258
+ }
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Handle Input Click
264
+ * @param {Event} e
265
+ */
266
+
267
+ }, {
268
+ key: '_handleInputClick',
269
+ value: function _handleInputClick(e) {
270
+ this.open();
271
+ }
272
+
273
+ /**
274
+ * Handle Container Mousedown and Touchstart
275
+ * @param {Event} e
276
+ */
277
+
278
+ }, {
279
+ key: '_handleContainerMousedownAndTouchstart',
280
+ value: function _handleContainerMousedownAndTouchstart(e) {
281
+ this._mousedown = true;
282
+ }
283
+
284
+ /**
285
+ * Handle Container Mouseup and Touchend
286
+ * @param {Event} e
287
+ */
288
+
289
+ }, {
290
+ key: '_handleContainerMouseupAndTouchend',
291
+ value: function _handleContainerMouseupAndTouchend(e) {
292
+ this._mousedown = false;
293
+ }
294
+
295
+ /**
296
+ * Highlight partial match
297
+ */
298
+
299
+ }, {
300
+ key: '_highlight',
301
+ value: function _highlight(string, $el) {
302
+ var img = $el.find('img');
303
+ var matchStart = $el.text().toLowerCase().indexOf('' + string.toLowerCase() + ''),
304
+ matchEnd = matchStart + string.length - 1,
305
+ beforeMatch = $el.text().slice(0, matchStart),
306
+ matchText = $el.text().slice(matchStart, matchEnd + 1),
307
+ afterMatch = $el.text().slice(matchEnd + 1);
308
+ $el.html('<span>' + beforeMatch + '<span class=\'highlight\'>' + matchText + '</span>' + afterMatch + '</span>');
309
+ if (img.length) {
310
+ $el.prepend(img);
311
+ }
312
+ }
313
+
314
+ /**
315
+ * Reset current element position
316
+ */
317
+
318
+ }, {
319
+ key: '_resetCurrentElement',
320
+ value: function _resetCurrentElement() {
321
+ this.activeIndex = -1;
322
+ this.$active.removeClass('active');
323
+ }
324
+
325
+ /**
326
+ * Reset autocomplete elements
327
+ */
328
+
329
+ }, {
330
+ key: '_resetAutocomplete',
331
+ value: function _resetAutocomplete() {
332
+ $(this.container).empty();
333
+ this._resetCurrentElement();
334
+ this.oldVal = null;
335
+ this.isOpen = false;
336
+ this._mousedown = false;
337
+ }
338
+
339
+ /**
340
+ * Select autocomplete option
341
+ * @param {Element} el Autocomplete option list item element
342
+ */
343
+
344
+ }, {
345
+ key: 'selectOption',
346
+ value: function selectOption(el) {
347
+ var text = el.text().trim();
348
+ this.el.value = text;
349
+ this.$el.trigger('change');
350
+ this._resetAutocomplete();
351
+ this.close();
352
+
353
+ // Handle onAutocomplete callback.
354
+ if (typeof this.options.onAutocomplete === 'function') {
355
+ this.options.onAutocomplete.call(this, text);
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Render dropdown content
361
+ * @param {Object} data data set
362
+ * @param {String} val current input value
363
+ */
364
+
365
+ }, {
366
+ key: '_renderDropdown',
367
+ value: function _renderDropdown(data, val) {
368
+ var _this3 = this;
369
+
370
+ this._resetAutocomplete();
371
+
372
+ var matchingData = [];
373
+
374
+ // Gather all matching data
375
+ for (var key in data) {
376
+ if (data.hasOwnProperty(key) && key.toLowerCase().indexOf(val) !== -1) {
377
+ // Break if past limit
378
+ if (this.count >= this.options.limit) {
379
+ break;
380
+ }
381
+
382
+ var entry = {
383
+ data: data[key],
384
+ key: key
385
+ };
386
+ matchingData.push(entry);
387
+
388
+ this.count++;
389
+ }
390
+ }
391
+
392
+ // Sort
393
+ if (this.options.sortFunction) {
394
+ var sortFunctionBound = function (a, b) {
395
+ return _this3.options.sortFunction(a.key.toLowerCase(), b.key.toLowerCase(), val.toLowerCase());
396
+ };
397
+ matchingData.sort(sortFunctionBound);
398
+ }
399
+
400
+ // Render
401
+ for (var i = 0; i < matchingData.length; i++) {
402
+ var _entry = matchingData[i];
403
+ var $autocompleteOption = $('<li></li>');
404
+ if (!!_entry.data) {
405
+ $autocompleteOption.append('<img src="' + _entry.data + '" class="right circle"><span>' + _entry.key + '</span>');
406
+ } else {
407
+ $autocompleteOption.append('<span>' + _entry.key + '</span>');
408
+ }
409
+
410
+ $(this.container).append($autocompleteOption);
411
+ this._highlight(val, $autocompleteOption);
412
+ }
413
+ }
414
+
415
+ /**
416
+ * Open Autocomplete Dropdown
417
+ */
418
+
419
+ }, {
420
+ key: 'open',
421
+ value: function open() {
422
+ var val = this.el.value.toLowerCase();
423
+
424
+ this._resetAutocomplete();
425
+
426
+ if (val.length >= this.options.minLength) {
427
+ this.isOpen = true;
428
+ this._renderDropdown(this.options.data, val);
429
+ }
430
+
431
+ // Open dropdown
432
+ if (!this.dropdown.isOpen) {
433
+ this.dropdown.open();
434
+ } else {
435
+ // Recalculate dropdown when its already open
436
+ this.dropdown.recalculateDimensions();
437
+ }
438
+ }
439
+
440
+ /**
441
+ * Close Autocomplete Dropdown
442
+ */
443
+
444
+ }, {
445
+ key: 'close',
446
+ value: function close() {
447
+ this.dropdown.close();
448
+ }
449
+
450
+ /**
451
+ * Update Data
452
+ * @param {Object} data
453
+ */
454
+
455
+ }, {
456
+ key: 'updateData',
457
+ value: function updateData(data) {
458
+ var val = this.el.value.toLowerCase();
459
+ this.options.data = data;
460
+
461
+ if (this.isOpen) {
462
+ this._renderDropdown(data, val);
463
+ }
464
+ }
465
+ }], [{
466
+ key: 'init',
467
+ value: function init(els, options) {
468
+ return _get(Autocomplete.__proto__ || Object.getPrototypeOf(Autocomplete), 'init', this).call(this, this, els, options);
469
+ }
470
+
471
+ /**
472
+ * Get Instance
473
+ */
474
+
475
+ }, {
476
+ key: 'getInstance',
477
+ value: function getInstance(el) {
478
+ var domElem = !!el.jquery ? el[0] : el;
479
+ return domElem.M_Autocomplete;
480
+ }
481
+ }, {
482
+ key: 'defaults',
483
+ get: function () {
484
+ return _defaults;
485
+ }
486
+ }]);
487
+
488
+ return Autocomplete;
489
+ }(Component);
490
+
491
+ /**
492
+ * @static
493
+ * @memberof Autocomplete
494
+ */
495
+
496
+
497
+ Autocomplete._keydown = false;
498
+
499
+ M.Autocomplete = Autocomplete;
500
+
501
+ if (M.jQueryLoaded) {
502
+ M.initializeJqueryWrapper(Autocomplete, 'autocomplete', 'M_Autocomplete');
503
+ }
504
+ })(cash);