aboutsummaryrefslogtreecommitdiffstats
path: root/library/cropperjs/src/js/change.js
diff options
context:
space:
mode:
Diffstat (limited to 'library/cropperjs/src/js/change.js')
-rw-r--r--library/cropperjs/src/js/change.js128
1 files changed, 74 insertions, 54 deletions
diff --git a/library/cropperjs/src/js/change.js b/library/cropperjs/src/js/change.js
index 014222ef0..c0ddf27ee 100644
--- a/library/cropperjs/src/js/change.js
+++ b/library/cropperjs/src/js/change.js
@@ -14,14 +14,14 @@ import {
CLASS_HIDDEN,
} from './constants';
import {
- each,
+ forEach,
getMaxZoomRatio,
getOffset,
removeClass,
} from './utilities';
export default {
- change(e) {
+ change(event) {
const {
options,
canvasData,
@@ -47,7 +47,7 @@ export default {
let offset;
// Locking aspect ratio in "free mode" by holding shift key
- if (!aspectRatio && e.shiftKey) {
+ if (!aspectRatio && event.shiftKey) {
aspectRatio = width && height ? width / height : 1;
}
@@ -113,8 +113,8 @@ export default {
// Resize crop box
case ACTION_EAST:
- if (range.x >= 0 && (right >= maxWidth || (aspectRatio &&
- (top <= minTop || bottom >= maxHeight)))) {
+ if (range.x >= 0 && (right >= maxWidth || (aspectRatio
+ && (top <= minTop || bottom >= maxHeight)))) {
renderable = false;
break;
}
@@ -122,21 +122,22 @@ export default {
check(ACTION_EAST);
width += range.x;
- if (aspectRatio) {
- height = width / aspectRatio;
- top -= (range.x / aspectRatio) / 2;
- }
-
if (width < 0) {
action = ACTION_WEST;
- width = 0;
+ width = -width;
+ left -= width;
+ }
+
+ if (aspectRatio) {
+ height = width / aspectRatio;
+ top += (cropBoxData.height - height) / 2;
}
break;
case ACTION_NORTH:
- if (range.y <= 0 && (top <= minTop || (aspectRatio &&
- (left <= minLeft || right >= maxWidth)))) {
+ if (range.y <= 0 && (top <= minTop || (aspectRatio
+ && (left <= minLeft || right >= maxWidth)))) {
renderable = false;
break;
}
@@ -145,21 +146,22 @@ export default {
height -= range.y;
top += range.y;
- if (aspectRatio) {
- width = height * aspectRatio;
- left += (range.y * aspectRatio) / 2;
- }
-
if (height < 0) {
action = ACTION_SOUTH;
- height = 0;
+ height = -height;
+ top -= height;
+ }
+
+ if (aspectRatio) {
+ width = height * aspectRatio;
+ left += (cropBoxData.width - width) / 2;
}
break;
case ACTION_WEST:
- if (range.x <= 0 && (left <= minLeft || (aspectRatio &&
- (top <= minTop || bottom >= maxHeight)))) {
+ if (range.x <= 0 && (left <= minLeft || (aspectRatio
+ && (top <= minTop || bottom >= maxHeight)))) {
renderable = false;
break;
}
@@ -168,21 +170,22 @@ export default {
width -= range.x;
left += range.x;
- if (aspectRatio) {
- height = width / aspectRatio;
- top += (range.x / aspectRatio) / 2;
- }
-
if (width < 0) {
action = ACTION_EAST;
- width = 0;
+ width = -width;
+ left -= width;
+ }
+
+ if (aspectRatio) {
+ height = width / aspectRatio;
+ top += (cropBoxData.height - height) / 2;
}
break;
case ACTION_SOUTH:
- if (range.y >= 0 && (bottom >= maxHeight || (aspectRatio &&
- (left <= minLeft || right >= maxWidth)))) {
+ if (range.y >= 0 && (bottom >= maxHeight || (aspectRatio
+ && (left <= minLeft || right >= maxWidth)))) {
renderable = false;
break;
}
@@ -190,14 +193,15 @@ export default {
check(ACTION_SOUTH);
height += range.y;
- if (aspectRatio) {
- width = height * aspectRatio;
- left -= (range.y * aspectRatio) / 2;
- }
-
if (height < 0) {
action = ACTION_NORTH;
- height = 0;
+ height = -height;
+ top -= height;
+ }
+
+ if (aspectRatio) {
+ width = height * aspectRatio;
+ left += (cropBoxData.width - width) / 2;
}
break;
@@ -240,14 +244,18 @@ export default {
if (width < 0 && height < 0) {
action = ACTION_SOUTH_WEST;
- height = 0;
- width = 0;
+ height = -height;
+ width = -width;
+ top -= height;
+ left -= width;
} else if (width < 0) {
action = ACTION_NORTH_WEST;
- width = 0;
+ width = -width;
+ left -= width;
} else if (height < 0) {
action = ACTION_SOUTH_EAST;
- height = 0;
+ height = -height;
+ top -= height;
}
break;
@@ -263,7 +271,7 @@ export default {
height -= range.y;
top += range.y;
width = height * aspectRatio;
- left += range.y * aspectRatio;
+ left += cropBoxData.width - width;
} else {
check(ACTION_NORTH);
check(ACTION_WEST);
@@ -293,14 +301,18 @@ export default {
if (width < 0 && height < 0) {
action = ACTION_SOUTH_EAST;
- height = 0;
- width = 0;
+ height = -height;
+ width = -width;
+ top -= height;
+ left -= width;
} else if (width < 0) {
action = ACTION_NORTH_EAST;
- width = 0;
+ width = -width;
+ left -= width;
} else if (height < 0) {
action = ACTION_SOUTH_WEST;
- height = 0;
+ height = -height;
+ top -= height;
}
break;
@@ -343,14 +355,18 @@ export default {
if (width < 0 && height < 0) {
action = ACTION_NORTH_EAST;
- height = 0;
- width = 0;
+ height = -height;
+ width = -width;
+ top -= height;
+ left -= width;
} else if (width < 0) {
action = ACTION_SOUTH_EAST;
- width = 0;
+ width = -width;
+ left -= width;
} else if (height < 0) {
action = ACTION_NORTH_WEST;
- height = 0;
+ height = -height;
+ top -= height;
}
break;
@@ -390,14 +406,18 @@ export default {
if (width < 0 && height < 0) {
action = ACTION_NORTH_WEST;
- height = 0;
- width = 0;
+ height = -height;
+ width = -width;
+ top -= height;
+ left -= width;
} else if (width < 0) {
action = ACTION_SOUTH_WEST;
- width = 0;
+ width = -width;
+ left -= width;
} else if (height < 0) {
action = ACTION_NORTH_EAST;
- height = 0;
+ height = -height;
+ top -= height;
}
break;
@@ -410,7 +430,7 @@ export default {
// Zoom canvas
case ACTION_ZOOM:
- this.zoom(getMaxZoomRatio(pointers), e);
+ this.zoom(getMaxZoomRatio(pointers), event);
renderable = false;
break;
@@ -463,7 +483,7 @@ export default {
}
// Override
- each(pointers, (p) => {
+ forEach(pointers, (p) => {
p.startX = p.endX;
p.startY = p.endY;
});