veksen
veksen

Reputation: 7003

imgareaselect: cancel new selection if selection already exists

I'd like to cancel my "new" selection if a selection already exists. My attempt to return false on onSelectStart doesn't work like I expect it.

How could I achieve that?

code example below :

currentCoords = {
    x1: $('input[name="thumb-x1"]')
};

selectthumb = $('.img-orig-thumb').imgAreaSelect({
    instance:    true,
    handles:     true,
    aspectRatio: '1:1',
    imageWidth:  <?php echo $imgsize[0]; ?>,
    imageHeight: <?php echo $imgsize[1]; ?>,
    onSelectStart: function(img, selection) {
        _selection = parseInt(currentCoords.x1.val());
        if(_selection > 0) return false;
    }
});

Upvotes: 0

Views: 157

Answers (1)

GramThanos
GramThanos

Reputation: 3622

The only action you can do is reset the imgAreaSelect

var options = {
    instance : true,
    handles : true,
    aspectRatio : '1:1',
    imageWidth : <?php echo $imgsize[0]; ?>,
    imageHeight : <?php echo $imgsize[1]; ?>,
    onSelectStart : function(img, selection) {
        _selection = parseInt(currentCoords.x1.val());
        if(_selection > 0){
            $(img).imgAreaSelect({remove:true});
            $(img).imgAreaSelect(options);
            return;
        };
    }
}

selectthumb = $('.img-orig-thumb').imgAreaSelect(options);

Upvotes: 1

Related Questions