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
@@ -0,0 +1,420 @@
1
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2
+
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+
5
+ (function ($) {
6
+ 'use strict';
7
+
8
+ var _defaults = {
9
+ data: {}, // Autocomplete data set
10
+ limit: Infinity, // Limit of results the autocomplete shows
11
+ onAutocomplete: null, // Callback for when autocompleted
12
+ minLength: 1, // Min characters before autocomplete starts
13
+ sortFunction: function (a, b, inputString) {
14
+ // Sort function for sorting autocomplete results
15
+ return a.indexOf(inputString) - b.indexOf(inputString);
16
+ }
17
+ };
18
+
19
+ /**
20
+ * @class
21
+ *
22
+ */
23
+
24
+ var Autocomplete = function () {
25
+ /**
26
+ * Construct Autocomplete instance
27
+ * @constructor
28
+ * @param {Element} el
29
+ * @param {Object} options
30
+ */
31
+ function Autocomplete(el, options) {
32
+ _classCallCheck(this, Autocomplete);
33
+
34
+ // If exists, destroy and reinitialize
35
+ if (!!el.M_Autocomplete) {
36
+ el.M_Autocomplete.destroy();
37
+ }
38
+
39
+ this.el = el;
40
+ this.$el = $(el);
41
+ this.el.M_Autocomplete = this;
42
+
43
+ /**
44
+ * Options for the autocomplete
45
+ * @member Autocomplete#options
46
+ * @prop {Number} duration
47
+ * @prop {Number} dist
48
+ * @prop {number} shift
49
+ * @prop {number} padding
50
+ * @prop {Boolean} fullWidth
51
+ * @prop {Boolean} indicators
52
+ * @prop {Boolean} noWrap
53
+ * @prop {Function} onCycleTo
54
+ */
55
+ this.options = $.extend({}, Autocomplete.defaults, options);
56
+
57
+ // Setup
58
+ this.isOpen = false;
59
+ this.count = 0;
60
+ this.activeIndex = -1;
61
+ this.oldVal;
62
+ this.$inputField = this.$el.closest('.input-field');
63
+ this.$active = $();
64
+ this._setupDropdown();
65
+
66
+ this._setupEventHandlers();
67
+ }
68
+
69
+ _createClass(Autocomplete, [{
70
+ key: 'destroy',
71
+
72
+
73
+ /**
74
+ * Teardown component
75
+ */
76
+ value: function destroy() {
77
+ this._removeEventHandlers();
78
+ this._removeDropdown();
79
+ this.el.M_Autocomplete = undefined;
80
+ }
81
+
82
+ /**
83
+ * Setup Event Handlers
84
+ */
85
+
86
+ }, {
87
+ key: '_setupEventHandlers',
88
+ value: function _setupEventHandlers() {
89
+ this._handleInputBlurBound = this._handleInputBlur.bind(this);
90
+ this._handleInputKeyupAndFocusBound = this._handleInputKeyupAndFocus.bind(this);
91
+ this._handleInputKeydownBound = this._handleInputKeydown.bind(this);
92
+ this._handleContainerMousedownAndTouchstartBound = this._handleContainerMousedownAndTouchstart.bind(this);
93
+
94
+ this.el.addEventListener('blur', this._handleInputBlurBound);
95
+ this.el.addEventListener('keyup', this._handleInputKeyupAndFocusBound);
96
+ this.el.addEventListener('focus', this._handleInputKeyupAndFocusBound);
97
+ this.el.addEventListener('keydown', this._handleInputKeydownBound);
98
+ this.container.addEventListener('mousedown', this._handleContainerMousedownAndTouchstartBound);
99
+
100
+ if (typeof window.ontouchstart !== 'undefined') {
101
+ this.container.addEventListener('touchstart', this._handleContainerMousedownAndTouchstartBound);
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Remove Event Handlers
107
+ */
108
+
109
+ }, {
110
+ key: '_removeEventHandlers',
111
+ value: function _removeEventHandlers() {
112
+ this.el.removeEventListener('blur', this._handleInputBlurBound);
113
+ this.el.removeEventListener('keyup', this._handleInputKeyupAndFocusBound);
114
+ this.el.removeEventListener('focus', this._handleInputKeyupAndFocusBound);
115
+ this.el.removeEventListener('keydown', this._handleInputKeydownBound);
116
+ this.container.removeEventListener('mousedown', this._handleContainerMousedownAndTouchstartBound);
117
+
118
+ if (typeof window.ontouchstart !== 'undefined') {
119
+ this.container.removeEventListener('touchstart', this._handleContainerMousedownAndTouchstartBound);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Setup dropdown
125
+ */
126
+
127
+ }, {
128
+ key: '_setupDropdown',
129
+ value: function _setupDropdown() {
130
+ this.container = document.createElement('ul');
131
+ $(this.container).addClass('autocomplete-content dropdown-content');
132
+ this.$inputField.append(this.container);
133
+ }
134
+
135
+ /**
136
+ * Remove dropdown
137
+ */
138
+
139
+ }, {
140
+ key: '_removeDropdown',
141
+ value: function _removeDropdown() {
142
+ this.container.parentNode.removeChild(this.container);
143
+ }
144
+
145
+ /**
146
+ * Handle Input Blur
147
+ */
148
+
149
+ }, {
150
+ key: '_handleInputBlur',
151
+ value: function _handleInputBlur() {
152
+ this._removeAutocomplete();
153
+ }
154
+
155
+ /**
156
+ * Handle Input Keyup and Focus
157
+ * @param {Event} e
158
+ */
159
+
160
+ }, {
161
+ key: '_handleInputKeyupAndFocus',
162
+ value: function _handleInputKeyupAndFocus(e) {
163
+ if (e.type === 'keyup') {
164
+ Autocomplete._keydown = false;
165
+ }
166
+
167
+ this.count = 0;
168
+ var val = this.el.value.toLowerCase();
169
+
170
+ // Don't capture enter or arrow key usage.
171
+ if (e.keyCode === 13 || e.keyCode === 38 || e.keyCode === 40) {
172
+ return;
173
+ }
174
+
175
+ // Check if the input isn't empty
176
+ if (this.oldVal !== val) {
177
+ this._removeAutocomplete();
178
+
179
+ if (val.length >= this.options.minLength) {
180
+ this.isOpen = true;
181
+ this._renderDropdown(this.options.data, val);
182
+ }
183
+ }
184
+
185
+ // Update oldVal
186
+ this.oldVal = val;
187
+ }
188
+
189
+ /**
190
+ * Handle Input Keydown
191
+ * @param {Event} e
192
+ */
193
+
194
+ }, {
195
+ key: '_handleInputKeydown',
196
+ value: function _handleInputKeydown(e) {
197
+ Autocomplete._keydown = true;
198
+
199
+ // Arrow keys and enter key usage
200
+ var keyCode = e.keyCode,
201
+ liElement = void 0,
202
+ numItems = $(this.container).children('li').length;
203
+
204
+ // select element on Enter
205
+ if (keyCode === 13 && this.activeIndex >= 0) {
206
+ liElement = $(this.container).children('li').eq(this.activeIndex);
207
+ if (liElement.length) {
208
+ this.selectOption(liElement);
209
+ e.preventDefault();
210
+ }
211
+ return;
212
+ }
213
+
214
+ // Capture up and down key
215
+ if (keyCode === 38 || keyCode === 40) {
216
+ e.preventDefault();
217
+
218
+ if (keyCode === 38 && this.activeIndex > 0) {
219
+ this.activeIndex--;
220
+ }
221
+
222
+ if (keyCode === 40 && this.activeIndex < numItems - 1) {
223
+ this.activeIndex++;
224
+ }
225
+
226
+ this.$active.removeClass('active');
227
+ if (this.activeIndex >= 0) {
228
+ this.$active = $(this.container).children('li').eq(this.activeIndex);
229
+ this.$active.addClass('active');
230
+ }
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Handle Container Mousedown and Touchstart
236
+ * @param {Event} e
237
+ */
238
+
239
+ }, {
240
+ key: '_handleContainerMousedownAndTouchstart',
241
+ value: function _handleContainerMousedownAndTouchstart(e) {
242
+ var $autocompleteOption = $(e.target).closest('li');
243
+ this.selectOption($autocompleteOption);
244
+ }
245
+
246
+ /**
247
+ * Highlight partial match
248
+ */
249
+
250
+ }, {
251
+ key: '_highlight',
252
+ value: function _highlight(string, $el) {
253
+ var img = $el.find('img');
254
+ var matchStart = $el.text().toLowerCase().indexOf("" + string.toLowerCase() + ""),
255
+ matchEnd = matchStart + string.length - 1,
256
+ beforeMatch = $el.text().slice(0, matchStart),
257
+ matchText = $el.text().slice(matchStart, matchEnd + 1),
258
+ afterMatch = $el.text().slice(matchEnd + 1);
259
+ $el.html("<span>" + beforeMatch + "<span class='highlight'>" + matchText + "</span>" + afterMatch + "</span>");
260
+ if (img.length) {
261
+ $el.prepend(img);
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Reset current element position
267
+ */
268
+
269
+ }, {
270
+ key: '_resetCurrentElement',
271
+ value: function _resetCurrentElement() {
272
+ this.activeIndex = -1;
273
+ this.$active.removeClass('active');
274
+ }
275
+
276
+ /**
277
+ * Remove autocomplete elements
278
+ */
279
+
280
+ }, {
281
+ key: '_removeAutocomplete',
282
+ value: function _removeAutocomplete() {
283
+ $(this.container).empty();
284
+ this._resetCurrentElement();
285
+ this.oldVal = null;
286
+ this.isOpen = false;
287
+ }
288
+
289
+ /**
290
+ * Select autocomplete option
291
+ * @param {Element} el Autocomplete option list item element
292
+ */
293
+
294
+ }, {
295
+ key: 'selectOption',
296
+ value: function selectOption(el) {
297
+ var text = el.text().trim();
298
+ this.el.value = text;
299
+ this.$el.trigger('change');
300
+ this._removeAutocomplete();
301
+
302
+ // Handle onAutocomplete callback.
303
+ if (typeof this.options.onAutocomplete === 'function') {
304
+ this.options.onAutocomplete.call(this, text);
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Render dropdown content
310
+ * @param {Object} data data set
311
+ * @param {String} val current input value
312
+ */
313
+
314
+ }, {
315
+ key: '_renderDropdown',
316
+ value: function _renderDropdown(data, val) {
317
+ var _this = this;
318
+
319
+ this._removeAutocomplete();
320
+
321
+ var matchingData = [];
322
+
323
+ // Gather all matching data
324
+ for (var key in data) {
325
+ if (data.hasOwnProperty(key) && key.toLowerCase().indexOf(val) !== -1) {
326
+ // Break if past limit
327
+ if (this.count >= this.options.limit) {
328
+ break;
329
+ }
330
+
331
+ var entry = {
332
+ data: data[key],
333
+ key: key
334
+ };
335
+ matchingData.push(entry);
336
+
337
+ this.count++;
338
+ }
339
+ }
340
+
341
+ // Sort
342
+ var sortFunctionBound = function (a, b) {
343
+ return _this.options.sortFunction(a.key.toLowerCase(), b.key.toLowerCase(), val.toLowerCase());
344
+ };
345
+ matchingData.sort(sortFunctionBound);
346
+
347
+ // Render
348
+ for (var i = 0; i < matchingData.length; i++) {
349
+ var _entry = matchingData[i];
350
+ var $autocompleteOption = $('<li></li>');
351
+ if (!!_entry.data) {
352
+ $autocompleteOption.append('<img src="' + _entry.data + '" class="right circle"><span>' + _entry.key + '</span>');
353
+ } else {
354
+ $autocompleteOption.append('<span>' + _entry.key + '</span>');
355
+ }
356
+
357
+ $(this.container).append($autocompleteOption);
358
+ this._highlight(val, $autocompleteOption);
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Update Data
364
+ * @param {Object} data
365
+ */
366
+
367
+ }, {
368
+ key: 'updateData',
369
+ value: function updateData(data) {
370
+ var val = this.el.value.toLowerCase();
371
+ this.options.data = data;
372
+
373
+ if (this.isOpen) {
374
+ this._renderDropdown(data, val);
375
+ }
376
+ }
377
+ }], [{
378
+ key: 'init',
379
+ value: function init($els, options) {
380
+ var arr = [];
381
+ $els.each(function () {
382
+ arr.push(new Autocomplete(this, options));
383
+ });
384
+ return arr;
385
+ }
386
+
387
+ /**
388
+ * Get Instance
389
+ */
390
+
391
+ }, {
392
+ key: 'getInstance',
393
+ value: function getInstance(el) {
394
+ var domElem = !!el.jquery ? el[0] : el;
395
+ return domElem.M_Autocomplete;
396
+ }
397
+ }, {
398
+ key: 'defaults',
399
+ get: function () {
400
+ return _defaults;
401
+ }
402
+ }]);
403
+
404
+ return Autocomplete;
405
+ }();
406
+
407
+ /**
408
+ * @static
409
+ * @memberof Autocomplete
410
+ */
411
+
412
+
413
+ Autocomplete._keydown = false;
414
+
415
+ M.Autocomplete = Autocomplete;
416
+
417
+ if (M.jQueryLoaded) {
418
+ M.initializeJqueryWrapper(Autocomplete, 'autocomplete', 'M_Autocomplete');
419
+ }
420
+ })(cash);
@@ -0,0 +1,388 @@
1
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2
+
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+
5
+ (function ($, Vel) {
6
+ 'use strict';
7
+
8
+ var _defaults = {
9
+ direction: 'top',
10
+ hoverEnabled: true,
11
+ toolbarEnabled: false
12
+ };
13
+
14
+ $.fn.reverse = [].reverse;
15
+
16
+ /**
17
+ * @class
18
+ *
19
+ */
20
+
21
+ var FloatingActionButton = function () {
22
+ /**
23
+ * Construct FloatingActionButton instance
24
+ * @constructor
25
+ * @param {Element} el
26
+ * @param {Object} options
27
+ */
28
+ function FloatingActionButton(el, options) {
29
+ _classCallCheck(this, FloatingActionButton);
30
+
31
+ // If exists, destroy and reinitialize
32
+ if (!!el.M_FloatingActionButton) {
33
+ el.M_FloatingActionButton.destroy();
34
+ }
35
+
36
+ this.el = el;
37
+ this.$el = $(el);
38
+ this.el.M_FloatingActionButton = this;
39
+
40
+ /**
41
+ * Options for the fab
42
+ * @member FloatingActionButton#options
43
+ * @prop {Boolean} [direction] - Direction fab menu opens
44
+ * @prop {Boolean} [hoverEnabled=true] - Enable hover vs click
45
+ * @prop {Boolean} [toolbarEnabled=false] - Enable toolbar transition
46
+ */
47
+ this.options = $.extend({}, FloatingActionButton.defaults, options);
48
+
49
+ this.isOpen = false;
50
+ this.$anchor = this.$el.children('a').first();
51
+ this.$menu = this.$el.children('ul').first();
52
+ this.$floatingBtns = this.$el.find('ul .btn-floating');
53
+ this.$floatingBtnsReverse = this.$el.find('ul .btn-floating').reverse();
54
+ if (this.options.direction === 'top') {
55
+ this.$el.addClass('direction-top');
56
+ this.offsetY = 40;
57
+ } else if (this.options.direction === 'right') {
58
+ this.$el.addClass('direction-right');
59
+ this.offsetX = -40;
60
+ } else if (this.options.direction === 'bottom') {
61
+ this.$el.addClass('direction-bottom');
62
+ this.offsetY = -40;
63
+ } else {
64
+ this.$el.addClass('direction-left');
65
+ this.offsetX = 40;
66
+ }
67
+ this._setupEventHandlers();
68
+ }
69
+
70
+ _createClass(FloatingActionButton, [{
71
+ key: 'destroy',
72
+
73
+
74
+ /**
75
+ * Teardown component
76
+ */
77
+ value: function destroy() {
78
+ this._removeEventHandlers();
79
+ this.el.M_FloatingActionButton = undefined;
80
+ }
81
+
82
+ /**
83
+ * Setup Event Handlers
84
+ */
85
+
86
+ }, {
87
+ key: '_setupEventHandlers',
88
+ value: function _setupEventHandlers() {
89
+ this._handleFABClickBound = this._handleFABClick.bind(this);
90
+ this._handleOpenBound = this.open.bind(this);
91
+ this._handleCloseBound = this.close.bind(this);
92
+
93
+ if (this.options.hoverEnabled && !this.options.toolbarEnabled) {
94
+ this.el.addEventListener('mouseenter', this._handleOpenBound);
95
+ this.el.addEventListener('mouseleave', this._handleCloseBound);
96
+ } else {
97
+ this.el.addEventListener('click', this._handleFABClickBound);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Remove Event Handlers
103
+ */
104
+
105
+ }, {
106
+ key: '_removeEventHandlers',
107
+ value: function _removeEventHandlers() {
108
+ if (this.options.hoverEnabled && !this.options.toolbarEnabled) {
109
+ this.el.removeEventListener('mouseenter', this._handleOpenBound);
110
+ this.el.removeEventListener('mouseleave', this._handleCloseBound);
111
+ } else {
112
+ this.el.removeEventListener('click', this._handleFABClickBound);
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Handle FAB Click
118
+ */
119
+
120
+ }, {
121
+ key: '_handleFABClick',
122
+ value: function _handleFABClick() {
123
+ if (this.isOpen) {
124
+ this.close();
125
+ } else {
126
+ this.open();
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Handle Document Click
132
+ * @param {Event} e
133
+ */
134
+
135
+ }, {
136
+ key: '_handleDocumentClick',
137
+ value: function _handleDocumentClick(e) {
138
+ if (!$(e.target).closest(this.$menu).length) {
139
+ this.close();
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Open FAB
145
+ */
146
+
147
+ }, {
148
+ key: 'open',
149
+ value: function open() {
150
+ if (this.isOpen) {
151
+ return;
152
+ }
153
+
154
+ if (this.options.toolbarEnabled) {
155
+ this._animateInToolbar();
156
+ } else {
157
+ this._animateInFAB();
158
+ }
159
+ this.isOpen = true;
160
+ }
161
+
162
+ /**
163
+ * Close FAB
164
+ */
165
+
166
+ }, {
167
+ key: 'close',
168
+ value: function close() {
169
+ if (!this.isOpen) {
170
+ return;
171
+ }
172
+
173
+ if (this.options.toolbarEnabled) {
174
+ window.removeEventListener('scroll', this._handleCloseBound, true);
175
+ document.body.removeEventListener('click', this._handleDocumentClickBound, true);
176
+ this._animateOutToolbar();
177
+ } else {
178
+ this._animateOutFAB();
179
+ }
180
+ this.isOpen = false;
181
+ }
182
+
183
+ /**
184
+ * Classic FAB Menu open
185
+ */
186
+
187
+ }, {
188
+ key: '_animateInFAB',
189
+ value: function _animateInFAB() {
190
+ this.$el.addClass('active');
191
+ Vel.hook(this.$floatingBtns, 'scaleX', 0.4);
192
+ Vel.hook(this.$floatingBtns, 'scaleY', 0.4);
193
+ Vel.hook(this.$floatingBtns, 'translateY', this.offsetY + 'px');
194
+ Vel.hook(this.$floatingBtns, 'translateX', this.offsetX + 'px');
195
+
196
+ var time = 0;
197
+ this.$floatingBtnsReverse.each(function () {
198
+ Vel(this, { opacity: "1", scaleX: 1, scaleY: 1, translateY: 0, translateX: 0 }, { duration: 80, delay: time });
199
+ time += 40;
200
+ });
201
+ }
202
+
203
+ /**
204
+ * Classic FAB Menu close
205
+ */
206
+
207
+ }, {
208
+ key: '_animateOutFAB',
209
+ value: function _animateOutFAB() {
210
+ this.$el.removeClass('active');
211
+ Vel(this.$floatingBtns, 'stop');
212
+ Vel(this.$floatingBtns, { opacity: "0", scaleX: .4, scaleY: .4, translateY: this.offsetY, translateX: this.offsetX }, { duration: 80 });
213
+ }
214
+
215
+ /**
216
+ * Toolbar transition Menu open
217
+ */
218
+
219
+ }, {
220
+ key: '_animateInToolbar',
221
+ value: function _animateInToolbar() {
222
+ var _this = this;
223
+
224
+ var scaleFactor = void 0;
225
+ var windowWidth = window.innerWidth;
226
+ var windowHeight = window.innerHeight;
227
+ var btnRect = this.el.getBoundingClientRect();
228
+ var backdrop = $('<div class="fab-backdrop"></div>');
229
+ var fabColor = this.$anchor.css('background-color');
230
+ this.$anchor.append(backdrop);
231
+
232
+ this.offsetX = btnRect.left - windowWidth / 2 + btnRect.width / 2;
233
+ this.offsetY = windowHeight - btnRect.bottom;
234
+ scaleFactor = windowWidth / backdrop[0].clientWidth;
235
+ this.btnBottom = btnRect.bottom;
236
+ this.btnLeft = btnRect.left;
237
+ this.btnWidth = btnRect.width;
238
+
239
+ // Set initial state
240
+ this.$el.addClass('active');
241
+ this.$el.css({
242
+ 'text-align': 'center',
243
+ width: '100%',
244
+ bottom: 0,
245
+ left: 0,
246
+ transform: 'translateX(' + this.offsetX + 'px)',
247
+ transition: 'none'
248
+ });
249
+ this.$anchor.css({
250
+ transform: 'translateY(' + -this.offsetY + 'px)',
251
+ transition: 'none'
252
+ });
253
+ backdrop.css({
254
+ 'background-color': fabColor
255
+ });
256
+
257
+ setTimeout(function () {
258
+ _this.$el.css({
259
+ transform: '',
260
+ transition: 'transform .2s cubic-bezier(0.550, 0.085, 0.680, 0.530), background-color 0s linear .2s'
261
+ });
262
+ _this.$anchor.css({
263
+ overflow: 'visible',
264
+ transform: '',
265
+ transition: 'transform .2s'
266
+ });
267
+
268
+ setTimeout(function () {
269
+ _this.$el.css({
270
+ overflow: 'hidden',
271
+ 'background-color': fabColor
272
+ });
273
+ backdrop.css({
274
+ transform: 'scale(' + scaleFactor + ')',
275
+ transition: 'transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)'
276
+ });
277
+ _this.$menu.children('li').children('a').css({
278
+ opacity: 1
279
+ });
280
+
281
+ // Scroll to close.
282
+ _this._handleDocumentClickBound = _this._handleDocumentClick.bind(_this);
283
+ window.addEventListener('scroll', _this._handleCloseBound, true);
284
+ document.body.addEventListener('click', _this._handleDocumentClickBound, true);
285
+ }, 100);
286
+ }, 0);
287
+ }
288
+
289
+ /**
290
+ * Toolbar transition Menu close
291
+ */
292
+
293
+ }, {
294
+ key: '_animateOutToolbar',
295
+ value: function _animateOutToolbar() {
296
+ var _this2 = this;
297
+
298
+ var windowWidth = window.innerWidth;
299
+ var windowHeight = window.innerHeight;
300
+ var backdrop = this.$el.find('.fab-backdrop');
301
+ var fabColor = anchor.css('background-color');
302
+
303
+ this.offsetX = this.btnLeft - windowWidth / 2 + this.btnWidth / 2;
304
+ this.offsetY = windowHeight - this.btnBottom;
305
+
306
+ // Hide backdrop
307
+ this.$el.removeClass('active');
308
+ this.$el.css({
309
+ 'background-color': 'transparent',
310
+ transition: 'none'
311
+ });
312
+ this.$anchor.css({
313
+ transition: 'none'
314
+ });
315
+ backdrop.css({
316
+ transform: 'scale(0)',
317
+ 'background-color': fabColor
318
+ });
319
+ this.$menu.children('li').children('a').css({
320
+ opacity: ''
321
+ });
322
+
323
+ setTimeout(function () {
324
+ backdrop.remove();
325
+
326
+ // Set initial state.
327
+ _this2.$el.css({
328
+ 'text-align': '',
329
+ width: '',
330
+ bottom: '',
331
+ left: '',
332
+ overflow: '',
333
+ 'background-color': '',
334
+ transform: 'translate3d(' + -_this2.offsetX + 'px,0,0)'
335
+ });
336
+ _this2.$anchor.css({
337
+ overflow: '',
338
+ transform: 'translate3d(0,' + _this2.offsetY + 'px,0)'
339
+ });
340
+
341
+ setTimeout(function () {
342
+ _this2.$el.css({
343
+ transform: 'translate3d(0,0,0)',
344
+ transition: 'transform .2s'
345
+ });
346
+ _this2.$anchor.css({
347
+ transform: 'translate3d(0,0,0)',
348
+ transition: 'transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)'
349
+ });
350
+ }, 20);
351
+ }, 200);
352
+ }
353
+ }], [{
354
+ key: 'init',
355
+ value: function init($els, options) {
356
+ var arr = [];
357
+ $els.each(function () {
358
+ arr.push(new FloatingActionButton(this, options));
359
+ });
360
+ return arr;
361
+ }
362
+
363
+ /**
364
+ * Get Instance
365
+ */
366
+
367
+ }, {
368
+ key: 'getInstance',
369
+ value: function getInstance(el) {
370
+ var domElem = !!el.jquery ? el[0] : el;
371
+ return domElem.M_FloatingActionButton;
372
+ }
373
+ }, {
374
+ key: 'defaults',
375
+ get: function () {
376
+ return _defaults;
377
+ }
378
+ }]);
379
+
380
+ return FloatingActionButton;
381
+ }();
382
+
383
+ M.FloatingActionButton = FloatingActionButton;
384
+
385
+ if (M.jQueryLoaded) {
386
+ M.initializeJqueryWrapper(FloatingActionButton, 'floatingActionButton', 'M_FloatingActionButton');
387
+ }
388
+ })(cash, M.Vel);