bupy7 / js-cropbox

A lightweight and simple js extension to crop your image.
http://bupy7.github.io/js-cropbox
5 stars 1 forks source link

Issue If cropped Twice #10

Closed AhmedEmadAhmedABD closed 6 years ago

AhmedEmadAhmedABD commented 6 years ago

When you press crop twice image disappear and 2 cropped image appear in bottom? is there any solution for this issue?

bupy7 commented 6 years ago

@AhmedEmadAhmedABD hi! there is solution, of course. You can use delay after to press the button.

Example:

var cropBtn = document.querySelector('#btn-crop'),
  processed = false;
cropBtn.addEventListener('click', function () {
  if (processed) {
    return;
  }
  processed = true;
  cropbox.crop();
  setTimeout(function () {
    processed = false;
  }, 5000);
});

Or you can use the cb:cropped event:

// crop
var cropBtn = document.querySelector('#btn-crop'),
  processed = false;
cropBtn.addEventListener('click', function(){
  if (processed) {
    return;
  }
  processed = true;
  cropbox.crop();
});
// the cropped event
cropbox.getCb().addEventListener('cb:cropped', function(event){
  processed = false;
});
AhmedEmadAhmedABD commented 6 years ago

I tried the 2 solution but the issue still exist. press crop for first time works properly . the second time the main image disappear and 2 cropped image appear below.

bupy7 commented 6 years ago

@AhmedEmadAhmedABD wow, i have understood. this is feature. after everything options of cropping the main image will disappear.

AhmedEmadAhmedABD commented 6 years ago

but i may need to re crop after reviewing cropped image . is there any solution ?

bupy7 commented 6 years ago

@AhmedEmadAhmedABD just press the "start" button again. =)

AhmedEmadAhmedABD commented 6 years ago

I already transferred logic of start button to on load event on upload to load automatically after choosing image : fileInput.onchange = function (evt) { var fileReader = new FileReader(); fileReader.readAsDataURL(fileInput.files[0]); fileReader.addEventListener('load', function (event) { cropbox.load(event.target.result); }); }

AhmedEmadAhmedABD commented 6 years ago

can I edit crop event to stop this behavior?

bupy7 commented 6 years ago

@AhmedEmadAhmedABD I don't understand you. What do you mean?

AhmedEmadAhmedABD commented 6 years ago

untitled

as above picture only allowed number of cropping is two then image disappear . can I change this behavior by removing this limit and view always the last cropped image and the original image still appears and can be cropped again

bupy7 commented 6 years ago

@AhmedEmadAhmedABD no, this can do each of developers himself. Just call "start" again.

bupy7 commented 6 years ago

No activity.