Skip to content

Instantly share code, notes, and snippets.

@spint
Created September 1, 2011 07:59
Show Gist options
  • Save spint/1185672 to your computer and use it in GitHub Desktop.
Save spint/1185672 to your computer and use it in GitHub Desktop.
Build up jQuery-UI dialogs on the fly
// Creates a jQuery UI dialog on the fly, every time a link .user-link is clicked,
// dialog content will be loaded from the url specified by the clicked link
$(function(){
$(".user-link").live('click', function(){
var link = $(this);
$("<div><img src='" + BASEPATH + "images/small-spinner.gif' /> </div>")
.dialog({
autoOpen: true, //for info, true is default
modal: true,
title: 'Apps used by ' + link.attr('data-name'),
width: '720',
minHeight: '400',
open: function(){
$(this).load(link.attr('href'));
},
close: function(){
$(this).dialog('destroy');
}
});
return false;
});
}
@joerixaop
Copy link

$dialog typo or intended?

@joerixaop
Copy link

Also, you need to close your img tag at least with a >

@joerixaop
Copy link

And why autoOpen false, followed immediately by open? It's not that it will be reused

@spint
Copy link
Author

spint commented Sep 1, 2011

$dialog is in this case not necessary indeed.
And yes, it's easier to just let it autoOpen here :-)
gist updated

@spint
Copy link
Author

spint commented Sep 1, 2011

todo: error handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment