Created
September 20, 2012 04:09
-
-
Save craigmccoy/3753941 to your computer and use it in GitHub Desktop.
Ajax loaded content for jQuery UI 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
/** | |
* 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