-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize the documentation JS files (#20075)
This PR optimizes the three files in the `/docs/_assets/js` directory for performance. In `toolbar.js`, jQuery selectors have been cached as variables to prevent constant calls to the DOM. In `sidebar.js`, the multiple `toggleClass(...).toggleClass(...)` have been merged into one In `api-search.js`: - Defined functions have been switched to newer ES format (`const myFunc = () => {}`) - JSON has been switched to **JS**ON (`{"key":"value"}` -> `{key:"value"}`) [Cherry-picked fa2f7bf]
- Loading branch information
1 parent
3c4b415
commit f3129fc
Showing
3 changed files
with
52 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
$(document).ready(function() { | ||
$("#menu-icon").click(() => { | ||
$(".sidebar").toggleClass("toggled"); | ||
}) | ||
$("#search-icon").click(() => { | ||
$("#searchbar").toggleClass("shown"); | ||
$("#search-api-input").focus(); | ||
}) | ||
const searchInput = $("#search-api-input"); | ||
searchInput.keydown(evt => { | ||
if (evt.which == 13) { | ||
const baseUrl = $("#baseurl-input").val(); | ||
window.location = ( | ||
baseUrl + "/api/search.html?" + | ||
"searchTerm=" + searchInput.val() + | ||
"&previousUrl=" + encodeURI(window.location) | ||
); | ||
$(function() { | ||
const menuIcon = $("#menu-icon"); | ||
const sidebar = $(".sidebar"); | ||
menuIcon.on("click", () => { | ||
sidebar.toggleClass("toggled"); | ||
}); | ||
|
||
const searchIcon = $("#search-icon"); | ||
const searchbar = $("#searchbar"); | ||
const searchApiInput = $("#search-api-input"); | ||
searchIcon.on("click", () => { | ||
searchbar.toggleClass("shown"); | ||
searchApiInput.focus(); | ||
}); | ||
|
||
const baseurlInput = $("#baseurl-input"); | ||
searchApiInput.keydown(evt => { | ||
if (evt.which === 13) { // Enter | ||
const baseUrl = baseurlInput.val(); | ||
const searchTerm = searchApiInput.val(); | ||
const previousUrl = encodeURI(window.location); | ||
const searchUrl = `${baseUrl}/api/search.html?searchTerm=${searchTerm}&previousUrl=${previousUrl}`; | ||
window.location = searchUrl; | ||
} | ||
}) | ||
}) | ||
}); | ||
}); |