1
1
import { Component } from "./component" ;
2
- import $ , { Selector } from "cash-dom" ;
3
2
import anim from "animejs" ;
4
3
5
- let _defaults = { } ;
4
+ const _defaults = { } ;
5
+
6
+ // TODO: !!!!!
6
7
7
8
export class Range extends Component {
9
+ el : HTMLInputElement ;
8
10
private _mousedown : boolean ;
9
11
private _handleRangeChangeBound : any ;
10
12
private _handleRangeMousedownTouchstartBound : any ;
11
13
private _handleRangeInputMousemoveTouchmoveBound : any ;
12
14
private _handleRangeMouseupTouchendBound : any ;
13
15
private _handleRangeBlurMouseoutTouchleaveBound : any ;
14
- value : Selector ;
15
- thumb : Selector ;
16
+ value : HTMLElement ;
17
+ thumb : HTMLElement ;
16
18
17
19
constructor ( el , options ) {
18
20
super ( Range , el , options ) ;
@@ -32,7 +34,7 @@ import anim from "animejs";
32
34
}
33
35
34
36
static getInstance ( el ) {
35
- let domElem = ! ! el . jquery ? el [ 0 ] : el ;
37
+ const domElem = ! ! el . jquery ? el [ 0 ] : el ;
36
38
return domElem . M_Range ;
37
39
}
38
40
@@ -76,55 +78,55 @@ import anim from "animejs";
76
78
}
77
79
78
80
_handleRangeChange ( ) {
79
- $ ( this . value ) . html ( this . $el . val ( ) ) ;
80
- if ( ! $ ( this . thumb ) . hasClass ( 'active' ) ) {
81
+ //$(this.value).html(this.$el.val());
82
+ this . value . innerHTML = this . el . value ;
83
+ if ( ! this . thumb . classList . contains ( 'active' ) ) {
81
84
this . _showRangeBubble ( ) ;
82
85
}
83
- let offsetLeft = this . _calcRangeOffset ( ) ;
84
- $ ( this . thumb )
85
- . addClass ( 'active' )
86
- . css ( 'left' , offsetLeft + 'px' ) ;
86
+ const offsetLeft = this . _calcRangeOffset ( ) ;
87
+ this . thumb . classList . add ( 'active' ) ;
88
+ this . thumb . style . left = offsetLeft + 'px' ;
87
89
}
88
90
89
91
_handleRangeMousedownTouchstart ( e ) {
90
92
// Set indicator value
91
- $ ( this . value ) . html ( this . $el . val ( ) ) ;
93
+ //$(this.value).html(this.$el.val());
94
+ this . value . innerHTML = this . el . value ;
92
95
this . _mousedown = true ;
93
- this . $ el. addClass ( 'active' ) ;
94
- if ( ! $ ( this . thumb ) . hasClass ( 'active' ) ) {
96
+ this . el . classList . add ( 'active' ) ;
97
+ if ( ! this . thumb . classList . contains ( 'active' ) ) {
95
98
this . _showRangeBubble ( ) ;
96
99
}
97
100
if ( e . type !== 'input' ) {
98
- let offsetLeft = this . _calcRangeOffset ( ) ;
99
- $ ( this . thumb )
100
- . addClass ( 'active' )
101
- . css ( 'left' , offsetLeft + 'px' ) ;
101
+ const offsetLeft = this . _calcRangeOffset ( ) ;
102
+ this . thumb . classList . add ( 'active' ) ;
103
+ this . thumb . style . left = offsetLeft + 'px' ;
102
104
}
103
105
}
104
106
105
107
_handleRangeInputMousemoveTouchmove ( ) {
106
108
if ( this . _mousedown ) {
107
- if ( ! $ ( this . thumb ) . hasClass ( 'active' ) ) {
109
+ if ( ! this . thumb . classList . contains ( 'active' ) ) {
108
110
this . _showRangeBubble ( ) ;
109
111
}
110
- let offsetLeft = this . _calcRangeOffset ( ) ;
111
- $ ( this . thumb )
112
- . addClass ( 'active' )
113
- . css ( 'left' , offsetLeft + 'px' ) ;
114
- $ ( this . value ) . html ( this . $ el. val ( ) ) ;
112
+ const offsetLeft = this . _calcRangeOffset ( ) ;
113
+ this . thumb . classList . add ( 'active' ) ;
114
+ this . thumb . style . left = offsetLeft + 'px' ;
115
+ //$(this.value).html(this.$el.val() );
116
+ this . value . innerHTML = this . el . value ;
115
117
}
116
118
}
117
119
118
120
_handleRangeMouseupTouchend ( ) {
119
121
this . _mousedown = false ;
120
- this . $ el. removeClass ( 'active' ) ;
122
+ this . el . classList . remove ( 'active' ) ;
121
123
}
122
124
123
125
_handleRangeBlurMouseoutTouchleave ( ) {
124
126
if ( ! this . _mousedown ) {
125
- let paddingLeft = parseInt ( this . $el . css ( 'padding-left' ) ) ;
126
- let marginLeft = 7 + paddingLeft + 'px' ;
127
- if ( $ ( this . thumb ) . hasClass ( 'active' ) ) {
127
+ const paddingLeft = parseInt ( this . $el . css ( 'padding-left' ) ) ;
128
+ const marginLeft = 7 + paddingLeft + 'px' ;
129
+ if ( this . thumb . classList . contains ( 'active' ) ) {
128
130
anim . remove ( this . thumb ) ;
129
131
anim ( {
130
132
targets : this . thumb ,
@@ -136,30 +138,26 @@ import anim from "animejs";
136
138
duration : 100
137
139
} ) ;
138
140
}
139
- $ ( this . thumb ) . removeClass ( 'active' ) ;
141
+ this . thumb . classList . remove ( 'active' ) ;
140
142
}
141
143
}
142
144
143
145
_setupThumb ( ) {
144
146
this . thumb = document . createElement ( 'span' ) ;
145
147
this . value = document . createElement ( 'span' ) ;
146
- $ ( this . thumb ) . addClass ( 'thumb' ) ;
147
- $ ( this . value ) . addClass ( 'value' ) ;
148
- $ ( this . thumb ) . append ( this . value ) ;
149
- this . $ el. after ( this . thumb ) ;
148
+ this . thumb . classList . add ( 'thumb' ) ;
149
+ this . value . classList . add ( 'value' ) ;
150
+ this . thumb . append ( this . value ) ;
151
+ this . el . after ( this . thumb ) ;
150
152
}
151
153
152
154
_removeThumb ( ) {
153
- $ ( this . thumb ) . remove ( ) ;
155
+ this . thumb . remove ( ) ;
154
156
}
155
157
156
158
_showRangeBubble ( ) {
157
- let paddingLeft = parseInt (
158
- $ ( this . thumb )
159
- . parent ( )
160
- . css ( 'padding-left' )
161
- ) ;
162
- let marginLeft = - 7 + paddingLeft + 'px' ; // TODO: fix magic number?
159
+ const paddingLeft = parseInt ( getComputedStyle ( this . thumb . parentElement ) . paddingLeft ) ;
160
+ const marginLeft = - 7 + paddingLeft + 'px' ; // TODO: fix magic number?
163
161
anim . remove ( this . thumb ) ;
164
162
anim ( {
165
163
targets : this . thumb ,
@@ -173,10 +171,10 @@ import anim from "animejs";
173
171
}
174
172
175
173
_calcRangeOffset ( ) : number {
176
- let width = this . $ el. width ( ) - 15 ;
177
- let max = parseFloat ( this . $ el. attr ( 'max' ) ) || 100 ; // Range default max
178
- let min = parseFloat ( this . $ el. attr ( 'min' ) ) || 0 ; // Range default min
179
- let percent = ( parseFloat ( this . $ el. val ( ) ) - min ) / ( max - min ) ;
174
+ const width = this . el . getBoundingClientRect ( ) . width - 15 ;
175
+ const max = parseFloat ( this . el . getAttribute ( 'max' ) ) || 100 ; // Range default max
176
+ const min = parseFloat ( this . el . getAttribute ( 'min' ) ) || 0 ; // Range default min
177
+ const percent = ( parseFloat ( this . el . getAttribute ( 'value' ) ) - min ) / ( max - min ) ;
180
178
return percent * width ;
181
179
}
182
180
}
0 commit comments