Last active
October 13, 2017 06:23
-
-
Save boboidream/6cbcd8f6e65a6242006cab1a029f8cb8 to your computer and use it in GitHub Desktop.
从剪切板粘贴图片
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 从剪切板粘贴图片 | |
$document.on('paste', '.my_editor pre', function(ev) { | |
var clipboardData, file, item, j, k, ref1, len | |
var clipboardData = (ev.originalEvent || ev).clipboardData | |
var $my_editor = $(this).closest('.my_editor') | |
var text = (ev.originalEvent || ev).clipboardData.getData('Text') // 获取到纯文本 | |
if (text) { | |
ev.preventDefault(); | |
text.replace(/\n/g, '<br/>') | |
document.execCommand("insertHTML", false, text.trim()); | |
} | |
if (clipboardData.items) { | |
ref1 = clipboardData.items; | |
for (j = 0, len = ref1.length; j < len; j++) { | |
item = ref1[j]; | |
if (item.type.match(/^image\//)) { | |
file = item.getAsFile() | |
uploadImg(file, $my_editor) | |
ev.preventDefault(); | |
break; | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment