-
-
Save chukon/a863e66b7af859f3a7bca4dca57a8c84 to your computer and use it in GitHub Desktop.
Revisions
-
dusanmarsa revised this gist
Oct 29, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,5 +23,5 @@ document.onpaste = function(e){ } } e.PreventDefault() } -
dusanmarsa created this gist
Oct 29, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ var IMAGE_MIME_REGEX = /^image\/(p?jpeg|gif|png)$/i; var loadImage = function (file) { var reader = new FileReader(); reader.onload = function(e){ var img = document.createElement('img'); img.src = e.target.result; var range = window.getSelection().getRangeAt(0); range.deleteContents(); range.insertNode(img); }; reader.readAsDataURL(file); }; document.onpaste = function(e){ var items = e.clipboardData.items; for (var i = 0; i < items.length; i++) { if (IMAGE_MIME_REGEX.test(items[i].type)) { loadImage(items[i].getAsFile()); return; } } // Normal paste handling here }