2017-04-19 16:20:42 +03:00
|
|
|
import Component from 'ember-component';
|
|
|
|
import run from 'ember-runloop';
|
2017-05-08 13:35:42 +03:00
|
|
|
import {
|
|
|
|
IMAGE_MIME_TYPES,
|
|
|
|
IMAGE_EXTENSIONS
|
|
|
|
} from 'ghost-admin/components/gh-image-uploader';
|
2017-04-19 16:20:42 +03:00
|
|
|
|
|
|
|
const {debounce} = run;
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
|
2017-05-08 21:15:56 +03:00
|
|
|
classNameBindings: [
|
|
|
|
'isDraggedOver:-drag-over',
|
|
|
|
'isFullScreen:gh-editor-fullscreen'
|
|
|
|
],
|
2017-05-08 13:35:42 +03:00
|
|
|
|
|
|
|
// Public attributes
|
|
|
|
navIsClosed: false,
|
|
|
|
|
|
|
|
// Internal attributes
|
|
|
|
droppedFiles: null,
|
2017-04-19 16:20:42 +03:00
|
|
|
headerClass: '',
|
2017-05-08 13:35:42 +03:00
|
|
|
imageExtensions: IMAGE_EXTENSIONS,
|
|
|
|
imageMimeTypes: IMAGE_MIME_TYPES,
|
|
|
|
isDraggedOver: false,
|
2017-05-08 21:15:56 +03:00
|
|
|
isFullScreen: false,
|
|
|
|
isSplitScreen: false,
|
2017-05-08 13:35:42 +03:00
|
|
|
uploadedImageUrls: null,
|
|
|
|
|
|
|
|
// Private
|
|
|
|
_dragCounter: 0,
|
2017-04-19 16:20:42 +03:00
|
|
|
_navIsClosed: false,
|
2017-05-08 13:35:42 +03:00
|
|
|
_onResizeHandler: null,
|
2017-04-19 16:20:42 +03:00
|
|
|
_viewActionsWidth: 190,
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._onResizeHandler = (evt) => {
|
|
|
|
debounce(this, this._setHeaderClass, evt, 100);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
window.addEventListener('resize', this._onResizeHandler);
|
|
|
|
this._setHeaderClass();
|
|
|
|
},
|
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
let navIsClosed = this.get('navIsClosed');
|
|
|
|
|
|
|
|
if (navIsClosed !== this._navIsClosed) {
|
|
|
|
run.scheduleOnce('afterRender', this, this._setHeaderClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._navIsClosed = navIsClosed;
|
|
|
|
},
|
|
|
|
|
|
|
|
_setHeaderClass() {
|
2017-05-08 13:35:42 +03:00
|
|
|
let $editorTitle = this.$('.gh-editor-title');
|
2017-05-08 21:15:56 +03:00
|
|
|
let smallHeaderClass = 'gh-editor-header-small';
|
|
|
|
|
|
|
|
if (this.get('isSplitScreen')) {
|
|
|
|
this.set('headerClass', smallHeaderClass);
|
|
|
|
return;
|
|
|
|
}
|
2017-04-19 16:20:42 +03:00
|
|
|
|
2017-05-08 13:35:42 +03:00
|
|
|
if ($editorTitle.length > 0) {
|
|
|
|
let boundingRect = $editorTitle[0].getBoundingClientRect();
|
2017-04-19 16:20:42 +03:00
|
|
|
let maxRight = window.innerWidth - this._viewActionsWidth;
|
|
|
|
|
|
|
|
if (boundingRect.right >= maxRight) {
|
2017-05-08 21:15:56 +03:00
|
|
|
this.set('headerClass', smallHeaderClass);
|
2017-04-19 16:20:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('headerClass', '');
|
2017-05-08 13:35:42 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// dragOver is needed so that drop works
|
|
|
|
dragOver(event) {
|
|
|
|
if (!event.dataTransfer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is needed to work around inconsistencies with dropping files
|
|
|
|
// from Chrome's downloads bar
|
|
|
|
let eA = event.dataTransfer.effectAllowed;
|
|
|
|
event.dataTransfer.dropEffect = (eA === 'move' || eA === 'linkMove') ? 'move' : 'copy';
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
},
|
|
|
|
|
|
|
|
// dragEnter is needed so that the drag class is correctly removed
|
|
|
|
dragEnter(event) {
|
|
|
|
if (!event.dataTransfer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
// the counter technique prevents flickering of the drag class when
|
|
|
|
// dragging across child elements
|
|
|
|
this._dragCounter++;
|
|
|
|
|
|
|
|
this.set('isDraggedOver', true);
|
|
|
|
},
|
|
|
|
|
|
|
|
dragLeave(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
this._dragCounter--;
|
|
|
|
if (this._dragCounter === 0) {
|
|
|
|
this.set('isDraggedOver', false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
drop(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
this._dragCounter = 0;
|
|
|
|
this.set('isDraggedOver', false);
|
|
|
|
|
|
|
|
if (event.dataTransfer.files) {
|
|
|
|
this.set('droppedFiles', event.dataTransfer.files);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
window.removeEventListener('resize', this._onResizeHandler);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
toggleFullScreen() {
|
2017-05-08 21:15:56 +03:00
|
|
|
this.toggleProperty('isFullScreen');
|
|
|
|
run.scheduleOnce('afterRender', this, this._setHeaderClass);
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleSplitScreen() {
|
|
|
|
this.toggleProperty('isSplitScreen');
|
|
|
|
run.scheduleOnce('afterRender', this, this._setHeaderClass);
|
2017-05-08 13:35:42 +03:00
|
|
|
},
|
|
|
|
|
2017-05-10 18:16:36 +03:00
|
|
|
uploadImages(fileList) {
|
|
|
|
this.set('droppedFiles', fileList);
|
|
|
|
},
|
|
|
|
|
2017-05-08 13:35:42 +03:00
|
|
|
uploadComplete(uploads) {
|
|
|
|
this.set('uploadedImageUrls', uploads.mapBy('url'));
|
|
|
|
this.set('droppedFiles', null);
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadCancelled() {
|
|
|
|
this.set('droppedFiles', null);
|
|
|
|
}
|
2017-04-19 16:20:42 +03:00
|
|
|
}
|
|
|
|
});
|