Ghost/ghost/admin/app/components/gh-uploader.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-02-13 07:22:32 +03:00
import Ember from 'ember';
2014-09-16 02:46:40 +04:00
import uploader from 'ghost/assets/lib/uploader';
var PostImageUploader = Ember.Component.extend({
classNames: ['image-uploader', 'js-post-image-upload'],
config: Ember.inject.service(),
imageSource: Ember.computed('image', function () {
return this.get('image') || '';
}),
/**
* Sets up the uploader on render
*/
2014-09-16 02:46:40 +04:00
setup: function () {
var $this = this.$(),
self = this;
this.set('uploaderReference', uploader.call($this, {
2014-09-16 02:46:40 +04:00
editor: true,
fileStorage: this.get('config.fileStorage')
}));
2014-09-16 02:46:40 +04:00
$this.on('uploadsuccess', function (event, result) {
if (result && result !== '' && result !== 'http://') {
self.sendAction('uploaded', result);
}
});
$this.on('imagecleared', function () {
2014-09-16 02:46:40 +04:00
self.sendAction('canceled');
});
},
2014-09-16 02:46:40 +04:00
// removes event listeners from the uploader
2014-09-16 02:46:40 +04:00
removeListeners: function () {
var $this = this.$();
2014-09-16 02:46:40 +04:00
$this.off();
$this.find('.js-cancel').off();
},
didInsertElement: function () {
this.setup();
},
willDestroyElement: function () {
this.removeListeners();
}
2014-09-16 02:46:40 +04:00
});
export default PostImageUploader;