Created
March 2, 2011 20:31
-
-
Save anolson/851686 to your computer and use it in GitHub Desktop.
Super simple ajax javascript dialog
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
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