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

Take search query from URL params #395

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Take search query from URL params
The search query can be taken from URL params if we simulate a single keyup to get the autocomplete to render suggestions.
  • Loading branch information
mrhwick authored Apr 24, 2020
commit a42952c81d35786f0f76fa62633ace9470d01d4c
24 changes: 24 additions & 0 deletions static/js/learn.js
Original file line number Diff line number Diff line change
@@ -173,6 +173,30 @@ jQuery(document).ready(function() {
}
}

// Define a url param parser
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;

for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');

if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
};

// Set the search input
jQuery('[data-search-input]').focus().val(getUrlParameter("q"));

// Simulate a keyup event for the autocomplete to render suggestions.
var e = $.Event('keyup');
e.which = 32;
jQuery('[data-search-input]').get(0).keyupHandler(e);

// clipboard
var clipInit = false;
$('code').each(function() {