2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2017-05-08 13:35:42 +03:00
|
|
|
import {
|
2017-05-29 21:50:03 +03:00
|
|
|
IMAGE_EXTENSIONS,
|
|
|
|
IMAGE_MIME_TYPES
|
2017-05-08 13:35:42 +03:00
|
|
|
} from 'ghost-admin/components/gh-image-uploader';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2017-04-19 16:20:42 +03:00
|
|
|
|
|
|
|
export default Component.extend({
|
2021-07-01 14:04:59 +03:00
|
|
|
feature: service(),
|
|
|
|
|
2017-10-30 12:38:01 +03:00
|
|
|
ui: service(),
|
2017-04-19 16:20:42 +03:00
|
|
|
|
2017-05-08 21:15:56 +03:00
|
|
|
classNameBindings: [
|
|
|
|
'isDraggedOver:-drag-over',
|
2017-05-12 11:06:56 +03:00
|
|
|
'isFullScreen:gh-editor-fullscreen',
|
|
|
|
'isPreview:gh-editor-preview'
|
2017-05-08 21:15:56 +03:00
|
|
|
],
|
2017-05-08 13:35:42 +03:00
|
|
|
|
|
|
|
// Internal attributes
|
|
|
|
droppedFiles: null,
|
2018-05-01 17:55:51 +03:00
|
|
|
headerHeight: 0,
|
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,
|
|
|
|
_onResizeHandler: null,
|
2017-04-19 16:20:42 +03:00
|
|
|
_viewActionsWidth: 190,
|
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
actions: {
|
|
|
|
toggleFullScreen(isFullScreen) {
|
|
|
|
this.set('isFullScreen', isFullScreen);
|
2019-03-06 16:53:54 +03:00
|
|
|
this.ui.set('isFullScreen', isFullScreen);
|
2018-01-11 20:43:23 +03:00
|
|
|
},
|
2017-04-19 16:20:42 +03:00
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
togglePreview(isPreview) {
|
|
|
|
this.set('isPreview', isPreview);
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleSplitScreen(isSplitScreen) {
|
|
|
|
this.set('isSplitScreen', isSplitScreen);
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadImages(fileList, resetInput) {
|
|
|
|
// convert FileList to an array so that resetting the input doesn't
|
|
|
|
// clear the file references before upload actions can be triggered
|
|
|
|
let files = Array.from(fileList);
|
|
|
|
this.set('droppedFiles', files);
|
|
|
|
resetInput();
|
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2018-05-02 14:50:53 +03:00
|
|
|
_setHeaderHeight() {
|
|
|
|
if (this.headerClass && this._editorTitleElement) {
|
|
|
|
let height = this._editorTitleElement.offsetHeight;
|
|
|
|
return this.set('headerHeight', height);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('headerHeight', 0);
|
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
|
2017-12-12 14:53:35 +03:00
|
|
|
if (navigator.userAgent.indexOf('Chrome') > -1) {
|
|
|
|
let eA = event.dataTransfer.effectAllowed;
|
|
|
|
event.dataTransfer.dropEffect = (eA === 'move' || eA === 'linkMove') ? 'move' : 'copy';
|
|
|
|
}
|
2017-05-08 13:35:42 +03:00
|
|
|
|
|
|
|
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
|
2018-01-05 18:38:23 +03:00
|
|
|
this._dragCounter += 1;
|
2017-05-08 13:35:42 +03:00
|
|
|
|
|
|
|
this.set('isDraggedOver', true);
|
|
|
|
},
|
|
|
|
|
|
|
|
dragLeave(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
this._dragCounter -= 1;
|
2017-05-08 13:35:42 +03:00
|
|
|
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);
|
|
|
|
}
|
2017-04-19 16:20:42 +03:00
|
|
|
}
|
|
|
|
});
|