-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fake_crop.js
48 lines (47 loc) · 1.42 KB
/
jquery.fake_crop.js
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
// Generated by CoffeeScript 1.6.3
(function() {
jQuery.fn.fakeCrop = function() {
var fakeCrop,
_this = this;
fakeCrop = function(wrap) {
var dimension, final, img, initial, offset, offsetDirection, otherDimension, _ref, _ref1;
wrap.css({
overflow: 'hidden'
});
img = wrap.find('img');
img.css({
marginLeft: "",
marginTop: "",
width: "",
height: ""
});
initial = {
width: img[0].width,
height: img[0].height
};
final = {
width: wrap.width(),
height: wrap.height()
};
initial.ratio = initial.width / initial.height;
final.ratio = final.width / final.height;
if (initial.ratio === final.ratio) {
img.width(final.width);
} else {
if (initial.ratio < final.ratio) {
_ref = ['width', 'height', 'top'], dimension = _ref[0], otherDimension = _ref[1], offsetDirection = _ref[2];
} else {
_ref1 = ['height', 'width', 'left'], dimension = _ref1[0], otherDimension = _ref1[1], offsetDirection = _ref1[2];
}
img[dimension](final[dimension]);
offset = (img[otherDimension]() - final[otherDimension]) / -2;
img.css("margin-" + offsetDirection, "" + offset + "px");
}
return img.show();
};
$(this).each(function(i, e) {
return fakeCrop($(e));
});
return $(this);
};
}).call(this);