summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-11-30 16:26:41 -0500
committerJulie Lala <jules@okfoc.us>2014-11-30 16:26:41 -0500
commit4f2f5dc5580359bba21150af3ce5d34ad14b3ab4 (patch)
treef9f0ea8d666c94148f1d950b7b3680a1e9efbb91 /js
parent698f2aa71ffc1b9e56193c13e6366765134152c9 (diff)
export to ascii / mirc / irssi
Diffstat (limited to 'js')
-rw-r--r--js/app.js2
-rw-r--r--js/clipboard.js114
-rw-r--r--js/matrix.js2
-rw-r--r--js/ui/controls.js34
4 files changed, 104 insertions, 48 deletions
diff --git a/js/app.js b/js/app.js
index 284ea13..b2f1dfa 100644
--- a/js/app.js
+++ b/js/app.js
@@ -34,7 +34,7 @@ function bind () {
window.addEventListener('mouseup', function(){
dragging = erasing = false
- if (current_tool.name != 'shader') { cursor_input.focus() }
+ if (current_tool.name != 'shader' && current_tool.name != 'load' && current_tool.name != 'save') { cursor_input.focus() }
});
window.addEventListener('mousedown', function(e){
diff --git a/js/clipboard.js b/js/clipboard.js
index 501b189..97261bc 100644
--- a/js/clipboard.js
+++ b/js/clipboard.js
@@ -1,49 +1,79 @@
var clipboard = (function () {
- var format;
- var disabled = false;
- var contentType = 'text/plain;charset=utf-8'
- document.body.addEventListener('copy', function (e) {
- if (disabled) { return }
- if (e.clipboardData) {
- e.preventDefault();
- e.clipboardData.setData(contentType, canvas.irssi());
- }
- if (window.clipboardData) {
- e.returnValue = false;
- window.clipboardData.setData(contentType, canvas.irssi());
- }
- }, false);
-
- function import_data () {
- var data = import_textarea.value
- lines = data.split("\n")
- }
- function export_data () {
- var output
- switch (format) {
- case 'ascii':
- output = canvas.ascii()
- break
- case 'mirc':
- output = canvas.mirc()
- break
- case 'irssi':
- output = canvas.irssi()
- break
- }
- }
+ var exports = {
+ format: "irssi",
+ importing: false,
+ visible: false,
+
+ 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_data)
+ export_button.addEventListener("click", exports.export_data)
+ import_textarea.addEventListener("focus", exports.focus)
+ import_textarea.addEventListener("blur", exports.blur)
+ import_irssi.setAttribute("checked", true)
+ },
+ setFormat: function (name) {
+ return function () {
+ clipboard.format = name
+ if (! clipboard.importing) { clipboard.export_data() }
+ }
+ },
+ show: function () { import_rapper.style.display = "block"; clipboard.visible = true },
+ hide: function () { import_rapper.style.display = "none"; clipboard.visible = false },
+ focus: function () {
+ if (! clipboard.importing) {
+ import_textarea.focus()
+ import_textarea.select()
+ }
+ },
+ blur: function () {
+ },
- import_ascii.addEventListener("click", function(){ format = "ascii" })
- import_irssi.addEventListener("click", function(){ format = "irssi" })
- import_mirc.addEventListener("click", function(){ format = "mirc" })
- import_button.addEventListener("click", import_data)
- export_button.addEventListener("click", export_data)
- // import_textarea
+ import_mode: function () {
+ focus()
+ clipboard.importing = true
+ import_button.style.display = "inline-block"
+ export_button.style.display = format_group.display = "none"
+ import_textarea.value = ""
+ },
+ export_mode: function () {
+ focus()
+ clipboard.importing = false
+ import_button.style.display = "none"
+ export_button.style.display = format_group.display = "inline-block"
+ clipboard.export_data()
+ },
+ import_data: function () {
+ var data = import_textarea.value
+ lines = data.split("\n")
+ var width = lines.reduce(function(a,b){ return Math.max(a, b.length) })
+ var height = lines.length
+ },
+ export_data: function () {
+ var output
+ switch (clipboard.format) {
+ case 'ascii':
+ output = canvas.ascii()
+ break
+ case 'mirc':
+ output = canvas.mirc()
+ break
+ case 'irssi':
+ output = canvas.irssi()
+ break
+ }
+ import_textarea.value = output
+ clipboard.focus()
+ return output
+ },
- return {
- enable: function(){ disabled = false },
- disable: function(){ disabled = true }
}
+ exports.bind()
+
+ return exports
+
})() \ No newline at end of file
diff --git a/js/matrix.js b/js/matrix.js
index 4366eaa..81ced3e 100644
--- a/js/matrix.js
+++ b/js/matrix.js
@@ -107,7 +107,7 @@ Matrix.prototype.mirc = function () {
}
})
if (last && ! last.isClear()) { line += "\x03" }
- return line.replace(/\s+$/,"")
+ return line
}).filter(function(line){ return line.length > 0 })
return lines.join("\n")
}
diff --git a/js/ui/controls.js b/js/ui/controls.js
index c780c50..d575725 100644
--- a/js/ui/controls.js
+++ b/js/ui/controls.js
@@ -64,12 +64,10 @@ var controls = (function(){
shader_textarea.style.display = "block"
// setTimeout(function(){ shader_textarea.focus() })
shader_textarea.focus()
- clipboard.disable()
}
controls.shader.blur = function(){
Tool.prototype.blur.call(this)
shader_textarea.style.display = "none"
- clipboard.enable()
}
shader_textarea.value = demo_shader.innerHTML
shader_textarea.addEventListener("input", function(){
@@ -77,7 +75,25 @@ var controls = (function(){
fn && shader.run(canvas)
})
-
+ controls.save = new Tool (save_el)
+ controls.save.use = function(){
+ clipboard.show()
+ clipboard.export_mode()
+ }
+ controls.save.blur = function(){
+ Tool.prototype.blur.call(this)
+ clipboard.hide()
+ }
+ controls.load = new Tool (load_el)
+ controls.load.use = function(){
+ clipboard.show()
+ clipboard.import_mode()
+ }
+ controls.load.blur = function(){
+ Tool.prototype.blur.call(this)
+ clipboard.hide()
+ }
+
controls.animate = new Tool (animate_checkbox)
controls.animate.use = function(){
var state = shader.toggle()
@@ -100,7 +116,17 @@ var controls = (function(){
})
});
- [controls.square, controls.circle, controls.text, controls.clear, controls.grid, controls.shader, controls.animate].forEach(function(tool){
+ [
+ controls.square,
+ controls.circle,
+ controls.text,
+ controls.clear,
+ controls.grid,
+ controls.shader,
+ controls.animate,
+ controls.save,
+ controls.load
+ ].forEach(function(tool){
tool.span.addEventListener('mousedown', function(e){
tool.focus()
})