I'm using Jcrop to edit images uploaded by users, when a user decides to edit their image, an AJAX call gets made to get the original image of the user, my code is as follows:
var jcrop_api;
$('.edit_image').on('click', function(e)
{
var url = $(this).attr('data-url');
e.preventDefault();
$.ajax({
url: url,
type: 'GET',
cache: false,
beforeSend: function()
{
// Remove old box in case user uploaded new image bring the latest one
$('#edit_box').remove();
},
success: function(result)
{
if (result.error)
{
alert(result.error);
}
else
{
$('.edit_image_box').html(result);
$('#edit_box').modal({ show: true});
$('#original_img').load( function()
{
$(this).Jcrop({
aspectRatio: 1,
onSelect: updateCoords,
boxWidth: 700,
boxHeight: 700
}, function()
{
jcrop_api = this;
});
});
}
}
})
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
The box gets loaded, the modal is displayed and the image gets loaded perfectly, but once it finishes loading and Jcrop comes to play it shrinks the width completely, leaving an image of about 20px wide.
Can someone please help me with this, almost 80% of the times this happens. Cheers!