Skip to content

Instantly share code, notes, and snippets.

@olback
Created February 20, 2018 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olback/2a9900260d2473b6fd6ea05020f660af to your computer and use it in GitHub Desktop.
Save olback/2a9900260d2473b6fd6ea05020f660af to your computer and use it in GitHub Desktop.
/**
* SQLite Blogger Main JS
* github.com/olback/sqlite-blogger
*/
window.onload = () => {
// Tell the user if the search box is empty
const searchBox = document.getElementById('search');
document.getElementById('search-submit').onclick = () => {
if(typeof(searchBox.value) == 'string' && searchBox.value !== '') {
window.location = window.location.origin + '/search/' + searchBox.value;
} else {
document.getElementById('search-error').style.display = 'inline-block';
}
}
// Search when pressing enter
searchBox.onkeypress = (e) => {
e = e || window.event;
if(e.keyCode === 13) {
window.location = window.location.origin + '/search/' + searchBox.value;
}
}
// Close modal button
document.getElementById('close-modal').onclick = () => {
document.getElementById('modal').style.display = 'none';
}
// Strip get parameters from url for a cleaner look
window.history.replaceState(null, null, window.location.pathname);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment