Skip to content

Commit 4e605b7

Browse files
committed
Added continueAbortedUploads option to the example code.
1 parent b4a0ce2 commit 4e605b7

File tree

2 files changed

+84
-47
lines changed

2 files changed

+84
-47
lines changed

example/application.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin JS Example 4.3
2+
* jQuery File Upload Plugin JS Example 4.3.1
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -16,6 +16,8 @@ $(function () {
1616
url: 'upload.php',
1717
uploadDir: 'files/',
1818
thumbnailsDir: 'thumbnails/',
19-
autoUpload: false
19+
autoUpload: false,
20+
maxChunkSize: 10000000,
21+
continueAbortedUploads: true
2022
});
2123
});

example/jquery.fileupload-uix.js

Lines changed: 80 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload User Interface Extended Plugin 4.3
2+
* jQuery File Upload User Interface Extended Plugin 4.3.1
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -25,7 +25,7 @@
2525
$(this).removeClass(
2626
'ui-button ui-widget ui-state-default ui-corner-all' +
2727
' ui-button-icon-only ui-button-text-icon-primary'
28-
).html($(this).children('.ui-button-text').text());
28+
).html($(this).text());
2929
} else {
3030
$(this)
3131
.addClass('ui-button ui-widget ui-state-default ui-corner-all')
@@ -48,14 +48,14 @@
4848

4949
this.uploadDir = this.thumbnailsDir = null;
5050
this.autoUpload = true;
51-
this.maxChunkSize = 10000000;
51+
this.continueAbortedUploads = false;
5252
this.dropZone = container.find('form:first');
5353
this.uploadTable = container.find('.files:first');
5454
this.downloadTable = this.uploadTable;
5555
this.progressAllNode = container.find('.file_upload_overall_progress div:first');
5656
this.uploadTemplate = this.uploadTable.find('.file_upload_template:first');
5757
this.downloadTemplate = this.uploadTable.find('.file_download_template:first');
58-
this.buttons = container.find('.file_upload_buttons:first');
58+
this.multiButtons = container.find('.file_upload_buttons:first');
5959

6060
this.formatFileSize = function (bytes) {
6161
if (typeof bytes !== 'number' || bytes === null) {
@@ -90,10 +90,11 @@
9090
this.buildUploadRow = function (files, index, handler) {
9191
var file = files[index],
9292
fileName = handler.formatFileName(file.name),
93-
encodedFileName = encodeURIComponent(fileName),
9493
uploadRow = handler.uploadTemplate
95-
.clone().removeAttr('id')
96-
.attr('data-file-id', encodedFileName);
94+
.clone().removeAttr('id');
95+
uploadRow.attr('data-name', file.name);
96+
uploadRow.attr('data-size', file.size);
97+
uploadRow.attr('data-type', file.type);
9798
uploadRow.find('.file_name')
9899
.text(fileName);
99100
uploadRow.find('.file_size')
@@ -109,20 +110,31 @@
109110
return uploadRow;
110111
};
111112

113+
this.getFileUrl = function (file, handler) {
114+
return handler.uploadDir + encodeURIComponent(file.name);
115+
};
116+
117+
this.getThumbnailUrl = function (file, handler) {
118+
return handler.thumbnailsDir + encodeURIComponent(file.name);
119+
};
120+
112121
this.buildDownloadRow = function (file, handler) {
113-
var encodedFileName = encodeURIComponent(file.name),
114-
filePath = handler.uploadDir + encodedFileName,
115-
thumbnailPath = handler.thumbnailsDir + encodedFileName,
122+
var fileName = handler.formatFileName(file.name),
123+
fileUrl = handler.getFileUrl(file, handler),
116124
downloadRow = handler.downloadTemplate
117-
.clone().removeAttr('id')
118-
.attr('data-file-id', encodedFileName);
125+
.clone().removeAttr('id');
126+
$.each(file, function (name, value) {
127+
downloadRow.attr('data-' + name, value);
128+
});
119129
downloadRow.find('.file_name a')
120-
.text(file.name).attr('href', filePath);
130+
.attr('href', fileUrl)
131+
.text(fileName);
121132
downloadRow.find('.file_size')
122133
.text(handler.formatFileSize(file.size));
123134
if (file.thumbnail) {
124135
downloadRow.find('.file_download_preview').append(
125-
$('<a href="' + filePath + '"><img src="' + thumbnailPath + '"/></a>')
136+
$('<a href="' + fileUrl + '"><img src="' +
137+
handler.getThumbnailUrl(file, handler) + '"/></a>')
126138
);
127139
downloadRow.find('a').attr('target', '_blank');
128140
}
@@ -134,43 +146,45 @@
134146
};
135147

136148
this.uploadCallBack = function (event, files, index, xhr, handler, callBack) {
149+
if (handler.autoUpload) {
150+
callBack();
151+
} else {
152+
handler.uploadRow.find('.file_upload_start button').click(function (e) {
153+
$(this).fadeOut();
154+
callBack();
155+
e.preventDefault();
156+
});
157+
}
158+
};
159+
160+
this.continueUploadCallBack = function (event, files, index, xhr, handler, callBack) {
137161
$.getJSON(
138162
handler.url,
139-
{file: handler.uploadRow.attr('data-file-id')},
163+
{file: handler.uploadRow.attr('data-name')},
140164
function (file) {
141165
if (file && file.size !== files[index].size) {
142166
handler.uploadedBytes = file.size;
143167
}
144-
callBack();
168+
handler.uploadCallBack(event, files, index, xhr, handler, callBack);
145169
}
146170
);
147171
};
148172

149173
this.beforeSend = function (event, files, index, xhr, handler, callBack) {
150-
if (handler.autoUpload) {
151-
handler.uploadCallBack(event, files, index, xhr, handler, callBack);
174+
if (handler.continueAbortedUploads) {
175+
handler.continueUploadCallBack(event, files, index, xhr, handler, callBack);
152176
} else {
153-
handler.uploadRow.find('.file_upload_start button').click(function (e) {
154-
$(this).fadeOut();
155-
handler.uploadCallBack(event, files, index, xhr, handler, callBack);
156-
e.preventDefault();
157-
});
177+
handler.uploadCallBack(event, files, index, xhr, handler, callBack);
158178
}
159179
};
160180

161-
this.loadFiles = function () {
162-
$.getJSON(uploadHandler.url, function (files) {
163-
$.each(files, function (index, file) {
164-
uploadHandler.buildDownloadRow(file, uploadHandler)
165-
.appendTo(uploadHandler.downloadTable).fadeIn();
166-
});
167-
});
168-
};
169-
170-
this.initExtended = function () {
181+
this.initDeleteHandler = function () {
171182
container.find('.file_download_delete button').live('click', function (e) {
172183
var row = $(this).closest('tr');
173-
$.ajax(uploadHandler.url + '?file=' + row.attr('data-file-id'), {
184+
$.ajax({
185+
url: uploadHandler.url + '?file=' + encodeURIComponent(
186+
row.attr('data-id') || row.attr('data-name')
187+
),
174188
type: 'DELETE',
175189
success: function () {
176190
row.fadeOut(function () {
@@ -180,34 +194,55 @@
180194
});
181195
e.preventDefault();
182196
});
183-
uploadHandler.buttons.find('.file_upload_start:first')
184-
.button({icons: {primary: 'ui-icon-circle-arrow-e'}})
185-
.click(function (e) {
186-
uploadHandler.uploadTable.find('.file_upload_start button:visible').click();
187-
e.preventDefault();
188-
});
189-
uploadHandler.buttons.find('.file_upload_cancel:first')
197+
};
198+
199+
this.initMultiButtons = function () {
200+
if (uploadHandler.autoUpload) {
201+
uploadHandler.multiButtons.find('.file_upload_start:first').hide();
202+
} else {
203+
uploadHandler.multiButtons.find('.file_upload_start:first')
204+
.button({icons: {primary: 'ui-icon-circle-arrow-e'}})
205+
.click(function (e) {
206+
uploadHandler.uploadTable.find('.file_upload_start button:visible').click();
207+
e.preventDefault();
208+
});
209+
}
210+
uploadHandler.multiButtons.find('.file_upload_cancel:first')
190211
.button({icons: {primary: 'ui-icon-cancel'}})
191212
.click(function (e) {
192213
uploadHandler.uploadTable.find('.file_upload_cancel button:visible').click();
193214
e.preventDefault();
194215
});
195-
uploadHandler.buttons.find('.file_download_delete:first')
216+
uploadHandler.multiButtons.find('.file_download_delete:first')
196217
.button({icons: {primary: 'ui-icon-trash'}})
197218
.click(function (e) {
198219
uploadHandler.downloadTable.find('.file_download_delete button:visible').click();
199220
e.preventDefault();
200221
});
222+
};
223+
224+
this.loadFiles = function () {
225+
$.getJSON(uploadHandler.url, function (files) {
226+
$.each(files, function (index, file) {
227+
uploadHandler.buildDownloadRow(file, uploadHandler)
228+
.appendTo(uploadHandler.downloadTable).fadeIn();
229+
});
230+
});
231+
};
232+
233+
this.initExtended = function () {
234+
uploadHandler.initDeleteHandler();
235+
uploadHandler.initMultiButtons();
201236
if (uploadHandler.loadFiles) {
202237
uploadHandler.loadFiles();
203238
}
204239
};
205240

206241
this.destroyExtended = function () {
207242
container.find('.file_download_delete button').die('click');
208-
uploadHandler.buttons.find('.file_upload_start:first').button('destroy');
209-
uploadHandler.buttons.find('.file_upload_cancel:first').button('destroy');
210-
uploadHandler.buttons.find('.file_download_delete:first').button('destroy');
243+
uploadHandler.multiButtons.find('.file_upload_start:first').button('destroy').show();
244+
uploadHandler.multiButtons.find('.file_upload_cancel:first').button('destroy');
245+
uploadHandler.multiButtons.find('.file_download_delete:first').button('destroy');
211246
};
212247

213248
$.extend(this, options);

0 commit comments

Comments
 (0)