Copy and Paste between instances of jspaint
parent
ff6db611a1
commit
8e7e6cf396
|
@ -36,9 +36,8 @@ You can also install it as a chrome app.
|
|||
* [A lot of stuff](TODO.md)
|
||||
|
||||
One thing that may not be doable is full clipboard support.
|
||||
You can paste with <kbd>Ctrl+V</kbd>, but you can't copy or cut, and you can't use the menu items.
|
||||
After all, it would be terrible if web pages were able to access your clipboard at will...
|
||||
It would be nice if web pages could *request* it, though!
|
||||
You can copy with <kbd>Ctrl+C</kbd>, cut with <kbd>Ctrl+X</kbd>, and paste with <kbd>Ctrl+V</kbd>,
|
||||
but copied data can only be pasted into other instances of jspaint, and you can't use the menu items.
|
||||
|
||||
|
||||
## Staying True to the Original
|
||||
|
|
20
src/app.js
20
src/app.js
|
@ -292,9 +292,10 @@ $G.on("cut copy paste", function(e){
|
|||
|
||||
if(e.type === "copy" || e.type === "cut"){
|
||||
if(selection && selection.canvas){
|
||||
var data = selection.canvas.toDataURL("image/png");
|
||||
cd.setData("URL", data);
|
||||
cd.setData("image/png", data);
|
||||
var data_url = selection.canvas.toDataURL();
|
||||
cd.setData("text/x-data-uri; type=image/png", data_url);
|
||||
cd.setData("text/uri-list", data_url);
|
||||
cd.setData("URL", data_url);
|
||||
if(e.type === "cut"){
|
||||
selection.destroy();
|
||||
selection = null;
|
||||
|
@ -302,9 +303,18 @@ $G.on("cut copy paste", function(e){
|
|||
}
|
||||
}else if(e.type === "paste"){
|
||||
$.each(cd.items, function(i, item){
|
||||
if(item.type.match(/image/)){
|
||||
if(item.type.match(/^text\/(?:x-data-)?uri/)){
|
||||
item.getAsString(function(str){
|
||||
var img = E("img");
|
||||
img.onload = function(){
|
||||
paste(img);
|
||||
};
|
||||
img.src = str;
|
||||
});
|
||||
return false; // break $.each
|
||||
}else if(item.type.match(/^image/)){
|
||||
paste_file(item.getAsFile());
|
||||
return false;
|
||||
return false; // break $.each
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue