Skip to content

Instantly share code, notes, and snippets.

@craigmccoy
Created September 20, 2012 04:09
Show Gist options
  • Save craigmccoy/3753941 to your computer and use it in GitHub Desktop.
Save craigmccoy/3753941 to your computer and use it in GitHub Desktop.
Ajax loaded content for jQuery UI Dialog
/**
* Example HTML markup: <a class="ajax-dialog" href="/path/to/ajax/page" rel="#dialog">Click to open</a>
*/
$(function() {
$('a.ajax-dialog').click(function(evt) {
evt.preventDefault();
var link = $(evt.target);
var contentUrl = link.attr('href');
var targetDialog = $(link.attr('rel'));
if(targetDialog.size() < 1) {
targetDialog = $('<div />').attr('id', link.attr('rel').substr(1)).css('display', 'none');
$('body').append(targetDialog);
targetDialog.load(contentUrl, function() {
// dialog configuration can change as needed
targetDialog.dialog({
modal : true,
width : 700,
height: 600
});
});
} else {
targetDialog.dialog('open');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment