Created
February 2, 2014 14:47
-
-
Save pavelk2/8769432 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
$("body").bind("paste", function(ev) { | |
var $this = $(this); | |
var original = ev.originalEvent; | |
var file = original.clipboardData.items[0].getAsFile(); | |
var reader = new FileReader(); | |
reader.onload = function (evt) { | |
var result = evt.target.result; | |
var result = evt.target.result; | |
var arr = result.split(","); | |
var clip_data = arr[1]; // raw base64 | |
var contentType = arr[0].split(";")[0].split(":")[1]; | |
notificationShow('Uploading an image from clipboard','constant',0); | |
// this needs to post to a server route that can accept raw base64 content and save to a file | |
$.post(settings.uploadImageURL, { | |
contentType: contentType, | |
data: clip_data | |
},function(data){ | |
var image = new Image(); | |
if (data.id>0){ | |
image.init(data); | |
image.display(); | |
notificationShow('Image '+data.title+' is uploaded','instant'); | |
}else{ | |
notificationShow(data.details,'instant'); | |
} | |
}); | |
}; | |
reader.readAsDataURL(file); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment