Skip to content

Instantly share code, notes, and snippets.

@ahamilton9
Created June 25, 2020 18:18
Show Gist options
  • Save ahamilton9/cfe22b1499b2b6bed529fb5ffa1017f4 to your computer and use it in GitHub Desktop.
Save ahamilton9/cfe22b1499b2b6bed529fb5ffa1017f4 to your computer and use it in GitHub Desktop.
Prompt Promise for Modals
function promptPromise(message) {
return new Promise(function(resolve, reject) {
// Open the modal and pass it message, resolve, and reject
// Have the modal call resolve(<response if you need one>) on confirm, reject() on cancel
});
}
var button = document.getElementById('action');
button.addEventListener('click', function() {
promptPromise('What is your name?')
.then(function(responseIfYouNeedOne) {
// resolve (confirm) code, hide modal, do stuff
},
function() {
// reject (cancel) code, hide modal
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment