summaryrefslogtreecommitdiff
path: root/js/clipboard.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-02-08 11:01:56 -0500
committerJules Laplace <jules@okfoc.us>2015-02-08 11:01:56 -0500
commitc8fde3784b0c211e59e38138251bdc0b3aa3f4c2 (patch)
tree748df758a32344d05812302c57e12955f9d67bcf /js/clipboard.js
parent2b040e6b7ce737e3f0eab8a25996fc2f71540713 (diff)
making clipboard stuff work in firefox
Diffstat (limited to 'js/clipboard.js')
-rw-r--r--js/clipboard.js50
1 files changed, 17 insertions, 33 deletions
diff --git a/js/clipboard.js b/js/clipboard.js
index af368a5..28ab99e 100644
--- a/js/clipboard.js
+++ b/js/clipboard.js
@@ -50,34 +50,19 @@ var clipboard = (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;
- }
+ e.preventDefault()
+ // images will come through as files
+ var types = toArray(e.clipboardData.types)
+ import_textarea.value = ""
+ types.forEach(function(type, i){
+ console.log(type)
// this can be text/plain or text/html..
- else if (item.kind == 'string' && item.type.match('text/plain') && e.clipboardData.items.length > 1) {
+ if (type.match('text/plain') && types.length > 1) {
return
}
- else if (item.kind == 'string') {
- item.getAsString(function(text){
- import_textarea.value = text
- })
+ else if (type.match('text/')) {
+ import_textarea.value = e.clipboardData.getData(type)
+ console.log(e.clipboardData.getData(type))
}
else {
console.error("unknown type!", item.type)
@@ -92,12 +77,10 @@ var clipboard = (function () {
var rapper = document.createElement("div")
rapper.innerHTML = import_textarea.value
- var lines = rapper.innerText.split("\n")
- var width = lines.reduce(function(a,b){ return Math.max(a, b.length) })
- var height = lines.length
- zz = rapper.children
var y = 0;
- toArray(rapper.children).forEach(function(span){
+ console.log(rapper.childNodes)
+ zz=rapper
+ toArray(rapper.childNodes).forEach(function(span){
if (span.nodeName !== "SPAN") { return }
var x = 0;
var row = canvas.aa[y++]
@@ -105,17 +88,18 @@ var clipboard = (function () {
toArray(span.childNodes).forEach(function(el){
console.log(el)
if (x >= row.length) return;
- var line, colorcode = el.nodeName;
+ var line;
+ var colorcode = el.nodeName;
if (colorcode === "SPAN") {
colorcode = "F" + css_lookup[el.style.color]
- line = el.innerText
+ line = el.innerText || el.textContent
}
else if (colorcode === "#text") {
colorcode = "FA"
line = el.nodeValue
}
else {
- line = el.innerText
+ line = el.innerText || el.textContent
}
if (colorcode[0] !== "F") { return }
if (colorcode.length == 2) { colorcode += "BB" }