@@ -55,10 +55,11 @@ function createLightbox(id) {
55
55
56
56
var search = /** @type {HTMLInputElement } */ document . getElementById ( 'searchInput' ) ;
57
57
search . addEventListener ( 'keydown' , function ( e ) {
58
- if ( e . key === "Enter" ) sort ( search . value ) ;
58
+ if ( e . key === "Enter" ) sort ( localStorage . sort , search . value ) ;
59
59
} ) ;
60
- document . getElementById ( 'searchButton' ) . addEventListener ( 'click' , function ( ) {
61
- return false ;
60
+ var search_button = /** @type {HTMLInputElement } */ document . getElementById ( 'searchButton' ) ;
61
+ search_button . addEventListener ( 'click' , function ( ) {
62
+ return sort ( localStorage . sort , search . value ) ;
62
63
} ) ;
63
64
64
65
/* Load Content
@@ -72,44 +73,25 @@ function createLightbox(id) {
72
73
if ( ! localStorage . sort ) localStorage . sort = 'latest' ;
73
74
74
75
/*
75
- * Make the sort icon a button .
76
+ * Add event to sort when an option is chosen. .
76
77
*/
77
- var sort_trigger = /** @type {HTMLElement } */ document . getElementById ( 'js-sortSwitcher' ) ;
78
- sort_trigger . addEventListener ( 'click' , function ( ) {
79
- return toggle_sorting ( ) ;
78
+ var sort_menu = /** @type {HTMLSelectElement } */ document . getElementById ( 'js-sort-menu' ) ;
79
+ sort_menu . addEventListener ( 'change' , function ( ) {
80
+ var name = /** @type {string } */ sort_menu . selectedOptions [ 0 ] . getAttribute ( 'name' ) ;
81
+ sort ( name ) ;
80
82
} ) ;
81
- sort ( ) ;
82
-
83
- /**
84
- * Toggle the sorting type of the themes.
85
- **/
86
- function toggle_sorting ( ) {
87
- switch ( localStorage . sort ) {
88
- case 'latest' :
89
- localStorage . sort = 'updated' ;
90
- break ;
91
- case 'updated' :
92
- localStorage . sort = 'stars' ;
93
- break ;
94
- case 'stars' :
95
- localStorage . sort = 'random' ;
96
- break ;
97
- case 'random' :
98
- localStorage . sort = 'oldest' ;
99
- break ;
100
- default :
101
- localStorage . sort = 'latest' ;
102
- }
103
- return sort ( ) ;
104
- }
83
+ sort ( localStorage . sort ) ;
84
+ var current_option = sort_menu . options . namedItem ( localStorage . sort ) ;
85
+ if ( current_option ) current_option . selected = true ;
105
86
106
87
/**
107
88
* Toggle the sorting type of the themes.
108
89
*
90
+ * @param {string } kind How to sort the themes.
109
91
* @param {string= } filter Term to filter the themes.
110
92
**/
111
- function sort ( filter ) {
112
- sort_trigger . title = "\"" . concat ( localStorage . sort , "\"" ) ;
93
+ function sort ( kind , filter ) {
94
+ localStorage . sort = kind ;
113
95
114
96
// Remove all themes cards from the page.
115
97
var cards_container = document . getElementById ( 'themes_container' ) ;
0 commit comments