-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.html
More file actions
209 lines (180 loc) · 4.92 KB
/
example.html
File metadata and controls
209 lines (180 loc) · 4.92 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dropzone test</title>
<style>
body {
font-family: Helvetica Neue, Helvetica, sans-serif;
padding: 2em;
}
#dropzone {
display: block;
position: relative;
border: 3px solid rgba(0,0,0,.3);
height: 300px;
overflow: hidden;
clear: both;
}
.gallery-grid {
display: block;
clear: both;
}
.gallery-grid > li {
display: inline-block;
width: 20%;
margin: 0 15px;
padding: 0;
margin-bottom: 24px;
height: 200px;
float: left;
}
.gallery-item {
border: 1px solid silver;
background: rgba(0,0,0,.4);
}
.dropzone {
text-align: center;
}
.dropzone-success {
border: 3px dashed green;
}
.dropzone-error {
border: 3px dashed red;
}
.dropzone-progress {
border: 3px dashed yellow;
}
.dropzone-progress > .progress-bar{
background-color: yellow;
height: 10px;
width: 0%;
}
.dropzone-default {
border: 3px dashed gray;
}
.dropzone-default > .dropzone-default-body,
.dropzone-default > .dropzone-dragover-body {
display: block;
height: 100%;
}
.dropzone-success,
.dropzone-error,
.dropzone-default,
.dropzone-progress {
display: none;
}
.dropzone.is-success .dropzone-success,
.dropzone.is-error .dropzone-error,
.dropzone.is-default .dropzone-default,
.dropzone.is-dragover .dropzone-default,
.dropzone.is-progress .dropzone-progress {
display: block;
}
.dropzone.is-dragover .dropzone-default {
color: olive;
}
.page-section {
display: block;
clear: both;
margin-bottom: 24px;
}
</style>
</head>
<body>
<h1>Dropzone test</h1>
<div class="page-section">
<ul class="gallery-grid">
<li class="gallery-item">Block</li>
</ul>
</div>
<div class="page-section">
<div class="dropzone-placeholder js-second-dropzone-holder">
</div>
<ul class="js-second-list">
<li>item</li>
</ul>
</div>
<script src="build/build.js"></script>
<script>
var Dropzone = require('dropzone');
// ===============================================================
// DROPZONE 1 - the easy way
var dropOptions = {
inputUploadUrl: 'http://daidalos.apiary.io/image-block/image/upload'
}
var drop = new Dropzone('.gallery-grid', dropOptions);
// show dropzone in DOM using variables
drop.show();
//
// Emitted events
//
drop.on('uploadBegin', function(){
// Do something on upload begin
console.log('Upload beginned');
});
drop.on('uploadProgress', function(){
// Do something on upload progress
console.log('Upload in progress', event.percent + '%');
});
drop.on('uploadError', function(e){
// Do something on upload error
console.log('Upload Error', e);
});
drop.on('uploadEnd', function(){
// Do something on upload end
console.log('Upload Ended', this.xhrResponseArray);
});
// ===============================================================
// DROPZONE 2 - the more customized way
// defined options
var dropSecond = new Dropzone('.js-second-dropzone-holder', {
inputUploadUrl: 'http://daidalos.apiary.io/image-block/image/upload',
inputName: 'pekabooo',
inputMultiple: 'multiple',
maxUploadedItems: '10',
maxFileSize: '1200000',
allowedFileTypes: [
'image/jpeg',
'image/png'
]
});
// defined own templates for states
var _templateData = {
'dragoverState' : '<span>{{=it.dragoverMsg}}</span>',
'successState' : '<i class="icon-plus"></i><span>{{=it.successMsg}}</span>',
'progressState' : '{{=it.progressMsg}}<div class="progress-bar" style="width:0%;"></div>'
}
// defined data for own states
var _stateMsgs = {
'defaultMsg' : '<strong>Hola hombres!!!</strong>',
'successMsg' : 'Yahoooo!!',
'progressMsg' : 'Uploading ...'
}
// push customized templateData and stateData to stored html template
dropSecond.cusomizeTemplate(_templateData, _stateMsgs);
// show dropzone, using template from stored html string
dropSecond.show();
// do something on unloadEnd
dropSecond.on('uploadEnd', function(){
console.log('Upload Ended', this.xhrResponseArray);
// update various states on upload end
dropSecond.updateState('defaultState', {'defaultMsg' : 'Nová defaulta'});
dropSecond.updateState('successState', {'successMsg' : 'Ouuuu lalala!'});
});
dropSecond.on('error', function() {
console.log( 'oh, yaiks!' ,this.errorMsg);
});
// do something on upload progress
dropSecond.on('uploadProgress', function() {
// loading progress bar
var self = document.getElementById(this.dropzoneId).getElementsByClassName('progress-bar');
var selector = '#' + this.dropzoneId + ' .progress-bar';
// var self = document.querySelectorAll(selector); // querySelectorAll works, but it's broken by livereloading page
if (self) {
self[0].style.width = event.percent + '%';
}
});
</script>
</body>
</html>