mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 18:52:05 +03:00
413d999462
no issue - fixes problems with "re-definition of $" errors
61 lines
1.9 KiB
JavaScript
61 lines
1.9 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._super(...arguments);
|
|
this._scrollWrapper = this.$().closest('.entry-preview-content');
|
|
this.adjustScrollPosition(this.get('scrollPosition'));
|
|
run.scheduleOnce('afterRender', this, this.dropzoneHandler);
|
|
},
|
|
|
|
didReceiveAttrs(attrs) {
|
|
this._super(...arguments);
|
|
|
|
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());
|
|
}
|
|
}
|
|
});
|