Last active
September 27, 2016 18:35
-
-
Save dallin/fb557180afd048025186807e2005ecde to your computer and use it in GitHub Desktop.
JS for Man
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
<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