Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions ordering/static/js/bookmark-episode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const bookmarkEpisode = ({target}) => {
const { episodeId } = target.dataset
let bookmarks = JSON.parse(localStorage.getItem('bookmarks'))
const index = bookmarks?.indexOf(episodeId)
if (target.checked) {
//add episode to localstorage
if (!bookmarks) bookmarks = [episodeId] //bookmarks array doesnt exist. create it
else {
//check to see if it exists in array already
if (index === -1) {//does not exist, push to array
bookmarks.push(episodeId)
}
else return //already in array, no need to do anything
}
} else {
//remove episode from localstorage
if (!bookmarks || index === -1) return //array does not exist OR does not exist in array, no need to do anything
else {
bookmarks.splice(index, 1) //remove from bookmarks array
}
}
if (bookmarks) localStorage.setItem('bookmarks', JSON.stringify(bookmarks)) //if bookmarks array exists, save it to local storage
}

const setupBookmarks = () => {
const elems = document.querySelectorAll('input[type="checkbox"]') // get all inputs
const bookmarks = JSON.parse(localStorage.getItem('bookmarks')) //get bookmarks from local storage
for (const elem in elems) if (bookmarks && bookmarks.indexOf(elem.dataset.episodeId) !== -1) elem.checked = true //loop through inputs, if bookmarks exist and episode id is found in array, set checked to true
}
5 changes: 4 additions & 1 deletion ordering/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% include 'ads.html' %}
</head>

<body>
<body onload="setupBookmarks()">
{% if using_old_site %}
<section class="old-site-banner container-fluid sticky-top">
<div class="row">
Expand Down Expand Up @@ -160,6 +160,7 @@
<table class="table table-bordered col-sm-12" id="episode-list">
<thead>
<tr>
<th></th>
<th>#</th>
<th>Series</th>
<th>Episode</th>
Expand All @@ -171,6 +172,7 @@
<tbody>
{% for row in table_content %}
<tr class="episode {{ series_map[row.series].id }}">
<td><input aria-label="bookmark for {{ row.series }} {{ row.episode_id }}" type='checkbox' data-episodeId="{{ row.series }} {{ row.episode_id }}" onclick="(event) => bookmarkEpisode(event)"/></td>
<td>{{ row.row_number }}</td>
<td>{{ row.series }}</td>
<td>{{ row.episode_id }}</td>
Expand Down Expand Up @@ -334,6 +336,7 @@ <h5 class="modal-title">Contact</h5>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.js"></script>
<script src="{{ static_url('js/index.js') }}"></script>
<script src="{{ static_url('js/bookmark-episode.js') }}"></script>
{% include 'analytics.html' %}
</body>
</html>