diff options
Diffstat (limited to 'assets')
| -rw-r--r-- | assets/test/clipboard.html | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/assets/test/clipboard.html b/assets/test/clipboard.html index 53634b4..3f17b9c 100644 --- a/assets/test/clipboard.html +++ b/assets/test/clipboard.html @@ -4,6 +4,7 @@ <script src="/assets/javascripts/math/util.js"></script> <script> + document.body.addEventListener('copy', function (e) { if (disabled) { return } if (e.clipboardData) { @@ -19,16 +20,34 @@ document.body.addEventListener('copy', function (e) { document.body.addEventListener('paste', function (e) { toArray(e.clipboardData.items).forEach(function(item,i){ -// if (item.kind == 'file' && item.type.match('image/')) { + console.log(item.kind, item.type) + if (item.kind == 'file' && item.type.match('image/')) { var blob = item.getAsFile(); window.URL = window.URL || window.webkitURL; var blobUrl = window.URL.createObjectURL(blob); var img = document.createElement('img'); + img.onerror = function(){ + // error! + console.log("error! bad image!") + } + img.onload = function(){ + // load! + document.body.appendChild(img); + } img.src = blobUrl; - console.log(blob, blobUrl) - document.body.appendChild(img); -// } + } + // this can be text/plain or text/html.. + else if (item.kind == 'string') { + item.getAsString(function(text){ + var node = document.createElement('span') + node.innerHTML = text + document.body.appendChild(node) + }); + } + else { + console.error("unknown type!", item.type) + } }) }) </script>
\ No newline at end of file |
