cephei_vv
cephei_vv

Reputation: 220

jCrop force cropping

Any idea how to force cropping, only if the image hasn't the correct size?

I'm using the jQuery jCrop plugin. I need to force any image to be cropped, but if you click away from the cropping area, the croping were released. I tried to do:

$('#cropthumb').Jcrop({
  onRelease: setSelect,
}

this calls the function setSelect() on any release. and then in a function I'm setting the selection again.

function setSelect(){
  jcrop_api.setSelect([10,10,180,160]);
}

This works as I want. But on the initial load I'm checking, if the thumbnail is allready displayd in the correct size. If the consition match I do:

jcrop_api.release();
jcrop_api.disable();

This is not working, because my initial load will then always call the setSelect() function and the already cropped image can be cropped again.

Upvotes: 1

Views: 848

Answers (1)

Huseyin Yagli
Huseyin Yagli

Reputation: 10285

Create an external variable which will be set by your disable code and checked by your setSelect function.

var isDisabled = false;

function setSelect(){
    if(!isDisabled)
        jcrop_api.setSelect([10,10,180,160]);
}

And in your code where you disable jCrop:

isDisabled = true;
jcrop_api.release();
jcrop_api.disable();

Upvotes: 1

Related Questions