-
Notifications
You must be signed in to change notification settings - Fork 0
/
papaparse_issue.html
92 lines (77 loc) · 2.2 KB
/
papaparse_issue.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="papaparse.js"></script>
</head>
<body>
<form id='submit_spreadsheet'>
<fieldset>
<legend>Load Spreadsheet</legend>
<div>
<label for='fileselect'>Select local CSV:</label>
<input type='file' id='fileselect' name='fileselect' />
<div id='filedrag'>or drop file here.</div>
</div>
<div id='submitbutton'>
<button type='submit'>Load</button>
</div>
</fieldset>
</form>
</body>
<script type="text/javascript">
var file;
// getElementById
function $id(id) {
return document.getElementById(id);
}
// file selection
function FileSelectHandler(e) {
// cancel event and hover styling
FileDragHover(e);
// fetch FileList object
var files = e.target.files || e.dataTransfer.files;
// process first File object
// ParseFile(files[0]);
file = files[0];
// https://www.papaparse.com/
Papa.parse(file, {
delimiter: ",",
complete: function(results, file) {
console.log("Parsing complete:", results, file);
}
});
}
// file drag hover
function FileDragHover(e) {
e.stopPropagation();
e.preventDefault();
e.target.className = (e.type == "dragover" ? "hover" : "");
}
// call initialization file
if (window.File && window.FileList && window.FileReader) {
Init();
}
//
// initialize
function Init() {
var fileselect = $id("fileselect"),
filedrag = $id("filedrag"),
submitbutton = $id("submitbutton");
// file select
fileselect.addEventListener("change", FileSelectHandler, false);
// is XHR2 available?
var xhr = new XMLHttpRequest();
if (xhr.upload) {
// file drop
filedrag.addEventListener("dragover", FileDragHover, false);
filedrag.addEventListener("dragleave", FileDragHover, false);
filedrag.addEventListener("drop", FileSelectHandler, false);
filedrag.style.display = "block";
// remove submit button
submitbutton.style.display = "none";
}
}
</script>
</html>