Skip to content
This repository has been archived by the owner on Aug 1, 2020. It is now read-only.

Commit

Permalink
Fix issue #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Fengyuan Chen committed Jul 6, 2014
1 parent 14c20fe commit c5349e4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dist/cropper.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Cropper v0.3.5
* Cropper v0.3.6
* https://github.com/fengyuanchen/cropper
*
* Copyright 2014 Fengyuan Chen
Expand Down
22 changes: 11 additions & 11 deletions dist/cropper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Cropper v0.3.5
* Cropper v0.3.6
* https://github.com/fengyuanchen/cropper
*
* Copyright 2014 Fengyuan Chen
Expand Down Expand Up @@ -202,9 +202,7 @@
cropper.left = (container.width - cropper.width) / 2;
}

$.each(cropper, function (i, n) {
cropper[i] = Math.round(n);
});
cropper = Cropper.fn.floor(cropper);

image.height = cropper.height;
image.width = cropper.width;
Expand Down Expand Up @@ -254,7 +252,7 @@
dragger.left = (cropper.width - dragger.width) / 2;
dragger.top = (cropper.height - dragger.height) / 2;

this.defaultDragger = Cropper.fn.round(dragger);
this.defaultDragger = Cropper.fn.floor(dragger);
this.dragger = this.getDragger();
this.setData(this.defaults.data);
this.$image.trigger("ready.cropper").off("ready.cropper");
Expand All @@ -277,7 +275,7 @@
dragger.left = dragger.left < 0 ? 0 : dragger.left > dragger.maxLeft ? dragger.maxLeft : dragger.left;
dragger.top = dragger.top < 0 ? 0 : dragger.top > dragger.maxTop ? dragger.maxTop : dragger.top;

dragger = Cropper.fn.round(dragger);
dragger = Cropper.fn.floor(dragger);

this.$dragger.css({
height: dragger.height,
Expand Down Expand Up @@ -474,7 +472,7 @@
};

$this.css({overflow: "hidden"});
$this.find("img").css(Cropper.fn.round(styles, function (n) {
$this.find("img").css(Cropper.fn.floor(styles, function (n) {
return n * ratio;
}));
});
Expand Down Expand Up @@ -696,15 +694,17 @@
}
},

round: function (data, fn) {
floor: function (data, fn) {
var value,
i;

for (i in data) {
value = data[i];

if (data.hasOwnProperty(i) && typeof value === "number") {
data[i] = Math.round($.isFunction(fn) ? fn(value) : value);
// Use the "Math.floor" rather than "Math.round"
// https://github.com/fengyuanchen/cropper/issues/34
data[i] = Math.floor($.isFunction(fn) ? fn(value) : value);
}
}

Expand All @@ -717,7 +717,7 @@

$.each(data, function (i, n) {
if (_this.isDataOption(i) && $.isNumeric(n) && n >= 0) {
result[i] = Math.round(n * ratio);
result[i] = Math.floor(n * ratio);
}
});

Expand Down Expand Up @@ -798,7 +798,7 @@
return (typeof result !== "undefined" ? result : this);
};

$.fn.cropper.Constructor = Cropper;
$.fn.cropper.constructor = Cropper;
$.fn.cropper.setDefaults = Cropper.setDefaults;

$(function () {
Expand Down
2 changes: 1 addition & 1 deletion dist/cropper.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/cropper.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cropper",
"description": "A simple jQuery image cropping plugin.",
"version": "0.3.5",
"version": "0.3.6",
"keywords": [
"image",
"cropping",
Expand Down
20 changes: 10 additions & 10 deletions src/cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@
cropper.left = (container.width - cropper.width) / 2;
}

$.each(cropper, function (i, n) {
cropper[i] = Math.round(n);
});
cropper = Cropper.fn.floor(cropper);

image.height = cropper.height;
image.width = cropper.width;
Expand Down Expand Up @@ -246,7 +244,7 @@
dragger.left = (cropper.width - dragger.width) / 2;
dragger.top = (cropper.height - dragger.height) / 2;

this.defaultDragger = Cropper.fn.round(dragger);
this.defaultDragger = Cropper.fn.floor(dragger);
this.dragger = this.getDragger();
this.setData(this.defaults.data);
this.$image.trigger("ready.cropper").off("ready.cropper");
Expand All @@ -269,7 +267,7 @@
dragger.left = dragger.left < 0 ? 0 : dragger.left > dragger.maxLeft ? dragger.maxLeft : dragger.left;
dragger.top = dragger.top < 0 ? 0 : dragger.top > dragger.maxTop ? dragger.maxTop : dragger.top;

dragger = Cropper.fn.round(dragger);
dragger = Cropper.fn.floor(dragger);

this.$dragger.css({
height: dragger.height,
Expand Down Expand Up @@ -466,7 +464,7 @@
};

$this.css({overflow: "hidden"});
$this.find("img").css(Cropper.fn.round(styles, function (n) {
$this.find("img").css(Cropper.fn.floor(styles, function (n) {
return n * ratio;
}));
});
Expand Down Expand Up @@ -688,15 +686,17 @@
}
},

round: function (data, fn) {
floor: function (data, fn) {
var value,
i;

for (i in data) {
value = data[i];

if (data.hasOwnProperty(i) && typeof value === "number") {
data[i] = Math.round($.isFunction(fn) ? fn(value) : value);
// Use the "Math.floor" rather than "Math.round"
// https://github.com/fengyuanchen/cropper/issues/34
data[i] = Math.floor($.isFunction(fn) ? fn(value) : value);
}
}

Expand All @@ -709,7 +709,7 @@

$.each(data, function (i, n) {
if (_this.isDataOption(i) && $.isNumeric(n) && n >= 0) {
result[i] = Math.round(n * ratio);
result[i] = Math.floor(n * ratio);
}
});

Expand Down Expand Up @@ -790,7 +790,7 @@
return (typeof result !== "undefined" ? result : this);
};

$.fn.cropper.Constructor = Cropper;
$.fn.cropper.constructor = Cropper;
$.fn.cropper.setDefaults = Cropper.setDefaults;

$(function () {
Expand Down

0 comments on commit c5349e4

Please sign in to comment.