@@ -58,7 +58,6 @@ class Raty {
58
58
this . scoreField . removeAttribute ( 'value' ) ;
59
59
}
60
60
}
61
-
62
61
click ( score ) {
63
62
if ( ! this . _isReadOnly ( ) ) {
64
63
score = this . _adjustedScore ( score ) ;
@@ -69,7 +68,6 @@ class Raty {
69
68
this . _target ( score ) ;
70
69
}
71
70
}
72
-
73
71
move ( score ) {
74
72
var integer = parseInt ( score , 10 ) ;
75
73
var decimal = this . _getDecimal ( score , 1 ) ;
@@ -87,7 +85,6 @@ class Raty {
87
85
star . dispatchEvent ( evt ) ;
88
86
this . isMove = false ;
89
87
}
90
-
91
88
readOnly ( readonly ) {
92
89
if ( this . _isReadOnly ( ) !== readonly ) {
93
90
if ( readonly ) {
@@ -144,7 +141,6 @@ class Raty {
144
141
}
145
142
return this ;
146
143
}
147
-
148
144
_adjustedScore ( score ) {
149
145
if ( score || score === 0 ) {
150
146
return this . _between ( score , 0 , this . opt . number ) ;
@@ -187,7 +183,6 @@ class Raty {
187
183
this . opt [ replaces [ i ] ] = this . opt [ replaces [ i ] ] . replace ( '.' , '-' ) ;
188
184
}
189
185
}
190
-
191
186
_apply ( score ) {
192
187
this . _fill ( score ) ;
193
188
if ( score ) {
@@ -215,7 +210,6 @@ class Raty {
215
210
_between ( value , min , max ) {
216
211
return Math . min ( Math . max ( parseFloat ( value ) , min ) , max ) ;
217
212
}
218
-
219
213
_binds ( ) {
220
214
if ( this . cancelButton ) {
221
215
this . _bindOverCancel ( ) ;
@@ -226,7 +220,6 @@ class Raty {
226
220
this . _bindClick ( ) ;
227
221
this . _bindOut ( ) ;
228
222
}
229
-
230
223
_bindClick ( ) {
231
224
this . stars . forEach ( value => {
232
225
value . addEventListener ( 'click' , evt => {
@@ -247,7 +240,6 @@ class Raty {
247
240
} ) ;
248
241
} ) ;
249
242
}
250
-
251
243
_bindClickCancel ( ) {
252
244
this . cancelButton . addEventListener ( 'click' , evt => {
253
245
this . scoreField . removeAttribute ( 'value' ) ;
@@ -256,7 +248,6 @@ class Raty {
256
248
}
257
249
} ) ;
258
250
}
259
-
260
251
_bindOut ( ) {
261
252
this . element . addEventListener ( 'mouseleave' , evt => {
262
253
const score = + this . scoreField . value || undefined ;
@@ -268,7 +259,6 @@ class Raty {
268
259
}
269
260
} ) ;
270
261
}
271
-
272
262
_bindOutCancel ( ) {
273
263
this . cancelButton . addEventListener ( 'mouseleave' , evt => {
274
264
let icon = this . opt . cancelOff ;
@@ -282,7 +272,6 @@ class Raty {
282
272
}
283
273
} ) ;
284
274
}
285
-
286
275
_bindOver ( ) {
287
276
const action = this . opt . half ? 'mousemove' : 'mouseover' ;
288
277
this . stars . forEach ( value => {
@@ -301,7 +290,6 @@ class Raty {
301
290
} ) ;
302
291
} ) ;
303
292
}
304
-
305
293
_bindOverCancel ( ) {
306
294
this . cancelButton . addEventListener ( 'mouseover' , evt => {
307
295
if ( this . _isReadOnly ( ) ) {
@@ -326,15 +314,13 @@ class Raty {
326
314
}
327
315
} ) ;
328
316
}
329
-
330
317
_buildScoreField ( ) {
331
318
const input = document . createElement ( 'input' ) ;
332
319
input . name = this . opt . scoreName ;
333
320
input . type = 'hidden' ;
334
321
this . element . appendChild ( input ) ;
335
322
return input ;
336
323
}
337
-
338
324
_createCancel ( ) {
339
325
const button = document . createElement ( this . opt . starType ) ;
340
326
const icon = this . opt . path + this . opt . cancelOff ;
@@ -345,7 +331,6 @@ class Raty {
345
331
button . setAttribute ( 'src' , icon ) ;
346
332
} else {
347
333
button . classList . add ( icon ) ;
348
-
349
334
button . setAttribute ( 'data-alt' , 'x' ) ;
350
335
}
351
336
if ( this . opt . cancelPlace === 'left' ) {
@@ -357,7 +342,6 @@ class Raty {
357
342
}
358
343
this . cancelButton = button ;
359
344
}
360
-
361
345
_createScore ( ) {
362
346
this . scoreField = document . querySelector ( this . opt . targetScore ) || this . _buildScoreField ( ) ;
363
347
}
@@ -375,7 +359,6 @@ class Raty {
375
359
}
376
360
this . stars = this . element . querySelectorAll ( this . opt . starType ) ;
377
361
}
378
-
379
362
_error ( message ) {
380
363
throw new Error ( message ) ;
381
364
}
@@ -392,7 +375,6 @@ class Raty {
392
375
}
393
376
}
394
377
}
395
-
396
378
_fill ( score ) {
397
379
let hash = 0 ;
398
380
if ( this . opt . iconRangeSame && this . opt . iconRange ) {
@@ -430,21 +412,18 @@ class Raty {
430
412
}
431
413
return result ;
432
414
}
433
-
434
415
_getRangeIcon ( irange , turnOn ) {
435
416
return turnOn ? irange . on || this . opt . starOn : irange . off || this . opt . starOff ;
436
417
}
437
-
438
418
_getScoreByPosition ( evt , icon ) {
439
419
let score = parseInt ( icon . alt || icon . getAttribute ( 'data-alt' ) , 10 ) ;
440
420
if ( this . opt . half ) {
441
421
const size = this . _getWidth ( ) ;
442
- const percent = parseFloat ( ( evt . pageX - icon . offsetLeft ) / size ) ;
422
+ const percent = parseFloat ( ( evt . pageX - icon . getBoundingClientRect ( ) . x ) / size ) ;
443
423
score = score - 1 + percent ;
444
424
}
445
425
return score ;
446
426
}
447
-
448
427
_getHint ( score , evt ) {
449
428
if ( score !== 0 && ! score ) {
450
429
return this . opt . noRatedMsg ;
@@ -465,7 +444,6 @@ class Raty {
465
444
}
466
445
return hint === '' ? '' : hint || score ;
467
446
}
468
-
469
447
_getWidth ( ) {
470
448
const width = parseFloat ( this . stars [ 0 ] . offsetWidth ) || 16 ;
471
449
if ( ! width ) {
@@ -478,7 +456,6 @@ class Raty {
478
456
true : true
479
457
} [ this . element . dataset . readOnly ] || false ;
480
458
}
481
-
482
459
_lock ( ) {
483
460
const hint = this . _getHint ( this . scoreField . value ) ;
484
461
this . element . style . pointerEvents = 'none' ;
@@ -495,7 +472,6 @@ class Raty {
495
472
_nameForIndex ( i ) {
496
473
return this . opt . score && this . opt . score >= i ? 'starOn' : 'starOff' ;
497
474
}
498
-
499
475
_resetTitle ( ) {
500
476
for ( let i = 0 ; i < this . opt . number ; i ++ ) {
501
477
this . stars [ i ] . title = this . _getHint ( i + 1 ) ;
@@ -515,7 +491,6 @@ class Raty {
515
491
return acc ;
516
492
} , { } ) ;
517
493
}
518
-
519
494
_roundHalfScore ( score ) {
520
495
const integer = parseInt ( score , 10 ) ;
521
496
let decimal = this . _getDecimal ( score , 1 ) ;
@@ -524,7 +499,6 @@ class Raty {
524
499
}
525
500
return integer + decimal ;
526
501
}
527
-
528
502
_roundStars ( score , evt ) {
529
503
const name = this . _starName ( score , evt ) ;
530
504
if ( name ) {
@@ -533,7 +507,6 @@ class Raty {
533
507
star && this . _setIcon ( star , icon ) ;
534
508
}
535
509
}
536
-
537
510
_setIcon ( star , icon ) {
538
511
star [ this . opt . starType === 'img' ? 'src' : 'className' ] = this . opt . path + icon ;
539
512
}
@@ -543,7 +516,6 @@ class Raty {
543
516
this . opt . path += '/' ;
544
517
}
545
518
}
546
-
547
519
_setTarget ( target , score ) {
548
520
if ( score ) {
549
521
score = this . opt . targetFormat . toString ( ) . replace ( '{score}' , score ) ;
@@ -554,7 +526,6 @@ class Raty {
554
526
target . textContent = score ;
555
527
}
556
528
}
557
-
558
529
_setTitle ( score , evt ) {
559
530
if ( score ) {
560
531
const integer = parseInt ( Math . ceil ( score ) , 10 ) ;
@@ -578,7 +549,6 @@ class Raty {
578
549
}
579
550
return 'starOn' ;
580
551
}
581
-
582
552
_target ( score , evt ) {
583
553
if ( this . opt . target ) {
584
554
const target = document . querySelector ( this . opt . target ) ;
@@ -604,11 +574,9 @@ class Raty {
604
574
this . _setTarget ( target , score ) ;
605
575
}
606
576
}
607
-
608
577
_turnOn ( i , score ) {
609
578
return this . opt . single ? i === score : i <= score ;
610
579
}
611
-
612
580
_unlock ( ) {
613
581
this . element . style . cursor = 'pointer' ;
614
582
this . element . style . pointerEvents = 'auto' ;
0 commit comments