|
1 | 1 | /*
|
2 |
| - * jQuery File Upload User Interface Extended Plugin 4.4.1 |
| 2 | + * jQuery File Upload User Interface Extended Plugin 4.5 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
9 | 9 | * http://creativecommons.org/licenses/MIT/
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -/*jslint regexp: false */ |
| 12 | +/*jslint regexp: false, unparam: true */ |
13 | 13 | /*global jQuery */
|
14 | 14 |
|
15 | 15 | (function ($) {
|
|
47 | 47 | UploadHandler = function (container, options) {
|
48 | 48 | var uploadHandler = this;
|
49 | 49 |
|
50 |
| - this.url = container.find('form:first').attr('action'); |
| 50 | + this.locale = {}; |
| 51 | + this.maxFileSize = 0; |
| 52 | + this.minFileSize = 1; |
| 53 | + this.acceptFileTypes = /.+$/i; |
51 | 54 | this.autoUpload = false;
|
52 | 55 | this.forceIframeDownload = true;
|
| 56 | + this.url = container.find('form:first').attr('action'); |
53 | 57 | this.dropZone = container.find('form:first');
|
54 | 58 | this.uploadTable = container.find('.files:first');
|
55 | 59 | this.downloadTable = this.uploadTable;
|
|
160 | 164 | .text(handler.formatFileSize(file.size));
|
161 | 165 | if (thumbnailUrl) {
|
162 | 166 | downloadRow.find('.file_download_preview').append(
|
163 |
| - $('<a/>').append($('<img/>').attr('src', thumbnailUrl || null)) |
| 167 | + $('<a/>').append($('<img/>').attr('src', thumbnailUrl)) |
164 | 168 | );
|
165 | 169 | downloadRow.find('a').attr('target', '_blank');
|
166 | 170 | }
|
|
172 | 176 | return downloadRow;
|
173 | 177 | };
|
174 | 178 |
|
| 179 | + this.uploadCallBack = function (event, files, index, xhr, handler, callBack) { |
| 180 | + callBack(); |
| 181 | + }; |
| 182 | + |
| 183 | + this.onError = function (event, files, index, xhr, handler) { |
| 184 | + handler.uploadRow.addClass('file_upload_error') |
| 185 | + .find('.file_upload_progress').append($('<div class="error"/>').append( |
| 186 | + handler.locale[event] || event |
| 187 | + )); |
| 188 | + }; |
| 189 | + |
| 190 | + this.validate = function (event, files, index, xhr, handler) { |
| 191 | + var isValid = true, |
| 192 | + file; |
| 193 | + if (typeof index !== 'number') { |
| 194 | + $.each(files, function (index, file) { |
| 195 | + isValid = handler.validate(event, files, index, xhr, handler); |
| 196 | + return isValid; |
| 197 | + }); |
| 198 | + } else { |
| 199 | + file = files[index]; |
| 200 | + if (handler.maxFileSize && file.size > handler.maxFileSize) { |
| 201 | + handler.onError('File is too big', files, index, xhr, handler); |
| 202 | + isValid = false; |
| 203 | + } else if (typeof file.size === 'number' && file.size < handler.minFileSize) { |
| 204 | + handler.onError('File is too small', files, index, xhr, handler); |
| 205 | + isValid = false; |
| 206 | + } |
| 207 | + if (!(handler.acceptFileTypes.test(file.type) || |
| 208 | + handler.acceptFileTypes.test(file.name))) { |
| 209 | + handler.onError('Filetype not allowed', files, index, xhr, handler); |
| 210 | + isValid = false; |
| 211 | + } |
| 212 | + } |
| 213 | + return isValid; |
| 214 | + }; |
| 215 | + |
175 | 216 | this.beforeSend = function (event, files, index, xhr, handler, callBack) {
|
| 217 | + if (!handler.validate(event, files, index, xhr, handler)) { |
| 218 | + return; |
| 219 | + } |
176 | 220 | if (handler.autoUpload) {
|
177 |
| - callBack(); |
| 221 | + handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
178 | 222 | } else {
|
179 | 223 | handler.uploadRow.find('.file_upload_start button').click(function (e) {
|
180 | 224 | $(this).fadeOut();
|
181 |
| - callBack(); |
| 225 | + handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
182 | 226 | e.preventDefault();
|
183 | 227 | });
|
184 | 228 | }
|
|
0 commit comments