Created
January 15, 2013 15:58
-
-
Save DouglasMeyer/4539663 to your computer and use it in GitHub Desktop.
Some dialog behavior. Would it be better for the dialog to be an iframe? Depends...
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
var dialog = $('<div />').appendTo(document.body); | |
// Close the dialog when the user clickes out of it. | |
$('body').on('mousedown', function(){ dialog.remove(); }); | |
dialog.on('mousedown', function(e){ | |
// Don't let clicks bouble-up to the body and remove the dialog. | |
e.stopPropagation(); | |
}); | |
// Open links in the dialog | |
dialog.on('click', 'a', function(e){ | |
e.preventDefault(); | |
dialog.load(this.href); | |
}); | |
// Submit forms within the dialog (Not complete, or probably safe). | |
dialog.on('click', 'form input[type="submit"]', function(e){ | |
e.preventDefault(); | |
var form = $(this).closest('form'); | |
$.ajax({ | |
type: 'POST', | |
url: form.attr('action'), | |
data: form.serialize(), | |
complete: function(xhr, status){ | |
dialog.html(xhr.responseText); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment