Created
February 20, 2018 00:32
-
-
Save olback/2a9900260d2473b6fd6ea05020f660af to your computer and use it in GitHub Desktop.
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
/** | |
* 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