Skip to content

Commit

Permalink
Add check if the resized overlay is within the image bounds on the bo…
Browse files Browse the repository at this point in the history
…ttom and the right
  • Loading branch information
morpheus-87 committed Aug 23, 2017
1 parent 8709edc commit a4c027f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ImageCropper/imageCropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ var ImageCropper = {
},

/* changes the overlay dimensions depending on the resize element */
changeOverlayDimensions: function(type, mousePosition, offsets, element){
changeOverlayDimensions: function(type, mousePosition, offsets, element, osdViewport, windowId){
var imageBounds = this.calculateImageBounds(osdViewport, windowId);
if(mousePosition.top > imageBounds.bottomLeft.y || mousePosition.left > imageBounds.topRight.x){
this.resizing = false;
return;
}

var newElementHeight = mousePosition.top - offsets.element.top;
var newElementWidth = mousePosition.left - offsets.element.left;
if(type === 'right' || type === 'bottom-right'){
Expand Down Expand Up @@ -376,7 +382,10 @@ var ImageCropper = {
if(this_.resizing){
event.preventDefault();
currentMousePosition = this_.calculatePositions(this.croppingOverlay, event).mouse;
this_.changeOverlayDimensions(typeOfResizeElement, currentMousePosition, offsets, this.croppingOverlay);
this_.changeOverlayDimensions(
typeOfResizeElement, currentMousePosition, offsets,
this.croppingOverlay, this.osd.viewport, this.windowId
);
}
}.bind(this)).on('mouseup', '.resize-anchor, .resize-bar', function(){
this_.resizing = false;
Expand Down

0 comments on commit a4c027f

Please sign in to comment.