Skip to content

Commit eb00541

Browse files
committed
feat(sorting): replace trigger with menu
1 parent 553ecf5 commit eb00541

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

dev/js/main.js

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ function createLightbox (id) {
8686
search.addEventListener('keydown', e => {
8787

8888
if (e.key === "Enter")
89-
sort(search.value)
89+
sort(localStorage.sort, search.value)
9090

9191
})
9292

93-
document.getElementById('searchButton').addEventListener('click', () => (false))
93+
const search_button = /** @type {HTMLInputElement} */ (document.getElementById('searchButton'))
94+
search_button.addEventListener('click', () => sort(localStorage.sort, search.value))
9495

9596
/* Load Content
9697
* ============
@@ -104,47 +105,28 @@ function createLightbox (id) {
104105
localStorage.sort = 'latest'
105106

106107
/*
107-
* Make the sort icon a button.
108+
* Add event to sort when an option is chosen..
108109
*/
109-
const sort_trigger = /** @type {HTMLElement} */ (document.getElementById('js-sortSwitcher'))
110-
sort_trigger.addEventListener('click', () => toggle_sorting())
111-
sort()
110+
const sort_menu = /** @type {HTMLSelectElement} */ (document.getElementById('js-sort-menu'))
111+
sort_menu.addEventListener('change', () => {
112+
const name = /** @type {string} */ (sort_menu.selectedOptions[0].getAttribute('name'))
113+
sort(name)
114+
})
112115

113-
/**
114-
* Toggle the sorting type of the themes.
115-
**/
116-
function toggle_sorting () {
117-
118-
switch (localStorage.sort)
119-
{
120-
case 'latest':
121-
localStorage.sort = 'updated'
122-
break
123-
case 'updated':
124-
localStorage.sort = 'stars'
125-
break
126-
case 'stars':
127-
localStorage.sort = 'random'
128-
break;
129-
case 'random':
130-
localStorage.sort = 'oldest'
131-
break
132-
default:
133-
localStorage.sort = 'latest'
134-
}
135-
136-
return sort()
137-
138-
}
116+
sort(localStorage.sort)
117+
const current_option = sort_menu.options.namedItem(localStorage.sort)
118+
if (current_option)
119+
current_option.selected = true
139120

140121
/**
141122
* Toggle the sorting type of the themes.
142123
*
124+
* @param {string} kind How to sort the themes.
143125
* @param {string=} filter Term to filter the themes.
144126
**/
145-
function sort (filter) {
127+
function sort (kind, filter) {
146128

147-
sort_trigger.title = `"${localStorage.sort}"`
129+
localStorage.sort = kind
148130

149131
// Remove all themes cards from the page.
150132
const cards_container = document.getElementById('themes_container')

dev/pug/includes/header.pug

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ header#main_header
55
a(href='index.html') Theme List
66
a#js-themeSwitcher(href='#')
77
i.fas.fa-moon
8-
a#js-sortSwitcher(href='#')
9-
i.fas.fa-sort
8+
select#js-sort-menu
9+
option(name='updated') Updated
10+
option(name='stars') Stars
11+
option(name='latest') Latest
12+
option(name='oldest') Oldest
13+
option(name='random') Random
1014
div.searchform(method='get')
1115
.inputgroup
1216
input.searchinput#searchInput(type='text', placeholder='Search')

dev/scss/base/_typography.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ body {
1313
}
1414

1515

16-
1716
a {
1817

1918
text-decoration: none;
@@ -25,6 +24,7 @@ a {
2524
&:hover { color: var(--linkc-hover) }
2625
&:focus { outline: var(--focus-thickness) solid var(--focus-colour); }
2726

27+
2828
}
2929

3030

0 commit comments

Comments
 (0)