@@ -115,69 +115,20 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
115
115
116
116
public static readonly is = 'node-projects-slider' ;
117
117
118
- public static properties = {
119
- valueMin : Number ,
120
- valueMax : Number ,
121
- min : Number ,
122
- max : Number
123
- }
124
-
125
118
static observedAttributes = [ 'value-min' , 'value-max' , 'min' , 'max' ] ;
126
119
127
120
private _numberInputs : HTMLInputElement [ ] ;
128
121
private _rangeInputs : HTMLInputElement [ ] ;
129
122
private _valuesGap : number = 1 ;
130
123
private _suppressAttributeChange : boolean = false ;
131
124
132
- public get valueMin ( ) {
133
- return this . getAttribute ( 'value-min' ) ;
134
- }
135
- public set valueMin ( value ) {
136
- this . _suppressAttributeChange = true ;
137
- this . setAttribute ( 'value-min' , value . toString ( ) ) ;
138
- this . _suppressAttributeChange = false ;
139
- this . _updateInputValues ( ) ;
140
- this . _updateRangeInputsValues ( ) ;
141
- }
142
-
143
- public get valueMax ( ) {
144
- return this . getAttribute ( 'value-max' ) ;
145
- }
146
- public set valueMax ( value ) {
147
- this . _suppressAttributeChange = true ;
148
- this . setAttribute ( 'value-max' , value . toString ( ) ) ;
149
- this . _suppressAttributeChange = false ;
150
- this . _updateInputValues ( ) ;
151
- this . _updateRangeInputsValues ( ) ;
152
- }
153
-
154
- public get min ( ) {
155
- return this . getAttribute ( 'min' ) ;
156
- }
157
- public set min ( value ) {
158
- this . _suppressAttributeChange = true ;
159
- this . setAttribute ( 'min' , value . toString ( ) ) ;
160
- this . _suppressAttributeChange = false ;
161
- this . _updateRangeInputsMinMax ( ) ;
162
- }
163
-
164
- public get max ( ) {
165
- return this . getAttribute ( 'max' ) ;
166
- }
167
- public set max ( value ) {
168
- this . _suppressAttributeChange = true ;
169
- this . setAttribute ( 'max' , value . toString ( ) ) ;
170
- this . _suppressAttributeChange = false ;
171
- this . _updateRangeInputsMinMax ( ) ;
172
- }
173
-
174
125
attributeChangedCallback ( name : string , oldValue : string , newValue : string ) {
175
126
if ( this . _suppressAttributeChange ) return ;
176
127
if ( name === "value-min" || name === "value-max" ) {
177
128
this . _updateInputValues ( ) ;
178
129
this . _updateRangeInputsValues ( ) ;
179
- this . _updateSliderPosition ( parseInt ( this . valueMin ) , parseInt ( this . _rangeInputs [ 0 ] . max ) , true ) ;
180
- this . _updateSliderPosition ( parseInt ( this . valueMax ) , parseInt ( this . _rangeInputs [ 1 ] . max ) , false ) ;
130
+ this . _updateSliderPosition ( parseInt ( this . getAttribute ( 'value-min' ) ) , parseInt ( this . getAttribute ( ' max' ) ) , true ) ;
131
+ this . _updateSliderPosition ( parseInt ( this . getAttribute ( 'value-max' ) ) , parseInt ( this . getAttribute ( ' max' ) ) , false ) ;
181
132
}
182
133
if ( name === "min" || name === "max" ) {
183
134
this . _updateRangeInputsMinMax ( ) ;
@@ -227,42 +178,42 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
227
178
}
228
179
} else {
229
180
// Update input values and range progress
230
- this . valueMin = minVal . toString ( ) ;
231
- this . valueMax = maxVal . toString ( ) ;
181
+ this . setAttribute ( 'value-min' , minVal . toString ( ) ) ;
182
+ this . setAttribute ( 'value-max' , maxVal . toString ( ) ) ;
232
183
}
233
184
} ) ;
234
185
235
186
this . _rangeInputs [ i ] . addEventListener ( "change" , e => {
236
187
let minVal = parseInt ( this . _rangeInputs [ 0 ] . value ) ;
237
188
let maxVal = parseInt ( this . _rangeInputs [ 1 ] . value ) ;
238
189
239
- this . valueMin = minVal . toString ( ) ;
240
- this . valueMax = maxVal . toString ( ) ;
190
+ this . setAttribute ( 'value-min' , minVal . toString ( ) ) ;
191
+ this . setAttribute ( 'value-max' , maxVal . toString ( ) ) ;
241
192
} ) ;
242
193
}
243
194
244
195
this . _updateInputValues ( ) ;
245
196
this . _updateRangeInputsMinMax ( ) ;
246
197
this . _updateRangeInputsValues ( ) ;
247
- this . _updateSliderPosition ( parseInt ( this . valueMin ) , parseInt ( this . _rangeInputs [ 0 ] . max ) , true ) ;
248
- this . _updateSliderPosition ( parseInt ( this . valueMax ) , parseInt ( this . _rangeInputs [ 1 ] . max ) , false ) ;
198
+ this . _updateSliderPosition ( parseInt ( this . getAttribute ( 'value-min' ) ) , parseInt ( this . getAttribute ( ' max' ) ) , true ) ;
199
+ this . _updateSliderPosition ( parseInt ( this . getAttribute ( 'value-max' ) ) , parseInt ( this . getAttribute ( ' max' ) ) , false ) ;
249
200
}
250
201
251
202
private _updateInputValues ( ) {
252
- this . _numberInputs [ 0 ] . value = this . valueMin . toString ( ) ;
253
- this . _numberInputs [ 1 ] . value = this . valueMax . toString ( ) ;
203
+ this . _numberInputs [ 0 ] . value = this . getAttribute ( 'value-min' ) ;
204
+ this . _numberInputs [ 1 ] . value = this . getAttribute ( 'value-max' ) ;
254
205
}
255
206
256
207
private _updateRangeInputsMinMax ( ) {
257
208
this . _rangeInputs . forEach ( rangeInput => {
258
- rangeInput . min = this . min . toString ( ) ;
259
- rangeInput . max = this . max . toString ( ) ;
209
+ rangeInput . min = this . getAttribute ( 'min' ) ;
210
+ rangeInput . max = this . getAttribute ( 'max' ) ;
260
211
} ) ;
261
212
}
262
213
263
214
private _updateRangeInputsValues ( ) {
264
- this . _rangeInputs [ 0 ] . value = this . valueMin . toString ( ) ;
265
- this . _rangeInputs [ 1 ] . value = this . valueMax . toString ( ) ;
215
+ this . _rangeInputs [ 0 ] . value = this . getAttribute ( 'value-min' ) ;
216
+ this . _rangeInputs [ 1 ] . value = this . getAttribute ( 'value-max' ) ;
266
217
}
267
218
268
219
private _handleInputChange ( e : Event ) {
@@ -273,29 +224,29 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
273
224
let maxp = parseInt ( this . _numberInputs [ 1 ] . value ) ;
274
225
let diff = maxp - minp ;
275
226
276
- if ( minp < parseInt ( this . min ) ) {
277
- console . log ( `Minimum value cannot be less than ${ this . min . toString ( ) } ` ) ;
278
- this . _numberInputs [ 0 ] . value = this . min . toString ( ) ;
279
- minp = parseInt ( this . min ) ;
227
+ if ( minp < parseInt ( this . getAttribute ( ' min' ) ) ) {
228
+ console . log ( `Minimum value cannot be less than ${ this . getAttribute ( 'min' ) } ` ) ;
229
+ this . _numberInputs [ 0 ] . value = this . getAttribute ( 'min' ) ;
230
+ minp = parseInt ( this . getAttribute ( ' min' ) ) ;
280
231
}
281
232
282
- if ( maxp > parseInt ( this . max ) ) {
283
- console . log ( `Maximum value cannot be greater than ${ this . max . toString ( ) } ` )
284
- this . _numberInputs [ 1 ] . value = this . max . toString ( ) ;
285
- maxp = parseInt ( this . max ) ;
233
+ if ( maxp > parseInt ( this . getAttribute ( ' max' ) ) ) {
234
+ console . log ( `Maximum value cannot be greater than ${ this . getAttribute ( 'max' ) } ` )
235
+ this . _numberInputs [ 1 ] . value = this . getAttribute ( 'max' ) ;
236
+ maxp = parseInt ( this . getAttribute ( ' max' ) ) ;
286
237
}
287
238
288
239
if ( minp > maxp - diff ) {
289
240
this . _numberInputs [ 0 ] . value = ( maxp - diff ) . toString ( ) ;
290
241
minp = maxp - diff ;
291
242
292
- if ( minp < parseInt ( this . min ) ) {
293
- this . _numberInputs [ 0 ] . value = this . min . toString ( ) ;
294
- minp = parseInt ( this . min ) ;
243
+ if ( minp < parseInt ( this . getAttribute ( ' min' ) ) ) {
244
+ this . _numberInputs [ 0 ] . value = this . getAttribute ( 'min' ) ;
245
+ minp = parseInt ( this . getAttribute ( ' min' ) ) ;
295
246
}
296
247
}
297
248
298
- if ( diff >= this . _valuesGap && maxp <= parseInt ( this . _rangeInputs [ 1 ] . max ) ) {
249
+ if ( diff >= this . _valuesGap && maxp <= parseInt ( this . getAttribute ( ' max' ) ) ) {
299
250
if ( inputIndex === 0 ) {
300
251
this . _rangeInputs [ 0 ] . value = minp . toString ( ) ;
301
252
let value1 = parseInt ( this . _rangeInputs [ 0 ] . max ) ;
@@ -306,19 +257,19 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
306
257
this . _updateSliderPosition ( maxp , value2 , false ) ;
307
258
}
308
259
}
309
- this . valueMin = this . _rangeInputs [ 0 ] . value ;
310
- this . valueMax = this . _rangeInputs [ 1 ] . value ;
260
+ this . setAttribute ( 'value-min' , this . _rangeInputs [ 0 ] . value ) ;
261
+ this . setAttribute ( 'value-max' , this . _rangeInputs [ 1 ] . value ) ;
311
262
}
312
263
313
264
private _updateSliderPosition ( value : number , max : number , isMin : boolean ) {
314
265
const rangevalue : HTMLDivElement = this . _getDomElement ( "slider" ) ;
315
- const range = parseInt ( this . max ) - parseInt ( this . min ) ; // Calculate the total range
266
+ const range = parseInt ( this . getAttribute ( ' max' ) ) - parseInt ( this . getAttribute ( ' min' ) ) ; // Calculate the total range
316
267
317
268
if ( isMin ) {
318
- const relativeValue = value - parseInt ( this . min ) ; // Calculate the relative value within the range
269
+ const relativeValue = value - parseInt ( this . getAttribute ( ' min' ) ) ; // Calculate the relative value within the range
319
270
rangevalue . style . left = `${ ( relativeValue / range ) * 100 } %` ;
320
271
} else {
321
- const relativeValue = value - parseInt ( this . min ) ; // Calculate the relative value within the range
272
+ const relativeValue = value - parseInt ( this . getAttribute ( ' min' ) ) ; // Calculate the relative value within the range
322
273
rangevalue . style . right = `${ 100 - ( relativeValue / range ) * 100 } %` ;
323
274
}
324
275
}
0 commit comments