Commit 92c19a48e9274a9671075ddfe95b3de7c7b27014

Authored by Adabriand Furtado
1 parent 66f61f43
Exists in master

Fix a bug on Jcrop

Showing 1 changed file with 21 additions and 13 deletions   Show diff stats
pybossa/themes/default/static/js/image_crop.js
... ... @@ -17,19 +17,28 @@
17 17  
18 18 oFReader.onload = function (oFREvent) {
19 19  
20   - document.getElementById("uploadPreview").src = oFREvent.target.result;
21   - var img = document.getElementById('uploadPreview');
22   - //or however you get a handle to the IMG
23   - var width = img.clientWidth;
24   - var height = img.clientHeight;
25   - if (width > height) {
26   - width = height - 100;
27   - }
28   - else {
29   - height = width - 100;
30   - }
31   -
32 20 jQuery(function($) {
  21 + document.getElementById("uploadPreview").src = oFREvent.target.result;
  22 + var img = document.getElementById('uploadPreview');
  23 + var width = img.clientWidth;
  24 + var height = img.clientHeight;
  25 +
  26 + // Check if Jcrop preview has a image and clears the previous set up
  27 + var previewImg = $('#uploadPreview + .jcrop-holder img')[0];
  28 + if (previewImg) {
  29 + width = previewImg.clientWidth;
  30 + height = previewImg.clientHeight;
  31 + $('#uploadPreview').data('Jcrop').destroy();
  32 + $('#uploadPreview').removeAttr("style");
  33 + }
  34 +
  35 + if (width > height) {
  36 + width = height - 100;
  37 + }
  38 + else {
  39 + height = width - 100;
  40 + }
  41 +
33 42 $('#uploadPreview').Jcrop({
34 43 onSelect: _updateCoords,
35 44 onChange: _updateCoords,
... ... @@ -42,7 +51,6 @@
42 51 (height/ 2)],
43 52 aspectRatio: 1,
44 53 boxWidth: 450
45   -
46 54 });
47 55 });
48 56 };
... ...