andersthorborg / ACF-Image-Crop

98 stars 35 forks source link

When image too small or canceling crop, remove image selection #37

Closed rafecolton closed 3 years ago

rafecolton commented 8 years ago

If the user cancels the crop then the image is not cropped. If one or both of the image's dimensions are too small, the crop window does not appear and the image is also not cropped.

If the image is not cropped, the user can still save it, resulting an image of an undesirable ratio being saved. This change ensures that the image selection is removed if the user cancels the crop or the image is too small.

rafecolton commented 8 years ago

Updated this to work with ACF v5 as well

1ucay commented 8 years ago

There should be some condition, if width/height of image is equal of target size, then dont show crop window. Before your pull it works, if I cancel window. Can you look at it?

1ucay commented 8 years ago

edit: upps, there should be OR, not AND

else{
    if ( (data['width'] !== $options.data('width')) || (data['height'] !== $options.data('height') ) ) {
        if($options.data('force_crop')){
            initCrop($field);
        }
    }
}
1ucay commented 8 years ago
$field.find('.cancel-crop-button').click(function(e){
    e.preventDefault();

    var iW = $options.find('.crop-stage img.crop-image').data('width'),
        iH = $options.find('.crop-stage img.crop-image').data('height');

    cancelCrop($field);

    if ( $options.data('width') !== iW && $options.data('height') !==iH && $options.data('force_crop'))
        removeImage($field);
});
rafecolton commented 3 years ago

Author is clearly not accepting improvements, and I no longer work for the company that uses (a fork of) this. Closing this out.