-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
138 lines (110 loc) · 4.31 KB
/
index.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!--
* jstar JavaScript Library v0.0.01a
* https://github.com/chriswininger/jstar
*
* Copyright 2013 Chris Wininger
* Released under the MIT license
* https://github.com/chriswininger/jstar/license
*
* Date: Sat Apr 20 2013
* -->
<!DOCTYPE html>
<html>
<head>
<title>jsTar Example</title>
<script type="text/javascript" src="jstar.js"></script>
<script type="text/javascript">
(function (window) {
var txtTextFileName1, txtTextFileName2, txtTextFileContents1, txtTextFileContents2, btnExportTar, lblErrorMessage, fileChooser;
var fileSelection = null;
window.onload = function() {
txtTextFileName1 = document.getElementById('txtTextFileName1');
txtTextFileName2 = document.getElementById('txtTextFileName2');
txtTextFileContents1 = document.getElementById('txtTextFileContents1');
txtTextFileContents2 = document.getElementById('txtTextFileContents2');
btnExportTar = document.getElementById('btnExportTar');
lblErrorMessage = document.getElementById('lblErrorMessage');
fileChooser = document.getElementById('fileChooser');
fileChooser.addEventListener('change', function (event){
var files = event.target.files;
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(file) {
return function(e){
fileSelection = {'name': file.name, 'data': this.result };
}
})(f);
reader.readAsBinaryString(f);
}
}, false);
// Convert the text value and save
btnExportTar.addEventListener('click', function(event) {
if (validateForm()) {
var arrayFiles = [
{ 'name': txtTextFileName1.value, 'data': txtTextFileContents1.value },
{ 'name': txtTextFileName2.value, 'data': txtTextFileContents2.value },
];
if (fileSelection !== null) {
arrayFiles.push(fileSelection);
}
jsTar.toTar(arrayFiles, {
'complete': tarComplete,
'error': tarError
});
} else {
lblErrorMessage.innerHTML = 'Please choose a valid name for each text file.';
}
}, false);
};
function tarComplete(info) {
if (info.status === 'success') {
// Save the blob to disk
window.location.href = window.URL.createObjectURL(info.data);
} else {
lblErrorMessage.innerHTML = info.message;
}
}
function tarError (info) {
lblErrorMessage.innerHTML = info.message;
}
function validateForm() {
return txtTextFileName1.value.length > 0 && txtTextFileName2.value.length > 0;
}
})(window);
</script>
</head>
<body>
<div>
<strong id = "lblErrorMessage"></strong>
</div>
<div>
<h3>The following fields will appear in the tar as text files</h3>
</div>
<div>
<label for="txtTextFileName1">File Name: </label>
<input type="text" id="txtTextFileName1">
<span>, </span>
<label for="txtTextFileContents1">File Contents: </label>
<input type="text" id="txtTextFileContents1">
</div>
<div>
<label for="txtTextFileName2">File Name: </label>
<input type="text" id="txtTextFileName2">
<span>, </span>
<label for="txtTextFileContents2">File Contents: </label>
<input type="text" id="txtTextFileContents2">
</div>
<hr />
<div>
<h3>The following file selected from your hard drive will be included in the tar</h3>
</div>
<div>
<input type="file" id = "fileChooser" />
</div>
<hr />
<div>
<button id="btnExportTar">Export Tar</button>
</div>
</body>
</html>