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)
|
* [A lot of stuff](TODO.md)
|
||||||
|
|
||||||
One thing that may not be doable is full clipboard support.
|
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.
|
You can copy with <kbd>Ctrl+C</kbd>, cut with <kbd>Ctrl+X</kbd>, and paste with <kbd>Ctrl+V</kbd>,
|
||||||
After all, it would be terrible if web pages were able to access your clipboard at will...
|
but copied data can only be pasted into other instances of jspaint, and you can't use the menu items.
|
||||||
It would be nice if web pages could *request* it, though!
|
|
||||||
|
|
||||||
|
|
||||||
## Staying True to the Original
|
## 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(e.type === "copy" || e.type === "cut"){
|
||||||
if(selection && selection.canvas){
|
if(selection && selection.canvas){
|
||||||
var data = selection.canvas.toDataURL("image/png");
|
var data_url = selection.canvas.toDataURL();
|
||||||
cd.setData("URL", data);
|
cd.setData("text/x-data-uri; type=image/png", data_url);
|
||||||
cd.setData("image/png", data);
|
cd.setData("text/uri-list", data_url);
|
||||||
|
cd.setData("URL", data_url);
|
||||||
if(e.type === "cut"){
|
if(e.type === "cut"){
|
||||||
selection.destroy();
|
selection.destroy();
|
||||||
selection = null;
|
selection = null;
|
||||||
|
@ -302,9 +303,18 @@ $G.on("cut copy paste", function(e){
|
||||||
}
|
}
|
||||||
}else if(e.type === "paste"){
|
}else if(e.type === "paste"){
|
||||||
$.each(cd.items, function(i, item){
|
$.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());
|
paste_file(item.getAsFile());
|
||||||
return false;
|
return false; // break $.each
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue