Ghost/ghost/admin/app/components/gh-ed-preview.js
Kevin Ansfield 2f4f6db133 Use es6 across client and add ember-suave to enforce rules
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
2015-11-30 10:41:01 +00:00

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());
}
}
});