-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathview-import.php
90 lines (81 loc) · 2.66 KB
/
view-import.php
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>The Sausage Machine</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/primer.css">
<link rel="stylesheet" href="css/sausagemachine.css">
<link rel="icon" href="favicon.ico">
</head>
<body>
<div class="container">
<div class="tabnav">
<nav class="tabnav-tabs">
<a href="index.php?import" id="import-link" class="tabnav-tab selected">Import file(s)</a>
<a href="index.php?edit" id="edit-link" class="tabnav-tab">Start a book</a>
<a href="index.php?projects" class="tabnav-tab">Book projects</a>
<a href="index.php?about" class="tabnav-tab">About</a>
</nav>
</div>
<div class="columns">
<div class="one-half column centered">
<div class="blankslate" id="upload">
Drop files here (e.g. Word documents)
</div>
</div>
</div?
</div>
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/sausagemachine.js"></script>
<script>
var upload = $('#upload');
$(upload).on('dragover', function(e) {
$(this).addClass('upload-hovering');
return false;
});
$(upload).on('dragleave', function(e) {
$(this).removeClass('upload-hovering');
return false;
});
$(upload).on('drop', function(e) {
$(this).removeClass('upload-hovering');
// dropped files need to be read immediately
var formData = new FormData();
for (var i=0; i < e.originalEvent.dataTransfer.files.length; i++) {
formData.append('uploads', e.originalEvent.dataTransfer.files[i]);
}
var on_files_uploaded = function(data) {
// redirect to edit
window.location = 'index.php?edit#' + $.sausagemachine._get('temp');
};
var upload_files = function() {
var xhr = new XMLHttpRequest();
xhr.onload = on_files_uploaded;
xhr.open('POST', 'api.php?temps/files/upload/' + $.sausagemachine._get('temp'));
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.send(formData);
};
var on_temp_crated = function(data) {
$.sausagemachine._clear();
$.sausagemachine._set('temp', data.temp);
$.sausagemachine._set('repo', data.repo);
// upload dropped files to newly created temp
upload_files();
};
if ($.sausagemachine._get('temp')) {
upload_files();
} else {
$.sausagemachine.create_temp({}, on_temp_crated);
}
return false;
});
// make it possible to get back to edit without looking temp
var hash = window.location.hash.substring(1);
if (hash.length) {
$('#import-link').attr('href', $('#import-link').attr('href') + '#' + hash);
$('#edit-link').attr('href', $('#edit-link').attr('href') + '#' + hash);
}
</script>
</body>
</html>