Commit 18ad13ac authored by Taddeüs Kroes's avatar Taddeüs Kroes

Use HTML data attribute to record scores, cleaner & probably faster code

parent 9f298a6c
...@@ -30,12 +30,16 @@ if table.classList.contains 'match-editable' ...@@ -30,12 +30,16 @@ if table.classList.contains 'match-editable'
subtotal = 0 subtotal = 0
subtotal += scores[dirty_row * w + col] for col in [0...w] subtotal += scores[dirty_row * w + col] for col in [0...w]
sub(dirty_row).innerHTML = subtotal rowsub = sub dirty_row
rowsub.innerHTML = subtotal
rowsub.dataset.score = Math.floor(subtotal / w)
total = if dirty_row then num tot(dirty_row - 1).innerHTML else 0 total = if dirty_row then num tot(dirty_row - 1).innerHTML else 0
for row in [dirty_row...h] for row in [dirty_row...h]
total += num sub(row).innerHTML total += num sub(row).innerHTML
tot(row).innerHTML = total rowtot = tot row
rowtot.innerHTML = total
rowtot.dataset.score = Math.floor(total / ((row + 1) * w))
match_total.innerHTML = total match_total.innerHTML = total
match_avg.innerHTML = Math.round(total / inputs.length * 10) / 10 match_avg.innerHTML = Math.round(total / inputs.length * 10) / 10
...@@ -47,7 +51,7 @@ if table.classList.contains 'match-editable' ...@@ -47,7 +51,7 @@ if table.classList.contains 'match-editable'
cb = -> cb = ->
value = num @.value value = num @.value
if set_score col, row, value if set_score col, row, value
cell.className = cell.className.replace /val-\d+/, 'val-' + value cell.dataset.score = value
if value != 10 if value != 10
@.nextElementSibling.value = 0 @.nextElementSibling.value = 0
@.parentNode.querySelector('.cross-popup') @.parentNode.querySelector('.cross-popup')
...@@ -82,6 +86,7 @@ if table.classList.contains 'match-editable' ...@@ -82,6 +86,7 @@ if table.classList.contains 'match-editable'
localStorage.setItem 'hide-total-scores', true localStorage.setItem 'hide-total-scores', true
else else
localStorage.removeItem 'hide-total-scores' localStorage.removeItem 'hide-total-scores'
render 0
# notes area grows automatically with each added line # notes area grows automatically with each added line
if notes = document.getElementById('notes') if notes = document.getElementById('notes')
......
...@@ -67,25 +67,26 @@ $lg-width: 1200px ...@@ -67,25 +67,26 @@ $lg-width: 1200px
$white: #F2F2F2 $white: #F2F2F2
&.colored &.colored
.val-10, .val-9 td[data-score="10"], td[data-score="9"]
background-color: $yellow background-color: $yellow
.val-8, .val-7 td[data-score="8"], td[data-score="7"]
background-color: $red background-color: $red
.val-6, .val-5 td[data-score="6"], td[data-score="5"]
background-color: $blue background-color: $blue
.val-4, .val-3 td[data-score="4"], td[data-score="3"]
background-color: $black background-color: $black
color: white color: white
.val-2, .val-1 td[data-score="2"], td[data-score="1"]
background-color: $white background-color: $white
&.hide-total-scores &.hide-total-scores
.row-total, .total, .match-avg, .match-total .row-total, .total, .match-avg, .match-total
color: #fff background-color: white !important
color: white
.popup-container .popup-container
position: relative position: relative
...@@ -109,7 +110,7 @@ $lg-width: 1200px ...@@ -109,7 +110,7 @@ $lg-width: 1200px
border-left-color: rgb(51, 51, 51) border-left-color: rgb(51, 51, 51)
display: block display: block
.val-10:hover .cross-popup td[data-score="10"]:hover .cross-popup
display: block display: block
&.match-editable .cross-popup &.match-editable .cross-popup
......
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
<tbody> <tbody>
<tr n:foreach="$rows as $i => $row"> <tr n:foreach="$rows as $i => $row">
<th class="separator">{$i + 1}</th> <th class="separator">{$i + 1}</th>
<td n:foreach="$row as $j => $arrow" <td n:foreach="$row as $j => $arrow" data-score="{$arrow}"
class="val-{$arrow} {$j == $match->arrows - 1 ? separator}"> class="{$j == $match->arrows - 1 ? separator}">
<input type="number" name="scores[]" min="0" max="10" <input type="number" name="scores[]" min="0" max="10"
value="{$arrow ? $arrow}"> value="{$arrow ? $arrow}">
<input type="hidden" name="crosses[]" <input type="hidden" name="crosses[]"
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
title="{_'Inner 10?'}">&times;</div> title="{_'Inner 10?'}">&times;</div>
</div> </div>
</td> </td>
<td class="row-total">{$sum = array_sum($row)}</td> <td class="row-total" data-score="{floor(($sum = array_sum($row)) / $match->arrows)}">{$sum}</td>
<td class="total">{$total = $total + $sum}</td> <td class="total" data-score="{floor(($total = $total + $sum) / ($match->arrows * ($i + 1)))}">{$total}</td>
</tr> </tr>
</tbody> </tbody>
<tbody> <tbody>
......
...@@ -43,15 +43,15 @@ ...@@ -43,15 +43,15 @@
<tbody> <tbody>
<tr n:foreach="$rows as $i => $row"> <tr n:foreach="$rows as $i => $row">
<th class="separator">{$i + 1}</th> <th class="separator">{$i + 1}</th>
<td n:foreach="$row as $j => $arrow" <td n:foreach="$row as $j => $arrow" data-score="{$arrow}"
class="val-{$arrow} {$j == $match->arrows - 1 ? separator}"> class="{$j == $match->arrows - 1 ? separator}">
<input type="text" disabled value="{$arrow}"> <input type="text" disabled value="{$arrow}">
<div n:if="$crosses[$i][$j]" class="popup-container"> <div n:if="$crosses[$i][$j]" class="popup-container">
<div class="cross-popup enabled" title="{_'Inner 10?'}">&times;</div> <div class="cross-popup enabled" title="{_'Inner 10?'}">&times;</div>
</div> </div>
</td> </td>
<td class="val-{floor(($sum = array_sum($row)) / $match->arrows)}">{$sum}</td> <td class="row-total" data-score="{floor(($sum = array_sum($row)) / $match->arrows)}">{$sum}</td>
<td class="val-{floor(($total = $total + $sum) / ($match->arrows * ($i + 1)))}">{$total}</td> <td class="total" data-score="{floor(($total = $total + $sum) / ($match->arrows * ($i + 1)))}">{$total}</td>
</tr> </tr>
</tbody> </tbody>
<tbody> <tbody>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment