Skip to content

Commit

Permalink
Fix enforce boundary (#484)
Browse files Browse the repository at this point in the history
* Linting - avoid type coercion

* Linting - remove unncessary semi colons

* Fix issue with enforceBoundary = false

Whenvever enforceBoundary is set to false, the image cannot get smaller the original image size. Adding conditional that will skip this check if enforceBoundary = false
  • Loading branch information
jlane9 authored and thedustinsmith committed Mar 16, 2018
1 parent 32b4f59 commit 3a61566
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions croppie.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/* Polyfills */
if (typeof Promise !== 'function') {
/*! promise-polyfill 3.1.0 */
!function(a){function b(a,b){return function(){a.apply(b,arguments)}}function c(a){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof a)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],i(a,b(e,this),b(f,this))}function d(a){var b=this;return null===this._state?void this._deferreds.push(a):void k(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var d;try{d=c(b._value)}catch(e){return void a.reject(e)}a.resolve(d)})}function e(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"==typeof a||"function"==typeof a)){var c=a.then;if("function"==typeof c)return void i(b(c,a),b(e,this),b(f,this))}this._state=!0,this._value=a,g.call(this)}catch(d){f.call(this,d)}}function f(a){this._state=!1,this._value=a,g.call(this)}function g(){for(var a=0,b=this._deferreds.length;b>a;a++)d.call(this,this._deferreds[a]);this._deferreds=null}function h(a,b,c,d){this.onFulfilled="function"==typeof a?a:null,this.onRejected="function"==typeof b?b:null,this.resolve=c,this.reject=d}function i(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(e){if(d)return;d=!0,c(e)}}var j=setTimeout,k="function"==typeof setImmediate&&setImmediate||function(a){j(a,1)},l=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};c.prototype["catch"]=function(a){return this.then(null,a)},c.prototype.then=function(a,b){var e=this;return new c(function(c,f){d.call(e,new h(a,b,c,f))})},c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&l(arguments[0])?arguments[0]:arguments);return new c(function(b,c){function d(f,g){try{if(g&&("object"==typeof g||"function"==typeof g)){var h=g.then;if("function"==typeof h)return void h.call(g,function(a){d(f,a)},c)}a[f]=g,0===--e&&b(a)}catch(i){c(i)}}if(0===a.length)return b([]);for(var e=a.length,f=0;f<a.length;f++)d(f,a[f])})},c.resolve=function(a){return a&&"object"==typeof a&&a.constructor===c?a:new c(function(b){b(a)})},c.reject=function(a){return new c(function(b,c){c(a)})},c.race=function(a){return new c(function(b,c){for(var d=0,e=a.length;e>d;d++)a[d].then(b,c)})},c._setImmediateFn=function(a){k=a},"undefined"!=typeof module&&module.exports?module.exports=c:a.Promise||(a.Promise=c)}(this);
!function(a){function b(a,b){return function(){a.apply(b,arguments)}}function c(a){if("object"!==typeof this)throw new TypeError("Promises must be constructed via new");if("function"!==typeof a)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],i(a,b(e,this),b(f,this))}function d(a){var b=this;return null===this._state?void this._deferreds.push(a):void k(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var d;try{d=c(b._value)}catch(e){return void a.reject(e)}a.resolve(d)})}function e(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"===typeof a||"function"===typeof a)){var c=a.then;if("function"===typeof c)return void i(b(c,a),b(e,this),b(f,this))}this._state=!0,this._value=a,g.call(this)}catch(d){f.call(this,d)}}function f(a){this._state=!1,this._value=a,g.call(this)}function g(){for(var a=0,b=this._deferreds.length;b>a;a++)d.call(this,this._deferreds[a]);this._deferreds=null}function h(a,b,c,d){this.onFulfilled="function"===typeof a?a:null,this.onRejected="function"===typeof b?b:null,this.resolve=c,this.reject=d}function i(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(e){if(d)return;d=!0,c(e)}}var j=setTimeout,k="function"===typeof setImmediate&&setImmediate||function(a){j(a,1)},l=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};c.prototype["catch"]=function(a){return this.then(null,a)},c.prototype.then=function(a,b){var e=this;return new c(function(c,f){d.call(e,new h(a,b,c,f))})},c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&l(arguments[0])?arguments[0]:arguments);return new c(function(b,c){function d(f,g){try{if(g&&("object"===typeof g||"function"===typeof g)){var h=g.then;if("function"===typeof h)return void h.call(g,function(a){d(f,a)},c)}a[f]=g,0===--e&&b(a)}catch(i){c(i)}}if(0===a.length)return b([]);for(var e=a.length,f=0;f<a.length;f++)d(f,a[f])})},c.resolve=function(a){return a&&"object"===typeof a&&a.constructor===c?a:new c(function(b){b(a)})},c.reject=function(a){return new c(function(b,c){c(a)})},c.race=function(a){return new c(function(b,c){for(var d=0,e=a.length;e>d;d++)a[d].then(b,c)})},c._setImmediateFn=function(a){k=a},"undefined"!==typeof module&&module.exports?module.exports=c:a.Promise||(a.Promise=c)}(this);
}

if ( typeof window.CustomEvent !== "function" ) {
Expand Down Expand Up @@ -630,7 +630,7 @@
function scroll(ev) {
var delta, targetZoom;

if(self.options.mouseWheelZoom === 'ctrl' && ev.ctrlKey != true){
if(self.options.mouseWheelZoom === 'ctrl' && ev.ctrlKey !== true){
return 0;
} else if (ev.wheelDelta) {
delta = ev.wheelDelta / 1200; //wheelDelta min: -120 max: 120 // max x 10 x 2
Expand Down Expand Up @@ -814,9 +814,9 @@
RIGHT_ARROW = 39,
DOWN_ARROW = 40;

if (ev.shiftKey && (ev.keyCode == UP_ARROW || ev.keyCode == DOWN_ARROW)) {
if (ev.shiftKey && (ev.keyCode === UP_ARROW || ev.keyCode === DOWN_ARROW)) {
var zoom = 0.0;
if (ev.keyCode == UP_ARROW) {
if (ev.keyCode === UP_ARROW) {
zoom = parseFloat(self.elements.zoomer.value, 10) + parseFloat(self.elements.zoomer.step, 10)
}
else {
Expand All @@ -832,7 +832,7 @@
document.body.style[CSS_USERSELECT] = 'none';
vpRect = self.elements.viewport.getBoundingClientRect();
keyMove(movement);
};
}

function parseKeyDown(key) {
switch (key) {
Expand All @@ -844,8 +844,8 @@
return [-1, 0];
case DOWN_ARROW:
return [0, -1];
};
};
}
}
}

function keyMove(movement) {
Expand Down Expand Up @@ -903,7 +903,7 @@
deltaY = pageY - originalY,
newCss = {};

if (ev.type == 'touchmove') {
if (ev.type === 'touchmove') {
if (ev.touches.length > 1) {
var touch1 = ev.touches[0];
var touch2 = ev.touches[1];
Expand Down Expand Up @@ -973,7 +973,7 @@
}

self.options.update.call(self, data);
if (self.$ && typeof Prototype == 'undefined') {
if (self.$ && typeof Prototype === 'undefined') {
self.$(self.element).trigger('update.croppie', data);
}
else {
Expand Down Expand Up @@ -1080,7 +1080,7 @@
}

function _bindPoints(points) {
if (points.length != 4) {
if (points.length !== 4) {
throw "Croppie - Invalid number of points supplied: " + points;
}
var self = this,
Expand Down Expand Up @@ -1170,8 +1170,10 @@
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
}

width=Math.min(width, self._originalImageWidth);
height=Math.min(height, self._originalImageHeight)
if (self.options.enforceBoundary !== false) {
width = Math.min(width, self._originalImageWidth);
height = Math.min(height, self._originalImageHeight);
}

// console.table({ left, right, top, bottom, canvasWidth, canvasHeight });
ctx.drawImage(this.elements.preview, left, top, width, height, startX, startY, canvasWidth, canvasHeight);
Expand Down Expand Up @@ -1244,7 +1246,7 @@
else if (Array.isArray(options)) {
points = options.slice();
}
else if (typeof (options) == 'undefined' && self.data.url) { //refreshing
else if (typeof (options) === 'undefined' && self.data.url) { //refreshing
_updatePropertiesFromImage.call(self);
_triggerUpdate.call(self);
return null;
Expand Down

0 comments on commit 3a61566

Please sign in to comment.