Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
archery
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
archery
Commits
18ad13ac
Commit
18ad13ac
authored
Jul 24, 2017
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use HTML data attribute to record scores, cleaner & probably faster code
parent
9f298a6c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
18 deletions
+24
-18
coffee/scores.coffee
coffee/scores.coffee
+8
-3
sass/main.sass
sass/main.sass
+8
-7
templates/match/scores.latte
templates/match/scores.latte
+4
-4
templates/match/view.latte
templates/match/view.latte
+4
-4
No files found.
coffee/scores.coffee
View file @
18ad13ac
...
...
@@ -30,12 +30,16 @@ if table.classList.contains 'match-editable'
subtotal
=
0
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
for
row
in
[
dirty_row
...
h
]
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_avg
.
innerHTML
=
Math
.
round
(
total
/ inputs.length * 10) /
10
...
...
@@ -47,7 +51,7 @@ if table.classList.contains 'match-editable'
cb
=
->
value
=
num
@
.
value
if
set_score
col
,
row
,
value
cell
.
className
=
cell
.
className
.
replace
/val-\d+/
,
'val-'
+
value
cell
.
dataset
.
score
=
value
if
value
!=
10
@
.
nextElementSibling
.
value
=
0
@
.
parentNode
.
querySelector
(
'.cross-popup'
)
...
...
@@ -82,6 +86,7 @@ if table.classList.contains 'match-editable'
localStorage
.
setItem
'hide-total-scores'
,
true
else
localStorage
.
removeItem
'hide-total-scores'
render
0
# notes area grows automatically with each added line
if
notes
=
document
.
getElementById
(
'notes'
)
...
...
sass/main.sass
View file @
18ad13ac
...
...
@@ -67,25 +67,26 @@ $lg-width: 1200px
$white
:
#F2F2F2
&
.colored
.val-10
,
.val-9
td
[
data-score
=
"10"
],
td
[
data-score
=
"9"
]
background-color
:
$yellow
.val-8
,
.val-7
td
[
data-score
=
"8"
],
td
[
data-score
=
"7"
]
background-color
:
$red
.val-6
,
.val-5
td
[
data-score
=
"6"
],
td
[
data-score
=
"5"
]
background-color
:
$blue
.val-4
,
.val-3
td
[
data-score
=
"4"
],
td
[
data-score
=
"3"
]
background-color
:
$black
color
:
white
.val-2
,
.val-1
td
[
data-score
=
"2"
],
td
[
data-score
=
"1"
]
background-color
:
$white
&
.hide-total-scores
.row-total
,
.total
,
.match-avg
,
.match-total
color
:
#fff
background-color
:
white
!
important
color
:
white
.popup-container
position
:
relative
...
...
@@ -109,7 +110,7 @@ $lg-width: 1200px
border-left-color
:
rgb
(
51
,
51
,
51
)
display
:
block
.val-10
:hover
.cross-popup
td
[
data-score
=
"10"
]
:hover
.cross-popup
display
:
block
&
.match-editable
.cross-popup
...
...
templates/match/scores.latte
View file @
18ad13ac
...
...
@@ -32,8 +32,8 @@
<tbody>
<tr n:foreach="$rows as $i => $row">
<th class="separator">{$i + 1}</th>
<td n:foreach="$row as $j => $arrow"
class="
val-{$arrow}
{$j == $match->arrows - 1 ? separator}">
<td n:foreach="$row as $j => $arrow"
data-score="{$arrow}"
class="{$j == $match->arrows - 1 ? separator}">
<input type="number" name="scores[]" min="0" max="10"
value="{$arrow ? $arrow}">
<input type="hidden" name="crosses[]"
...
...
@@ -43,8 +43,8 @@
title="{_'Inner 10?'}">×</div>
</div>
</td>
<td class="row-total"
>{$sum = array_sum($row)
}</td>
<td class="total"
>{$total = $total + $sum
}</td>
<td class="row-total"
data-score="{floor(($sum = array_sum($row)) / $match->arrows)}">{$sum
}</td>
<td class="total"
data-score="{floor(($total = $total + $sum) / ($match->arrows * ($i + 1)))}">{$total
}</td>
</tr>
</tbody>
<tbody>
...
...
templates/match/view.latte
View file @
18ad13ac
...
...
@@ -43,15 +43,15 @@
<tbody>
<tr n:foreach="$rows as $i => $row">
<th class="separator">{$i + 1}</th>
<td n:foreach="$row as $j => $arrow"
class="
val-{$arrow}
{$j == $match->arrows - 1 ? separator}">
<td n:foreach="$row as $j => $arrow"
data-score="{$arrow}"
class="{$j == $match->arrows - 1 ? separator}">
<input type="text" disabled value="{$arrow}">
<div n:if="$crosses[$i][$j]" class="popup-container">
<div class="cross-popup enabled" title="{_'Inner 10?'}">×</div>
</div>
</td>
<td class="
val-
{floor(($sum = array_sum($row)) / $match->arrows)}">{$sum}</td>
<td class="
val-
{floor(($total = $total + $sum) / ($match->arrows * ($i + 1)))}">{$total}</td>
<td class="
row-total" data-score="
{floor(($sum = array_sum($row)) / $match->arrows)}">{$sum}</td>
<td class="
total" data-score="
{floor(($total = $total + $sum) / ($match->arrows * ($i + 1)))}">{$total}</td>
</tr>
</tbody>
<tbody>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment