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.
- checksums.yaml +5 -5
- data/README.md +18 -42
- data/Rakefile +17 -17
- data/{app/assets → assets}/javascripts/materialize-sprockets.js +8 -12
- data/assets/javascripts/materialize.js +11877 -0
- data/assets/javascripts/materialize/autocomplete.js +420 -0
- data/assets/javascripts/materialize/buttons.js +388 -0
- data/assets/javascripts/materialize/cards.js +28 -0
- data/assets/javascripts/materialize/carousel.js +791 -0
- data/assets/javascripts/materialize/cash.js +992 -0
- data/assets/javascripts/materialize/characterCounter.js +180 -0
- data/assets/javascripts/materialize/chips.js +555 -0
- data/assets/javascripts/materialize/collapsible.js +275 -0
- data/assets/javascripts/materialize/datepicker.js +898 -0
- data/assets/javascripts/materialize/dropdown.js +530 -0
- data/{app/assets → assets}/javascripts/materialize/extras/nouislider.js +1 -1
- data/{app/assets → assets}/javascripts/materialize/extras/nouislider.min.js +1 -1
- data/assets/javascripts/materialize/forms.js +223 -0
- data/assets/javascripts/materialize/global.js +353 -0
- data/assets/javascripts/materialize/materialbox.js +432 -0
- data/{app/assets → assets}/javascripts/materialize/modal.js +82 -113
- data/assets/javascripts/materialize/parallax.js +135 -0
- data/assets/javascripts/materialize/pushpin.js +158 -0
- data/assets/javascripts/materialize/range.js +305 -0
- data/assets/javascripts/materialize/scrollspy.js +322 -0
- data/assets/javascripts/materialize/select.js +426 -0
- data/assets/javascripts/materialize/sidenav.js +584 -0
- data/assets/javascripts/materialize/slider.js +383 -0
- data/assets/javascripts/materialize/tabs.js +460 -0
- data/assets/javascripts/materialize/tapTarget.js +347 -0
- data/assets/javascripts/materialize/timepicker.js +616 -0
- data/{app/assets → assets}/javascripts/materialize/toasts.js +42 -46
- data/assets/javascripts/materialize/tooltip.js +325 -0
- data/assets/javascripts/materialize/velocity.min.js +782 -0
- data/{app/assets → assets}/javascripts/materialize/waves.js +0 -0
- data/{app/assets → assets}/stylesheets/materialize.scss +5 -6
- data/{app/assets → assets}/stylesheets/materialize/components/_badges.scss +1 -1
- data/{app/assets → assets}/stylesheets/materialize/components/_buttons.scss +34 -2
- data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_carousel.scss +1 -1
- data/{app/assets → assets}/stylesheets/materialize/components/_chips.scss +6 -5
- data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +3 -3
- data/{app/assets → assets}/stylesheets/materialize/components/_color.scss +0 -0
- data/assets/stylesheets/materialize/components/_datepicker.scss +180 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_dropdown.scss +16 -15
- data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +49 -14
- data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +1 -1
- data/{app/assets → assets}/stylesheets/materialize/components/_icons-material-design.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +0 -0
- data/assets/stylesheets/materialize/components/_mixins.scss +5 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +1 -1
- data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +0 -0
- data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_pulse.scss +0 -0
- data/{app/assets/stylesheets/materialize/components/_sideNav.scss → assets/stylesheets/materialize/components/_sidenav.scss} +23 -21
- data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +3 -3
- data/{app/assets → assets}/stylesheets/materialize/components/_tabs.scss +2 -2
- data/{app/assets → assets}/stylesheets/materialize/components/_tapTarget.scss +0 -0
- data/assets/stylesheets/materialize/components/_timepicker.scss +182 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_tooltip.scss +1 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_transitions.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +8 -8
- data/{app/assets → assets}/stylesheets/materialize/components/_variables.scss +42 -44
- data/{app/assets → assets}/stylesheets/materialize/components/_waves.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_checkboxes.scss +24 -24
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_file-input.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_forms.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_input-fields.scss +49 -35
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_radio-buttons.scss +29 -29
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_range.scss +32 -31
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_select.scss +20 -11
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_switches.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/extras/nouislider.css +1 -1
- data/lib/materialize-sass.rb +13 -23
- data/lib/materialize-sass/engine.rb +6 -9
- data/lib/materialize-sass/version.rb +1 -1
- data/materialize-sass.gemspec +2 -1
- metadata +97 -97
- 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.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff2 +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.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff2 +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.js +0 -10021
- data/app/assets/javascripts/materialize/animation.js +0 -7
- data/app/assets/javascripts/materialize/buttons.js +0 -253
- data/app/assets/javascripts/materialize/cards.js +0 -28
- data/app/assets/javascripts/materialize/carousel.js +0 -543
- data/app/assets/javascripts/materialize/character_counter.js +0 -64
- data/app/assets/javascripts/materialize/chips.js +0 -315
- data/app/assets/javascripts/materialize/collapsible.js +0 -178
- data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1399
- data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1196
- data/app/assets/javascripts/materialize/date_picker/picker.time.js +0 -646
- data/app/assets/javascripts/materialize/dropdown.js +0 -257
- data/app/assets/javascripts/materialize/forms.js +0 -806
- data/app/assets/javascripts/materialize/global.js +0 -170
- data/app/assets/javascripts/materialize/hammer.min.js +0 -424
- data/app/assets/javascripts/materialize/initial.js +0 -10
- data/app/assets/javascripts/materialize/jquery.easing.1.4.js +0 -144
- data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
- data/app/assets/javascripts/materialize/materialbox.js +0 -263
- data/app/assets/javascripts/materialize/parallax.js +0 -54
- data/app/assets/javascripts/materialize/pushpin.js +0 -68
- data/app/assets/javascripts/materialize/scrollFire.js +0 -49
- data/app/assets/javascripts/materialize/scrollspy.js +0 -230
- data/app/assets/javascripts/materialize/sideNav.js +0 -395
- data/app/assets/javascripts/materialize/slider.js +0 -295
- data/app/assets/javascripts/materialize/tabs.js +0 -244
- data/app/assets/javascripts/materialize/tapTarget.js +0 -184
- data/app/assets/javascripts/materialize/tooltip.js +0 -227
- data/app/assets/javascripts/materialize/transitions.js +0 -163
- data/app/assets/javascripts/materialize/velocity.min.js +0 -626
- data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -424
- data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -39
- data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -469
- data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -216
- data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -267
@@ -0,0 +1,322 @@
|
|
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
|
+
throttle: 100,
|
10
|
+
scrollOffset: 200, // offset - 200 allows elements near bottom of page to scroll
|
11
|
+
activeClass: 'active',
|
12
|
+
getActiveElement: function (id) {
|
13
|
+
return 'a[href="#' + id + '"]';
|
14
|
+
}
|
15
|
+
};
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @class
|
19
|
+
*
|
20
|
+
*/
|
21
|
+
|
22
|
+
var ScrollSpy = function () {
|
23
|
+
/**
|
24
|
+
* Construct ScrollSpy instance
|
25
|
+
* @constructor
|
26
|
+
* @param {Element} el
|
27
|
+
* @param {Object} options
|
28
|
+
*/
|
29
|
+
function ScrollSpy(el, options) {
|
30
|
+
_classCallCheck(this, ScrollSpy);
|
31
|
+
|
32
|
+
// If exists, destroy and reinitialize
|
33
|
+
if (!!el.M_ScrollSpy) {
|
34
|
+
el.M_ScrollSpy.destroy();
|
35
|
+
}
|
36
|
+
|
37
|
+
this.el = el;
|
38
|
+
this.$el = $(el);
|
39
|
+
this.el.M_ScrollSpy = this;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Options for the modal
|
43
|
+
* @member Modal#options
|
44
|
+
* @prop {Number} [throttle=100] - Throttle of scroll handler
|
45
|
+
* @prop {Number} [scrollOffset=200] - Offset for centering element when scrolled to
|
46
|
+
* @prop {String} [activeClass='active'] - Class applied to active elements
|
47
|
+
* @prop {Function} [getActiveElement] - Used to find active element
|
48
|
+
*/
|
49
|
+
this.options = $.extend({}, ScrollSpy.defaults, options);
|
50
|
+
|
51
|
+
// setup
|
52
|
+
ScrollSpy._elements.push(this);
|
53
|
+
ScrollSpy._count++;
|
54
|
+
ScrollSpy._increment++;
|
55
|
+
this.tickId = -1;
|
56
|
+
this.id = ScrollSpy._increment;
|
57
|
+
this._setupEventHandlers();
|
58
|
+
this._handleWindowScroll();
|
59
|
+
}
|
60
|
+
|
61
|
+
_createClass(ScrollSpy, [{
|
62
|
+
key: 'destroy',
|
63
|
+
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Teardown component
|
67
|
+
*/
|
68
|
+
value: function destroy() {
|
69
|
+
ScrollSpy._elements.splice(ScrollSpy._elements.indexOf(this), 1);
|
70
|
+
ScrollSpy._elementsInView.splice(ScrollSpy._elementsInView.indexOf(this), 1);
|
71
|
+
ScrollSpy._visibleElements.splice(ScrollSpy._visibleElements.indexOf(this.$el), 1);
|
72
|
+
ScrollSpy._count--;
|
73
|
+
this._removeEventHandlers();
|
74
|
+
$(this.options.getActiveElement(this.$el.attr('id'))).removeClass(this.options.activeClass);
|
75
|
+
this.el.M_ScrollSpy = undefined;
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Setup Event Handlers
|
80
|
+
*/
|
81
|
+
|
82
|
+
}, {
|
83
|
+
key: '_setupEventHandlers',
|
84
|
+
value: function _setupEventHandlers() {
|
85
|
+
var throttledResize = M.throttle(this._handleWindowScroll, 200);
|
86
|
+
this._handleThrottledResizeBound = throttledResize.bind(this);
|
87
|
+
this._handleWindowScrollBound = this._handleWindowScroll.bind(this);
|
88
|
+
if (ScrollSpy._count === 1) {
|
89
|
+
window.addEventListener('scroll', this._handleWindowScrollBound);
|
90
|
+
window.addEventListener('resize', this._handleThrottledResizeBound);
|
91
|
+
document.body.addEventListener('click', this._handleTriggerClick);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Remove Event Handlers
|
97
|
+
*/
|
98
|
+
|
99
|
+
}, {
|
100
|
+
key: '_removeEventHandlers',
|
101
|
+
value: function _removeEventHandlers() {
|
102
|
+
if (ScrollSpy._count === 0) {
|
103
|
+
window.removeEventListener('scroll', this._handleWindowScrollBound);
|
104
|
+
window.removeEventListener('resize', this._handleThrottledResizeBound);
|
105
|
+
document.body.removeEventListener('click', this._handleTriggerClick);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Handle Trigger Click
|
111
|
+
* @param {Event} e
|
112
|
+
*/
|
113
|
+
|
114
|
+
}, {
|
115
|
+
key: '_handleTriggerClick',
|
116
|
+
value: function _handleTriggerClick(e) {
|
117
|
+
var $trigger = $(e.target);
|
118
|
+
for (var i = ScrollSpy._elements.length - 1; i >= 0; i--) {
|
119
|
+
var scrollspy = ScrollSpy._elements[i];
|
120
|
+
if ($trigger.is('a[href="#' + scrollspy.$el.attr('id') + '"]')) {
|
121
|
+
e.preventDefault();
|
122
|
+
var offset = scrollspy.$el.offset().top + 1;
|
123
|
+
Vel(document.body, 'scroll', { duration: 400, offset: offset - scrollspy.options.scrollOffset, easing: 'easeOutCubic' });
|
124
|
+
break;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Handle Window Scroll
|
131
|
+
*/
|
132
|
+
|
133
|
+
}, {
|
134
|
+
key: '_handleWindowScroll',
|
135
|
+
value: function _handleWindowScroll() {
|
136
|
+
// unique tick id
|
137
|
+
ScrollSpy._ticks++;
|
138
|
+
|
139
|
+
// viewport rectangle
|
140
|
+
var top = M.getDocumentScrollTop(),
|
141
|
+
left = M.getDocumentScrollLeft(),
|
142
|
+
right = left + window.innerWidth,
|
143
|
+
bottom = top + window.innerHeight;
|
144
|
+
|
145
|
+
// determine which elements are in view
|
146
|
+
var intersections = ScrollSpy._findElements(top, right, bottom, left);
|
147
|
+
for (var i = 0; i < intersections.length; i++) {
|
148
|
+
var scrollspy = intersections[i];
|
149
|
+
var lastTick = scrollspy.tickId;
|
150
|
+
if (lastTick < 0) {
|
151
|
+
// entered into view
|
152
|
+
scrollspy._enter();
|
153
|
+
}
|
154
|
+
|
155
|
+
// update tick id
|
156
|
+
scrollspy.tickId = ScrollSpy._ticks;
|
157
|
+
}
|
158
|
+
|
159
|
+
for (var _i = 0; _i < ScrollSpy._elementsInView.length; _i++) {
|
160
|
+
var _scrollspy = ScrollSpy._elementsInView[_i];
|
161
|
+
var _lastTick = _scrollspy.tickId;
|
162
|
+
if (_lastTick >= 0 && _lastTick !== ScrollSpy._ticks) {
|
163
|
+
// exited from view
|
164
|
+
_scrollspy._exit();
|
165
|
+
_scrollspy.tickId = -1;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
// remember elements in view for next tick
|
170
|
+
ScrollSpy._elementsInView = intersections;
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Find elements that are within the boundary
|
175
|
+
* @param {number} top
|
176
|
+
* @param {number} right
|
177
|
+
* @param {number} bottom
|
178
|
+
* @param {number} left
|
179
|
+
* @return {Array.<ScrollSpy>} A collection of elements
|
180
|
+
*/
|
181
|
+
|
182
|
+
}, {
|
183
|
+
key: '_enter',
|
184
|
+
value: function _enter() {
|
185
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function (value) {
|
186
|
+
return value.height() != 0;
|
187
|
+
});
|
188
|
+
|
189
|
+
if (ScrollSpy._visibleElements[0]) {
|
190
|
+
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(this.options.activeClass);
|
191
|
+
if (ScrollSpy._visibleElements[0][0].M_ScrollSpy && this.id < ScrollSpy._visibleElements[0][0].M_ScrollSpy.id) {
|
192
|
+
ScrollSpy._visibleElements.unshift(this.$el);
|
193
|
+
} else {
|
194
|
+
ScrollSpy._visibleElements.push(this.$el);
|
195
|
+
}
|
196
|
+
} else {
|
197
|
+
ScrollSpy._visibleElements.push(this.$el);
|
198
|
+
}
|
199
|
+
|
200
|
+
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(this.options.activeClass);
|
201
|
+
}
|
202
|
+
}, {
|
203
|
+
key: '_exit',
|
204
|
+
value: function _exit() {
|
205
|
+
var _this = this;
|
206
|
+
|
207
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function (value) {
|
208
|
+
return value.height() != 0;
|
209
|
+
});
|
210
|
+
|
211
|
+
if (ScrollSpy._visibleElements[0]) {
|
212
|
+
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(this.options.activeClass);
|
213
|
+
|
214
|
+
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function (el) {
|
215
|
+
return el.attr('id') != _this.$el.attr('id');
|
216
|
+
});
|
217
|
+
if (ScrollSpy._visibleElements[0]) {
|
218
|
+
// Check if empty
|
219
|
+
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(this.options.activeClass);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
}
|
223
|
+
}], [{
|
224
|
+
key: 'init',
|
225
|
+
value: function init($els, options) {
|
226
|
+
var arr = [];
|
227
|
+
$els.each(function () {
|
228
|
+
arr.push(new ScrollSpy(this, options));
|
229
|
+
});
|
230
|
+
return arr;
|
231
|
+
}
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Get Instance
|
235
|
+
*/
|
236
|
+
|
237
|
+
}, {
|
238
|
+
key: 'getInstance',
|
239
|
+
value: function getInstance(el) {
|
240
|
+
var domElem = !!el.jquery ? el[0] : el;
|
241
|
+
return domElem.M_ScrollSpy;
|
242
|
+
}
|
243
|
+
}, {
|
244
|
+
key: '_findElements',
|
245
|
+
value: function _findElements(top, right, bottom, left) {
|
246
|
+
var hits = [];
|
247
|
+
for (var i = 0; i < ScrollSpy._elements.length; i++) {
|
248
|
+
var scrollspy = ScrollSpy._elements[i];
|
249
|
+
var currTop = top + scrollspy.options.scrollOffset || 200;
|
250
|
+
|
251
|
+
if (scrollspy.$el.height() > 0) {
|
252
|
+
var elTop = scrollspy.$el.offset().top,
|
253
|
+
elLeft = scrollspy.$el.offset().left,
|
254
|
+
elRight = elLeft + scrollspy.$el.width(),
|
255
|
+
elBottom = elTop + scrollspy.$el.height();
|
256
|
+
|
257
|
+
var isIntersect = !(elLeft > right || elRight < left || elTop > bottom || elBottom < currTop);
|
258
|
+
|
259
|
+
if (isIntersect) {
|
260
|
+
hits.push(scrollspy);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
}
|
264
|
+
return hits;
|
265
|
+
}
|
266
|
+
}, {
|
267
|
+
key: 'defaults',
|
268
|
+
get: function () {
|
269
|
+
return _defaults;
|
270
|
+
}
|
271
|
+
}]);
|
272
|
+
|
273
|
+
return ScrollSpy;
|
274
|
+
}();
|
275
|
+
|
276
|
+
/**
|
277
|
+
* @static
|
278
|
+
* @memberof ScrollSpy
|
279
|
+
* @type {Array.<ScrollSpy>}
|
280
|
+
*/
|
281
|
+
|
282
|
+
|
283
|
+
ScrollSpy._elements = [];
|
284
|
+
|
285
|
+
/**
|
286
|
+
* @static
|
287
|
+
* @memberof ScrollSpy
|
288
|
+
* @type {Array.<ScrollSpy>}
|
289
|
+
*/
|
290
|
+
ScrollSpy._elementsInView = [];
|
291
|
+
|
292
|
+
/**
|
293
|
+
* @static
|
294
|
+
* @memberof ScrollSpy
|
295
|
+
* @type {Array.<cash>}
|
296
|
+
*/
|
297
|
+
ScrollSpy._visibleElements = [];
|
298
|
+
|
299
|
+
/**
|
300
|
+
* @static
|
301
|
+
* @memberof ScrollSpy
|
302
|
+
*/
|
303
|
+
ScrollSpy._count = 0;
|
304
|
+
|
305
|
+
/**
|
306
|
+
* @static
|
307
|
+
* @memberof ScrollSpy
|
308
|
+
*/
|
309
|
+
ScrollSpy._increment = 0;
|
310
|
+
|
311
|
+
/**
|
312
|
+
* @static
|
313
|
+
* @memberof ScrollSpy
|
314
|
+
*/
|
315
|
+
ScrollSpy._ticks = 0;
|
316
|
+
|
317
|
+
M.ScrollSpy = ScrollSpy;
|
318
|
+
|
319
|
+
if (M.jQueryLoaded) {
|
320
|
+
M.initializeJqueryWrapper(ScrollSpy, 'scrollSpy', 'M_ScrollSpy');
|
321
|
+
}
|
322
|
+
})(cash, M.Vel);
|
@@ -0,0 +1,426 @@
|
|
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
|
+
classes: ''
|
10
|
+
};
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @class
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
|
17
|
+
var Select = function () {
|
18
|
+
/**
|
19
|
+
* Construct Select instance
|
20
|
+
* @constructor
|
21
|
+
* @param {Element} el
|
22
|
+
* @param {Object} options
|
23
|
+
*/
|
24
|
+
function Select(el, options) {
|
25
|
+
_classCallCheck(this, Select);
|
26
|
+
|
27
|
+
// If exists, destroy and reinitialize
|
28
|
+
if (!!el.M_Select) {
|
29
|
+
el.M_Select.destroy();
|
30
|
+
}
|
31
|
+
|
32
|
+
this.el = el;
|
33
|
+
this.$el = $(el);
|
34
|
+
this.el.M_Select = this;
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Options for the select
|
38
|
+
* @member Select#options
|
39
|
+
*/
|
40
|
+
this.options = $.extend({}, Select.defaults, options);
|
41
|
+
|
42
|
+
this.isMultiple = this.$el.prop('multiple');
|
43
|
+
|
44
|
+
// Setup
|
45
|
+
this.valuesSelected = [];
|
46
|
+
this.$selectedOptions = $();
|
47
|
+
this._setupDropdown();
|
48
|
+
|
49
|
+
this._setupEventHandlers();
|
50
|
+
}
|
51
|
+
|
52
|
+
_createClass(Select, [{
|
53
|
+
key: 'destroy',
|
54
|
+
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Teardown component
|
58
|
+
*/
|
59
|
+
value: function destroy() {
|
60
|
+
this._removeEventHandlers();
|
61
|
+
this._removeDropdown();
|
62
|
+
this.el.M_Select = undefined;
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Setup Event Handlers
|
67
|
+
*/
|
68
|
+
|
69
|
+
}, {
|
70
|
+
key: '_setupEventHandlers',
|
71
|
+
value: function _setupEventHandlers() {
|
72
|
+
var _this = this;
|
73
|
+
|
74
|
+
this._handleSelectChangeBound = this._handleSelectChange.bind(this);
|
75
|
+
this._handleOptionClickBound = this._handleOptionClick.bind(this);
|
76
|
+
this._handleInputClickBound = this._handleInputClick.bind(this);
|
77
|
+
|
78
|
+
$(this.dropdownOptions).find('li:not(.optgroup)').each(function (el) {
|
79
|
+
el.addEventListener('click', _this._handleOptionClickBound);
|
80
|
+
});
|
81
|
+
this.el.addEventListener('change', this._handleSelectChangeBound);
|
82
|
+
this.input.addEventListener('click', this._handleInputClickBound);
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Remove Event Handlers
|
87
|
+
*/
|
88
|
+
|
89
|
+
}, {
|
90
|
+
key: '_removeEventHandlers',
|
91
|
+
value: function _removeEventHandlers() {
|
92
|
+
var _this2 = this;
|
93
|
+
|
94
|
+
$(this.dropdownOptions).find('li:not(.optgroup)').each(function (el) {
|
95
|
+
el.removeEventListener('click', _this2._handleOptionClickBound);
|
96
|
+
});
|
97
|
+
this.el.removeEventListener('change', this._handleSelectChangeBound);
|
98
|
+
this.input.removeEventListener('click', this._handleInputClickBound);
|
99
|
+
this.input.removeEventListener('focus', this._handleInputFocusBound);
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Handle Select Change
|
104
|
+
* @param {Event} e
|
105
|
+
*/
|
106
|
+
|
107
|
+
}, {
|
108
|
+
key: '_handleSelectChange',
|
109
|
+
value: function _handleSelectChange(e) {
|
110
|
+
this._setValueToInput();
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Handle Option Click
|
115
|
+
* @param {Event} e
|
116
|
+
*/
|
117
|
+
|
118
|
+
}, {
|
119
|
+
key: '_handleOptionClick',
|
120
|
+
value: function _handleOptionClick(e) {
|
121
|
+
e.preventDefault();
|
122
|
+
var option = $(e.target).closest('li')[0];
|
123
|
+
var optionIndex = $(this.dropdownOptions).find('li:not(.optgroup)').index(option);
|
124
|
+
if (!$(option).hasClass('disabled') && !$(option).hasClass('optgroup')) {
|
125
|
+
var selected = true;
|
126
|
+
|
127
|
+
if (this.isMultiple) {
|
128
|
+
var checkbox = $(option).find('input[type="checkbox"]');
|
129
|
+
checkbox.prop('checked', !checkbox.prop('checked'));
|
130
|
+
selected = this._toggleEntryFromArray(optionIndex);
|
131
|
+
} else {
|
132
|
+
$(this.dropdownOptions).find('li').removeClass('active');
|
133
|
+
$(option).toggleClass('active');
|
134
|
+
this.input.value = option.textContent;
|
135
|
+
}
|
136
|
+
|
137
|
+
this._activateOption($(this.dropdownOptions), option);
|
138
|
+
this.$el.find('option').eq(optionIndex).prop('selected', selected);
|
139
|
+
this.$el.trigger('change');
|
140
|
+
}
|
141
|
+
|
142
|
+
e.stopPropagation();
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Handle Input Click
|
147
|
+
*/
|
148
|
+
|
149
|
+
}, {
|
150
|
+
key: '_handleInputClick',
|
151
|
+
value: function _handleInputClick() {
|
152
|
+
if (this.dropdown && this.dropdown.isOpen) {
|
153
|
+
this._setValueToInput();
|
154
|
+
this._setSelectedStates();
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Setup dropdown
|
160
|
+
*/
|
161
|
+
|
162
|
+
}, {
|
163
|
+
key: '_setupDropdown',
|
164
|
+
value: function _setupDropdown() {
|
165
|
+
var _this3 = this;
|
166
|
+
|
167
|
+
this.wrapper = document.createElement('div');
|
168
|
+
this.wrapper.classList.add();
|
169
|
+
$(this.wrapper).addClass('select-wrapper' + ' ' + this.options.classes);
|
170
|
+
this.$el.before($(this.wrapper));
|
171
|
+
this.wrapper.appendChild(this.el);
|
172
|
+
|
173
|
+
if (this.el.disabled) {
|
174
|
+
this.wrapper.classList.add('disabled');
|
175
|
+
}
|
176
|
+
|
177
|
+
// Create dropdown
|
178
|
+
this.$selectOptions = this.$el.children('option, optgroup');
|
179
|
+
this.dropdownOptions = document.createElement('ul');
|
180
|
+
this.dropdownOptions.id = 'select-options-' + M.guid();
|
181
|
+
$(this.dropdownOptions).addClass('dropdown-content select-dropdown ' + (this.isMultiple ? 'multiple-select-dropdown' : ''));
|
182
|
+
|
183
|
+
// Create dropdown structure.
|
184
|
+
if (this.$selectOptions.length) {
|
185
|
+
this.$selectOptions.each(function (el) {
|
186
|
+
if ($(el).is('option')) {
|
187
|
+
// Direct descendant option.
|
188
|
+
var optionEl = void 0;
|
189
|
+
if (_this3.isMultiple) {
|
190
|
+
optionEl = _this3._appendOptionWithIcon(_this3.$el, el, 'multiple');
|
191
|
+
} else {
|
192
|
+
optionEl = _this3._appendOptionWithIcon(_this3.$el, el);
|
193
|
+
}
|
194
|
+
|
195
|
+
if ($(el).prop('selected')) {
|
196
|
+
_this3.$selectedOptions.add(optionEl);
|
197
|
+
}
|
198
|
+
} else if ($(el).is('optgroup')) {
|
199
|
+
// Optgroup.
|
200
|
+
var selectOptions = $(el).children('option');
|
201
|
+
$(_this3.dropdownOptions).append($('<li class="optgroup"><span>' + el.getAttribute('label') + '</span></li>')[0]);
|
202
|
+
|
203
|
+
selectOptions.each(function (el) {
|
204
|
+
var optionEl = _this3._appendOptionWithIcon(_this3.$el, el, 'optgroup-option');
|
205
|
+
if ($(el).prop('selected')) {
|
206
|
+
_this3.$selectedOptions.add(optionEl);
|
207
|
+
}
|
208
|
+
});
|
209
|
+
}
|
210
|
+
});
|
211
|
+
}
|
212
|
+
|
213
|
+
this.$el.after(this.dropdownOptions);
|
214
|
+
|
215
|
+
// Add input dropdown
|
216
|
+
this.input = document.createElement('input');
|
217
|
+
$(this.input).addClass('select-dropdown dropdown-trigger');
|
218
|
+
this.input.setAttribute('type', 'text');
|
219
|
+
this.input.setAttribute('readonly', 'true');
|
220
|
+
this.input.setAttribute('data-target', this.dropdownOptions.id);
|
221
|
+
if (this.el.disabled) {
|
222
|
+
$(this.input).prop('disabled', 'true');
|
223
|
+
}
|
224
|
+
|
225
|
+
this.$el.before(this.input);
|
226
|
+
this._setValueToInput();
|
227
|
+
|
228
|
+
// Add caret
|
229
|
+
var dropdownIcon = $('<svg class="caret" fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>');
|
230
|
+
this.$el.before(dropdownIcon[0]);
|
231
|
+
|
232
|
+
// Initialize dropdown
|
233
|
+
if (!this.el.disabled) {
|
234
|
+
var dropdownOptions = {};
|
235
|
+
if (this.isMultiple) {
|
236
|
+
dropdownOptions.closeOnClick = false;
|
237
|
+
}
|
238
|
+
this.dropdown = new M.Dropdown(this.input, dropdownOptions);
|
239
|
+
}
|
240
|
+
|
241
|
+
// Add initial selections
|
242
|
+
this._setSelectedStates();
|
243
|
+
}
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Remove dropdown
|
247
|
+
*/
|
248
|
+
|
249
|
+
}, {
|
250
|
+
key: '_removeDropdown',
|
251
|
+
value: function _removeDropdown() {
|
252
|
+
$(this.wrapper).find('.caret').remove();
|
253
|
+
$(this.input).remove();
|
254
|
+
$(this.dropdownOptions).remove();
|
255
|
+
$(this.wrapper).before(this.$el);
|
256
|
+
$(this.wrapper).remove();
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Setup dropdown
|
261
|
+
* @param {Element} select select element
|
262
|
+
* @param {Element} option option element from select
|
263
|
+
* @param {String} type
|
264
|
+
* @return {Element} option element added
|
265
|
+
*/
|
266
|
+
|
267
|
+
}, {
|
268
|
+
key: '_appendOptionWithIcon',
|
269
|
+
value: function _appendOptionWithIcon(select, option, type) {
|
270
|
+
// Add disabled attr if disabled
|
271
|
+
var disabledClass = option.disabled ? 'disabled ' : '';
|
272
|
+
var optgroupClass = type === 'optgroup-option' ? 'optgroup-option ' : '';
|
273
|
+
var multipleCheckbox = this.isMultiple ? '<label><input type="checkbox"' + disabledClass + '"/><span>' + option.innerHTML + '</span></label>' : option.innerHTML;
|
274
|
+
var liEl = $('<li></li>');
|
275
|
+
var spanEl = $('<span></span>');
|
276
|
+
spanEl.html(multipleCheckbox);
|
277
|
+
liEl.addClass(disabledClass + ' ' + optgroupClass);
|
278
|
+
liEl.append(spanEl);
|
279
|
+
|
280
|
+
// add icons
|
281
|
+
var iconUrl = option.getAttribute('data-icon');
|
282
|
+
var classes = option.getAttribute('class');
|
283
|
+
if (!!iconUrl) {
|
284
|
+
var imgEl = $('<img alt="" src="' + iconUrl + '">');
|
285
|
+
liEl.prepend(imgEl);
|
286
|
+
}
|
287
|
+
|
288
|
+
// Check for multiple type.
|
289
|
+
$(this.dropdownOptions).append(liEl[0]);
|
290
|
+
return liEl[0];
|
291
|
+
}
|
292
|
+
|
293
|
+
/**
|
294
|
+
* Toggle entry from option
|
295
|
+
* @param {Number} entryIndex
|
296
|
+
* @return {Boolean} if entry was added or removed
|
297
|
+
*/
|
298
|
+
|
299
|
+
}, {
|
300
|
+
key: '_toggleEntryFromArray',
|
301
|
+
value: function _toggleEntryFromArray(entryIndex) {
|
302
|
+
var index = this.valuesSelected.indexOf(entryIndex),
|
303
|
+
notAdded = index === -1;
|
304
|
+
|
305
|
+
if (notAdded) {
|
306
|
+
this.valuesSelected.push(entryIndex);
|
307
|
+
} else {
|
308
|
+
this.valuesSelected.splice(index, 1);
|
309
|
+
}
|
310
|
+
|
311
|
+
$(this.dropdownOptions).find('li:not(.optgroup)').eq(entryIndex).toggleClass('active');
|
312
|
+
|
313
|
+
// use notAdded instead of true (to detect if the option is selected or not)
|
314
|
+
this.$el.find('option').eq(entryIndex).prop('selected', notAdded);
|
315
|
+
|
316
|
+
return notAdded;
|
317
|
+
}
|
318
|
+
|
319
|
+
/**
|
320
|
+
* Set value to input
|
321
|
+
*/
|
322
|
+
|
323
|
+
}, {
|
324
|
+
key: '_setValueToInput',
|
325
|
+
value: function _setValueToInput() {
|
326
|
+
var value = '';
|
327
|
+
var options = this.$el.find('option');
|
328
|
+
|
329
|
+
options.each(function (el, i) {
|
330
|
+
if ($(el).prop('selected')) {
|
331
|
+
var text = $(el).text();
|
332
|
+
value === '' ? value += text : value += ', ' + text;
|
333
|
+
}
|
334
|
+
});
|
335
|
+
|
336
|
+
if (value === '') {
|
337
|
+
var firstDisabled = this.$el.find('option:disabled').eq(0);
|
338
|
+
if (firstDisabled.length) {
|
339
|
+
value = firstDisabled.text();
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
this.input.value = value;
|
344
|
+
}
|
345
|
+
|
346
|
+
/**
|
347
|
+
* Set selected state of dropdown too match actual select element
|
348
|
+
*/
|
349
|
+
|
350
|
+
}, {
|
351
|
+
key: '_setSelectedStates',
|
352
|
+
value: function _setSelectedStates() {
|
353
|
+
var _this4 = this;
|
354
|
+
|
355
|
+
this.valuesSelected = [];
|
356
|
+
var $onlyOptions = $(this.dropdownOptions).find('li:not(.optgroup)');
|
357
|
+
this.$el.find('option').each(function (el, i) {
|
358
|
+
var option = $onlyOptions.eq(i);
|
359
|
+
|
360
|
+
if ($(el).prop('selected')) {
|
361
|
+
option.find('input[type="checkbox"]').prop("checked", true);
|
362
|
+
_this4._activateOption($(_this4.dropdownOptions), option);
|
363
|
+
_this4.valuesSelected.push(i);
|
364
|
+
} else {
|
365
|
+
option.find('input[type="checkbox"]').prop("checked", false);
|
366
|
+
option.removeClass('selected');
|
367
|
+
}
|
368
|
+
});
|
369
|
+
}
|
370
|
+
|
371
|
+
/**
|
372
|
+
* Make option as selected and scroll to selected position
|
373
|
+
* @param {jQuery} collection Select options jQuery element
|
374
|
+
* @param {Element} newOption element of the new option
|
375
|
+
*/
|
376
|
+
|
377
|
+
}, {
|
378
|
+
key: '_activateOption',
|
379
|
+
value: function _activateOption(collection, newOption) {
|
380
|
+
if (newOption) {
|
381
|
+
if (!this.isMultiple) {
|
382
|
+
collection.find('li.selected').removeClass('selected');
|
383
|
+
}
|
384
|
+
|
385
|
+
var option = $(newOption);
|
386
|
+
option.addClass('selected');
|
387
|
+
}
|
388
|
+
}
|
389
|
+
}], [{
|
390
|
+
key: 'init',
|
391
|
+
value: function init($els, options) {
|
392
|
+
var arr = [];
|
393
|
+
$els.each(function () {
|
394
|
+
if (!$(this).hasClass('browser-default')) {
|
395
|
+
arr.push(new Select(this, options));
|
396
|
+
}
|
397
|
+
});
|
398
|
+
return arr;
|
399
|
+
}
|
400
|
+
|
401
|
+
/**
|
402
|
+
* Get Instance
|
403
|
+
*/
|
404
|
+
|
405
|
+
}, {
|
406
|
+
key: 'getInstance',
|
407
|
+
value: function getInstance(el) {
|
408
|
+
var domElem = !!el.jquery ? el[0] : el;
|
409
|
+
return domElem.M_Select;
|
410
|
+
}
|
411
|
+
}, {
|
412
|
+
key: 'defaults',
|
413
|
+
get: function () {
|
414
|
+
return _defaults;
|
415
|
+
}
|
416
|
+
}]);
|
417
|
+
|
418
|
+
return Select;
|
419
|
+
}();
|
420
|
+
|
421
|
+
M.Select = Select;
|
422
|
+
|
423
|
+
if (M.jQueryLoaded) {
|
424
|
+
M.initializeJqueryWrapper(Select, 'select', 'M_Select');
|
425
|
+
}
|
426
|
+
})(cash);
|