Skip to content

Instantly share code, notes, and snippets.

@dallin
Last active September 27, 2016 18:35
Show Gist options
  • Save dallin/fb557180afd048025186807e2005ecde to your computer and use it in GitHub Desktop.
Save dallin/fb557180afd048025186807e2005ecde to your computer and use it in GitHub Desktop.
JS for Man
<script>
var windows = [];
// Show the modal window
function showModal(modal_id) {
// Get the modal
var modal = document.getElementById(modal_id);
// Show the modal
modal.style.display = "block";
// Add it to the windows array
windows.push(modal_id);
}
// Close modal window
function closeModal(modal_id) {
// Get the modal
var modal = document.getElementById(modal_id);
// Close the modal
modal.style.display = "none";
windows.pop();
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (windows.length > 0) {
var modal = document.getElementById(windows[windows.length-1]);
if (event.target == modal) {
modal.style.display = "none";
windows.pop();
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment