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.
- checksums.yaml +5 -5
- data/.gitattributes +1 -0
- data/.gitignore +1 -0
- data/README.md +34 -32
- data/Rakefile +38 -21
- data/assets/javascripts/materialize/anime.min.js +417 -0
- data/assets/javascripts/materialize/autocomplete.js +504 -0
- data/assets/javascripts/materialize/buttons.js +409 -0
- data/assets/javascripts/materialize/cards.js +34 -0
- data/assets/javascripts/materialize/carousel.js +797 -0
- data/assets/javascripts/materialize/cash.js +990 -0
- data/assets/javascripts/materialize/characterCounter.js +180 -0
- data/assets/javascripts/materialize/chips.js +564 -0
- data/assets/javascripts/materialize/collapsible.js +337 -0
- data/assets/javascripts/materialize/component.js +57 -0
- data/assets/javascripts/materialize/datepicker.js +935 -0
- data/assets/javascripts/materialize/dropdown.js +659 -0
- data/assets/javascripts/materialize/extras/nouislider.js +2147 -0
- data/assets/javascripts/materialize/extras/nouislider.min.js +1 -0
- data/assets/javascripts/materialize/forms.js +244 -0
- data/assets/javascripts/materialize/global.js +408 -0
- data/assets/javascripts/materialize/materialbox.js +513 -0
- data/assets/javascripts/materialize/modal.js +449 -0
- data/assets/javascripts/materialize/parallax.js +173 -0
- data/assets/javascripts/materialize/pushpin.js +179 -0
- data/assets/javascripts/materialize/range.js +310 -0
- data/assets/javascripts/materialize/scrollspy.js +328 -0
- data/assets/javascripts/materialize/select.js +497 -0
- data/assets/javascripts/materialize/sidenav.js +655 -0
- data/assets/javascripts/materialize/slider.js +424 -0
- data/assets/javascripts/materialize/tabs.js +476 -0
- data/assets/javascripts/materialize/tapTarget.js +364 -0
- data/assets/javascripts/materialize/timepicker.js +647 -0
- data/assets/javascripts/materialize/toasts.js +355 -0
- data/assets/javascripts/materialize/tooltip.js +351 -0
- data/{app/assets → assets}/javascripts/materialize/waves.js +42 -47
- data/{app/assets → assets}/javascripts/materialize-sprockets.js +12 -13
- data/assets/javascripts/materialize.js +12374 -0
- data/assets/stylesheets/materialize/components/_badges.scss +55 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_buttons.scss +99 -58
- data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +14 -6
- data/{app/assets → assets}/stylesheets/materialize/components/_carousel.scss +12 -7
- data/{app/assets → assets}/stylesheets/materialize/components/_chips.scss +13 -6
- data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +16 -15
- data/assets/stylesheets/materialize/components/_color-classes.scss +32 -0
- data/{app/assets/stylesheets/materialize/components/_color.scss → assets/stylesheets/materialize/components/_color-variables.scss} +2 -44
- data/assets/stylesheets/materialize/components/_datepicker.scss +191 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_dropdown.scss +35 -15
- data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +96 -125
- data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +45 -36
- data/{app/assets → assets}/stylesheets/materialize/components/_icons-material-design.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +13 -12
- data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +7 -3
- data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +29 -11
- data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +2 -2
- data/assets/stylesheets/materialize/components/_pulse.scss +34 -0
- data/{app/assets/stylesheets/materialize/components/_sideNav.scss → assets/stylesheets/materialize/components/_sidenav.scss} +47 -47
- data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +5 -5
- data/{app/assets → assets}/stylesheets/materialize/components/_tabs.scss +10 -10
- data/assets/stylesheets/materialize/components/_tapTarget.scss +103 -0
- data/assets/stylesheets/materialize/components/_timepicker.scss +183 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +7 -14
- data/{app/assets → assets}/stylesheets/materialize/components/_tooltip.scss +3 -3
- data/assets/stylesheets/materialize/components/_transitions.scss +13 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +8 -9
- data/{app/assets → assets}/stylesheets/materialize/components/_variables.scss +65 -29
- data/assets/stylesheets/materialize/components/_waves.scss +114 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_checkboxes.scss +26 -46
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_file-input.scss +6 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_forms.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_input-fields.scss +131 -63
- data/assets/stylesheets/materialize/components/forms/_radio-buttons.scss +115 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_range.scss +35 -33
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_select.scss +88 -19
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_switches.scss +32 -21
- data/assets/stylesheets/materialize/extras/nouislider.css +406 -0
- data/{app/assets → assets}/stylesheets/materialize.scss +10 -9
- data/lib/materialize-sass/engine.rb +9 -7
- data/lib/materialize-sass/helpers.rb +38 -0
- data/lib/materialize-sass/version.rb +1 -1
- data/lib/materialize-sass.rb +13 -28
- data/materialize-sass.gemspec +5 -5
- metadata +97 -119
- data/app/assets/fonts/roboto/Roboto-Bold.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
- data/app/assets/javascripts/materialize/animation.js +0 -9
- data/app/assets/javascripts/materialize/buttons.js +0 -267
- data/app/assets/javascripts/materialize/cards.js +0 -26
- data/app/assets/javascripts/materialize/carousel.js +0 -454
- data/app/assets/javascripts/materialize/character_counter.js +0 -72
- data/app/assets/javascripts/materialize/chips.js +0 -289
- data/app/assets/javascripts/materialize/collapsible.js +0 -160
- data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1430
- data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1123
- data/app/assets/javascripts/materialize/dropdown.js +0 -265
- data/app/assets/javascripts/materialize/extras/nouislider.js +0 -1666
- data/app/assets/javascripts/materialize/extras/nouislider.min.js +0 -1
- data/app/assets/javascripts/materialize/forms.js +0 -682
- data/app/assets/javascripts/materialize/global.js +0 -98
- data/app/assets/javascripts/materialize/hammer.min.js +0 -1
- data/app/assets/javascripts/materialize/init.js +0 -174
- data/app/assets/javascripts/materialize/initial.js +0 -11
- data/app/assets/javascripts/materialize/jquery.easing.1.3.js +0 -205
- data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
- data/app/assets/javascripts/materialize/jquery.timeago.min.js +0 -1
- data/app/assets/javascripts/materialize/materialbox.js +0 -269
- data/app/assets/javascripts/materialize/modal.js +0 -184
- data/app/assets/javascripts/materialize/parallax.js +0 -58
- data/app/assets/javascripts/materialize/prism.js +0 -8
- data/app/assets/javascripts/materialize/pushpin.js +0 -71
- data/app/assets/javascripts/materialize/scrollFire.js +0 -48
- data/app/assets/javascripts/materialize/scrollspy.js +0 -284
- data/app/assets/javascripts/materialize/sideNav.js +0 -370
- data/app/assets/javascripts/materialize/slider.js +0 -321
- data/app/assets/javascripts/materialize/tabs.js +0 -164
- data/app/assets/javascripts/materialize/toasts.js +0 -137
- data/app/assets/javascripts/materialize/tooltip.js +0 -236
- data/app/assets/javascripts/materialize/transitions.js +0 -169
- data/app/assets/javascripts/materialize/velocity.min.js +0 -5
- data/app/assets/javascripts/materialize.js +0 -5
- data/app/assets/stylesheets/materialize/components/_mixins.scss +0 -5
- data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -424
- data/app/assets/stylesheets/materialize/components/_prefixer.scss +0 -384
- data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -49
- data/app/assets/stylesheets/materialize/components/_waves.scss +0 -177
- data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -435
- data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -201
- data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -125
- data/app/assets/stylesheets/materialize/components/forms/_radio-buttons.scss +0 -117
- data/app/assets/stylesheets/materialize/extras/nouislider.css +0 -259
@@ -0,0 +1,659 @@
|
|
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 ($, anim) {
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _defaults = {
|
15
|
+
alignment: 'left',
|
16
|
+
autoFocus: true,
|
17
|
+
constrainWidth: true,
|
18
|
+
container: null,
|
19
|
+
coverTrigger: true,
|
20
|
+
closeOnClick: true,
|
21
|
+
hover: false,
|
22
|
+
inDuration: 150,
|
23
|
+
outDuration: 250,
|
24
|
+
onOpenStart: null,
|
25
|
+
onOpenEnd: null,
|
26
|
+
onCloseStart: null,
|
27
|
+
onCloseEnd: null,
|
28
|
+
onItemClick: null
|
29
|
+
};
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @class
|
33
|
+
*/
|
34
|
+
|
35
|
+
var Dropdown = function (_Component) {
|
36
|
+
_inherits(Dropdown, _Component);
|
37
|
+
|
38
|
+
function Dropdown(el, options) {
|
39
|
+
_classCallCheck(this, Dropdown);
|
40
|
+
|
41
|
+
var _this = _possibleConstructorReturn(this, (Dropdown.__proto__ || Object.getPrototypeOf(Dropdown)).call(this, Dropdown, el, options));
|
42
|
+
|
43
|
+
_this.el.M_Dropdown = _this;
|
44
|
+
Dropdown._dropdowns.push(_this);
|
45
|
+
|
46
|
+
_this.id = M.getIdFromTrigger(el);
|
47
|
+
_this.dropdownEl = document.getElementById(_this.id);
|
48
|
+
_this.$dropdownEl = $(_this.dropdownEl);
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Options for the dropdown
|
52
|
+
* @member Dropdown#options
|
53
|
+
* @prop {String} [alignment='left'] - Edge which the dropdown is aligned to
|
54
|
+
* @prop {Boolean} [autoFocus=true] - Automatically focus dropdown el for keyboard
|
55
|
+
* @prop {Boolean} [constrainWidth=true] - Constrain width to width of the button
|
56
|
+
* @prop {Element} container - Container element to attach dropdown to (optional)
|
57
|
+
* @prop {Boolean} [coverTrigger=true] - Place dropdown over trigger
|
58
|
+
* @prop {Boolean} [closeOnClick=true] - Close on click of dropdown item
|
59
|
+
* @prop {Boolean} [hover=false] - Open dropdown on hover
|
60
|
+
* @prop {Number} [inDuration=150] - Duration of open animation in ms
|
61
|
+
* @prop {Number} [outDuration=250] - Duration of close animation in ms
|
62
|
+
* @prop {Function} onOpenStart - Function called when dropdown starts opening
|
63
|
+
* @prop {Function} onOpenEnd - Function called when dropdown finishes opening
|
64
|
+
* @prop {Function} onCloseStart - Function called when dropdown starts closing
|
65
|
+
* @prop {Function} onCloseEnd - Function called when dropdown finishes closing
|
66
|
+
*/
|
67
|
+
_this.options = $.extend({}, Dropdown.defaults, options);
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Describes open/close state of dropdown
|
71
|
+
* @type {Boolean}
|
72
|
+
*/
|
73
|
+
_this.isOpen = false;
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Describes if dropdown content is scrollable
|
77
|
+
* @type {Boolean}
|
78
|
+
*/
|
79
|
+
_this.isScrollable = false;
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Describes if touch moving on dropdown content
|
83
|
+
* @type {Boolean}
|
84
|
+
*/
|
85
|
+
_this.isTouchMoving = false;
|
86
|
+
|
87
|
+
_this.focusedIndex = -1;
|
88
|
+
_this.filterQuery = [];
|
89
|
+
|
90
|
+
// Move dropdown-content after dropdown-trigger
|
91
|
+
if (!!_this.options.container) {
|
92
|
+
$(_this.options.container).append(_this.dropdownEl);
|
93
|
+
} else {
|
94
|
+
_this.$el.after(_this.dropdownEl);
|
95
|
+
}
|
96
|
+
|
97
|
+
_this._makeDropdownFocusable();
|
98
|
+
_this._resetFilterQueryBound = _this._resetFilterQuery.bind(_this);
|
99
|
+
_this._handleDocumentClickBound = _this._handleDocumentClick.bind(_this);
|
100
|
+
_this._handleDocumentTouchmoveBound = _this._handleDocumentTouchmove.bind(_this);
|
101
|
+
_this._handleDropdownClickBound = _this._handleDropdownClick.bind(_this);
|
102
|
+
_this._handleDropdownKeydownBound = _this._handleDropdownKeydown.bind(_this);
|
103
|
+
_this._handleTriggerKeydownBound = _this._handleTriggerKeydown.bind(_this);
|
104
|
+
_this._setupEventHandlers();
|
105
|
+
return _this;
|
106
|
+
}
|
107
|
+
|
108
|
+
_createClass(Dropdown, [{
|
109
|
+
key: 'destroy',
|
110
|
+
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Teardown component
|
114
|
+
*/
|
115
|
+
value: function destroy() {
|
116
|
+
this._resetDropdownStyles();
|
117
|
+
this._removeEventHandlers();
|
118
|
+
Dropdown._dropdowns.splice(Dropdown._dropdowns.indexOf(this), 1);
|
119
|
+
this.el.M_Dropdown = undefined;
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Setup Event Handlers
|
124
|
+
*/
|
125
|
+
|
126
|
+
}, {
|
127
|
+
key: '_setupEventHandlers',
|
128
|
+
value: function _setupEventHandlers() {
|
129
|
+
// Trigger keydown handler
|
130
|
+
this.el.addEventListener('keydown', this._handleTriggerKeydownBound);
|
131
|
+
|
132
|
+
// Item click handler
|
133
|
+
this.dropdownEl.addEventListener('click', this._handleDropdownClickBound);
|
134
|
+
|
135
|
+
// Hover event handlers
|
136
|
+
if (this.options.hover) {
|
137
|
+
this._handleMouseEnterBound = this._handleMouseEnter.bind(this);
|
138
|
+
this.el.addEventListener('mouseenter', this._handleMouseEnterBound);
|
139
|
+
this._handleMouseLeaveBound = this._handleMouseLeave.bind(this);
|
140
|
+
this.el.addEventListener('mouseleave', this._handleMouseLeaveBound);
|
141
|
+
this.dropdownEl.addEventListener('mouseleave', this._handleMouseLeaveBound);
|
142
|
+
|
143
|
+
// Click event handlers
|
144
|
+
} else {
|
145
|
+
this._handleClickBound = this._handleClick.bind(this);
|
146
|
+
this.el.addEventListener('click', this._handleClickBound);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Remove Event Handlers
|
152
|
+
*/
|
153
|
+
|
154
|
+
}, {
|
155
|
+
key: '_removeEventHandlers',
|
156
|
+
value: function _removeEventHandlers() {
|
157
|
+
this.el.removeEventListener('keydown', this._handleTriggerKeydownBound);
|
158
|
+
this.dropdownEl.removeEventListener('click', this._handleDropdownClickBound);
|
159
|
+
|
160
|
+
if (this.options.hover) {
|
161
|
+
this.el.removeEventListener('mouseenter', this._handleMouseEnterBound);
|
162
|
+
this.el.removeEventListener('mouseleave', this._handleMouseLeaveBound);
|
163
|
+
this.dropdownEl.removeEventListener('mouseleave', this._handleMouseLeaveBound);
|
164
|
+
} else {
|
165
|
+
this.el.removeEventListener('click', this._handleClickBound);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
}, {
|
169
|
+
key: '_setupTemporaryEventHandlers',
|
170
|
+
value: function _setupTemporaryEventHandlers() {
|
171
|
+
// Use capture phase event handler to prevent click
|
172
|
+
document.body.addEventListener('click', this._handleDocumentClickBound, true);
|
173
|
+
document.body.addEventListener('touchend', this._handleDocumentClickBound);
|
174
|
+
document.body.addEventListener('touchmove', this._handleDocumentTouchmoveBound);
|
175
|
+
this.dropdownEl.addEventListener('keydown', this._handleDropdownKeydownBound);
|
176
|
+
}
|
177
|
+
}, {
|
178
|
+
key: '_removeTemporaryEventHandlers',
|
179
|
+
value: function _removeTemporaryEventHandlers() {
|
180
|
+
// Use capture phase event handler to prevent click
|
181
|
+
document.body.removeEventListener('click', this._handleDocumentClickBound, true);
|
182
|
+
document.body.removeEventListener('touchend', this._handleDocumentClickBound);
|
183
|
+
document.body.removeEventListener('touchmove', this._handleDocumentTouchmoveBound);
|
184
|
+
this.dropdownEl.removeEventListener('keydown', this._handleDropdownKeydownBound);
|
185
|
+
}
|
186
|
+
}, {
|
187
|
+
key: '_handleClick',
|
188
|
+
value: function _handleClick(e) {
|
189
|
+
e.preventDefault();
|
190
|
+
this.open();
|
191
|
+
}
|
192
|
+
}, {
|
193
|
+
key: '_handleMouseEnter',
|
194
|
+
value: function _handleMouseEnter() {
|
195
|
+
this.open();
|
196
|
+
}
|
197
|
+
}, {
|
198
|
+
key: '_handleMouseLeave',
|
199
|
+
value: function _handleMouseLeave(e) {
|
200
|
+
var toEl = e.toElement || e.relatedTarget;
|
201
|
+
var leaveToDropdownContent = !!$(toEl).closest('.dropdown-content').length;
|
202
|
+
var leaveToActiveDropdownTrigger = false;
|
203
|
+
|
204
|
+
var $closestTrigger = $(toEl).closest('.dropdown-trigger');
|
205
|
+
if ($closestTrigger.length && !!$closestTrigger[0].M_Dropdown && $closestTrigger[0].M_Dropdown.isOpen) {
|
206
|
+
leaveToActiveDropdownTrigger = true;
|
207
|
+
}
|
208
|
+
|
209
|
+
// Close hover dropdown if mouse did not leave to either active dropdown-trigger or dropdown-content
|
210
|
+
if (!leaveToActiveDropdownTrigger && !leaveToDropdownContent) {
|
211
|
+
this.close();
|
212
|
+
}
|
213
|
+
}
|
214
|
+
}, {
|
215
|
+
key: '_handleDocumentClick',
|
216
|
+
value: function _handleDocumentClick(e) {
|
217
|
+
var _this2 = this;
|
218
|
+
|
219
|
+
var $target = $(e.target);
|
220
|
+
if (this.options.closeOnClick && $target.closest('.dropdown-content').length && !this.isTouchMoving) {
|
221
|
+
// isTouchMoving to check if scrolling on mobile.
|
222
|
+
setTimeout(function () {
|
223
|
+
_this2.close();
|
224
|
+
}, 0);
|
225
|
+
} else if ($target.closest('.dropdown-trigger').length || !$target.closest('.dropdown-content').length) {
|
226
|
+
setTimeout(function () {
|
227
|
+
_this2.close();
|
228
|
+
}, 0);
|
229
|
+
}
|
230
|
+
this.isTouchMoving = false;
|
231
|
+
}
|
232
|
+
}, {
|
233
|
+
key: '_handleTriggerKeydown',
|
234
|
+
value: function _handleTriggerKeydown(e) {
|
235
|
+
// ARROW DOWN OR ENTER WHEN SELECT IS CLOSED - open Dropdown
|
236
|
+
if ((e.which === M.keys.ARROW_DOWN || e.which === M.keys.ENTER) && !this.isOpen) {
|
237
|
+
e.preventDefault();
|
238
|
+
this.open();
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* Handle Document Touchmove
|
244
|
+
* @param {Event} e
|
245
|
+
*/
|
246
|
+
|
247
|
+
}, {
|
248
|
+
key: '_handleDocumentTouchmove',
|
249
|
+
value: function _handleDocumentTouchmove(e) {
|
250
|
+
var $target = $(e.target);
|
251
|
+
if ($target.closest('.dropdown-content').length) {
|
252
|
+
this.isTouchMoving = true;
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Handle Dropdown Click
|
258
|
+
* @param {Event} e
|
259
|
+
*/
|
260
|
+
|
261
|
+
}, {
|
262
|
+
key: '_handleDropdownClick',
|
263
|
+
value: function _handleDropdownClick(e) {
|
264
|
+
// onItemClick callback
|
265
|
+
if (typeof this.options.onItemClick === 'function') {
|
266
|
+
var itemEl = $(e.target).closest('li')[0];
|
267
|
+
this.options.onItemClick.call(this, itemEl);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
|
271
|
+
/**
|
272
|
+
* Handle Dropdown Keydown
|
273
|
+
* @param {Event} e
|
274
|
+
*/
|
275
|
+
|
276
|
+
}, {
|
277
|
+
key: '_handleDropdownKeydown',
|
278
|
+
value: function _handleDropdownKeydown(e) {
|
279
|
+
if (e.which === M.keys.TAB) {
|
280
|
+
e.preventDefault();
|
281
|
+
this.close();
|
282
|
+
|
283
|
+
// Navigate down dropdown list
|
284
|
+
} else if ((e.which === M.keys.ARROW_DOWN || e.which === M.keys.ARROW_UP) && this.isOpen) {
|
285
|
+
e.preventDefault();
|
286
|
+
var direction = e.which === M.keys.ARROW_DOWN ? 1 : -1;
|
287
|
+
var newFocusedIndex = this.focusedIndex;
|
288
|
+
var foundNewIndex = false;
|
289
|
+
do {
|
290
|
+
newFocusedIndex = newFocusedIndex + direction;
|
291
|
+
|
292
|
+
if (!!this.dropdownEl.children[newFocusedIndex] && this.dropdownEl.children[newFocusedIndex].tabIndex !== -1) {
|
293
|
+
foundNewIndex = true;
|
294
|
+
break;
|
295
|
+
}
|
296
|
+
} while (newFocusedIndex < this.dropdownEl.children.length && newFocusedIndex >= 0);
|
297
|
+
|
298
|
+
if (foundNewIndex) {
|
299
|
+
this.focusedIndex = newFocusedIndex;
|
300
|
+
this._focusFocusedItem();
|
301
|
+
}
|
302
|
+
|
303
|
+
// ENTER selects choice on focused item
|
304
|
+
} else if (e.which === M.keys.ENTER && this.isOpen) {
|
305
|
+
// Search for <a> and <button>
|
306
|
+
var focusedElement = this.dropdownEl.children[this.focusedIndex];
|
307
|
+
var $activatableElement = $(focusedElement).find('a, button').first();
|
308
|
+
|
309
|
+
// Click a or button tag if exists, otherwise click li tag
|
310
|
+
if (!!$activatableElement.length) {
|
311
|
+
$activatableElement[0].click();
|
312
|
+
} else if (!!focusedElement) {
|
313
|
+
focusedElement.click();
|
314
|
+
}
|
315
|
+
|
316
|
+
// Close dropdown on ESC
|
317
|
+
} else if (e.which === M.keys.ESC && this.isOpen) {
|
318
|
+
e.preventDefault();
|
319
|
+
this.close();
|
320
|
+
}
|
321
|
+
|
322
|
+
// CASE WHEN USER TYPE LETTERS
|
323
|
+
var letter = String.fromCharCode(e.which).toLowerCase(),
|
324
|
+
nonLetters = [9, 13, 27, 38, 40];
|
325
|
+
if (letter && nonLetters.indexOf(e.which) === -1) {
|
326
|
+
this.filterQuery.push(letter);
|
327
|
+
|
328
|
+
var string = this.filterQuery.join(''),
|
329
|
+
newOptionEl = $(this.dropdownEl).find('li').filter(function (el) {
|
330
|
+
return $(el).text().toLowerCase().indexOf(string) === 0;
|
331
|
+
})[0];
|
332
|
+
|
333
|
+
if (newOptionEl) {
|
334
|
+
this.focusedIndex = $(newOptionEl).index();
|
335
|
+
this._focusFocusedItem();
|
336
|
+
}
|
337
|
+
}
|
338
|
+
|
339
|
+
this.filterTimeout = setTimeout(this._resetFilterQueryBound, 1000);
|
340
|
+
}
|
341
|
+
|
342
|
+
/**
|
343
|
+
* Setup dropdown
|
344
|
+
*/
|
345
|
+
|
346
|
+
}, {
|
347
|
+
key: '_resetFilterQuery',
|
348
|
+
value: function _resetFilterQuery() {
|
349
|
+
this.filterQuery = [];
|
350
|
+
}
|
351
|
+
}, {
|
352
|
+
key: '_resetDropdownStyles',
|
353
|
+
value: function _resetDropdownStyles() {
|
354
|
+
this.$dropdownEl.css({
|
355
|
+
display: '',
|
356
|
+
width: '',
|
357
|
+
height: '',
|
358
|
+
left: '',
|
359
|
+
top: '',
|
360
|
+
'transform-origin': '',
|
361
|
+
transform: '',
|
362
|
+
opacity: ''
|
363
|
+
});
|
364
|
+
}
|
365
|
+
}, {
|
366
|
+
key: '_makeDropdownFocusable',
|
367
|
+
value: function _makeDropdownFocusable() {
|
368
|
+
// Needed for arrow key navigation
|
369
|
+
this.dropdownEl.tabIndex = 0;
|
370
|
+
|
371
|
+
// Only set tabindex if it hasn't been set by user
|
372
|
+
$(this.dropdownEl).children().each(function (el) {
|
373
|
+
if (!el.getAttribute('tabindex')) {
|
374
|
+
el.setAttribute('tabindex', 0);
|
375
|
+
}
|
376
|
+
});
|
377
|
+
}
|
378
|
+
}, {
|
379
|
+
key: '_focusFocusedItem',
|
380
|
+
value: function _focusFocusedItem() {
|
381
|
+
if (this.focusedIndex >= 0 && this.focusedIndex < this.dropdownEl.children.length && this.options.autoFocus) {
|
382
|
+
this.dropdownEl.children[this.focusedIndex].focus();
|
383
|
+
}
|
384
|
+
}
|
385
|
+
}, {
|
386
|
+
key: '_getDropdownPosition',
|
387
|
+
value: function _getDropdownPosition() {
|
388
|
+
var offsetParentBRect = this.el.offsetParent.getBoundingClientRect();
|
389
|
+
var triggerBRect = this.el.getBoundingClientRect();
|
390
|
+
var dropdownBRect = this.dropdownEl.getBoundingClientRect();
|
391
|
+
|
392
|
+
var idealHeight = dropdownBRect.height;
|
393
|
+
var idealWidth = dropdownBRect.width;
|
394
|
+
var idealXPos = triggerBRect.left - dropdownBRect.left;
|
395
|
+
var idealYPos = triggerBRect.top - dropdownBRect.top;
|
396
|
+
|
397
|
+
var dropdownBounds = {
|
398
|
+
left: idealXPos,
|
399
|
+
top: idealYPos,
|
400
|
+
height: idealHeight,
|
401
|
+
width: idealWidth
|
402
|
+
};
|
403
|
+
|
404
|
+
// Countainer here will be closest ancestor with overflow: hidden
|
405
|
+
var closestOverflowParent = !!this.dropdownEl.offsetParent ? this.dropdownEl.offsetParent : this.dropdownEl.parentNode;
|
406
|
+
|
407
|
+
var alignments = M.checkPossibleAlignments(this.el, closestOverflowParent, dropdownBounds, this.options.coverTrigger ? 0 : triggerBRect.height);
|
408
|
+
|
409
|
+
var verticalAlignment = 'top';
|
410
|
+
var horizontalAlignment = this.options.alignment;
|
411
|
+
idealYPos += this.options.coverTrigger ? 0 : triggerBRect.height;
|
412
|
+
|
413
|
+
// Reset isScrollable
|
414
|
+
this.isScrollable = false;
|
415
|
+
|
416
|
+
if (!alignments.top) {
|
417
|
+
if (alignments.bottom) {
|
418
|
+
verticalAlignment = 'bottom';
|
419
|
+
} else {
|
420
|
+
this.isScrollable = true;
|
421
|
+
|
422
|
+
// Determine which side has most space and cutoff at correct height
|
423
|
+
if (alignments.spaceOnTop > alignments.spaceOnBottom) {
|
424
|
+
verticalAlignment = 'bottom';
|
425
|
+
idealHeight += alignments.spaceOnTop;
|
426
|
+
idealYPos -= alignments.spaceOnTop;
|
427
|
+
} else {
|
428
|
+
idealHeight += alignments.spaceOnBottom;
|
429
|
+
}
|
430
|
+
}
|
431
|
+
}
|
432
|
+
|
433
|
+
// If preferred horizontal alignment is possible
|
434
|
+
if (!alignments[horizontalAlignment]) {
|
435
|
+
var oppositeAlignment = horizontalAlignment === 'left' ? 'right' : 'left';
|
436
|
+
if (alignments[oppositeAlignment]) {
|
437
|
+
horizontalAlignment = oppositeAlignment;
|
438
|
+
} else {
|
439
|
+
// Determine which side has most space and cutoff at correct height
|
440
|
+
if (alignments.spaceOnLeft > alignments.spaceOnRight) {
|
441
|
+
horizontalAlignment = 'right';
|
442
|
+
idealWidth += alignments.spaceOnLeft;
|
443
|
+
idealXPos -= alignments.spaceOnLeft;
|
444
|
+
} else {
|
445
|
+
horizontalAlignment = 'left';
|
446
|
+
idealWidth += alignments.spaceOnRight;
|
447
|
+
}
|
448
|
+
}
|
449
|
+
}
|
450
|
+
|
451
|
+
if (verticalAlignment === 'bottom') {
|
452
|
+
idealYPos = idealYPos - dropdownBRect.height + (this.options.coverTrigger ? triggerBRect.height : 0);
|
453
|
+
}
|
454
|
+
if (horizontalAlignment === 'right') {
|
455
|
+
idealXPos = idealXPos - dropdownBRect.width + triggerBRect.width;
|
456
|
+
}
|
457
|
+
return {
|
458
|
+
x: idealXPos,
|
459
|
+
y: idealYPos,
|
460
|
+
verticalAlignment: verticalAlignment,
|
461
|
+
horizontalAlignment: horizontalAlignment,
|
462
|
+
height: idealHeight,
|
463
|
+
width: idealWidth
|
464
|
+
};
|
465
|
+
}
|
466
|
+
|
467
|
+
/**
|
468
|
+
* Animate in dropdown
|
469
|
+
*/
|
470
|
+
|
471
|
+
}, {
|
472
|
+
key: '_animateIn',
|
473
|
+
value: function _animateIn() {
|
474
|
+
var _this3 = this;
|
475
|
+
|
476
|
+
anim.remove(this.dropdownEl);
|
477
|
+
anim({
|
478
|
+
targets: this.dropdownEl,
|
479
|
+
opacity: {
|
480
|
+
value: [0, 1],
|
481
|
+
easing: 'easeOutQuad'
|
482
|
+
},
|
483
|
+
scaleX: [0.3, 1],
|
484
|
+
scaleY: [0.3, 1],
|
485
|
+
duration: this.options.inDuration,
|
486
|
+
easing: 'easeOutQuint',
|
487
|
+
complete: function (anim) {
|
488
|
+
if (_this3.options.autoFocus) {
|
489
|
+
_this3.dropdownEl.focus();
|
490
|
+
}
|
491
|
+
|
492
|
+
// onOpenEnd callback
|
493
|
+
if (typeof _this3.options.onOpenEnd === 'function') {
|
494
|
+
_this3.options.onOpenEnd.call(_this3, _this3.el);
|
495
|
+
}
|
496
|
+
}
|
497
|
+
});
|
498
|
+
}
|
499
|
+
|
500
|
+
/**
|
501
|
+
* Animate out dropdown
|
502
|
+
*/
|
503
|
+
|
504
|
+
}, {
|
505
|
+
key: '_animateOut',
|
506
|
+
value: function _animateOut() {
|
507
|
+
var _this4 = this;
|
508
|
+
|
509
|
+
anim.remove(this.dropdownEl);
|
510
|
+
anim({
|
511
|
+
targets: this.dropdownEl,
|
512
|
+
opacity: {
|
513
|
+
value: 0,
|
514
|
+
easing: 'easeOutQuint'
|
515
|
+
},
|
516
|
+
scaleX: 0.3,
|
517
|
+
scaleY: 0.3,
|
518
|
+
duration: this.options.outDuration,
|
519
|
+
easing: 'easeOutQuint',
|
520
|
+
complete: function (anim) {
|
521
|
+
_this4._resetDropdownStyles();
|
522
|
+
|
523
|
+
// onCloseEnd callback
|
524
|
+
if (typeof _this4.options.onCloseEnd === 'function') {
|
525
|
+
_this4.options.onCloseEnd.call(_this4, _this4.el);
|
526
|
+
}
|
527
|
+
}
|
528
|
+
});
|
529
|
+
}
|
530
|
+
|
531
|
+
/**
|
532
|
+
* Place dropdown
|
533
|
+
*/
|
534
|
+
|
535
|
+
}, {
|
536
|
+
key: '_placeDropdown',
|
537
|
+
value: function _placeDropdown() {
|
538
|
+
// Set width before calculating positionInfo
|
539
|
+
var idealWidth = this.options.constrainWidth ? this.el.getBoundingClientRect().width : this.dropdownEl.getBoundingClientRect().width;
|
540
|
+
this.dropdownEl.style.width = idealWidth + 'px';
|
541
|
+
|
542
|
+
var positionInfo = this._getDropdownPosition();
|
543
|
+
this.dropdownEl.style.left = positionInfo.x + 'px';
|
544
|
+
this.dropdownEl.style.top = positionInfo.y + 'px';
|
545
|
+
this.dropdownEl.style.height = positionInfo.height + 'px';
|
546
|
+
this.dropdownEl.style.width = positionInfo.width + 'px';
|
547
|
+
this.dropdownEl.style.transformOrigin = (positionInfo.horizontalAlignment === 'left' ? '0' : '100%') + ' ' + (positionInfo.verticalAlignment === 'top' ? '0' : '100%');
|
548
|
+
}
|
549
|
+
|
550
|
+
/**
|
551
|
+
* Open Dropdown
|
552
|
+
*/
|
553
|
+
|
554
|
+
}, {
|
555
|
+
key: 'open',
|
556
|
+
value: function open() {
|
557
|
+
if (this.isOpen) {
|
558
|
+
return;
|
559
|
+
}
|
560
|
+
this.isOpen = true;
|
561
|
+
|
562
|
+
// onOpenStart callback
|
563
|
+
if (typeof this.options.onOpenStart === 'function') {
|
564
|
+
this.options.onOpenStart.call(this, this.el);
|
565
|
+
}
|
566
|
+
|
567
|
+
// Reset styles
|
568
|
+
this._resetDropdownStyles();
|
569
|
+
this.dropdownEl.style.display = 'block';
|
570
|
+
|
571
|
+
this._placeDropdown();
|
572
|
+
this._animateIn();
|
573
|
+
this._setupTemporaryEventHandlers();
|
574
|
+
}
|
575
|
+
|
576
|
+
/**
|
577
|
+
* Close Dropdown
|
578
|
+
*/
|
579
|
+
|
580
|
+
}, {
|
581
|
+
key: 'close',
|
582
|
+
value: function close() {
|
583
|
+
if (!this.isOpen) {
|
584
|
+
return;
|
585
|
+
}
|
586
|
+
this.isOpen = false;
|
587
|
+
this.focusedIndex = -1;
|
588
|
+
|
589
|
+
// onCloseStart callback
|
590
|
+
if (typeof this.options.onCloseStart === 'function') {
|
591
|
+
this.options.onCloseStart.call(this, this.el);
|
592
|
+
}
|
593
|
+
|
594
|
+
this._animateOut();
|
595
|
+
this._removeTemporaryEventHandlers();
|
596
|
+
|
597
|
+
if (this.options.autoFocus) {
|
598
|
+
this.el.focus();
|
599
|
+
}
|
600
|
+
}
|
601
|
+
|
602
|
+
/**
|
603
|
+
* Recalculate dimensions
|
604
|
+
*/
|
605
|
+
|
606
|
+
}, {
|
607
|
+
key: 'recalculateDimensions',
|
608
|
+
value: function recalculateDimensions() {
|
609
|
+
if (this.isOpen) {
|
610
|
+
this.$dropdownEl.css({
|
611
|
+
width: '',
|
612
|
+
height: '',
|
613
|
+
left: '',
|
614
|
+
top: '',
|
615
|
+
'transform-origin': ''
|
616
|
+
});
|
617
|
+
this._placeDropdown();
|
618
|
+
}
|
619
|
+
}
|
620
|
+
}], [{
|
621
|
+
key: 'init',
|
622
|
+
value: function init(els, options) {
|
623
|
+
return _get(Dropdown.__proto__ || Object.getPrototypeOf(Dropdown), 'init', this).call(this, this, els, options);
|
624
|
+
}
|
625
|
+
|
626
|
+
/**
|
627
|
+
* Get Instance
|
628
|
+
*/
|
629
|
+
|
630
|
+
}, {
|
631
|
+
key: 'getInstance',
|
632
|
+
value: function getInstance(el) {
|
633
|
+
var domElem = !!el.jquery ? el[0] : el;
|
634
|
+
return domElem.M_Dropdown;
|
635
|
+
}
|
636
|
+
}, {
|
637
|
+
key: 'defaults',
|
638
|
+
get: function () {
|
639
|
+
return _defaults;
|
640
|
+
}
|
641
|
+
}]);
|
642
|
+
|
643
|
+
return Dropdown;
|
644
|
+
}(Component);
|
645
|
+
|
646
|
+
/**
|
647
|
+
* @static
|
648
|
+
* @memberof Dropdown
|
649
|
+
*/
|
650
|
+
|
651
|
+
|
652
|
+
Dropdown._dropdowns = [];
|
653
|
+
|
654
|
+
M.Dropdown = Dropdown;
|
655
|
+
|
656
|
+
if (M.jQueryLoaded) {
|
657
|
+
M.initializeJqueryWrapper(Dropdown, 'dropdown', 'M_Dropdown');
|
658
|
+
}
|
659
|
+
})(cash, M.anime);
|