-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
138 lines (107 loc) · 4.09 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" sizes="715x714" href="/logo.png">
<title>Fablab Rothenburg Selfie Maker</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<style type="text/css">
input[type=file] {
position: absolute;
filter: alpha(opacity=0);
opacity: 0;
}
img {
max-width: 100%;
}
</style>
</head>
<body>
<div class="container">
<form enctype="multipart/form-data" method="post">
<div id="main" class="jumbotron">
<img src="fablab_ro42.jpg" alt="Logo Fablab Rothenburg" />
<h1>Selfie Maker</h1>
<p>
Verwende den Selfie Maker um ein Bild von deiner frisch gebastelten Erungenschaft mit den anderen Fablaberern zu teilen.
</p>
<label for="fileToUpload" class="btn btn-primary btn-lg">Los geht's, ich bin dabei!</label>
<input type="file" name="fileToUpload" id="fileToUpload" onchange="uploadFile();" accept="image/*" capture="user" />
<div id="progress"></div>
</div>
</form>
<div id="preview" class="jumbotron hide">
<h1>So veröffentlichen?</h1>
<div class="form-group">
<img id="preview_image" alt="Preview Image" />
</div>
<div class="form-group">
<label for="description">Kurze Beschreibung dazu (optional)</label>
<input type="text" class="form-control" id="description" placeholder="Was ist das? Warum ist es cool?">
</div>
<div class="form-group">
<button class="btn btn-primary btn-lg" onclick="publishIt();">Ja, das passt so!</button>
<button class="btn btn-default btn-lg" onclick="reset();">Abbrechen</button>
</div>
</div>
</div>
<script type="text/javascript">
var image_id;
function reset() {
document.getElementById('progress').innerHTML = '';
document.getElementById('main').classList.remove('hide');
document.getElementById('preview').classList.add('hide');
}
function uploadFile() {
var fd = new FormData();
var count = document.getElementById('fileToUpload').files.length;
for (var index = 0; index < count; index++) {
var file = document.getElementById('fileToUpload').files[index];
fd.append(file.name, file);
}
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', uploadProgress, false);
xhr.addEventListener('load', uploadComplete, false);
xhr.addEventListener('error', uploadFailed, false);
xhr.open('POST', 'upload.php');
xhr.send(fd);
}
function publishIt() {
var fd = new FormData();
fd.set('image_id', image_id);
fd.set('description', document.getElementById('description').value);
var xhr = new XMLHttpRequest();
xhr.addEventListener('load', reset, false);
xhr.addEventListener('error', uploadFailed, false);
xhr.open('POST', 'create.php');
xhr.send(fd);
}
function uploadProgress(evt) {
if (!evt.lengthComputable) {
return;
}
var percentComplete = Math.round(evt.loaded * 100 / evt.total);
document.getElementById('progress').innerHTML = 'Upload läuft ... ' + percentComplete.toString() + '%';
}
function uploadComplete(evt) {
try {
var result = JSON.parse(evt.target.responseText)[0];
} catch (e) {
alert('Server-Antwort konnte nicht verarbeitet werden. Sorry!\n\nServer-Antwort:\n' + evt.target.responseText);
reset();
return;
}
console.log(result);
document.getElementById('preview_image').src = result.source_url;
document.getElementById('main').classList.add('hide');
document.getElementById('preview').classList.remove('hide');
image_id = result.id;
}
function uploadFailed(evt) {
alert('There was an error attempting to upload the file.');
}
</script>
</body>
</html>