Skip to content

Instantly share code, notes, and snippets.

@SamWM
Created December 30, 2009 16:49
Show Gist options
  • Save SamWM/266176 to your computer and use it in GitHub Desktop.
Save SamWM/266176 to your computer and use it in GitHub Desktop.
jQuery UI Image Dialog (to replace thickbox)
$("a.thickbox").click(
function(e) {
e.preventDefault();
var link = this;
var $loading = $("<div></div>").dialog({ title: "Loading..." });
$("<img>").attr({ "src": this.href }).css({ "padding": 0 }).load(
function() {
$loading.dialog("destroy").remove();
var maxWidth = $(window).width() - 20;
var maxHeight = $(window).height() - 20;
var width = this.width;
var height = this.height;
if (width > maxWidth) {
height = height * (maxWidth / width);
width = maxWidth;
if (height > maxHeight) {
width = width * (maxHeight / height);
height = maxHeight;
}
}
else if (height > maxHeight) {
width = width * (maxHeight / height);
height = maxHeight;
if (width > maxWidth) {
height = height * (maxWidth / width);
width = maxWidth;
}
}
this.width = width;
this.height = height;
$(this).dialog({ width: width, title: $(link).text() }).css({ "height": "", "width": "" });
}
)
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment