4

I'm trying to realize auto resizing or cropbox when box size less than minimum allowed image size, for now I made this:

var cropper = document.getElementById('image_cropper').cropper;

        if (!cropper instanceof Cropper) {
            console.warning('cropper not initialized');
            return false;
        }

        var data = cropper.getData();

        if (data.width < app.avatar.min_width || data.height < app.avatar.min_height) {
            data.width = app.avatar.min_width;
            data.height = app.avatar.min_height;

            cropper.setData(data);

            return;
        }

But want to do this calc on cropend event handled:

canvas.addEventListener('cropend', function (event) {
                var data = cropper.getData();

                if (data.width < app.avatar.min_width || data.height < app.avatar.min_height) {
                    data.width = app.avatar.min_width;
                    data.height = app.avatar.min_height;

                    cropper.setData(data);

                }
            });

And my question is: how can I get cropper instance from event?

Oleg Shakhov
  • 426
  • 6
  • 27

1 Answers1

3

I found the solution: I can get cropper from canvas that is a target element of event, like this: event.target.cropper

Oleg Shakhov
  • 426
  • 6
  • 27