Created
April 13, 2015 14:12
-
-
Save chrism/196d7f587f9f494b6fa2 to your computer and use it in GitHub Desktop.
Computed Property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // this works (but doesn't cache the values for image.src, image.width, image.height) | |
| export default Ember.Component.extend({ | |
| didInsertElement: function() { | |
| var reader = new FileReader(); | |
| reader.onload = () => { | |
| var image = new Image(); | |
| image.onload = () => { | |
| this.addImage(image.src, image.width, image.height); | |
| }; | |
| image.src = reader.result; | |
| }; | |
| reader.readAsDataURL(this.get('file')); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // this always returned undefined | |
| imageObject: function() { | |
| var file = this.get('file'); | |
| if (Ember.isPresent(file)) { | |
| var reader = new FileReader(); | |
| reader.onload = () => { | |
| var image = new Image(); | |
| image.onload = () => { | |
| var imageObject = { | |
| src: image.src, | |
| width: image.width, | |
| height: image.height | |
| }; | |
| return imageObject; | |
| }; | |
| image.src = reader.result; | |
| }; | |
| reader.readAsDataURL(file); | |
| } else { | |
| return false; | |
| } | |
| }.property('file'), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment