2015-03-13 12:39:28 +03:00
|
|
|
import Ember from 'ember';
|
|
|
|
import uploader from 'ghost/assets/lib/uploader';
|
|
|
|
|
|
|
|
var Preview = Ember.Component.extend({
|
2015-05-26 05:10:50 +03:00
|
|
|
config: Ember.inject.service(),
|
|
|
|
|
2015-03-13 12:39:28 +03:00
|
|
|
didInsertElement: function () {
|
|
|
|
this.set('scrollWrapper', this.$().closest('.entry-preview-content'));
|
|
|
|
Ember.run.scheduleOnce('afterRender', this, this.dropzoneHandler);
|
|
|
|
},
|
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
adjustScrollPosition: Ember.observer('scrollPosition', function () {
|
2015-03-13 12:39:28 +03:00
|
|
|
var scrollWrapper = this.get('scrollWrapper'),
|
|
|
|
scrollPosition = this.get('scrollPosition');
|
|
|
|
|
2015-06-13 17:34:09 +03:00
|
|
|
if (scrollWrapper) {
|
|
|
|
scrollWrapper.scrollTop(scrollPosition);
|
|
|
|
}
|
2015-06-03 05:56:42 +03:00
|
|
|
}),
|
2015-03-13 12:39:28 +03:00
|
|
|
|
|
|
|
dropzoneHandler: function () {
|
|
|
|
var dropzones = $('.js-drop-zone');
|
|
|
|
|
|
|
|
uploader.call(dropzones, {
|
|
|
|
editor: true,
|
|
|
|
fileStorage: this.get('config.fileStorage')
|
|
|
|
});
|
|
|
|
|
|
|
|
dropzones.on('uploadstart', Ember.run.bind(this, 'sendAction', 'uploadStarted'));
|
|
|
|
dropzones.on('uploadfailure', Ember.run.bind(this, 'sendAction', 'uploadFinished'));
|
|
|
|
dropzones.on('uploadsuccess', Ember.run.bind(this, 'sendAction', 'uploadFinished'));
|
|
|
|
dropzones.on('uploadsuccess', Ember.run.bind(this, 'sendAction', 'uploadSuccess'));
|
|
|
|
|
|
|
|
// Set the current height so we can listen
|
2015-06-13 17:34:09 +03:00
|
|
|
this.sendAction('updateHeight', this.$().height());
|
2015-03-13 12:39:28 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// fire off 'enable' API function from uploadManager
|
|
|
|
// might need to make sure markdown has been processed first
|
2015-06-03 05:56:42 +03:00
|
|
|
reInitDropzones: Ember.observer('markdown', function () {
|
2015-03-13 12:39:28 +03:00
|
|
|
Ember.run.scheduleOnce('afterRender', this, this.dropzoneHandler);
|
2015-06-03 05:56:42 +03:00
|
|
|
})
|
2015-03-13 12:39:28 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
export default Preview;
|