-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added total drink counters for #2, other Sass and JS tweaks!
- Loading branch information
Showing
9 changed files
with
69 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[data-counter]:after | ||
content: attr(data-counter) | ||
position: relative | ||
display: inline-block | ||
left: 10px | ||
font-size: 16px | ||
|
||
#total | ||
position: absolute | ||
right: 1rem | ||
|
||
[data-counter]:after, #total | ||
font-family: monospace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
@import _layout | ||
@import _lists | ||
@import _links | ||
@import _counters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Globally available data and helper functions | ||
|
||
// "Parameterize" a string similar to Ruby | ||
// https://www.w3resource.com/javascript-exercises/javascript-string-exercise-7.php | ||
const string_parameterize = function (str1) { | ||
return str1.trim().toLowerCase().replace(/[^a-zA-Z0-9 -]/, '').replace(/\s/g, '-'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function fetchTotalDrinks() { | ||
const games = Array.from(document.getElementsByTagName('a')); | ||
|
||
games.forEach(function(game) { | ||
// Get current drink name from text | ||
const game_name = string_parameterize(game.innerText); | ||
|
||
// Get current drink value from localStorage | ||
const game_count = localStorage.getItem(`drinking-game-${game_name}-total-count`); | ||
|
||
// Set counter to localStorage value if set | ||
if (game_count > 0) { | ||
game.dataset.counter = game_count; | ||
} | ||
}) | ||
} | ||
|
||
// Run fetchTotalDrinks after DOM is loaded | ||
document.addEventListener('DOMContentLoaded', function(event) { | ||
fetchTotalDrinks(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters