Nel codice si è collegato v'è una funzione pasteHandler
con il seguente:
// Get the items from the clipboard
var items = e.clipboardData.items;
if (items) {
// Loop through all items, looking for any kind of image
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") !== -1) {
// We need to represent the image as a file,
var blob = items[i].getAsFile();
// and use a URL or webkitURL (whichever is available to the browser)
// to create a temporary URL to the object
var URLObj = window.URL || window.webkitURL;
var source = URLObj.createObjectURL(blob);
// The URL can then be used as the source of an image
createImage(source);
}
}
}
Telaio cromato sviluppatore mi sta dicendo che gli elementi [i] è un DataTransferItem
(reference)
Nella pagina di riferimento vedo una proprietà kind
e un metodo getAsString()
. Quest'ultimo sembra richiedere una funzione di callback che riceve il testo come parametro. Quindi, per gestire i valori di testo utilizzando lo script di cui sopra si potrebbe modificare la sezione ho collegato come segue:
// Get the items from the clipboard
var items = e.clipboardData.items;
if (items) {
// Loop through all items, looking for any kind of image
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") !== -1) {
// We need to represent the image as a file,
var blob = items[i].getAsFile();
// and use a URL or webkitURL (whichever is available to the browser)
// to create a temporary URL to the object
var URLObj = window.URL || window.webkitURL;
var source = URLObj.createObjectURL(blob);
// The URL can then be used as the source of an image
createImage(source);
}
if (items[i].kind === "string"){
items[i].getAsString(function(s) {
alert(s);
});
}
}
}
Ecco le specifiche per gli elementi degli Appunti si sta lavorando con: http://www.w3.org/TR /2011/WD-html5-20110113/dnd.html#the-datatransferitem-interface. – pimvdb