Skip to content

Commit 8412af7

Browse files
committed
Use 'const' instead of 'var'
1 parent 48be20b commit 8412af7

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

src/supplemental-ui/js/landing-page-support.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@
3535
(function () {
3636
'use strict'
3737

38-
var navbarBurger = document.querySelector('.navbar-burger')
38+
const navbarBurger = document.querySelector('.navbar-burger');
3939
if (!navbarBurger) return
4040
navbarBurger.addEventListener('click', toggleNavbarMenu.bind(navbarBurger))
4141

4242
function toggleNavbarMenu (e) {
4343
e.stopPropagation() // trap event
4444
document.classList.toggle('is-clipped--navbar')
45-
navbarBurger.setAttribute('aria-expanded', document.classList.contains('is-clipped--navbar'))
46-
var menu = document.getElementById("topbar-nav")
45+
navbarBurger.setAttribute('aria-expanded', document.classList.contains('is-clipped--navbar').toString())
46+
const menu = document.getElementById("topbar-nav");
4747
if (menu.classList.toggle('is-active')) {
4848
menu.style.maxHeight = ''
49-
var expectedMaxHeight = window.innerHeight - Math.round(menu.getBoundingClientRect().top)
50-
var actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight, 10)
49+
const expectedMaxHeight = window.innerHeight - Math.round(menu.getBoundingClientRect().top);
50+
const actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight, 10);
5151
if (actualMaxHeight !== expectedMaxHeight) menu.style.maxHeight = expectedMaxHeight + 'px'
5252
}
5353
}

src/supplemental-ui/js/search-ui.js

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
// ===----------------------------------------------------------------------===//
1616
;(function (globalScope) {
1717
/* eslint-disable no-var */
18-
var config = document.getElementById('search-ui-script').dataset
19-
var snippetLength = parseInt(config.snippetLength || 100, 10)
20-
var siteRootPath = config.siteRootPath || ''
18+
const config = document.getElementById('search-ui-script').dataset;
19+
const snippetLength = parseInt(config.snippetLength || 100, 10);
20+
const siteRootPath = config.siteRootPath || '';
2121
appendStylesheet(config.stylesheet)
22-
var searchInput = document.getElementById('search-input')
23-
var searchResult = document.createElement('div')
22+
const searchInput = document.getElementById('search-input');
23+
const searchResult = document.createElement('div');
2424
searchResult.classList.add('search-result-dropdown-menu')
2525
searchInput.parentNode.appendChild(searchResult)
2626

@@ -30,19 +30,19 @@
3030
}
3131

3232
function highlightText (doc, position) {
33-
var hits = []
34-
var start = position[0]
35-
var length = position[1]
33+
const hits = [];
34+
const start = position[0];
35+
const length = position[1];
3636

37-
var text = doc.text
38-
var highlightSpan = document.createElement('span')
37+
const text = doc.text;
38+
const highlightSpan = document.createElement('span');
3939
highlightSpan.classList.add('search-result-highlight')
4040
highlightSpan.innerText = text.substr(start, length)
4141

42-
var end = start + length
43-
var textEnd = text.length - 1
44-
var contextAfter = end + snippetLength > textEnd ? textEnd : end + snippetLength
45-
var contextBefore = start - snippetLength < 0 ? 0 : start - snippetLength
42+
const end = start + length;
43+
const textEnd = text.length - 1;
44+
const contextAfter = end + snippetLength > textEnd ? textEnd : end + snippetLength;
45+
const contextBefore = start - snippetLength < 0 ? 0 : start - snippetLength;
4646
if (start === 0 && end === textEnd) {
4747
hits.push(highlightSpan)
4848
} else if (start === 0) {
@@ -60,13 +60,13 @@
6060
}
6161

6262
function highlightTitle (hash, doc, position) {
63-
var hits = []
64-
var start = position[0]
65-
var length = position[1]
63+
const hits = [];
64+
const start = position[0];
65+
const length = position[1];
6666

67-
var highlightSpan = document.createElement('span')
67+
const highlightSpan = document.createElement('span');
6868
highlightSpan.classList.add('search-result-highlight')
69-
var title
69+
let title;
7070
if (hash) {
7171
title = doc.titles.filter(function (item) {
7272
return item.id === hash
@@ -76,8 +76,8 @@
7676
}
7777
highlightSpan.innerText = title.substr(start, length)
7878

79-
var end = start + length
80-
var titleEnd = title.length - 1
79+
const end = start + length;
80+
const titleEnd = title.length - 1;
8181
if (start === 0 && end === titleEnd) {
8282
hits.push(highlightSpan)
8383
} else if (start === 0) {
@@ -95,13 +95,13 @@
9595
}
9696

9797
function highlightHit (metadata, hash, doc) {
98-
var hits = []
99-
for (var token in metadata) {
100-
var fields = metadata[token]
101-
for (var field in fields) {
102-
var positions = fields[field]
98+
let hits = [];
99+
for (const token in metadata) {
100+
const fields = metadata[token];
101+
for (const field in fields) {
102+
const positions = fields[field];
103103
if (positions.position) {
104-
var position = positions.position[0] // only higlight the first match
104+
const position = positions.position[0]; // only higlight the first match
105105
if (field === 'title') {
106106
hits = highlightTitle(hash, doc, position)
107107
} else if (field === 'text') {
@@ -115,32 +115,32 @@
115115

116116
function createSearchResult (result, store, searchResultDataset) {
117117
result.forEach(function (item) {
118-
var url = item.ref
119-
var hash
118+
let url = item.ref;
119+
let hash;
120120
if (url.includes('#')) {
121121
hash = url.substring(url.indexOf('#') + 1)
122122
url = url.replace('#' + hash, '')
123123
}
124-
var doc = store[url]
125-
var metadata = item.matchData.metadata
126-
var hits = highlightHit(metadata, hash, doc)
124+
const doc = store[url];
125+
const metadata = item.matchData.metadata;
126+
const hits = highlightHit(metadata, hash, doc);
127127
searchResultDataset.appendChild(createSearchResultItem(doc, item, hits))
128128
})
129129
}
130130

131131
function createSearchResultItem (doc, item, hits) {
132-
var documentTitle = document.createElement('div')
132+
const documentTitle = document.createElement('div');
133133
documentTitle.classList.add('search-result-document-title')
134134
documentTitle.innerText = doc.title
135-
var documentHit = document.createElement('div')
135+
const documentHit = document.createElement('div');
136136
documentHit.classList.add('search-result-document-hit')
137-
var documentHitLink = document.createElement('a')
137+
const documentHitLink = document.createElement('a');
138138
documentHitLink.href = siteRootPath + item.ref
139139
documentHit.appendChild(documentHitLink)
140140
hits.forEach(function (hit) {
141141
documentHitLink.appendChild(hit)
142142
})
143-
var searchResultItem = document.createElement('div')
143+
const searchResultItem = document.createElement('div');
144144
searchResultItem.classList.add('search-result-item')
145145
searchResultItem.appendChild(documentTitle)
146146
searchResultItem.appendChild(documentHit)
@@ -151,11 +151,11 @@
151151
}
152152

153153
function createNoResult (text) {
154-
var searchResultItem = document.createElement('div')
154+
const searchResultItem = document.createElement('div');
155155
searchResultItem.classList.add('search-result-item')
156-
var documentHit = document.createElement('div')
156+
const documentHit = document.createElement('div');
157157
documentHit.classList.add('search-result-document-hit')
158-
var message = document.createElement('strong')
158+
const message = document.createElement('strong');
159159
message.innerText = 'No results found for query "' + text + '"'
160160
documentHit.appendChild(message)
161161
searchResultItem.appendChild(documentHit)
@@ -169,7 +169,7 @@
169169

170170
function search (index, text) {
171171
// execute an exact match search
172-
var result = index.search(text)
172+
let result = index.search(text);
173173
if (result.length > 0) {
174174
return result
175175
}
@@ -188,8 +188,8 @@
188188
if (text.trim() === '') {
189189
return
190190
}
191-
var result = search(index, text)
192-
var searchResultDataset = document.createElement('div')
191+
const result = search(index, text);
192+
const searchResultDataset = document.createElement('div');
193193
searchResultDataset.classList.add('search-result-dataset')
194194
searchResult.appendChild(searchResultDataset)
195195
if (result.length > 0) {
@@ -204,30 +204,30 @@
204204
}
205205

206206
function debounce (func, wait, immediate) {
207-
var timeout
207+
let timeout;
208208
return function () {
209-
var context = this
210-
var args = arguments
211-
var later = function () {
209+
const context = this;
210+
const args = arguments;
211+
const later = function () {
212212
timeout = null
213213
if (!immediate) func.apply(context, args)
214-
}
215-
var callNow = immediate && !timeout
214+
};
215+
const callNow = immediate && !timeout;
216216
clearTimeout(timeout)
217217
timeout = setTimeout(later, wait)
218218
if (callNow) func.apply(context, args)
219219
}
220220
}
221221

222222
function initSearch (lunr, data) {
223-
var index = Object.assign({ index: lunr.Index.load(data.index), store: data.store })
224-
var debug = 'URLSearchParams' in globalScope && new URLSearchParams(globalScope.location.search).has('lunr-debug')
223+
const index = Object.assign({index: lunr.Index.load(data.index), store: data.store});
224+
const debug = 'URLSearchParams' in globalScope && new URLSearchParams(globalScope.location.search).has('lunr-debug');
225225
searchInput.addEventListener(
226226
'keydown',
227227
debounce(function (e) {
228+
const query = searchInput.value;
228229
if (e.key === 'Escape' || e.key === 'Esc') return clearSearchResults(true)
229230
try {
230-
var query = searchInput.value
231231
if (!query) return clearSearchResults()
232232
searchIndex(index.index, index.store, searchInput.value)
233233
} catch (err) {

0 commit comments

Comments
 (0)