-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathjquery.dialogImage.js
More file actions
57 lines (55 loc) · 1.46 KB
/
jquery.dialogImage.js
File metadata and controls
57 lines (55 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
*
* Copyright (c) 2010 Sam Collett (http://www.texotela.co.uk)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version 1.0
*
*/
;(function($) {
/*
* Shows an image in a jQuery UI Dialog box.
*
*/
$.fn.dialogImage = function()
{
$(this).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();
// don't make wider than the window width
var maxWidth = $(window).width() - 20;
// don't make taller than the window height
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": "" });
}
)
}
);
}
})(jQuery);