|
1 | 1 | /*
|
2 |
| - * jQuery File Upload User Interface Extended Plugin 4.5 |
| 2 | + * jQuery File Upload User Interface Extended Plugin 4.6 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
48 | 48 | var uploadHandler = this;
|
49 | 49 |
|
50 | 50 | this.locale = {};
|
51 |
| - this.maxFileSize = 0; |
| 51 | + this.maxFileSize = null; |
52 | 52 | this.minFileSize = 1;
|
| 53 | + this.maxNumberOfFiles = null; |
53 | 54 | this.acceptFileTypes = /.+$/i;
|
54 | 55 | this.autoUpload = false;
|
55 | 56 | this.forceIframeDownload = true;
|
|
62 | 63 | this.downloadTemplate = this.uploadTable.find('.file_download_template:first');
|
63 | 64 | this.multiButtons = container.find('.file_upload_buttons:first');
|
64 | 65 |
|
| 66 | + this.adjustMaxNumberOfFiles = function (operand) { |
| 67 | + var number = container.fileUploadUIX('option', 'maxNumberOfFiles'); |
| 68 | + if (typeof number === 'number') { |
| 69 | + container.fileUploadUIX('option', 'maxNumberOfFiles', number + operand); |
| 70 | + } |
| 71 | + }; |
| 72 | + |
65 | 73 | this.formatFileSize = function (bytes) {
|
66 | 74 | if (typeof bytes !== 'number' || bytes === null) {
|
67 | 75 | return '';
|
|
176 | 184 | return downloadRow;
|
177 | 185 | };
|
178 | 186 |
|
179 |
| - this.uploadCallBack = function (event, files, index, xhr, handler, callBack) { |
180 |
| - callBack(); |
181 |
| - }; |
182 |
| - |
183 | 187 | this.onError = function (event, files, index, xhr, handler) {
|
184 | 188 | handler.uploadRow.addClass('file_upload_error')
|
185 | 189 | .find('.file_upload_progress').append($('<div class="error"/>').append(
|
|
193 | 197 | if (typeof index !== 'number') {
|
194 | 198 | $.each(files, function (index, file) {
|
195 | 199 | isValid = handler.validate(event, files, index, xhr, handler);
|
196 |
| - return isValid; |
197 | 200 | });
|
198 | 201 | } else {
|
199 | 202 | file = files[index];
|
|
209 | 212 | handler.onError('Filetype not allowed', files, index, xhr, handler);
|
210 | 213 | isValid = false;
|
211 | 214 | }
|
| 215 | + if (typeof handler.maxNumberOfFiles === 'number' && |
| 216 | + handler.maxNumberOfFiles < index + 1) { |
| 217 | + handler.onError('Max number exceeded', files, index, xhr, handler); |
| 218 | + isValid = false; |
| 219 | + } |
212 | 220 | }
|
213 | 221 | return isValid;
|
214 | 222 | };
|
| 223 | + |
| 224 | + this.uploadCallBack = function (event, files, index, xhr, handler, callBack) { |
| 225 | + callBack(); |
| 226 | + }; |
215 | 227 |
|
216 | 228 | this.beforeSend = function (event, files, index, xhr, handler, callBack) {
|
217 | 229 | if (!handler.validate(event, files, index, xhr, handler)) {
|
218 | 230 | return;
|
219 | 231 | }
|
| 232 | + var number = typeof index === 'number' ? 1 : files.length; |
| 233 | + handler.adjustMaxNumberOfFiles(-number); |
| 234 | + handler.uploadRow.find(handler.cancelSelector).click(function (e) { |
| 235 | + handler.adjustMaxNumberOfFiles(number); |
| 236 | + }); |
220 | 237 | if (handler.autoUpload) {
|
221 | 238 | handler.uploadCallBack(event, files, index, xhr, handler, callBack);
|
222 | 239 | } else {
|
|
246 | 263 | ),
|
247 | 264 | type: 'DELETE',
|
248 | 265 | success: function () {
|
| 266 | + uploadHandler.adjustMaxNumberOfFiles(1); |
249 | 267 | row.fadeOut(function () {
|
250 | 268 | row.remove();
|
251 | 269 | });
|
|
0 commit comments