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

Commit

Permalink
Fix #139
Browse files Browse the repository at this point in the history
  • Loading branch information
Fengyuan Chen committed Dec 20, 2014
1 parent 7e16f7c commit 0121083
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
4 changes: 4 additions & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
<button class="btn btn-info" id="rotateLeft" type="button">Rotate Left</button>
<button class="btn btn-info" id="rotateRight" type="button">Rotate Right</button>
<button class="btn btn-primary" id="setData" type="button">Set Data</button>
<label class="btn btn-primary" for="inputImage" title="Upload image file">
<input class="hide" id="inputImage" name="file" type="file" accept="image/*">
Upload
</label>
</div>
<div class="row eg-input">
<div class="col-md-6">
Expand Down
28 changes: 28 additions & 0 deletions demos/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ $(function() {
$image.cropper("rotate", 90);
});

var $inputImage = $("#inputImage");

if (window.FileReader) {
$inputImage.change(function() {
var fileReader = new FileReader(),
files = this.files,
file;

if (!files.length) {
return;
}

file = files[0];

if (/^image\/\w+$/.test(file.type)) {
fileReader.readAsDataURL(file);
fileReader.onload = function () {
$image.cropper("reset", true).cropper("replace", this.result);
$inputImage.val("");
};
} else {
showMessage("Please choose an image file.");
}
});
} else {
$inputImage.addClass("hide");
}

$("#setAspectRatio").click(function() {
$image.cropper("setAspectRatio", $("#aspectRatio").val());
});
Expand Down
4 changes: 2 additions & 2 deletions dist/cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@
this.addListeners();
this.initPreview();

this.built = TRUE;
this.built = TRUE; // Set `true` before update
this.update();
this.replaced = FALSE; // Reset to `false` after update

$this.one(EVENT_BUILT, defaults.built); // Only trigger once
$this.trigger(EVENT_BUILT);
Expand Down Expand Up @@ -448,7 +449,6 @@

// Reset image ratio
if (this.replaced) {
this.replaced = FALSE;
image.ratio = defaultImage.ratio;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/cropper.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@
this.addListeners();
this.initPreview();

this.built = TRUE;
this.built = TRUE; // Set `true` before update
this.update();
this.replaced = FALSE; // Reset to `false` after update

$this.one(EVENT_BUILT, defaults.built); // Only trigger once
$this.trigger(EVENT_BUILT);
Expand Down Expand Up @@ -440,7 +441,6 @@

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

0 comments on commit 0121083

Please sign in to comment.