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

Commit

Permalink
#119: Add "checkImageOrigin" option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fengyuan Chen committed Dec 6, 2014
1 parent 378bd12 commit 18d4f65
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 29 deletions.
6 changes: 1 addition & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ module.exports = function (grunt) {
src: "**",
dest: "docs/dist",
filter: "isFile"
},
others: {
src: "README.md",
dest: "docs/"
}
},
watch: {
Expand All @@ -151,6 +147,6 @@ module.exports = function (grunt) {

grunt.registerTask("build", ["clean:build", "copy:build"]);
grunt.registerTask("release", ["clean:release", "copy:release"]);
grunt.registerTask("docs", ["clean:docs", "copy:docs", "copy:others"]);
grunt.registerTask("docs", ["clean:docs", "copy:docs"]);
grunt.registerTask("default", ["clean:dist", "jshint", "jscs", "uglify", "copy:dist", "autoprefixer", "csscomb", "csslint", "cssmin", "htmlcomb", "usebanner", "build", "release", "docs"]);
};
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ Enable to zoom the image.
Enable to rotate the image.


#### checkImageOrigin

- type: `Boolean`
- default: `true`

By default, the plugin will check the image origin, and if it is a cross-origin image, a "crossOrigin" attribute will be added to the image element to enable "rotate" and "getDataURL".


#### minWidth

- type: `Number`
Expand Down Expand Up @@ -298,8 +306,8 @@ An event handler of the "dragend.cropper" event.
- Rotate the image (Replace the original image with a new rotated image which was generated by canvas).
- Param: a number (positive number for rotate right, negative number for rotate left).
- Usage: `$().cropper("rotate", 90)` or `$().cropper("rotate", -90)`.
- Note: Be sure the browser supports canvas before call this method.

- **Note**: Be sure the browser supports canvas before call this method.
- **Note**: Don't call this in IE9/10 (not support `crossOrigin` attribute) when it's a cross-origin image.

#### enable

Expand Down Expand Up @@ -408,6 +416,8 @@ $().cropper("getDataURL", {
```

**Note:** Be sure the browser supports canvas before call this method.
**Note:** Don't call this in IE9/10 (not support `crossOrigin` attribute) when it's a cross-origin image.



## Events
Expand Down
2 changes: 1 addition & 1 deletion bower.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.7.5-beta",
"version": "0.7.5",
"main": "dist/cropper.js",
"keywords": [
"image",
Expand Down
19 changes: 10 additions & 9 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,16 @@
},
preview: ".preview",

// multiple: FALSE,
// autoCrop: TRUE,
// dragCrop: TRUE,
// dashed: TRUE,
// modal: TRUE,
// movable: TRUE,
// resizable: TRUE,
// zoomable: TRUE,
// rotatable: TRUE,
// multiple: true,
// autoCrop: false,
// dragCrop: false,
// dashed: false,
// modal: false,
// movable: false,
// resizable: false,
// zoomable: false,
// rotatable: false,
// checkImageOrigin: false,

// maxWidth: 480,
// maxHeight: 270,
Expand Down
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.7.5-beta
* Cropper v0.7.5
* https://github.com/fengyuanchen/cropper
*
* Copyright 2014 Fengyuan Chen
Expand Down
21 changes: 17 additions & 4 deletions dist/cropper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Cropper v0.7.5-beta
* Cropper v0.7.5
* https://github.com/fengyuanchen/cropper
*
* Copyright 2014 Fengyuan Chen
Expand Down Expand Up @@ -138,6 +138,7 @@
$this = this.$element,
element = this.element,
image = this.image,
crossOrigin = "",
$clone,
url;

Expand All @@ -153,11 +154,16 @@

// Reset image rotate degree
if (this.replaced) {
this.replaced = FALSE;
image.rotate = 0;
}

this.$clone = ($clone = $("<img" + ((typeof $this.attr("crossOrigin") !== STRING_UNDEFINED || this.isCrossOriginURL(url)) ? " crossOrigin" : "") + ' src="' + url + '">'));
if (this.defaults.checkImageOrigin) {
if ($this.prop("crossOrigin") || this.isCrossOriginURL(url)) {
crossOrigin = " crossOrigin";
}
}

this.$clone = ($clone = $("<img" + crossOrigin + ' src="' + url + '">'));

$clone.one("load", function () {
image.naturalWidth = this.naturalWidth || $clone.width();
Expand Down Expand Up @@ -406,7 +412,13 @@
if (image._width !== cropper.width || image._height !== cropper.height) {
$.extend(image, defaultImage);
} else {
image = $.extend(defaultImage, image);
image = $.extend({}, defaultImage, image);

// Reset image ratio
if (this.replaced) {
this.replaced = FALSE;
image.ratio = defaultImage.ratio;
}
}

this.image = image;
Expand Down Expand Up @@ -1478,6 +1490,7 @@
resizable: TRUE,
zoomable: TRUE,
rotatable: TRUE,
checkImageOrigin: TRUE,

// Dimensions
minWidth: 0,
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.7.5-beta",
"version": "0.7.5",
"main": "dist/cropper.js",
"keywords": [
"image",
Expand Down
19 changes: 16 additions & 3 deletions src/cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
$this = this.$element,
element = this.element,
image = this.image,
crossOrigin = "",
$clone,
url;

Expand All @@ -145,11 +146,16 @@

// Reset image rotate degree
if (this.replaced) {
this.replaced = FALSE;
image.rotate = 0;
}

this.$clone = ($clone = $("<img" + ((typeof $this.attr("crossOrigin") !== STRING_UNDEFINED || this.isCrossOriginURL(url)) ? " crossOrigin" : "") + ' src="' + url + '">'));
if (this.defaults.checkImageOrigin) {
if ($this.prop("crossOrigin") || this.isCrossOriginURL(url)) {
crossOrigin = " crossOrigin";
}
}

this.$clone = ($clone = $("<img" + crossOrigin + ' src="' + url + '">'));

$clone.one("load", function () {
image.naturalWidth = this.naturalWidth || $clone.width();
Expand Down Expand Up @@ -398,7 +404,13 @@
if (image._width !== cropper.width || image._height !== cropper.height) {
$.extend(image, defaultImage);
} else {
image = $.extend(defaultImage, image);
image = $.extend({}, defaultImage, image);

// Reset image ratio
if (this.replaced) {
this.replaced = FALSE;
image.ratio = defaultImage.ratio;
}
}

this.image = image;
Expand Down Expand Up @@ -1470,6 +1482,7 @@
resizable: TRUE,
zoomable: TRUE,
rotatable: TRUE,
checkImageOrigin: TRUE,

// Dimensions
minWidth: 0,
Expand Down

0 comments on commit 18d4f65

Please sign in to comment.