@@ -55,10 +55,11 @@ function createLightbox(id) {
5555
5656 var search = /** @type {HTMLInputElement } */ document . getElementById ( 'searchInput' ) ;
5757 search . addEventListener ( 'keydown' , function ( e ) {
58- if ( e . key === "Enter" ) sort ( search . value ) ;
58+ if ( e . key === "Enter" ) sort ( localStorage . sort , search . value ) ;
5959 } ) ;
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 ) ;
6263 } ) ;
6364
6465 /* Load Content
@@ -72,44 +73,25 @@ function createLightbox(id) {
7273 if ( ! localStorage . sort ) localStorage . sort = 'latest' ;
7374
7475 /*
75- * Make the sort icon a button .
76+ * Add event to sort when an option is chosen. .
7677 */
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 ) ;
8082 } ) ;
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 ;
10586
10687 /**
10788 * Toggle the sorting type of the themes.
10889 *
90+ * @param {string } kind How to sort the themes.
10991 * @param {string= } filter Term to filter the themes.
11092 **/
111- function sort ( filter ) {
112- sort_trigger . title = "\"" . concat ( localStorage . sort , "\"" ) ;
93+ function sort ( kind , filter ) {
94+ localStorage . sort = kind ;
11395
11496 // Remove all themes cards from the page.
11597 var cards_container = document . getElementById ( 'themes_container' ) ;
0 commit comments