| 1 |
/* $Id */
|
| 2 |
function imagefieldCropSetDimensions(x, y, w, h) {
|
| 3 |
$(".edit-image-crop-x").val(x);
|
| 4 |
$(".edit-image-crop-y").val(y);
|
| 5 |
if (w) $(".edit-image-crop-width").val(w);
|
| 6 |
if (h) $(".edit-image-crop-height").val(h);
|
| 7 |
}
|
| 8 |
|
| 9 |
$(document).ready(function(){
|
| 10 |
var containerpos;
|
| 11 |
var resizeT;
|
| 12 |
var dragT;
|
| 13 |
if ($("#image-crop-container").size()) {
|
| 14 |
containerpos = findPos($("#image-crop-container").get(0));
|
| 15 |
}
|
| 16 |
else {
|
| 17 |
containerpos = {x:0, y:0};
|
| 18 |
}
|
| 19 |
|
| 20 |
function findPos(obj) {
|
| 21 |
var curleft = obj.offsetLeft || 0;
|
| 22 |
var curtop = obj.offsetTop || 0;
|
| 23 |
while (obj = obj.parent) {
|
| 24 |
curleft += obj.offsetLeft
|
| 25 |
curtop += obj.offsetTop
|
| 26 |
}
|
| 27 |
return {x:curleft,y:curtop};
|
| 28 |
}
|
| 29 |
|
| 30 |
$('#resizeMe').ready(function() {
|
| 31 |
/* this is needed to set the box initially according to the form values */
|
| 32 |
var obj = $('#resizeMe').get(0);
|
| 33 |
var newpos = {
|
| 34 |
left: parseInt($(".edit-image-crop-x").val()),
|
| 35 |
top: parseInt($(".edit-image-crop-y").val())
|
| 36 |
}
|
| 37 |
var newsize = {
|
| 38 |
width: parseInt($(".edit-image-crop-width").val()),
|
| 39 |
height: parseInt($(".edit-image-crop-height").val())
|
| 40 |
}
|
| 41 |
if ($('#resizeMe').size()) {
|
| 42 |
obj.style.backgroundPosition = (-1)*newpos.left + 'px ' + (-1)*newpos.top + 'px';
|
| 43 |
obj.style.left = (newpos.left + containerpos.x) + 'px';
|
| 44 |
obj.style.top = (newpos.top + containerpos.y) + 'px';
|
| 45 |
obj.style.width = newsize.width + 'px';
|
| 46 |
obj.style.height = newsize.height + 'px';
|
| 47 |
}
|
| 48 |
});
|
| 49 |
|
| 50 |
$('#resizeMe').Resizable(
|
| 51 |
{
|
| 52 |
minWidth: 20,
|
| 53 |
minHeight: 20,
|
| 54 |
maxWidth: 1 + $('#resizeMe').parents('.imagefield-crop-wrapper').width(),
|
| 55 |
maxHeight: 1 + $('#resizeMe').parents('.imagefield-crop-wrapper').height(),
|
| 56 |
minTop: 1,
|
| 57 |
minLeft: 1,
|
| 58 |
maxRight: $('#resizeMe').parents('.imagefield-crop-wrapper').width(),
|
| 59 |
maxBottom: $('#resizeMe').parents('.imagefield-crop-wrapper').height(),
|
| 60 |
dragHandle: true,
|
| 61 |
ratio: Drupal.imagefield_crop.ratio,
|
| 62 |
onDrag: function(x, y)
|
| 63 |
{
|
| 64 |
clearTimeout(dragT);
|
| 65 |
this.style.backgroundPosition = ((-1)*(x - containerpos.x)) + 'px ' + ((-1)*(y - containerpos.y)) + 'px';
|
| 66 |
xx = x-containerpos.x;
|
| 67 |
yy = y-containerpos.y;
|
| 68 |
dragT = setTimeout('imagefieldCropSetDimensions (xx, yy)', 200);
|
| 69 |
},
|
| 70 |
handlers: {
|
| 71 |
se: '#resizeSE',
|
| 72 |
e: '#resizeE',
|
| 73 |
ne: '#resizeNE',
|
| 74 |
n: '#resizeN',
|
| 75 |
nw: '#resizeNW',
|
| 76 |
w: '#resizeW',
|
| 77 |
sw: '#resizeSW',
|
| 78 |
s: '#resizeS'
|
| 79 |
},
|
| 80 |
onResize : function(size, position) {
|
| 81 |
clearTimeout(resizeT);
|
| 82 |
this.style.backgroundPosition = ((-1)*(position.left - containerpos.x)) + 'px ' + ((-1)*(position.top - containerpos.y)) + 'px';
|
| 83 |
x = position.left-containerpos.x;
|
| 84 |
y = position.top-containerpos.y;
|
| 85 |
w = size.width;
|
| 86 |
h = size.height;
|
| 87 |
resizeT = setTimeout('imagefieldCropSetDimensions (x, y, w, h)', 200);
|
| 88 |
}
|
| 89 |
}
|
| 90 |
);
|
| 91 |
});
|
| 92 |
|
| 93 |
|