Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small feature: Allow deletion of all cropped areas #182

Closed
paddington1983 opened this issue Apr 23, 2015 · 2 comments
Closed

Small feature: Allow deletion of all cropped areas #182

paddington1983 opened this issue Apr 23, 2015 · 2 comments

Comments

@paddington1983
Copy link

Currently it is not possible to delete all areas: in the function requestDelete around line 2350 there is a check on "this.ui.multi.length > 1". I can delete areas if there are two or more left, but never the last one. However it can be nice to be able to delete all areas and allow the user to start with a clean image.

I am not too familiar with this plugin so I changed the above check to "this.ui.multi.length > 0" and then I changed the function deleteSelection to :

deleteSelection: function () {
        if (this.ui.selection) {
            this.removeSelection(this.ui.selection);
            if (this.ui.multi[0]) {
                this.ui.multi[0].focus();
            } else {
                var max = this.getContainerSize();
                var selection = {
                    w: max[0],
                    x: 0,
                    x2: max[0],
                    h: max[1],
                    y: 0,
                    y2: max[1]
                }
                this.ui.selection.redraw(selection);
            }
            this.ui.selection.refresh();
        }
    }

Probably a clumsy solution but maybe it will help you with a clean solution. Thanks in advance :)

@tapmodo
Copy link
Owner

tapmodo commented Aug 31, 2015

It's intentional that you can't delete the last one (hence requestDelete()).
In 0.9.x versions, there was a sense of "selected" or nothing selected.
In 2.x versions, (ideally) it's intended that something is selected at all times.

Below references newest version of WIP-2.x branch
If you wanted to do this, a better workaround is to add a new API method.
(Re-write or polyfill the forEach method if your environment doesn't support it.)

$.Jcrop.prototype.deleteAll = function() {
  var self = this;
  this.ui.multi.forEach(function(item){
    self.deleteSelection(item);
  });
};

var jcp = $("#target").Jcrop('api');
jcp.deleteAll();

This exposes an additional display bug referened in Issue #202
I'm going to close this one since it isn't per se an issue.

@tapmodo tapmodo closed this as completed Aug 31, 2015
@tablatronix
Copy link

This should be a feature, i do not like new presumption that something should always be selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants