From a4c027f7b8a2c3a0f5561f32af0d08e5e4e91eda Mon Sep 17 00:00:00 2001 From: Matthias Lindinger Date: Wed, 23 Aug 2017 15:49:32 +0200 Subject: [PATCH] Add check if the resized overlay is within the image bounds on the bottom and the right --- ImageCropper/imageCropper.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ImageCropper/imageCropper.js b/ImageCropper/imageCropper.js index bbc6273..3a59a50 100644 --- a/ImageCropper/imageCropper.js +++ b/ImageCropper/imageCropper.js @@ -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'){ @@ -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;