mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 15:13:21 +08:00
32 lines
887 B
JavaScript
32 lines
887 B
JavaScript
export default {
|
|
data() {
|
|
return {
|
|
showClipboardPasteModal: false,
|
|
pasteImages: null,
|
|
};
|
|
},
|
|
mounted() {
|
|
document.addEventListener('paste', this.handlePaste);
|
|
},
|
|
unmounted() {
|
|
document.removeEventListener('paste', this.handlePaste);
|
|
},
|
|
methods: {
|
|
handlePaste(e) {
|
|
if ( e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' ) return;
|
|
this.pasteImages = this.getImagesFromClipboard(e);
|
|
if (this.pasteImages && this.firstObjectInViewport()) this.showClipboardPasteModal = true;
|
|
},
|
|
getImagesFromClipboard(e) {
|
|
let image = null;
|
|
if (e.clipboardData) {
|
|
for (let i = 0; i < e.clipboardData.items.length; i++) {
|
|
if (e.clipboardData.items[i].type.indexOf('image') !== -1) {
|
|
image = e.clipboardData.items[i];
|
|
}
|
|
}
|
|
}
|
|
return image;
|
|
},
|
|
},
|
|
};
|