Created
March 26, 2015 22:14
-
-
Save moudy/fbe6215549bd0d5667ca to your computer and use it in GitHub Desktop.
This file contains 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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
classNames: 'uploadThumbnail', | |
classNameBindings: ['upload.isLoaded'], | |
backgroundImageStyle: function () { | |
if (this.get('localFileUrl')) { | |
return 'background-image: url("'+this.get('localFileUrl')+'");'; | |
} | |
}.property('localFileUrl'), | |
percentComplete: function () { | |
return Math.round(this.get('upload.progress') * 100); | |
}.property('upload.progress'), | |
percentCompleteStyle: function () { | |
return 'width:'+this.get('percentComplete')+'%;'; | |
}.property('percentComplete'), | |
previewFile: function () { | |
Ember.run.once(this, function () { | |
var reader = new FileReader(); | |
reader.onload = (e) => { this.set('localFileUrl', e.target.result); }; | |
reader.readAsDataURL(this.get('upload.file')); | |
}); | |
}.observes('upload').on('init'), | |
onIsLoaded: function () { | |
Ember.run.once(this, function () { | |
if (this.get('upload.isLoaded')) { | |
this.sendAction('action', this.get('upload'), this.get('dimensions')); | |
} | |
}); | |
}.observes('upload.isLoaded'), | |
getDimesntions: function () { | |
if (!this.get('localFileUrl')) return; | |
var img = new Image(); | |
img.src = this.get('localFileUrl'); | |
this.set('dimensions', { | |
width: img.width, | |
height: img.height | |
}); | |
}.observes('localFileUrl'), | |
click: function () { | |
if (this.get('upload.isLoaded')) { | |
this.sendAction('uploadClicked', this.get('upload')); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment