33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- var projectCards = Array . from ( document . getElementsByClassName ( "project-card" ) )
7- var searchBox = document . getElementById ( "search-box" )
6+ const projectCards = Array . from ( document . getElementsByClassName ( "project-card" ) )
7+ const searchBox = document . getElementById ( "search-box" )
88
99// parse cards to build project list
10- var projects = [ ]
10+ const projects = [ ]
1111projectCards . forEach ( card => {
1212 projects . push ( {
1313 id : card . id ,
@@ -18,7 +18,7 @@ projectCards.forEach(card => {
1818} )
1919
2020// import fuse and initialize
21- var fuse ;
21+ let fuse ;
2222import ( "https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.esm.min.js" )
2323 . then ( module => {
2424 Fuse = module . default
@@ -48,7 +48,7 @@ import("https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.esm.min.js")
4848
4949// perform search on search-box keyup and store in browser history.
5050searchBox . addEventListener ( 'keyup' , function ( event ) {
51- let query = this . value
51+ const query = this . value
5252 search ( query )
5353
5454 // push new query onto history stack
@@ -65,7 +65,7 @@ searchBox.addEventListener('keyup', function(event) {
6565
6666// debounce wraps a function so that calls will be delayed to prevent repeated
6767// calls within the specified time window.
68- var debounce = ( fn , timeout = 500 ) => {
68+ const debounce = ( fn , timeout = 500 ) => {
6969 let timer
7070 return ( ...args ) => {
7171 clearTimeout ( timer )
@@ -76,14 +76,14 @@ var debounce = (fn, timeout = 500) => {
7676// pushState pushes the new search query onto the browser history on a slight
7777// delay. This is to prevent every individual keystroke from being pushed onto
7878// the history stack.
79- var pushState = debounce ( ( query , url ) => {
79+ const pushState = debounce ( ( query , url ) => {
8080 window . history . pushState ( { } , `Projects search: ${ query } ` , url )
8181} )
8282
8383// search the project list for the query string and display ranked results.
84- var search = ( query ) => {
84+ const search = ( query ) => {
8585 searchBox . value = query
86- let resultsBox = document . getElementById ( 'results' )
86+ const resultsBox = document . getElementById ( 'results' )
8787
8888 if ( ! query ) {
8989 // reset all project cards
@@ -94,7 +94,7 @@ var search = (query) => {
9494 resultsBox . classList . add ( "hide" )
9595 return
9696 }
97- let results = fuse . search ( query )
97+ const results = fuse . search ( query )
9898
9999 // first, hide all the projects
100100 projectCards . forEach ( card => {
@@ -105,7 +105,7 @@ var search = (query) => {
105105 // show results in ranked order
106106 let order = 1
107107 results . forEach ( r => {
108- var card = document . getElementById ( r . item . id )
108+ const card = document . getElementById ( r . item . id )
109109 card . classList . remove ( "hide" )
110110 card . style . setProperty ( "order" , order ++ )
111111 } )
0 commit comments