diff --git a/pybossa/themes/default/static/js/image_crop.js b/pybossa/themes/default/static/js/image_crop.js index c140911..431c8a9 100644 --- a/pybossa/themes/default/static/js/image_crop.js +++ b/pybossa/themes/default/static/js/image_crop.js @@ -17,19 +17,28 @@ oFReader.onload = function (oFREvent) { - document.getElementById("uploadPreview").src = oFREvent.target.result; - var img = document.getElementById('uploadPreview'); - //or however you get a handle to the IMG - var width = img.clientWidth; - var height = img.clientHeight; - if (width > height) { - width = height - 100; - } - else { - height = width - 100; - } - jQuery(function($) { + document.getElementById("uploadPreview").src = oFREvent.target.result; + var img = document.getElementById('uploadPreview'); + var width = img.clientWidth; + var height = img.clientHeight; + + // Check if Jcrop preview has a image and clears the previous set up + var previewImg = $('#uploadPreview + .jcrop-holder img')[0]; + if (previewImg) { + width = previewImg.clientWidth; + height = previewImg.clientHeight; + $('#uploadPreview').data('Jcrop').destroy(); + $('#uploadPreview').removeAttr("style"); + } + + if (width > height) { + width = height - 100; + } + else { + height = width - 100; + } + $('#uploadPreview').Jcrop({ onSelect: _updateCoords, onChange: _updateCoords, @@ -42,7 +51,6 @@ (height/ 2)], aspectRatio: 1, boxWidth: 450 - }); }); }; -- libgit2 0.21.2