mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 23:36:36 +00:00
js/clipboard.js: cleanup.
This commit is contained in:
parent
a9723b648c
commit
69dcc0677e
@ -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) {
|
||||
@ -238,18 +205,6 @@ var clipboard = (function () {
|
||||
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
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
return exports
|
||||
|
Loading…
Reference in New Issue
Block a user