Save the sorting option in local storage (#76)

This commit is contained in:
Alex Ling 2020-07-04 09:47:51 +00:00
parent c00016fa19
commit 38ba324fa9
2 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,10 @@
$(() => { $(() => {
const titleID = $('.data').attr('data-title-id') || 'library';
const sortItems = () => { const sortItems = () => {
const sort = $('#sort-select').find(':selected').attr('id'); const sort = $('#sort-select').find(':selected').attr('id');
localStorage.setItem(`sort-${titleID}`, sort);
const ary = sort.split('-'); const ary = sort.split('-');
const by = ary[0]; const by = ary[0];
const dir = ary[1]; const dir = ary[1];
@ -115,7 +119,10 @@ $(() => {
sortItems(); sortItems();
}); });
if ($('option#auto-up').length > 0) const sortID = localStorage.getItem(`sort-${titleID}`);
if (sortID)
$(`option#${sortID}`).attr('selected', '');
else if ($('option#auto-up').length > 0)
$('option#auto-up').attr('selected', ''); $('option#auto-up').attr('selected', '');
else else
$('option#name-up').attr('selected', ''); $('option#name-up').attr('selected', '');

View File

@ -1,3 +1,4 @@
<div class="data" data-title-id="<%= title.id %>"></div>
<div> <div>
<h2 class=uk-title><span><%= title.display_name %></span> <h2 class=uk-title><span><%= title.display_name %></span>
&nbsp; &nbsp;