Created
December 30, 2009 16:49
-
-
Save SamWM/266176 to your computer and use it in GitHub Desktop.
jQuery UI Image Dialog (to replace thickbox)
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
$("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