Skip to content

Instantly share code, notes, and snippets.

@johnistan
Created October 11, 2012 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnistan/3876362 to your computer and use it in GitHub Desktop.
Save johnistan/3876362 to your computer and use it in GitHub Desktop.
Image Copy from Clipboard GWT/Chrome solution
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)
temp.@com.project.gwt.client.mvc.ProjectView.MainClass::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