From 69dcc0677e045e328651e0ea26085b84491f031d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Thu, 25 Oct 2018 02:18:04 +0200 Subject: [PATCH] js/clipboard.js: cleanup. --- js/clipboard.js | 65 ++++++++----------------------------------------- 1 file changed, 10 insertions(+), 55 deletions(-) diff --git a/js/clipboard.js b/js/clipboard.js index 571514c..ffa4805 100644 --- a/js/clipboard.js +++ b/js/clipboard.js @@ -8,14 +8,10 @@ var clipboard = (function () { canvas_r: document.createElement("canvas"), bind: 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_colorcode) 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) { return function () { @@ -44,6 +40,16 @@ var clipboard = (function () { import_textarea.value = "" }, + export_mode: function () { + focus() + clipboard.importing = false + import_buttons.style.display = "none" + format_el.style.display = 'inline' + cutoff_warning_el.style.display = 'none' + gallery_rapper.style.display = 'inline' + clipboard.export_data() + }, + paste: function (e) { e.preventDefault() // images will come through as files @@ -84,10 +90,6 @@ var clipboard = (function () { .replace(/"\s*$/, '') } - // not a colorcode - if (!data.match(/\x03/)) - return exports.import_text(); - var to_json = function(string, opts){ var lines_in = string.split(/\r?\n/) var lines_out = [] @@ -176,41 +178,6 @@ var clipboard = (function () { current_filetool && current_filetool.blur() }, - import_text: function () { - var data = import_textarea.value - var lines = data.split("\n") - var width = lines.reduce(function(a,b){ console.log(a,b); return Math.max(a, b.length) }, 0) - var height = lines.length - if (width > canvas.max) { - return alert("input too wide") - } - if (height > canvas.max) { - return alert("input too tall") - } - undo.new() - undo.save_rect(0,0, canvas.w, canvas.h) - canvas.clear() - lines.forEach(function(line, y){ - var row = canvas.aa[y] - if (! row) return - for (var x = 0; x < line.length; x++) { - var lex = row[x] - if (! lex) return - lex.char = line[x] - lex.fg = brush.bg - lex.opacity = 1 - lex.build() - } - }) - // TODO: some notion of a "selected" region which cuts/clones the underlying region - -// var pasted_region = new Matrix (width, height, function(x,y){ -// var lex = new Lex (x,y) -// lex.char = lines[y][x] || " " -// lex.build() -// return lex -// }) - }, export_data: function () { var output // switch (clipboard.format) { @@ -237,18 +204,6 @@ var clipboard = (function () { clipboard.focus() return output }, - - rotate_canvas: function(){ - var cr = clipboard.canvas_r, c = clipboard.canvas - cr.width = c.height - cr.height = c.width - var ctx = cr.getContext('2d') - ctx.resetTransform() - ctx.translate(0, cr.height) - ctx.rotate(-Math.PI / 2) - ctx.drawImage(c, 0, 0) - return cr - }, }