@materializecss/materialize 1.2.2 → 2.0.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Gruntfile.js +68 -313
- package/README.md +26 -14
- package/dist/css/materialize.css +1009 -1822
- package/dist/css/materialize.min.css +2 -8
- package/dist/js/materialize.js +8414 -12299
- package/dist/js/materialize.min.js +8968 -2
- package/dist/js/materialize.min.js.map +1 -0
- package/package.json +13 -9
- package/sass/components/_badges.scss +12 -2
- package/sass/components/_buttons.scss +16 -11
- package/sass/components/_cards.scss +14 -9
- package/sass/components/_carousel.scss +5 -2
- package/sass/components/_chips.scss +3 -3
- package/sass/components/_collapsible.scss +22 -8
- package/sass/components/_collection.scss +14 -6
- package/sass/components/_datepicker.scss +30 -11
- package/sass/components/_dropdown.scss +6 -4
- package/sass/components/_global.scss +132 -111
- package/sass/components/_grid.scss +119 -98
- package/sass/components/_modal.scss +3 -3
- package/sass/components/_navbar.scss +31 -17
- package/sass/components/_normalize.scss +26 -124
- package/sass/components/_sidenav.scss +21 -20
- package/sass/components/_slider.scss +27 -7
- package/sass/components/_table_of_contents.scss +12 -12
- package/sass/components/_tabs.scss +47 -16
- package/sass/components/_tapTarget.scss +6 -6
- package/sass/components/_theme_variables.scss +98 -0
- package/sass/components/_timepicker.scss +54 -46
- package/sass/components/_toast.scss +3 -3
- package/sass/components/_tooltip.scss +4 -5
- package/sass/components/_typography.scss +1 -1
- package/sass/components/_variables.scss +185 -120
- package/sass/components/forms/_checkboxes.scss +9 -9
- package/sass/components/forms/_file-input.scss +9 -7
- package/sass/components/forms/_input-fields.scss +173 -234
- package/sass/components/forms/_radio-buttons.scss +1 -1
- package/sass/components/forms/_range.scss +11 -11
- package/sass/components/forms/_select.scss +29 -19
- package/sass/components/forms/_switches.scss +22 -18
- package/sass/materialize.scss +1 -1
- package/src/autocomplete.ts +459 -0
- package/src/bounding.ts +6 -0
- package/{js/buttons.js → src/buttons.ts} +103 -162
- package/src/cards.ts +54 -0
- package/{js/carousel.js → src/carousel.ts} +137 -262
- package/src/characterCounter.ts +88 -0
- package/src/chips.ts +350 -0
- package/src/collapsible.ts +184 -0
- package/{js/component.js → src/component.ts} +6 -19
- package/{js/datepicker.js → src/datepicker.ts} +213 -299
- package/{js/dropdown.js → src/dropdown.ts} +140 -254
- package/src/edges.ts +6 -0
- package/src/forms.ts +120 -0
- package/src/global.ts +385 -0
- package/src/materialbox.ts +348 -0
- package/src/modal.ts +256 -0
- package/{js/parallax.js → src/parallax.ts} +47 -60
- package/{js/pushpin.js → src/pushpin.ts} +19 -47
- package/{js/range.js → src/range.ts} +58 -139
- package/{js/scrollspy.js → src/scrollspy.ts} +81 -153
- package/src/select.ts +448 -0
- package/{js/sidenav.js → src/sidenav.ts} +96 -202
- package/src/slider.ts +415 -0
- package/src/tabs.ts +293 -0
- package/src/tapTarget.ts +240 -0
- package/{js/timepicker.js → src/timepicker.ts} +268 -272
- package/{js/toasts.js → src/toasts.ts} +75 -134
- package/{js/tooltip.js → src/tooltip.ts} +59 -96
- package/src/waves.ts +70 -0
- package/extras/noUiSlider/nouislider.css +0 -404
- package/extras/noUiSlider/nouislider.js +0 -2147
- package/extras/noUiSlider/nouislider.min.js +0 -1
- package/js/anime.min.js +0 -34
- package/js/autocomplete.js +0 -479
- package/js/cards.js +0 -40
- package/js/cash.js +0 -960
- package/js/characterCounter.js +0 -136
- package/js/chips.js +0 -486
- package/js/collapsible.js +0 -275
- package/js/forms.js +0 -285
- package/js/global.js +0 -428
- package/js/materialbox.js +0 -453
- package/js/modal.js +0 -382
- package/js/select.js +0 -391
- package/js/slider.js +0 -497
- package/js/tabs.js +0 -402
- package/js/tapTarget.js +0 -315
- package/js/waves.js +0 -615
- package/sass/components/_waves.scss +0 -187
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Component } from "./component";
|
|
2
|
+
import { M } from "./global";
|
|
3
3
|
|
|
4
4
|
let _defaults = {
|
|
5
5
|
responsiveThreshold: 0 // breakpoint for swipeable
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
class Parallax extends Component {
|
|
8
|
+
export class Parallax extends Component {
|
|
9
|
+
private _enabled: boolean;
|
|
10
|
+
private _img: HTMLImageElement;
|
|
11
|
+
private _handleImageLoadBound: any;
|
|
12
|
+
static _parallaxes: any;
|
|
13
|
+
static _handleScrollThrottled: any;
|
|
14
|
+
static _handleWindowResizeThrottled: () => any;
|
|
15
|
+
|
|
9
16
|
constructor(el, options) {
|
|
10
17
|
super(Parallax, el, options);
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Options for the Parallax
|
|
16
|
-
* @member Parallax#options
|
|
17
|
-
* @prop {Number} responsiveThreshold
|
|
18
|
-
*/
|
|
19
|
-
this.options = $.extend({}, Parallax.defaults, options);
|
|
18
|
+
(this.el as any).M_Parallax = this;
|
|
19
|
+
this.options = {...Parallax.defaults, ...options};
|
|
20
20
|
this._enabled = window.innerWidth > this.options.responsiveThreshold;
|
|
21
|
-
|
|
22
|
-
this.$img = this.$el.find('img').first();
|
|
23
|
-
this.$img.each(function() {
|
|
24
|
-
let el = this;
|
|
25
|
-
if (el.complete) $(el).trigger('load');
|
|
26
|
-
});
|
|
27
|
-
|
|
21
|
+
this._img = this.el.querySelector('img');
|
|
28
22
|
this._updateParallax();
|
|
29
23
|
this._setupEventHandlers();
|
|
30
24
|
this._setupStyles();
|
|
31
|
-
|
|
32
25
|
Parallax._parallaxes.push(this);
|
|
33
26
|
}
|
|
34
27
|
|
|
@@ -40,23 +33,16 @@
|
|
|
40
33
|
return super.init(this, els, options);
|
|
41
34
|
}
|
|
42
35
|
|
|
43
|
-
/**
|
|
44
|
-
* Get Instance
|
|
45
|
-
*/
|
|
46
36
|
static getInstance(el) {
|
|
47
37
|
let domElem = !!el.jquery ? el[0] : el;
|
|
48
38
|
return domElem.M_Parallax;
|
|
49
39
|
}
|
|
50
40
|
|
|
51
|
-
/**
|
|
52
|
-
* Teardown component
|
|
53
|
-
*/
|
|
54
41
|
destroy() {
|
|
55
42
|
Parallax._parallaxes.splice(Parallax._parallaxes.indexOf(this), 1);
|
|
56
|
-
this
|
|
43
|
+
this._img.style.transform = '';
|
|
57
44
|
this._removeEventHandlers();
|
|
58
|
-
|
|
59
|
-
this.$el[0].M_Parallax = undefined;
|
|
45
|
+
(this.el as any).M_Parallax = undefined;
|
|
60
46
|
}
|
|
61
47
|
|
|
62
48
|
static _handleScroll() {
|
|
@@ -76,20 +62,17 @@
|
|
|
76
62
|
|
|
77
63
|
_setupEventHandlers() {
|
|
78
64
|
this._handleImageLoadBound = this._handleImageLoad.bind(this);
|
|
79
|
-
this
|
|
80
|
-
|
|
65
|
+
this._img.addEventListener('load', this._handleImageLoadBound);
|
|
81
66
|
if (Parallax._parallaxes.length === 0) {
|
|
82
67
|
Parallax._handleScrollThrottled = M.throttle(Parallax._handleScroll, 5);
|
|
83
68
|
window.addEventListener('scroll', Parallax._handleScrollThrottled);
|
|
84
|
-
|
|
85
69
|
Parallax._handleWindowResizeThrottled = M.throttle(Parallax._handleWindowResize, 5);
|
|
86
70
|
window.addEventListener('resize', Parallax._handleWindowResizeThrottled);
|
|
87
71
|
}
|
|
88
72
|
}
|
|
89
73
|
|
|
90
74
|
_removeEventHandlers() {
|
|
91
|
-
this
|
|
92
|
-
|
|
75
|
+
this._img.removeEventListener('load', this._handleImageLoadBound);
|
|
93
76
|
if (Parallax._parallaxes.length === 0) {
|
|
94
77
|
window.removeEventListener('scroll', Parallax._handleScrollThrottled);
|
|
95
78
|
window.removeEventListener('resize', Parallax._handleWindowResizeThrottled);
|
|
@@ -97,42 +80,46 @@
|
|
|
97
80
|
}
|
|
98
81
|
|
|
99
82
|
_setupStyles() {
|
|
100
|
-
this
|
|
83
|
+
this._img.style.opacity = '1';
|
|
101
84
|
}
|
|
102
85
|
|
|
103
86
|
_handleImageLoad() {
|
|
104
87
|
this._updateParallax();
|
|
105
88
|
}
|
|
106
89
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
let windowBottom = scrollTop + windowHeight;
|
|
116
|
-
let percentScrolled = (windowBottom - top) / (containerHeight + windowHeight);
|
|
117
|
-
let parallax = parallaxDist * percentScrolled;
|
|
90
|
+
private _offset(el: Element) {
|
|
91
|
+
const box = el.getBoundingClientRect();
|
|
92
|
+
const docElem = document.documentElement;
|
|
93
|
+
return {
|
|
94
|
+
top: box.top + window.pageYOffset - docElem.clientTop,
|
|
95
|
+
left: box.left + window.pageXOffset - docElem.clientLeft
|
|
96
|
+
};
|
|
97
|
+
}
|
|
118
98
|
|
|
99
|
+
_updateParallax() {
|
|
100
|
+
const containerHeight = this.el.getBoundingClientRect().height > 0 ? (this.el.parentNode as any).offsetHeight : 500;
|
|
101
|
+
const imgHeight = this._img.offsetHeight;
|
|
102
|
+
const parallaxDist = imgHeight - containerHeight;
|
|
103
|
+
const bottom = this._offset(this.el).top + containerHeight;
|
|
104
|
+
const top = this._offset(this.el).top;
|
|
105
|
+
const scrollTop = M.getDocumentScrollTop();
|
|
106
|
+
const windowHeight = window.innerHeight;
|
|
107
|
+
const windowBottom = scrollTop + windowHeight;
|
|
108
|
+
const percentScrolled = (windowBottom - top) / (containerHeight + windowHeight);
|
|
109
|
+
const parallax = parallaxDist * percentScrolled;
|
|
110
|
+
|
|
119
111
|
if (!this._enabled) {
|
|
120
|
-
this
|
|
121
|
-
}
|
|
122
|
-
|
|
112
|
+
this._img.style.transform = '';
|
|
113
|
+
}
|
|
114
|
+
else if (bottom > scrollTop && top < scrollTop + windowHeight) {
|
|
115
|
+
this._img.style.transform = `translate3D(-50%, ${parallax}px, 0)`;
|
|
123
116
|
}
|
|
124
117
|
}
|
|
125
|
-
}
|
|
126
118
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
Parallax._parallaxes = [];
|
|
119
|
+
static {
|
|
120
|
+
Parallax._parallaxes = [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
132
123
|
|
|
133
|
-
|
|
124
|
+
|
|
134
125
|
|
|
135
|
-
if (M.jQueryLoaded) {
|
|
136
|
-
M.initializeJqueryWrapper(Parallax, 'parallax', 'M_Parallax');
|
|
137
|
-
}
|
|
138
|
-
})(cash);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Component } from "./component";
|
|
2
|
+
import { M } from "./global";
|
|
3
3
|
|
|
4
4
|
let _defaults = {
|
|
5
5
|
top: 0,
|
|
@@ -8,29 +8,15 @@
|
|
|
8
8
|
onPositionChange: null
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class Pushpin extends Component {
|
|
16
|
-
/**
|
|
17
|
-
* Construct Pushpin instance
|
|
18
|
-
* @constructor
|
|
19
|
-
* @param {Element} el
|
|
20
|
-
* @param {Object} options
|
|
21
|
-
*/
|
|
11
|
+
export class Pushpin extends Component {
|
|
12
|
+
static _pushpins: any[];
|
|
13
|
+
originalOffset: any;
|
|
14
|
+
|
|
22
15
|
constructor(el, options) {
|
|
23
16
|
super(Pushpin, el, options);
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Options for the modal
|
|
29
|
-
* @member Pushpin#options
|
|
30
|
-
*/
|
|
31
|
-
this.options = $.extend({}, Pushpin.defaults, options);
|
|
32
|
-
|
|
33
|
-
this.originalOffset = this.el.offsetTop;
|
|
17
|
+
(this.el as any).M_Pushpin = this;
|
|
18
|
+
this.options = {...Pushpin.defaults, ...options};
|
|
19
|
+
this.originalOffset = (this.el as HTMLElement).offsetTop;
|
|
34
20
|
Pushpin._pushpins.push(this);
|
|
35
21
|
this._setupEventHandlers();
|
|
36
22
|
this._updatePosition();
|
|
@@ -44,28 +30,21 @@
|
|
|
44
30
|
return super.init(this, els, options);
|
|
45
31
|
}
|
|
46
32
|
|
|
47
|
-
/**
|
|
48
|
-
* Get Instance
|
|
49
|
-
*/
|
|
50
33
|
static getInstance(el) {
|
|
51
34
|
let domElem = !!el.jquery ? el[0] : el;
|
|
52
35
|
return domElem.M_Pushpin;
|
|
53
36
|
}
|
|
54
37
|
|
|
55
|
-
/**
|
|
56
|
-
* Teardown component
|
|
57
|
-
*/
|
|
58
38
|
destroy() {
|
|
59
|
-
this.el.style.top = null;
|
|
39
|
+
(this.el as HTMLElement).style.top = null;
|
|
60
40
|
this._removePinClasses();
|
|
61
|
-
|
|
62
41
|
// Remove pushpin Inst
|
|
63
42
|
let index = Pushpin._pushpins.indexOf(this);
|
|
64
43
|
Pushpin._pushpins.splice(index, 1);
|
|
65
44
|
if (Pushpin._pushpins.length === 0) {
|
|
66
45
|
this._removeEventHandlers();
|
|
67
46
|
}
|
|
68
|
-
this.el.M_Pushpin = undefined;
|
|
47
|
+
(this.el as any).M_Pushpin = undefined;
|
|
69
48
|
}
|
|
70
49
|
|
|
71
50
|
static _updateElements() {
|
|
@@ -92,7 +71,7 @@
|
|
|
92
71
|
!this.el.classList.contains('pinned')
|
|
93
72
|
) {
|
|
94
73
|
this._removePinClasses();
|
|
95
|
-
this.el.style.top = `${this.options.offset}px`;
|
|
74
|
+
(this.el as HTMLElement).style.top = `${this.options.offset}px`;
|
|
96
75
|
this.el.classList.add('pinned');
|
|
97
76
|
|
|
98
77
|
// onPositionChange callback
|
|
@@ -104,7 +83,7 @@
|
|
|
104
83
|
// Add pin-top (when scrolled position is above top)
|
|
105
84
|
if (scrolled < this.options.top && !this.el.classList.contains('pin-top')) {
|
|
106
85
|
this._removePinClasses();
|
|
107
|
-
this.el.style.top = 0;
|
|
86
|
+
(this.el as HTMLElement).style.top = '0';
|
|
108
87
|
this.el.classList.add('pin-top');
|
|
109
88
|
|
|
110
89
|
// onPositionChange callback
|
|
@@ -117,7 +96,7 @@
|
|
|
117
96
|
if (scrolled > this.options.bottom && !this.el.classList.contains('pin-bottom')) {
|
|
118
97
|
this._removePinClasses();
|
|
119
98
|
this.el.classList.add('pin-bottom');
|
|
120
|
-
this.el.style.top = `${this.options.bottom - this.originalOffset}px`;
|
|
99
|
+
(this.el as HTMLElement).style.top = `${this.options.bottom - this.originalOffset}px`;
|
|
121
100
|
|
|
122
101
|
// onPositionChange callback
|
|
123
102
|
if (typeof this.options.onPositionChange === 'function') {
|
|
@@ -132,17 +111,10 @@
|
|
|
132
111
|
this.el.classList.remove('pinned');
|
|
133
112
|
this.el.classList.remove('pin-bottom');
|
|
134
113
|
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @static
|
|
139
|
-
* @memberof Pushpin
|
|
140
|
-
*/
|
|
141
|
-
Pushpin._pushpins = [];
|
|
142
114
|
|
|
143
|
-
|
|
115
|
+
static {
|
|
116
|
+
Pushpin._pushpins = [];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
144
119
|
|
|
145
|
-
|
|
146
|
-
M.initializeJqueryWrapper(Pushpin, 'pushpin', 'M_Pushpin');
|
|
147
|
-
}
|
|
148
|
-
})(cash);
|
|
120
|
+
|
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Component } from "./component";
|
|
2
|
+
import anim from "animejs";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const _defaults = {};
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
* @class
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
class Range extends Component {
|
|
11
|
-
/**
|
|
12
|
-
* Construct Range instance
|
|
13
|
-
* @constructor
|
|
14
|
-
* @param {Element} el
|
|
15
|
-
* @param {Object} options
|
|
16
|
-
*/
|
|
17
|
-
constructor(el, options) {
|
|
18
|
-
super(Range, el, options);
|
|
6
|
+
// TODO: !!!!!
|
|
19
7
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
export class Range extends Component {
|
|
9
|
+
el: HTMLInputElement;
|
|
10
|
+
private _mousedown: boolean;
|
|
11
|
+
private _handleRangeChangeBound: any;
|
|
12
|
+
private _handleRangeMousedownTouchstartBound: any;
|
|
13
|
+
private _handleRangeInputMousemoveTouchmoveBound: any;
|
|
14
|
+
private _handleRangeMouseupTouchendBound: any;
|
|
15
|
+
private _handleRangeBlurMouseoutTouchleaveBound: any;
|
|
16
|
+
value: HTMLElement;
|
|
17
|
+
thumb: HTMLElement;
|
|
27
18
|
|
|
19
|
+
constructor(el, options) {
|
|
20
|
+
super(Range, el, options);
|
|
21
|
+
(this.el as any).M_Range = this;
|
|
22
|
+
this.options = {...Range.defaults, ...options};
|
|
28
23
|
this._mousedown = false;
|
|
29
|
-
|
|
30
|
-
// Setup
|
|
31
24
|
this._setupThumb();
|
|
32
|
-
|
|
33
25
|
this._setupEventHandlers();
|
|
34
26
|
}
|
|
35
27
|
|
|
@@ -41,149 +33,97 @@
|
|
|
41
33
|
return super.init(this, els, options);
|
|
42
34
|
}
|
|
43
35
|
|
|
44
|
-
/**
|
|
45
|
-
* Get Instance
|
|
46
|
-
*/
|
|
47
36
|
static getInstance(el) {
|
|
48
|
-
|
|
37
|
+
const domElem = !!el.jquery ? el[0] : el;
|
|
49
38
|
return domElem.M_Range;
|
|
50
39
|
}
|
|
51
40
|
|
|
52
|
-
/**
|
|
53
|
-
* Teardown component
|
|
54
|
-
*/
|
|
55
41
|
destroy() {
|
|
56
42
|
this._removeEventHandlers();
|
|
57
43
|
this._removeThumb();
|
|
58
|
-
this.el.M_Range = undefined;
|
|
44
|
+
(this.el as any).M_Range = undefined;
|
|
59
45
|
}
|
|
60
46
|
|
|
61
|
-
/**
|
|
62
|
-
* Setup Event Handlers
|
|
63
|
-
*/
|
|
64
47
|
_setupEventHandlers() {
|
|
65
48
|
this._handleRangeChangeBound = this._handleRangeChange.bind(this);
|
|
66
49
|
this._handleRangeMousedownTouchstartBound = this._handleRangeMousedownTouchstart.bind(this);
|
|
67
|
-
this._handleRangeInputMousemoveTouchmoveBound = this._handleRangeInputMousemoveTouchmove.bind(
|
|
68
|
-
this
|
|
69
|
-
);
|
|
50
|
+
this._handleRangeInputMousemoveTouchmoveBound = this._handleRangeInputMousemoveTouchmove.bind(this);
|
|
70
51
|
this._handleRangeMouseupTouchendBound = this._handleRangeMouseupTouchend.bind(this);
|
|
71
|
-
this._handleRangeBlurMouseoutTouchleaveBound = this._handleRangeBlurMouseoutTouchleave.bind(
|
|
72
|
-
this
|
|
73
|
-
);
|
|
74
|
-
|
|
52
|
+
this._handleRangeBlurMouseoutTouchleaveBound = this._handleRangeBlurMouseoutTouchleave.bind(this);
|
|
75
53
|
this.el.addEventListener('change', this._handleRangeChangeBound);
|
|
76
|
-
|
|
77
54
|
this.el.addEventListener('mousedown', this._handleRangeMousedownTouchstartBound);
|
|
78
55
|
this.el.addEventListener('touchstart', this._handleRangeMousedownTouchstartBound);
|
|
79
|
-
|
|
80
56
|
this.el.addEventListener('input', this._handleRangeInputMousemoveTouchmoveBound);
|
|
81
57
|
this.el.addEventListener('mousemove', this._handleRangeInputMousemoveTouchmoveBound);
|
|
82
58
|
this.el.addEventListener('touchmove', this._handleRangeInputMousemoveTouchmoveBound);
|
|
83
|
-
|
|
84
59
|
this.el.addEventListener('mouseup', this._handleRangeMouseupTouchendBound);
|
|
85
60
|
this.el.addEventListener('touchend', this._handleRangeMouseupTouchendBound);
|
|
86
|
-
|
|
87
61
|
this.el.addEventListener('blur', this._handleRangeBlurMouseoutTouchleaveBound);
|
|
88
62
|
this.el.addEventListener('mouseout', this._handleRangeBlurMouseoutTouchleaveBound);
|
|
89
63
|
this.el.addEventListener('touchleave', this._handleRangeBlurMouseoutTouchleaveBound);
|
|
90
64
|
}
|
|
91
65
|
|
|
92
|
-
/**
|
|
93
|
-
* Remove Event Handlers
|
|
94
|
-
*/
|
|
95
66
|
_removeEventHandlers() {
|
|
96
67
|
this.el.removeEventListener('change', this._handleRangeChangeBound);
|
|
97
|
-
|
|
98
68
|
this.el.removeEventListener('mousedown', this._handleRangeMousedownTouchstartBound);
|
|
99
69
|
this.el.removeEventListener('touchstart', this._handleRangeMousedownTouchstartBound);
|
|
100
|
-
|
|
101
70
|
this.el.removeEventListener('input', this._handleRangeInputMousemoveTouchmoveBound);
|
|
102
71
|
this.el.removeEventListener('mousemove', this._handleRangeInputMousemoveTouchmoveBound);
|
|
103
72
|
this.el.removeEventListener('touchmove', this._handleRangeInputMousemoveTouchmoveBound);
|
|
104
|
-
|
|
105
73
|
this.el.removeEventListener('mouseup', this._handleRangeMouseupTouchendBound);
|
|
106
74
|
this.el.removeEventListener('touchend', this._handleRangeMouseupTouchendBound);
|
|
107
|
-
|
|
108
75
|
this.el.removeEventListener('blur', this._handleRangeBlurMouseoutTouchleaveBound);
|
|
109
76
|
this.el.removeEventListener('mouseout', this._handleRangeBlurMouseoutTouchleaveBound);
|
|
110
77
|
this.el.removeEventListener('touchleave', this._handleRangeBlurMouseoutTouchleaveBound);
|
|
111
78
|
}
|
|
112
79
|
|
|
113
|
-
/**
|
|
114
|
-
* Handle Range Change
|
|
115
|
-
* @param {Event} e
|
|
116
|
-
*/
|
|
117
80
|
_handleRangeChange() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (!$(this.thumb).hasClass('active')) {
|
|
81
|
+
this.value.innerHTML = this.el.value;
|
|
82
|
+
if (!this.thumb.classList.contains('active')) {
|
|
121
83
|
this._showRangeBubble();
|
|
122
84
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
.addClass('active')
|
|
127
|
-
.css('left', offsetLeft + 'px');
|
|
85
|
+
const offsetLeft = this._calcRangeOffset();
|
|
86
|
+
this.thumb.classList.add('active');
|
|
87
|
+
this.thumb.style.left = offsetLeft+'px';
|
|
128
88
|
}
|
|
129
89
|
|
|
130
|
-
/**
|
|
131
|
-
* Handle Range Mousedown and Touchstart
|
|
132
|
-
* @param {Event} e
|
|
133
|
-
*/
|
|
134
90
|
_handleRangeMousedownTouchstart(e) {
|
|
135
91
|
// Set indicator value
|
|
136
|
-
|
|
137
|
-
|
|
92
|
+
this.value.innerHTML = this.el.value;
|
|
138
93
|
this._mousedown = true;
|
|
139
|
-
this
|
|
140
|
-
|
|
141
|
-
if (!$(this.thumb).hasClass('active')) {
|
|
94
|
+
this.el.classList.add('active');
|
|
95
|
+
if (!this.thumb.classList.contains('active')) {
|
|
142
96
|
this._showRangeBubble();
|
|
143
97
|
}
|
|
144
|
-
|
|
145
98
|
if (e.type !== 'input') {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
.css('left', offsetLeft + 'px');
|
|
99
|
+
const offsetLeft = this._calcRangeOffset();
|
|
100
|
+
this.thumb.classList.add('active');
|
|
101
|
+
this.thumb.style.left = offsetLeft+'px';
|
|
150
102
|
}
|
|
151
103
|
}
|
|
152
104
|
|
|
153
|
-
/**
|
|
154
|
-
* Handle Range Input, Mousemove and Touchmove
|
|
155
|
-
*/
|
|
156
105
|
_handleRangeInputMousemoveTouchmove() {
|
|
157
106
|
if (this._mousedown) {
|
|
158
|
-
if (
|
|
107
|
+
if (!this.thumb.classList.contains('active')) {
|
|
159
108
|
this._showRangeBubble();
|
|
160
109
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
.css('left', offsetLeft + 'px');
|
|
166
|
-
$(this.value).html(this.$el.val());
|
|
110
|
+
const offsetLeft = this._calcRangeOffset();
|
|
111
|
+
this.thumb.classList.add('active');
|
|
112
|
+
this.thumb.style.left = offsetLeft+'px';
|
|
113
|
+
this.value.innerHTML = this.el.value;
|
|
167
114
|
}
|
|
168
115
|
}
|
|
169
116
|
|
|
170
|
-
/**
|
|
171
|
-
* Handle Range Mouseup and Touchend
|
|
172
|
-
*/
|
|
173
117
|
_handleRangeMouseupTouchend() {
|
|
174
118
|
this._mousedown = false;
|
|
175
|
-
this
|
|
119
|
+
this.el.classList.remove('active');
|
|
176
120
|
}
|
|
177
121
|
|
|
178
|
-
/**
|
|
179
|
-
* Handle Range Blur, Mouseout and Touchleave
|
|
180
|
-
*/
|
|
181
122
|
_handleRangeBlurMouseoutTouchleave() {
|
|
182
123
|
if (!this._mousedown) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if ($(this.thumb).hasClass('active')) {
|
|
124
|
+
const paddingLeft = parseInt(getComputedStyle(this.el).paddingLeft);
|
|
125
|
+
const marginLeft = 7 + paddingLeft + 'px';
|
|
126
|
+
if (this.thumb.classList.contains('active')) {
|
|
187
127
|
anim.remove(this.thumb);
|
|
188
128
|
anim({
|
|
189
129
|
targets: this.thumb,
|
|
@@ -195,39 +135,26 @@
|
|
|
195
135
|
duration: 100
|
|
196
136
|
});
|
|
197
137
|
}
|
|
198
|
-
|
|
138
|
+
this.thumb.classList.remove('active');
|
|
199
139
|
}
|
|
200
140
|
}
|
|
201
141
|
|
|
202
|
-
/**
|
|
203
|
-
* Setup dropdown
|
|
204
|
-
*/
|
|
205
142
|
_setupThumb() {
|
|
206
143
|
this.thumb = document.createElement('span');
|
|
207
144
|
this.value = document.createElement('span');
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this
|
|
145
|
+
this.thumb.classList.add('thumb');
|
|
146
|
+
this.value.classList.add('value');
|
|
147
|
+
this.thumb.append(this.value);
|
|
148
|
+
this.el.after(this.thumb);
|
|
212
149
|
}
|
|
213
150
|
|
|
214
|
-
/**
|
|
215
|
-
* Remove dropdown
|
|
216
|
-
*/
|
|
217
151
|
_removeThumb() {
|
|
218
|
-
|
|
152
|
+
this.thumb.remove();
|
|
219
153
|
}
|
|
220
154
|
|
|
221
|
-
/**
|
|
222
|
-
* morph thumb into bubble
|
|
223
|
-
*/
|
|
224
155
|
_showRangeBubble() {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
.parent()
|
|
228
|
-
.css('padding-left')
|
|
229
|
-
);
|
|
230
|
-
let marginLeft = -7 + paddingLeft + 'px'; // TODO: fix magic number?
|
|
156
|
+
const paddingLeft = parseInt(getComputedStyle(this.thumb.parentElement).paddingLeft);
|
|
157
|
+
const marginLeft = -7 + paddingLeft + 'px'; // TODO: fix magic number?
|
|
231
158
|
anim.remove(this.thumb);
|
|
232
159
|
anim({
|
|
233
160
|
targets: this.thumb,
|
|
@@ -240,24 +167,16 @@
|
|
|
240
167
|
});
|
|
241
168
|
}
|
|
242
169
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
let width = this.$el.width() - 15;
|
|
249
|
-
let max = parseFloat(this.$el.attr('max')) || 100; // Range default max
|
|
250
|
-
let min = parseFloat(this.$el.attr('min')) || 0; // Range default min
|
|
251
|
-
let percent = (parseFloat(this.$el.val()) - min) / (max - min);
|
|
170
|
+
_calcRangeOffset(): number {
|
|
171
|
+
const width = this.el.getBoundingClientRect().width - 15;
|
|
172
|
+
const max = parseFloat(this.el.getAttribute('max')) || 100; // Range default max
|
|
173
|
+
const min = parseFloat(this.el.getAttribute('min')) || 0; // Range default min
|
|
174
|
+
const percent = (parseFloat(this.el.value) - min) / (max - min);
|
|
252
175
|
return percent * width;
|
|
253
176
|
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
M.Range = Range;
|
|
257
177
|
|
|
258
|
-
|
|
259
|
-
|
|
178
|
+
static Init(){
|
|
179
|
+
Range.init(document.querySelectorAll('input[type=range]'), {});
|
|
180
|
+
}
|
|
260
181
|
}
|
|
261
182
|
|
|
262
|
-
Range.init($('input[type=range]'));
|
|
263
|
-
})(cash, M.anime);
|