2f4f6db133
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
import Ember from 'ember';
|
|
import uploader from 'ghost/assets/lib/uploader';
|
|
|
|
const {Component, inject, run} = Ember;
|
|
|
|
export default Component.extend({
|
|
config: inject.service(),
|
|
|
|
_scrollWrapper: null,
|
|
|
|
didInsertElement() {
|
|
this._scrollWrapper = this.$().closest('.entry-preview-content');
|
|
this.adjustScrollPosition(this.get('scrollPosition'));
|
|
run.scheduleOnce('afterRender', this, this.dropzoneHandler);
|
|
},
|
|
|
|
didReceiveAttrs(attrs) {
|
|
if (!attrs.oldAttrs) {
|
|
return;
|
|
}
|
|
|
|
if (attrs.newAttrs.scrollPosition && attrs.newAttrs.scrollPosition.value !== attrs.oldAttrs.scrollPosition.value) {
|
|
this.adjustScrollPosition(attrs.newAttrs.scrollPosition.value);
|
|
}
|
|
|
|
if (attrs.newAttrs.markdown.value !== attrs.oldAttrs.markdown.value) {
|
|
run.scheduleOnce('afterRender', this, this.dropzoneHandler);
|
|
}
|
|
},
|
|
|
|
adjustScrollPosition(scrollPosition) {
|
|
let scrollWrapper = this._scrollWrapper;
|
|
|
|
if (scrollWrapper) {
|
|
scrollWrapper.scrollTop(scrollPosition);
|
|
}
|
|
},
|
|
|
|
dropzoneHandler() {
|
|
let dropzones = $('.js-drop-zone[data-uploaderui!="true"]');
|
|
|
|
if (dropzones.length) {
|
|
uploader.call(dropzones, {
|
|
editor: true,
|
|
fileStorage: this.get('config.fileStorage')
|
|
});
|
|
|
|
dropzones.on('uploadstart', run.bind(this, 'sendAction', 'uploadStarted'));
|
|
dropzones.on('uploadfailure', run.bind(this, 'sendAction', 'uploadFinished'));
|
|
dropzones.on('uploadsuccess', run.bind(this, 'sendAction', 'uploadFinished'));
|
|
dropzones.on('uploadsuccess', run.bind(this, 'sendAction', 'uploadSuccess'));
|
|
|
|
// Set the current height so we can listen
|
|
this.sendAction('updateHeight', this.$().height());
|
|
}
|
|
}
|
|
});
|