@@ -81,15 +81,17 @@ function createLightbox (id) {
81
81
* ======================
82
82
*/
83
83
84
+ let running_sort = 0 ;
85
+
84
86
const search = /** @type {HTMLInputElement } */ ( document . getElementById ( 'searchInput' ) )
85
87
86
88
search . addEventListener ( 'keydown' , e => {
87
89
88
- if ( e . key === "Enter" )
89
- sort ( localStorage . sort , search . value )
90
+ if ( e . key === "Enter" )
91
+ sort ( localStorage . sort , search . value )
92
+
93
+ } )
90
94
91
- } )
92
-
93
95
const search_button = /** @type {HTMLInputElement } */ ( document . getElementById ( 'searchButton' ) )
94
96
search_button . addEventListener ( 'click' , ( ) => sort ( localStorage . sort , search . value ) )
95
97
@@ -125,6 +127,8 @@ function createLightbox (id) {
125
127
* @param {string= } filter Term to filter the themes.
126
128
**/
127
129
function sort ( kind , filter ) {
130
+
131
+ const my_run = ++ running_sort
128
132
129
133
localStorage . sort = kind
130
134
@@ -198,13 +202,17 @@ function createLightbox (id) {
198
202
199
203
for ( const [ index , entry ] of data )
200
204
{
205
+ if ( running_sort !== my_run )
206
+ return
207
+
201
208
const card = new Card ( entry , index )
202
209
card . render ( outputContainer )
203
- await new Promise ( r => setTimeout ( r , 666 ) ) ;
210
+ await new Promise ( r => setTimeout ( r , 444 ) )
204
211
}
205
212
206
- } )
207
- }
213
+ }
214
+ )
215
+ }
208
216
209
217
// add themes
210
218
const outputContainer = document . getElementById ( 'themes_container' )
0 commit comments