Prevent pasting images from word/excel/numbers which is normally text or html. Just past images if first item is really an image.
This commit is contained in:
parent
863e43e107
commit
33cbbed774
1 changed files with 23 additions and 24 deletions
|
@ -200,36 +200,35 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var clipboardData = e.clipboardData || e.originalEvent.clipboardData
|
var clipboardData = e.clipboardData || e.originalEvent.clipboardData
|
||||||
if (clipboardData && clipboardData.items) {
|
if (clipboardData && clipboardData.items && clipboardData.items[0]) {
|
||||||
var imageInserted = false
|
var imageInserted = false
|
||||||
jQuery.each(clipboardData.items, function(index, item){
|
var item = clipboardData.items[0]
|
||||||
console.log(index, item)
|
if (item.kind == 'file' && (item.type == 'image/png' || item.type == 'image/jpeg')) {
|
||||||
if (item.kind == 'file' && item.type == 'image/png') {
|
_this.log('paste image', item)
|
||||||
_this.log('paste image', item)
|
console.log(item)
|
||||||
|
|
||||||
var imageFile = item.getAsFile()
|
var imageFile = item.getAsFile()
|
||||||
var reader = new FileReader()
|
var reader = new FileReader()
|
||||||
|
|
||||||
reader.onload = function (e) {
|
reader.onload = function (e) {
|
||||||
var result = e.target.result
|
var result = e.target.result
|
||||||
var img = document.createElement('img')
|
var img = document.createElement('img')
|
||||||
img.src = result
|
img.src = result
|
||||||
|
|
||||||
insert = function(dataUrl, width, height) {
|
insert = function(dataUrl, width, height) {
|
||||||
//console.log('dataUrl', dataUrl)
|
//console.log('dataUrl', dataUrl)
|
||||||
_this.log('image inserted')
|
_this.log('image inserted')
|
||||||
result = dataUrl
|
result = dataUrl
|
||||||
img = "<img style=\"width: " + width + "px; height: " + height + "px\" src=\"" + result + "\">"
|
img = "<img style=\"width: " + width + "px; height: " + height + "px\" src=\"" + result + "\">"
|
||||||
document.execCommand('insertHTML', false, img)
|
document.execCommand('insertHTML', false, img)
|
||||||
}
|
|
||||||
|
|
||||||
// resize if to big
|
|
||||||
App.ImageService.resize(img.src, 460, 'auto', 2, 'image/jpeg', 'auto', insert)
|
|
||||||
}
|
}
|
||||||
reader.readAsDataURL(imageFile)
|
|
||||||
imageInserted = true
|
// resize if to big
|
||||||
|
App.ImageService.resize(img.src, 460, 'auto', 2, 'image/jpeg', 'auto', insert)
|
||||||
}
|
}
|
||||||
})
|
reader.readAsDataURL(imageFile)
|
||||||
|
imageInserted = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (imageInserted) {
|
if (imageInserted) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue