tapmodo/Jcrop — Issue #21: setSelect reloads the wrong selection intermittently
Author: thegrubbsian
Created: 2012-01-05 22:40:38+00:00
State: open

While using the setSelect method of the Jcrop object I'm finding that sometimes it reloads the selection in a totally wrong area of the image. For example if I have 100x100 pixel image with a selection of { x: 10, y:10, x2: 30, y2: 30} when I reload I might get a much smaller selected area in a completely different part of the image. Has anyone run into this and/or have ideas on a fix? It's very intermittent and I can't seem to find a pattern for how to reproduce it. Here is the code we're using:

$(function() {

jcrop_options = {
aspectRatio: 1,
onSelect: function(coords) {
updateCropFormFields(coords);
showCropFormButton();
}
};

if ($(".image_cropper img").length > 0) {
loadSelectionIfAvailable();
}

function loadSelectionIfAvailable() {
var form = $("#finalize_crop_form");
var x = parseInt($("#image_crop_offset_x", form).val());
var y = parseInt($("#image_crop_offset_y", form).val());
var height = parseInt($("#image_crop_height", form).val());
var width = parseInt($("#image_crop_width", form).val());
jcrop = $.Jcrop(".image_cropper img", jcrop_options);
jcrop.setSelect([x, y, height, width]);
}

});