Skip to content

Commit

Permalink
fix: add compatibillity for non cors
Browse files Browse the repository at this point in the history
  • Loading branch information
berviantoleo committed Nov 28, 2020
1 parent fb4dad3 commit bf41c59
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions packages/react-multi-crop/src/ReactMultiCrop/ReactMultiCrop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ReactMultiCrop extends Component {
initial: true,
};

this.REGEXP_ORIGINS = /^(\w+:)\/\/([^:/?#]*):?(\d*)/i;
this.color = props.cropBackgroundColor;
this.opacity = props.cropBackgroundOpacity;
this.strokeColor = props.cropOutlineColor;
Expand Down Expand Up @@ -62,20 +63,39 @@ class ReactMultiCrop extends Component {
}
}

isCrossOriginURL(url) {
var parts = url.match(this.REGEXP_ORIGINS);
return (
parts !== null &&
(parts[1] !== location.protocol ||
parts[2] !== location.hostname ||
parts[3] !== location.port)
);
}

initialImage() {
const { record, image } = this.props;
let loadImageNow = this.loadImage.bind(this);
const loadImageNow = this.loadImage.bind(this);
if (typeof record === "object" && record.image) {
fabric.Image.fromURL(record.image, loadImageNow, {
crossOrigin: "Anonymous",
});
const isCrossOrigin = this.isCrossOriginURL(record.image);
const options = {};
if (isCrossOrigin)
{
options.crossOrigin = "Anonymous";
}
fabric.Image.fromURL(record.image, loadImageNow, options);
} else if (typeof image === "string") {
fabric.Image.fromURL(image, loadImageNow, { crossOrigin: "Anonymous" });
const isCrossOrigin = this.isCrossOriginURL(image);
const options = {};
if (isCrossOrigin) {
options.crossOrigin = "Anonymous";
}
fabric.Image.fromURL(image, loadImageNow, options);
}
}

initialObjects() {
let { canvas } = this.state;
const { canvas } = this.state;
if (!canvas) {
return;
}
Expand Down

0 comments on commit bf41c59

Please sign in to comment.