Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding the ability to modify the url by search #2644

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
47 changes: 47 additions & 0 deletions assets/html/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ function worker_function(documenterSearchIndex, documenterBaseURL, filters) {

/////// SEARCH MAIN ///////

let initialLoadComplete = false; //global variable to fix the problem of q not persisting


function runSearchMainCode() {
// `worker = Threads.@spawn worker_function(documenterSearchIndex)`, but in JavaScript!
const filters = [
Expand Down Expand Up @@ -402,6 +405,26 @@ function runSearchMainCode() {
// Which filter is currently selected
var selected_filter = "";


//update the url with search query
function updateSearchURL(query) {
if(query && query.trim() !== "") {
const url = new URL(window.location);
url.searchParams.set('q', query);

window.history.replaceState({}, '', url);
} else {
// remove the 'q' param
if(initialLoadComplete) {
const url = new URL(window.location);
if(url.searchParams.has('q')) {
url.searchParams.delete('q');
window.history.replaceState({}, '', url);
}
}
}
}

$(document).on("input", ".documenter-search-input", function (event) {
if (!worker_is_running) {
launch_search();
Expand All @@ -411,6 +434,9 @@ function runSearchMainCode() {
function launch_search() {
worker_is_running = true;
last_search_text = $(".documenter-search-input").val();

updateSearchURL(last_search_text);

worker.postMessage(last_search_text);
}

Expand Down Expand Up @@ -442,6 +468,9 @@ function runSearchMainCode() {
function update_search() {
let querystring = $(".documenter-search-input").val();

//update the url here
updateSearchURL(querystring);

if (querystring.trim()) {
if (selected_filter == "") {
results = unfiltered_results;
Expand Down Expand Up @@ -515,6 +544,21 @@ function runSearchMainCode() {
}
}

//url param checking
function checkURLForSearch() {
const urlParams = new URLSearchParams(window.location.search);
const searchQuery = urlParams.get('q');

if(searchQuery) {
//opening of modal handled in shortcut.js

$(".documenter-search-input").val(searchQuery).trigger("input");

}

initialLoadComplete = true;
}

/**
* Make the modal filter html
*
Expand All @@ -537,6 +581,9 @@ function runSearchMainCode() {
${str}
</div>`;
}

//delaying the call by a little to make sure that the modal is in DOM
setTimeout(checkURLForSearch,100);
}

function waitUntilSearchIndexAvailable() {
Expand Down
20 changes: 18 additions & 2 deletions assets/html/js/shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
</footer>
`;




$(document.body).append(
`
<div class="modal" id="search-modal">
Expand All @@ -47,6 +50,19 @@
`
);

function checkURLForSearch() {
const urlParams = new URLSearchParams(window.location.search);
const searchQuery = urlParams.get('q');

if(searchQuery) {
//only if there is a search query, open the modal
openModal();
}
}

//this function will be called whenver the page will load

Check warning on line 63 in assets/html/js/shortcut.js

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"whenver" should be "whenever".

Check warning on line 63 in assets/html/js/shortcut.js

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"whenver" should be "whenever".
checkURLForSearch();

document.querySelector(".docs-search-query").addEventListener("click", () => {
openModal();
});
Expand Down Expand Up @@ -91,8 +107,8 @@
if (!$(".search-modal-card-body").hasClass("is-justify-content-center")) {
$(".search-modal-card-body").addClass("is-justify-content-center");
}

$(".documenter-search-input").val("");
// commenting this out so that the search value persist in the URL
// $(".documenter-search-input").val("");
$(".search-modal-card-body").html(initial_search_body);
}

Expand Down
118 changes: 0 additions & 118 deletions docs/DocumenterShowcase.jl

This file was deleted.

5 changes: 0 additions & 5 deletions docs/Project.toml

This file was deleted.

7 changes: 0 additions & 7 deletions docs/changelog.jl

This file was deleted.

26 changes: 0 additions & 26 deletions docs/instantiate.jl

This file was deleted.

Loading
Loading