Skip to content

Commit 0826983

Browse files
authored
Merge pull request #87 from sherlockode/feature/improve-drag-drop-single-file
Hide dropzone in non multiple case when one file is dropped
2 parents 0c9ae70 + 22203f8 commit 0826983

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

Resources/public/css/ajax-uploader.css

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
background-color: #f3f6f9;
4545
}
4646

47-
4847
.afb_file_container .afb_upload_container.afb_no_preview .afb_filename {
4948
flex: 1;
5049
overflow: hidden;
@@ -80,15 +79,14 @@
8079

8180
/*with preview option*/
8281

83-
.afb_file_container .afb_dropzone-preview .afb_item {
82+
.afb_file_container.with_preview .afb_item {
8483
position: relative;
8584
display: inline-block;
8685
vertical-align: top;
8786
margin: 16px;
88-
min-height: 100px;
8987
}
9088

91-
.afb_file_container .afb_dropzone-preview .afb_filename {
89+
.afb_file_container.with_preview .afb_filename {
9290
position: absolute;
9391
top: 40%;
9492
left: 0;
@@ -101,7 +99,7 @@
10199
line-height: 150%;
102100
}
103101

104-
.afb_file_container .afb_dropzone-preview .afb_file_preview {
102+
.afb_file_container.with_preview .afb_file_preview {
105103
border-radius: 0.42rem;
106104
overflow: hidden;
107105
width: 120px;
@@ -111,41 +109,41 @@
111109
z-index: 10;
112110
}
113111

114-
.afb_file_container .afb_dropzone-preview .afb_file_preview img {
112+
.afb_file_container.with_preview .afb_file_preview img {
115113
width: 100%;
116114
height: 100%;
117115
object-fit: cover;
118116
}
119117

120-
.afb_file_container .afb_dropzone-preview .afb_item:hover img {
118+
.afb_file_container.with_preview .afb_item:hover img {
121119
transform: scale(1.05, 1.05);
122120
filter: blur(8px);
123121
}
124122

125-
.afb_file_container .afb_dropzone-preview .afb_item:hover .afb_filename {
123+
.afb_file_container.with_preview .afb_item:hover .afb_filename {
126124
opacity: 1;
127125
z-index: 51;
128126
}
129127

130-
.afb_file_container .afb_dropzone-preview .afb_filename:not(:hover) {
128+
.afb_file_container.with_preview .afb_filename:not(:hover) {
131129
overflow: hidden;
132130
text-overflow: ellipsis;
133131
white-space: nowrap;
134132
}
135133

136-
.afb_file_container .afb_dropzone-preview .afb_item .afb_filename span {
134+
.afb_file_container.with_preview .afb_item .afb_filename span {
137135
background-color: rgba(255, 255, 255, .8);
138136
padding: 0 0.4em;
139137
border-radius: 3px;
140138
white-space: nowrap;
141139
}
142140

143-
.afb_file_container .afb_dropzone-preview.dz-complete .afb_file_progress {
141+
.afb_file_container.with_preview .dz-complete .afb_file_progress {
144142
opacity: 0;
145143
transition: opacity 0.4s ease-in;
146144
}
147145

148-
.afb_file_container .afb_dropzone-preview .afb_file_progress {
146+
.afb_file_container.with_preview .afb_file_progress {
149147
opacity: 1;
150148
z-index: 100;
151149
pointer-events: none;
@@ -161,7 +159,7 @@
161159
overflow: hidden;
162160
}
163161

164-
.afb_file_container .afb_dropzone-preview .afb_file_progress > div {
162+
.afb_file_container.with_preview .afb_file_progress > div {
165163
background: #333;
166164
background: linear-gradient(to bottom, #666, #444);
167165
position: absolute;
@@ -172,18 +170,18 @@
172170
transition: width 300ms ease-in-out;
173171
}
174172

175-
.afb_file_container .afb_dropzone-preview .afb_upload_complete .afb_file_progress {
173+
.afb_file_container.with_preview .afb_upload_complete .afb_file_progress {
176174
opacity: 0;
177175
transition: opacity 0.4s ease-in;
178176
}
179177

180-
.afb_file_container .afb_dropzone-preview .afb_upload_progressing .afb_file_progress {
178+
.afb_file_container.with_preview .afb_upload_progressing .afb_file_progress {
181179
opacity: 1;
182180
transition: all 0.2s linear;
183181
}
184182

185-
.afb_file_container .afb_dropzone-preview .afb_file_success-mark,
186-
.afb_file_container .afb_dropzone-preview .afb_file_error-mark {
183+
.afb_file_container.with_preview .afb_file_success-mark,
184+
.afb_file_container.with_preview .afb_file_error-mark {
187185
pointer-events: none;
188186
opacity: 0;
189187
z-index: 50;
@@ -195,12 +193,12 @@
195193
margin-top: -27px;
196194
}
197195

198-
.afb_file_container .afb_dropzone-preview .afb_upload_complete .afb_file_success-mark {
196+
.afb_file_container.with_preview .afb_upload_complete .afb_file_success-mark {
199197
opacity: 1;
200198
animation: slide-in 3s cubic-bezier(0.77, 0, 0.175, 1);
201199
}
202200

203-
.afb_file_container .afb_dropzone-preview .afb_remove_file {
201+
.afb_file_container.with_preview .afb_remove_file {
204202
position: absolute;
205203
top: -12.5px;
206204
right: -12.5px;
@@ -216,6 +214,12 @@
216214
justify-content: center;
217215
}
218216

219-
.afb_file_container .afb_dropzone-preview.afb_dropzone-started .afb_dropzone-title {
217+
.afb_file_container.with_preview .afb_dropzone-started .afb_dropzone-title {
220218
display: none;
221219
}
220+
221+
/** with preview non multiple **/
222+
.afb_file_container.with_preview .afb_upload_container .afb_item {
223+
position: relative;
224+
width: 120px;
225+
}

Resources/public/js/ajax-uploader.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ let $ = jQuery;
5757
if (!isMultiple) {
5858
if (files.length > 1) {
5959
return alert('You can only upload one file');
60+
} else {
61+
container.find('.afb_dropzone').hide();
6062
}
6163
}
6264
if (isAsync) {
@@ -213,6 +215,10 @@ let $ = jQuery;
213215
element.closest('.afb_item').remove();
214216
if (container.find('.afb_item').length === 0) {
215217
container.find('.afb_dropzone').removeClass('afb_dropzone-started');
218+
219+
if (!isMultiple) {
220+
container.find('.afb_dropzone').show();
221+
}
216222
}
217223
}
218224

Resources/views/Form/upload_file.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% block afb_file_widget %}
22
{% import _self as self %}
3-
<div class="afb_file_container" {{ block('data_attributes') }}
3+
<div class="afb_file_container {% if imagePreview %}with_preview{% endif %}" {{ block('data_attributes') }}
44
{% with {progressBar: true, img: null, fileName:null, uploadId: null, file: null} %}
55
data-prototype="{{ block('file_info')|e }}"
66
{% endwith %}
@@ -10,7 +10,7 @@
1010
{{ block('dropzone') }}
1111
{% set disabled = false %}
1212
{% endif %}
13-
{% if false == imagePreview %}
13+
{% if false == imagePreview or false == multiple %}
1414
{{ block('file_list') }}
1515
{% endif %}
1616
</div>
@@ -47,11 +47,11 @@
4747
{% endblock %}
4848

4949
{% block dropzone %}
50-
<label for="afb_file_input-{{ id }}" class="afb_dropzone {% if imagePreview %}afb_dropzone-preview{% endif %}"{% if files|length > 0 and false == multiple %} style="display:none"{% endif %}>
50+
<label for="afb_file_input-{{ id }}" class="afb_dropzone"{% if files|length > 0 and false == multiple %} style="display:none"{% endif %}>
5151
<h5 class="afb_dropzone-title">{{ (dropzoneLabel ?? label)|trans({}, translation_domain) }}</h5>
5252
<input type="file" {% if multiple %}multiple{% endif %} class="afb_file_input" id="afb_file_input-{{ id }}"/>
5353

54-
{% if true == imagePreview %}
54+
{% if true == imagePreview and true == multiple %}
5555
{{ block('file_list') }}
5656
{% endif %}
5757
</label>

0 commit comments

Comments
 (0)