Created
October 11, 2012 23:34
-
-
Save johnistan/3876362 to your computer and use it in GitHub Desktop.
Image Copy from Clipboard GWT/Chrome solution
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
public native void copyListener() /*-{ | |
var temp = this //hackish way to maintain this | |
var reader = new $wnd.FileReader(); | |
var blob; | |
reader.onloadend = (function(event){ | |
return function(){ | |
console.log("ahhhhhh in da' file reader!!!!"); | |
console.log(this.result); | |
// Here you replace with the class of your view | |
//where there is a public method onPaste(String data) | |
[email protected]::onPaste(Ljava/lang/String;)(this.result); | |
// take a moment and say woh. java methods in javascript | |
} | |
})(blob); | |
$doc.onpaste = function(event){ | |
var items = event.clipboardData.items; | |
// will give you the mime types | |
console.log(JSON.stringify(items)); | |
for (var i = 0; i < items.length; i++) { | |
//test if the file you are | |
//dealing with is an image | |
if (/^image/.test(items[i].type) ){ | |
console.log("IMAGE!!!!! WOOT WOOT"); | |
reader.readAsDataURL(items[i].getAsFile()); | |
} | |
} | |
} | |
}-*/; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment