Skip to content

Commit

Permalink
paste, drag and drop image applied fixed #305, #304, #300
Browse files Browse the repository at this point in the history
  • Loading branch information
shiren authored and seonim-ryu committed Jan 2, 2020
1 parent 412b26e commit 437ec4b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 44 deletions.
2 changes: 1 addition & 1 deletion apps/core/demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
done([1,2,3]);
}
},
exts: ['scrollFollow', 'colorSyntax'],
exts: ['scrollFollow', 'colorSyntax', 'textPalette'],
hooks: {
'previewBeforeHook': function($dom) {
//console.log('previewBeforeHook', $dom);
Expand Down
46 changes: 46 additions & 0 deletions apps/core/src/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ function NeonEditor(options) {
self.eventManager.emit('load', self);
});

this._initImportEvent();

__nedInstance.push(this);
}

Expand Down Expand Up @@ -147,6 +149,50 @@ NeonEditor.prototype._initDefaultCommands = function() {
this.commandManager.addCommand(wwTask);
};

NeonEditor.prototype._initImportEvent = function() {
var self = this;

this.eventManager.listen('paste', function(ev) {
var items, blob, i, itemLen;

items = ev.data.clipboardData && ev.data.clipboardData.items;

if (items) {
itemLen = items.length;

for (i = 0; i < itemLen; i += 1) {
if (items[i].type.indexOf('image') !== -1) {
blob = items[i].getAsFile();

self.eventManager.emit('addImageBlobHook', blob, function(url) {
self.eventManager.emit('command', 'AddImage', {imageUrl: url, altText: blob.name || 'image'});
});
}
}
}
});

this.eventManager.listen('drop', function(ev) {
var items, blob, i, itemLen;

items = ev.data.dataTransfer && ev.data.dataTransfer.files;

if (items) {
itemLen = items.length;

for (i = 0; i < itemLen; i += 1) {
if (items[i].type.indexOf('image') !== -1) {
blob = items[i];

self.eventManager.emit('addImageBlobHook', blob, function(url) {
self.eventManager.emit('command', 'AddImage', {imageUrl: url, altText: blob.name || 'image'});
});
}
}
}
});
};

/**
* 프리뷰가 보여지는 방식을 변경한다
* @param {string} style 스타일 이름 tab, vertical
Expand Down
43 changes: 0 additions & 43 deletions apps/core/src/js/markdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,54 +77,11 @@ MarkdownEditor.prototype._initEvent = function() {
});

this.cm.on('drop', function(cm, eventData) {
console.log(eventData);
self.eventManager.emit('drop', {
source: 'markdown',
data: eventData
});
});

this.eventManager.listen('paste', function(ev) {
var items, blob, i, itemLen;

items = ev.data.clipboardData && ev.data.clipboardData.items;

if (items) {
itemLen = items.length;

for (i = 0; i < itemLen; i += 1) {
if (items[i].type.indexOf('image') !== -1) {
blob = items[i].getAsFile();

self.eventManager.emit('addImageBlobHook', blob, function(url) {
self.eventManager.emit('command', 'AddImage', {imageUrl: url, altText: blob.name || 'image'});
});
}
}
}
});

this.eventManager.listen('drop', function(ev) {
var items, blob, i, itemLen;

items = ev.data.dataTransfer && ev.data.dataTransfer.files;

ev.data.preventDefault();
if (items) {
ev.data.preventDefault();
itemLen = items.length;

for (i = 0; i < itemLen; i += 1) {
if (items[i].type.indexOf('image') !== -1) {
blob = items[i];

self.eventManager.emit('addImageBlobHook', blob, function(url) {
self.eventManager.emit('command', 'AddImage', {imageUrl: url, altText: blob.name || 'image'});
});
}
}
}
});
};

/**
Expand Down
1 change: 1 addition & 0 deletions apps/core/src/js/popupAddImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ PopupAddImage.prototype._linkWithEventManager = function() {
} else {
self._preAltValue = self.$el.find('.altTextInput').val();
self.eventManager.emit('addImageFileHook', self._getImageFileForm(), self.applyImage);
//self.eventManager.emit('addImageBlobHook', self.$el.find('.imageFileInput')[0].files[0], self.applyImage);
}
});
};
Expand Down
9 changes: 9 additions & 0 deletions apps/core/src/js/wysiwygEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,20 @@ WysiwygEditor.prototype._initSquireEvent = function() {
});
});

this.getEditor().addEventListener('dragover', function(e) {
e.preventDefault();
return false;
});

this.getEditor().addEventListener('drop', function(eventData) {
eventData.preventDefault();

self.eventManager.emit('drop', {
source: 'wysiwyg',
data: eventData
});

return false;
});

this.getEditor().addEventListener('input', function() {
Expand Down

0 comments on commit 437ec4b

Please sign in to comment.