Created
March 9, 2016 23:29
-
-
Save karan/d01f4641f26aba222bbb to your computer and use it in GitHub Desktop.
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 characters
document.getElementsByClassName('compose-text-container')[0].onpaste = function (event) { | |
var items = (event.clipboardData || event.originalEvent.clipboardData).items; | |
// find pasted image among pasted items | |
var blob; | |
for (var i = 0; i < items.length; i++) { | |
if (items[i].type.indexOf("image") === 0) { | |
blob = items[i].getAsFile(); | |
} | |
} | |
// load image if there is a pasted image | |
if (blob !== null) { | |
var reader = new FileReader(); | |
reader.onload = function(event) { | |
media_el = '<div class="compose-media-bar-holder padding-al">' + | |
'<div class="compose-media-bar">' + | |
'<a class="js-media-bar-remove compose-media-bar-remove is-actionable">' + | |
'<i class="sprite sprite-close"></i>' + | |
'</a>' + | |
'<img class="js-media-bar-thumb compose-media-bar-thumb full-width" alt="" src="' + event.target.result + '" style="height: auto;">' + | |
'</div>' + | |
'</div>'; | |
var media_element = document.getElementsByClassName('js-media-added')[0]; | |
media_element.className = 'js-media-added'; | |
media_element.insertAdjacentHTML('beforeend', media_el); | |
}; | |
reader.readAsDataURL(blob); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment