Skip to content

Instantly share code, notes, and snippets.

@anolson
Created March 2, 2011 20:31
Show Gist options
  • Save anolson/851686 to your computer and use it in GitHub Desktop.
Save anolson/851686 to your computer and use it in GitHub Desktop.
Super simple ajax javascript dialog
document.observe('dom:loaded', function(){
$('click_me').observe('click', function(event) {
activateDialog(event);
});
});
function activateDialog(event) {
var element = Event.findElement(event);
fetchDialogContent(element.href);
event.stop();
}
function fetchDialogContent(url) {
new Ajax.Request(url, {
method:'get',
onSuccess: function(transport){
displayDialog(transport.responseText);
}
});
}
function displayDialog(content) {
$('dialog').replace('<div id="dialog">' + content + '</div>');
$('cancel').observe('click', function() {
dismissDialog();
});
}
function dismissDialog() {
$('dialog').replace('<div id="dialog"></div>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment