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,530 @@
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
+ alignment: 'left',
10
+ constrainWidth: true,
11
+ coverTrigger: true,
12
+ closeOnClick: true,
13
+ hover: false,
14
+ inDuration: 150,
15
+ outDuration: 250,
16
+ onOpenStart: null,
17
+ onOpenEnd: null,
18
+ onCloseStart: null,
19
+ onCloseEnd: null
20
+ };
21
+
22
+ /**
23
+ * @class
24
+ */
25
+
26
+ var Dropdown = function () {
27
+ function Dropdown(el, options) {
28
+ _classCallCheck(this, Dropdown);
29
+
30
+ // If exists, destroy and reinitialize
31
+ if (!!el.M_Dropdown) {
32
+ el.M_Dropdown.destroy();
33
+ }
34
+
35
+ this.el = el;
36
+ this.$el = $(el);
37
+ this.el.M_Dropdown = this;
38
+ Dropdown._dropdowns.push(this);
39
+
40
+ this.id = M.getIdFromTrigger(el);
41
+ this.dropdownEl = document.getElementById(this.id);
42
+ this.$dropdownEl = $(this.dropdownEl);
43
+
44
+ /**
45
+ * Options for the dropdown
46
+ * @member Dropdown#options
47
+ * @prop {Function} onOpenStart - Function called when sidenav starts entering
48
+ * @prop {Function} onOpenEnd - Function called when sidenav finishes entering
49
+ * @prop {Function} onCloseStart - Function called when sidenav starts exiting
50
+ * @prop {Function} onCloseEnd - Function called when sidenav finishes exiting
51
+ */
52
+ this.options = $.extend({}, Dropdown.defaults, options);
53
+
54
+ /**
55
+ * Describes open/close state of dropdown
56
+ * @type {Boolean}
57
+ */
58
+ this.isOpen = false;
59
+
60
+ this.focusedIndex = null;
61
+ this.filterQuery = [];
62
+
63
+ // Move dropdown-content after dropdown-trigger
64
+ this.$el.after(this.dropdownEl);
65
+
66
+ this._makeDropdownFocusable();
67
+ this._resetFilterQueryBound = this._resetFilterQuery.bind(this);
68
+ this._handleDocumentClickBound = this._handleDocumentClick.bind(this);
69
+ this._handleDropdownKeydownBound = this._handleDropdownKeydown.bind(this);
70
+ this._handleTriggerKeydownBound = this._handleTriggerKeydown.bind(this);
71
+ this._setupEventHandlers();
72
+ }
73
+
74
+ _createClass(Dropdown, [{
75
+ key: 'destroy',
76
+
77
+
78
+ /**
79
+ * Teardown component
80
+ */
81
+ value: function destroy() {
82
+ this._resetDropdownStyles();
83
+ this._removeEventHandlers();
84
+ Dropdown._dropdowns.splice(Dropdown._dropdowns.indexOf(this), 1);
85
+ this.el.M_Dropdown = undefined;
86
+ }
87
+
88
+ /**
89
+ * Setup Event Handlers
90
+ */
91
+
92
+ }, {
93
+ key: '_setupEventHandlers',
94
+ value: function _setupEventHandlers() {
95
+ // Trigger keydown handler
96
+ this.el.addEventListener('keydown', this._handleTriggerKeydownBound);
97
+
98
+ // Hover event handlers
99
+ if (this.options.hover) {
100
+ this._handleMouseEnterBound = this._handleMouseEnter.bind(this);
101
+ this.el.addEventListener('mouseenter', this._handleMouseEnterBound);
102
+ this._handleMouseLeaveBound = this._handleMouseLeave.bind(this);
103
+ this.el.addEventListener('mouseleave', this._handleMouseLeaveBound);
104
+ this.dropdownEl.addEventListener('mouseleave', this._handleMouseLeaveBound);
105
+
106
+ // Click event handlers
107
+ } else {
108
+ this._handleClickBound = this._handleClick.bind(this);
109
+ this.el.addEventListener('click', this._handleClickBound);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Remove Event Handlers
115
+ */
116
+
117
+ }, {
118
+ key: '_removeEventHandlers',
119
+ value: function _removeEventHandlers() {
120
+ // Trigger keydown handler
121
+ this.el.removeEventListener('keydown', this._handleTriggerKeydownBound);
122
+
123
+ if (this.options.hover) {
124
+ this.el.removeEventHandlers('mouseenter', this._handleMouseEnterBound);
125
+ this.el.removeEventHandlers('mouseleave', this._handleMouseLeaveBound);
126
+ this.dropdownEl.removeEventHandlers('mouseleave', this._handleMouseLeaveBound);
127
+ } else {
128
+ this.el.removeEventListener('click', this._handleClickBound);
129
+ }
130
+ }
131
+ }, {
132
+ key: '_setupTemporaryEventHandlers',
133
+ value: function _setupTemporaryEventHandlers() {
134
+ // Use capture phase event handler to prevent click
135
+ document.body.addEventListener('click', this._handleDocumentClickBound, true);
136
+ this.dropdownEl.addEventListener('keydown', this._handleDropdownKeydownBound);
137
+ }
138
+ }, {
139
+ key: '_removeTemporaryEventHandlers',
140
+ value: function _removeTemporaryEventHandlers() {
141
+ // Use capture phase event handler to prevent click
142
+ document.body.removeEventListener('click', this._handleDocumentClickBound, true);
143
+ this.dropdownEl.removeEventListener('keydown', this._handleDropdownKeydownBound);
144
+ }
145
+ }, {
146
+ key: '_handleClick',
147
+ value: function _handleClick(e) {
148
+ e.preventDefault();
149
+ this.open();
150
+ }
151
+ }, {
152
+ key: '_handleMouseEnter',
153
+ value: function _handleMouseEnter() {
154
+ this.open();
155
+ }
156
+ }, {
157
+ key: '_handleMouseLeave',
158
+ value: function _handleMouseLeave(e) {
159
+ var toEl = e.toElement || e.relatedTarget;
160
+ var leaveToDropdownContent = !!$(toEl).closest('.dropdown-content').length;
161
+ var leaveToActiveDropdownTrigger = false;
162
+
163
+ var $closestTrigger = $(toEl).closest('.dropdown-trigger');
164
+ if ($closestTrigger.length && !!$closestTrigger[0].M_Dropdown && $closestTrigger[0].M_Dropdown.isOpen) {
165
+ leaveToActiveDropdownTrigger = true;
166
+ }
167
+
168
+ // Close hover dropdown if mouse did not leave to either active dropdown-trigger or dropdown-content
169
+ if (!leaveToActiveDropdownTrigger && !leaveToDropdownContent) {
170
+ this.close();
171
+ }
172
+ }
173
+ }, {
174
+ key: '_handleDocumentClick',
175
+ value: function _handleDocumentClick(e) {
176
+ var _this = this;
177
+
178
+ var $target = $(e.target);
179
+ if (this.options.closeOnClick && $target.closest('.dropdown-content').length) {
180
+ setTimeout(function () {
181
+ _this.close();
182
+ }, 0);
183
+ } else if ($target.closest('.dropdown-trigger').length) {
184
+ setTimeout(function () {
185
+ _this.close();
186
+ }, 0);
187
+ } else if (!$target.closest('.dropdown-content').length) {
188
+ setTimeout(function () {
189
+ _this.close();
190
+ }, 0);
191
+ }
192
+ }
193
+ }, {
194
+ key: '_handleTriggerKeydown',
195
+ value: function _handleTriggerKeydown(e) {
196
+ // ARROW DOWN OR ENTER WHEN SELECT IS CLOSED - open Dropdown
197
+ if ((e.which === M.keys.ARROW_DOWN || e.which === M.keys.ENTER) && !this.isOpen) {
198
+ e.preventDefault();
199
+ this.open();
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Handle Dropdown Keydown
205
+ * @param {Event} e
206
+ */
207
+
208
+ }, {
209
+ key: '_handleDropdownKeydown',
210
+ value: function _handleDropdownKeydown(e) {
211
+ if (e.which === M.keys.TAB) {
212
+ e.preventDefault();
213
+ this.close();
214
+
215
+ // Navigate down dropdown list
216
+ } else if ((e.which === M.keys.ARROW_DOWN || e.which === M.keys.ARROW_UP) && this.isOpen) {
217
+ e.preventDefault();
218
+ var direction = e.which === M.keys.ARROW_DOWN ? 1 : -1;
219
+ this.focusedIndex = Math.max(Math.min(this.focusedIndex + direction, this.dropdownEl.children.length - 1), 0);
220
+ this._focusFocusedItem();
221
+
222
+ // ENTER selects choice on focused item
223
+ } else if (e.which === M.keys.ENTER && this.isOpen) {
224
+ // Search for <a> and <button>
225
+ var focusedElement = this.dropdownEl.children[this.focusedIndex];
226
+ var $activatableElement = $(focusedElement).find('a, button').first();
227
+
228
+ // Click a or button tag if exists, otherwise click li tag
229
+ !!$activatableElement.length ? $activatableElement[0].click() : focusedElement.click();
230
+
231
+ // Close dropdown on ESC
232
+ } else if (e.which === M.keys.ESC && this.isOpen) {
233
+ e.preventDefault();
234
+ this.close();
235
+ }
236
+
237
+ // CASE WHEN USER TYPE LETTERS
238
+ var letter = String.fromCharCode(e.which).toLowerCase(),
239
+ nonLetters = [9, 13, 27, 38, 40];
240
+ if (letter && nonLetters.indexOf(e.which) === -1) {
241
+ this.filterQuery.push(letter);
242
+
243
+ var string = this.filterQuery.join(''),
244
+ newOptionEl = $(this.dropdownEl).find('li').filter(function (el) {
245
+ return $(el).text().toLowerCase().indexOf(string) === 0;
246
+ })[0];
247
+
248
+ if (newOptionEl) {
249
+ this.focusedIndex = $(newOptionEl).index();
250
+ this._focusFocusedItem();
251
+ }
252
+ }
253
+
254
+ this.filterTimeout = setTimeout(this._resetFilterQueryBound, 1000);
255
+ }
256
+
257
+ /**
258
+ * Setup dropdown
259
+ */
260
+
261
+ }, {
262
+ key: '_resetFilterQuery',
263
+ value: function _resetFilterQuery() {
264
+ this.filterQuery = [];
265
+ }
266
+ }, {
267
+ key: '_resetDropdownStyles',
268
+ value: function _resetDropdownStyles() {
269
+ this.$dropdownEl.css({
270
+ display: '',
271
+ width: '',
272
+ height: '',
273
+ left: '',
274
+ top: '',
275
+ 'transform-origin': '',
276
+ transform: '',
277
+ opacity: ''
278
+ });
279
+ }
280
+ }, {
281
+ key: '_makeDropdownFocusable',
282
+ value: function _makeDropdownFocusable() {
283
+ if (this.dropdownEl.tabIndex === -1) {
284
+ this.dropdownEl.tabIndex = 0;
285
+ }
286
+
287
+ $(this.dropdownEl).children().attr('tabindex', 0);
288
+ }
289
+ }, {
290
+ key: '_focusFocusedItem',
291
+ value: function _focusFocusedItem() {
292
+ this.dropdownEl.children[this.focusedIndex].focus();
293
+ }
294
+ }, {
295
+ key: '_getDropdownPosition',
296
+ value: function _getDropdownPosition() {
297
+ var offsetParentBRect = this.el.offsetParent.getBoundingClientRect();
298
+ var triggerOffset = { left: this.el.offsetLeft, top: this.el.offsetTop, width: this.el.offsetWidth, height: this.el.offsetHeight };
299
+ var dropdownOffset = { left: this.dropdownEl.offsetLeft, top: this.dropdownEl.offsetTop, width: this.dropdownEl.offsetWidth, height: this.dropdownEl.offsetHeight };
300
+ var triggerBRect = this.el.getBoundingClientRect();
301
+ var dropdownBRect = this.dropdownEl.getBoundingClientRect();
302
+
303
+ var idealHeight = dropdownBRect.height;
304
+ var idealWidth = dropdownBRect.width;
305
+ var idealXPos = triggerOffset.left;
306
+ var idealYPos = triggerOffset.top;
307
+
308
+ var dropdownBounds = {
309
+ left: idealXPos,
310
+ top: idealYPos,
311
+ height: idealHeight,
312
+ width: idealWidth
313
+ };
314
+
315
+ // Countainer here will be closest ancestor with overflow: hidden
316
+ var closestOverflowParent = this.dropdownEl.offsetParent;
317
+ var alignments = M.checkPossibleAlignments(this.el, closestOverflowParent, dropdownBounds, this.options.coverTrigger ? 0 : triggerBRect.height);
318
+
319
+ var verticalAlignment = 'top';
320
+ var horizontalAlignment = this.options.alignment;
321
+ idealYPos += this.options.coverTrigger ? 0 : triggerBRect.height;
322
+ if (!alignments.top) {
323
+ if (alignments.bottom) {
324
+ verticalAlignment = 'bottom';
325
+ } else {
326
+ // Determine which side has most space and cutoff at correct height
327
+ if (alignments.spaceOnTop > alignments.spaceOnBottom) {
328
+ verticalAlignment = 'bottom';
329
+ idealHeight += alignments.spaceOnTop;
330
+ idealYPos -= alignments.spaceOnTop;
331
+ } else {
332
+ idealHeight += alignments.spaceOnBottom;
333
+ }
334
+ }
335
+ }
336
+
337
+ // If preferred horizontal alignment is possible
338
+ if (!alignments[horizontalAlignment]) {
339
+ var oppositeAlignment = horizontalAlignment === 'left' ? 'right' : 'left';
340
+ if (alignments[oppositeAlignment]) {
341
+ horizontalAlignment = oppositeAlignment;
342
+ } else {
343
+ // Determine which side has most space and cutoff at correct height
344
+ if (alignments.spaceOnLeft > alignments.spaceOnRight) {
345
+ horizontalAlignment = 'right';
346
+ idealWidth += alignments.spaceOnLeft;
347
+ idealXPos -= alignments.spaceOnLeft;
348
+ } else {
349
+ horizontalAlignment = 'left';
350
+ idealWidth += alignments.spaceOnRight;
351
+ }
352
+ }
353
+ }
354
+
355
+ if (verticalAlignment === 'bottom') {
356
+ idealYPos = idealYPos - dropdownBRect.height + (this.options.coverTrigger ? triggerBRect.height : 0);
357
+ }
358
+ if (horizontalAlignment === 'right') {
359
+ idealXPos = idealXPos - dropdownBRect.width + triggerBRect.width;
360
+ }
361
+ return { x: idealXPos,
362
+ y: idealYPos,
363
+ verticalAlignment: verticalAlignment,
364
+ horizontalAlignment: horizontalAlignment,
365
+ height: idealHeight,
366
+ width: idealWidth };
367
+ }
368
+
369
+ /**
370
+ * Animate in dropdown
371
+ */
372
+
373
+ }, {
374
+ key: '_animateIn',
375
+ value: function _animateIn(positionInfo) {
376
+ var _this2 = this;
377
+
378
+ // Place dropdown
379
+ this.dropdownEl.style.left = positionInfo.x + 'px';
380
+ this.dropdownEl.style.top = positionInfo.y + 'px';
381
+ this.dropdownEl.style.height = positionInfo.height + 'px';
382
+ this.dropdownEl.style.width = positionInfo.width + 'px';
383
+ this.dropdownEl.style.transformOrigin = (positionInfo.horizontalAlignment === 'left' ? '0' : '100%') + ' ' + (positionInfo.verticalAlignment === 'top' ? '0' : '100%');
384
+
385
+ Vel(this.dropdownEl, {
386
+ opacity: [1, 'easeOutQuad'],
387
+ scaleX: [1, .3],
388
+ scaleY: [1, .3] }, {
389
+ duration: this.options.inDuration,
390
+ queue: false,
391
+ easing: 'easeOutQuint',
392
+ complete: function () {
393
+ _this2._focusFocusedItem();
394
+
395
+ // onOpenEnd callback
396
+ if (typeof _this2.options.onOpenEnd === 'function') {
397
+ _this2.options.onOpenEnd.call(_this2, _this2.el);
398
+ }
399
+ }
400
+ });
401
+ }
402
+
403
+ /**
404
+ * Animate out dropdown
405
+ */
406
+
407
+ }, {
408
+ key: '_animateOut',
409
+ value: function _animateOut() {
410
+ var _this3 = this;
411
+
412
+ Vel(this.dropdownEl, {
413
+ opacity: [0, 'easeOutQuint'],
414
+ scaleX: [.3, 1],
415
+ scaleY: [.3, 1] }, {
416
+ duration: this.options.outDuration,
417
+ queue: false,
418
+ easing: 'easeOutQuint',
419
+ complete: function () {
420
+ _this3._resetDropdownStyles();
421
+
422
+ // onCloseEnd callback
423
+ if (typeof _this3.options.onCloseEnd === 'function') {
424
+ _this3.options.onCloseEnd.call(_this3, _this3.el);
425
+ }
426
+ }
427
+ });
428
+ }
429
+
430
+ /**
431
+ * Open Dropdown
432
+ */
433
+
434
+ }, {
435
+ key: 'open',
436
+ value: function open() {
437
+ if (this.isOpen) {
438
+ return;
439
+ }
440
+ this.isOpen = true;
441
+
442
+ // Highlight focused item
443
+ if (this.focusedIndex === null) {
444
+ this.focusedIndex = 0;
445
+ }
446
+
447
+ // onOpenStart callback
448
+ if (typeof this.options.onOpenStart === 'function') {
449
+ this.options.onOpenStart.call(this, this.el);
450
+ }
451
+
452
+ // Stop any previous animation
453
+ Vel(this.dropdownEl, 'stop');
454
+ this._resetDropdownStyles();
455
+ Vel.hook(this.dropdownEl, 'display', 'block');
456
+
457
+ // Set width before calculating positionInfo
458
+ var idealWidth = this.options.constrainWidth ? this.el.getBoundingClientRect().width : this.dropdownEl.getBoundingClientRect().width;
459
+ this.dropdownEl.style.width = idealWidth + 'px';
460
+
461
+ var positionInfo = this._getDropdownPosition();
462
+ this._animateIn(positionInfo);
463
+ this._setupTemporaryEventHandlers();
464
+ }
465
+
466
+ /**
467
+ * Close Dropdown
468
+ */
469
+
470
+ }, {
471
+ key: 'close',
472
+ value: function close() {
473
+ if (!this.isOpen) {
474
+ return;
475
+ }
476
+ this.isOpen = false;
477
+
478
+ // onCloseStart callback
479
+ if (typeof this.options.onCloseStart === 'function') {
480
+ this.options.onCloseStart.call(this, this.el);
481
+ }
482
+
483
+ this._animateOut();
484
+ this._removeTemporaryEventHandlers();
485
+ this.el.focus();
486
+ }
487
+ }], [{
488
+ key: 'init',
489
+ value: function init($els, options) {
490
+ var arr = [];
491
+ $els.each(function () {
492
+ arr.push(new Dropdown(this, options));
493
+ });
494
+ return arr;
495
+ }
496
+
497
+ /**
498
+ * Get Instance
499
+ */
500
+
501
+ }, {
502
+ key: 'getInstance',
503
+ value: function getInstance(el) {
504
+ var domElem = !!el.jquery ? el[0] : el;
505
+ return domElem.M_Dropdown;
506
+ }
507
+ }, {
508
+ key: 'defaults',
509
+ get: function () {
510
+ return _defaults;
511
+ }
512
+ }]);
513
+
514
+ return Dropdown;
515
+ }();
516
+
517
+ /**
518
+ * @static
519
+ * @memberof Dropdown
520
+ */
521
+
522
+
523
+ Dropdown._dropdowns = [];
524
+
525
+ window.M.Dropdown = Dropdown;
526
+
527
+ if (M.jQueryLoaded) {
528
+ M.initializeJqueryWrapper(Dropdown, 'dropdown', 'M_Dropdown');
529
+ }
530
+ })(cash, M.Vel);