Skip to content

Commit

Permalink
Merge pull request #1 from eliksir/improve-resize-minsize
Browse files Browse the repository at this point in the history
Allow increasing dimension when within min size
  • Loading branch information
fdanielsen authored May 27, 2020
2 parents 4560798 + 66dec7f commit d467148
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions croppie.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@
var direction;
var originalX;
var originalY;
var minSize = 50;
var minWidth = 0;
var minHeight = 0;
var maxWidth;
var maxHeight;
var sizeInfo;
Expand Down Expand Up @@ -501,6 +502,13 @@
wrap.appendChild(hr);
}

if (this.options.resizeControls.minWidth > 0) {
minWidth = this.options.resizeControls.minWidth;
}
if (this.options.resizeControls.minHeight > 0) {
minHeight = this.options.resizeControls.minHeight;
}

function mouseDown(ev) {
if (ev.button !== undefined && ev.button !== 0) return;

Expand Down Expand Up @@ -571,7 +579,7 @@
var newHeight = self.options.viewport.height + deltaY;
var newWidth = self.options.viewport.width + deltaX;

if (direction === 'v' && newHeight >= minSize && newHeight <= maxHeight) {
if (direction === 'v' && (newHeight >= minHeight || deltaY > 0) && newHeight <= maxHeight) {
css(wrap, {
height: newHeight + 'px'
});
Expand All @@ -586,7 +594,7 @@
height: self.options.viewport.height + 'px'
});
}
else if (direction === 'h' && newWidth >= minSize && newWidth <= maxWidth) {
else if (direction === 'h' && (newWidth >= minWidth || deltaX > 0) && newWidth <= maxWidth) {
css(wrap, {
width: newWidth + 'px'
});
Expand Down Expand Up @@ -1631,6 +1639,8 @@
resizeControls: {
width: true,
height: true,
minWidth: null,
minHeight: null,
maxWidth: null,
maxHeight: null,
sizeInfo: false,
Expand Down

0 comments on commit d467148

Please sign in to comment.