diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-02-06 14:16:20 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-02-06 14:16:20 -0500 |
| commit | 7c1e99bb1bc6c2a89bc42fb9c295933f38ac9e0c (patch) | |
| tree | 14352aa8cd7ac165d19c43644804241d14d483f5 /js | |
| parent | 92f59149b7982b5a6aad6efd39c648cc8582a900 (diff) | |
pull in clipboard paste function
Diffstat (limited to 'js')
| -rw-r--r-- | js/app.js | 3 | ||||
| -rw-r--r-- | js/clipboard.js | 51 | ||||
| -rw-r--r-- | js/draw.js | 1 | ||||
| -rw-r--r-- | js/util.js | 1 |
4 files changed, 51 insertions, 5 deletions
@@ -4,6 +4,7 @@ var drawing = false var erasing = false var selecting = false var filling = false +var changed = false var focused var canvas, tools, palette, controls, brush, mode, current_tool, current_canvas @@ -58,7 +59,7 @@ function bind () { }) window.onbeforeunload = function() { - return "Are you sure you want to navigate away?"; + if (changed) return "You have edited this drawing." } } diff --git a/js/clipboard.js b/js/clipboard.js index da326ff..66c0c67 100644 --- a/js/clipboard.js +++ b/js/clipboard.js @@ -9,10 +9,12 @@ var clipboard = (function () { import_ascii.addEventListener("change", exports.setFormat("ascii")) import_irssi.addEventListener("change", exports.setFormat("irssi")) import_mirc.addEventListener("change", exports.setFormat("mirc")) - import_button.addEventListener("click", exports.import_data) + import_button.addEventListener("click", exports.import_text) + import_html.addEventListener("click", exports.import_html) export_button.addEventListener("click", exports.export_data) import_textarea.addEventListener("focus", exports.focus) import_textarea.addEventListener("blur", exports.blur) + import_textarea.addEventListener('paste', exports.paste) import_irssi.setAttribute("checked", true) }, setFormat: function (name) { @@ -35,18 +37,59 @@ var clipboard = (function () { import_mode: function () { focus() clipboard.importing = true - import_button.style.display = "inline-block" + import_buttons.style.display = "inline-block" export_button.style.display = format_group.style.display = "none" import_textarea.value = "" }, export_mode: function () { focus() clipboard.importing = false - import_button.style.display = "none" + import_buttons.style.display = "none" export_button.style.display = format_group.style.display = "inline-block" clipboard.export_data() }, - import_data: function () { + + paste: function (e) { + toArray(e.clipboardData.items).forEach(function(item,i){ + 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); + // handle importing an image? + console.log("image import not supported") + } + img.src = blobUrl; + } + // this can be text/plain or text/html.. + else if (item.kind == 'string' && item.type.match('text/plain') && e.clipboardData.items.length > 1) { + return + } + else if (item.kind == 'string') { + item.getAsString(function(text){ + import_textarea.value = text + }) + } + else { + console.error("unknown type!", item.type) + } + }) + + }, + + import_html: function () { + }, + + import_text: function () { var data = import_textarea.value lines = data.split("\n") var width = lines.reduce(function(a,b){ return Math.max(a, b.length) }) @@ -5,6 +5,7 @@ var draw = (function(){ function down (e, lex, point) { erasing = (e.which == "3" || e.ctrlKey) + changed = true if (e.shiftKey) { line (lex, last_point, point, erasing) } @@ -83,6 +83,7 @@ function smoothstep(min,max,n){ return t * t * (3.0 - 2.0 * t) } +function toArray(a){ return Array.prototype.slice.call(a) } function shuffle(a){ for (var i = a.length; i > 0; i--){ var r = randint(i) |
