-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (33 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function setup() {
createCanvas(200, 200);
dropzone = select('#dropzone');
dropzone.dragOver(highlight);
dropzone.dragLeave(unhighlight);
dropzone.drop(gotFile, unhighlight);
function highlight() {
dropzone.style('background-color', 'pink');
}
function unhighlight(){
dropzone.style('background-color', '#fff');
}
function gotFile(file){
createP('File ' + file.name + "Loaded").class('fileInfo');
createP('File Type: ' + file.type).class('fileInfo');
createP('File Size: ' + file.size).class('fileInfo');
var txt = file.data;
editText(txt);
let canvas = createCanvas(600, 400);
canvas.class('canves');
}
}
function editText(txt){
let txtToArray = txt.split(/\n/); //Parse the string file to an array. Each new line is a new array element
for (let i = 0; i< txtToArray.length; i++){
let toTrim = txtToArray[i];
txtToArray[i] = toTrim.trim();
//console.log(txtToArray[i]);
//console.log(txtToArray[i].match(/[\n\r]/g));
if (txtToArray[i-1] == '' && txtToArray[i] == '') txtToArray.splice(i ,1);
createP(txtToArray[i]).class('text');
}
}