|
1 | 1 | /*
|
2 |
| - * jQuery File Upload User Interface Extended Plugin 4.4 |
| 2 | + * jQuery File Upload User Interface Extended Plugin 4.4.1 |
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.url = container.find('form:first').attr('action');
|
51 |
| - this.autoUpload = true; |
52 |
| - this.continueAbortedUploads = false; |
53 |
| - this.forceIframeDownload = false; |
| 51 | + this.autoUpload = false; |
| 52 | + this.forceIframeDownload = true; |
54 | 53 | this.dropZone = container.find('form:first');
|
55 | 54 | this.uploadTable = container.find('.files:first');
|
56 | 55 | this.downloadTable = this.uploadTable;
|
|
173 | 172 | return downloadRow;
|
174 | 173 | };
|
175 | 174 |
|
176 |
| - this.uploadCallBack = function (event, files, index, xhr, handler, callBack) { |
| 175 | + this.beforeSend = function (event, files, index, xhr, handler, callBack) { |
177 | 176 | if (handler.autoUpload) {
|
178 | 177 | callBack();
|
179 | 178 | } else {
|
|
185 | 184 | }
|
186 | 185 | };
|
187 | 186 |
|
188 |
| - this.continueUploadCallBack = function (event, files, index, xhr, handler, callBack) { |
189 |
| - if (typeof index !== 'undefined') { |
190 |
| - $.getJSON( |
191 |
| - handler.url, |
192 |
| - {file: files[index].name}, |
193 |
| - function (file) { |
194 |
| - if (file && file.size !== files[index].size) { |
195 |
| - handler.uploadedBytes = file.size; |
196 |
| - } |
197 |
| - handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
198 |
| - } |
199 |
| - ); |
200 |
| - } else { |
201 |
| - handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
202 |
| - } |
203 |
| - }; |
204 |
| - |
205 |
| - this.beforeSend = function (event, files, index, xhr, handler, callBack) { |
206 |
| - if (handler.continueAbortedUploads) { |
207 |
| - handler.continueUploadCallBack(event, files, index, xhr, handler, callBack); |
208 |
| - } else { |
209 |
| - handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
| 187 | + this.downloadHandler = function (e) { |
| 188 | + if (uploadHandler.forceIframeDownload) { |
| 189 | + // Open download dialogs via iframes, to prevent aborting current uploads: |
| 190 | + $('<iframe style="display:none;"/>') |
| 191 | + .attr('src', this.href) |
| 192 | + .appendTo(container); |
| 193 | + e.preventDefault(); |
210 | 194 | }
|
211 | 195 | };
|
212 | 196 |
|
213 |
| - this.initDownloadHandler = function () { |
214 |
| - if (uploadHandler.forceIframeDownload) { |
215 |
| - // Open download dialogs via iframes, to prevent aborting current uploads: |
216 |
| - uploadHandler.downloadTable.find('a:not([target="_blank"])') |
217 |
| - .live('click', function (e) { |
218 |
| - $('<iframe style="display:none;"/>') |
219 |
| - .attr('src', this.href) |
220 |
| - .appendTo(container); |
221 |
| - e.preventDefault(); |
| 197 | + this.deleteHandler = function (e) { |
| 198 | + var row = $(this).closest('tr'); |
| 199 | + $.ajax({ |
| 200 | + url: uploadHandler.url + '?file=' + encodeURIComponent( |
| 201 | + row.attr('data-id') |
| 202 | + ), |
| 203 | + type: 'DELETE', |
| 204 | + success: function () { |
| 205 | + row.fadeOut(function () { |
| 206 | + row.remove(); |
222 | 207 | });
|
223 |
| - } |
| 208 | + } |
| 209 | + }); |
| 210 | + e.preventDefault(); |
| 211 | + }; |
| 212 | + |
| 213 | + this.initEventHandlers = function () { |
| 214 | + uploadHandler.downloadTable.find('a:not([target="_blank"])') |
| 215 | + .live('click', uploadHandler.downloadHandler); |
| 216 | + uploadHandler.downloadTable.find('.file_download_delete button') |
| 217 | + .live('click', uploadHandler.deleteHandler); |
224 | 218 | };
|
225 | 219 |
|
226 |
| - this.initDeleteHandler = function () { |
| 220 | + this.destroyEventHandlers = function () { |
| 221 | + uploadHandler.downloadTable.find('a:not([target="_blank"])') |
| 222 | + .die('click', uploadHandler.downloadHandler); |
227 | 223 | uploadHandler.downloadTable.find('.file_download_delete button')
|
228 |
| - .live('click', function (e) { |
229 |
| - var row = $(this).closest('tr'); |
230 |
| - $.ajax({ |
231 |
| - url: uploadHandler.url + '?file=' + encodeURIComponent( |
232 |
| - row.attr('data-id') |
233 |
| - ), |
234 |
| - type: 'DELETE', |
235 |
| - success: function () { |
236 |
| - row.fadeOut(function () { |
237 |
| - row.remove(); |
238 |
| - }); |
239 |
| - } |
240 |
| - }); |
241 |
| - e.preventDefault(); |
242 |
| - }); |
| 224 | + .die('click', uploadHandler.deleteHandler); |
| 225 | + }; |
| 226 | + |
| 227 | + this.multiButtonHandler = function (e) { |
| 228 | + uploadHandler.uploadTable.find(e.data.selector + ' button:visible').click(); |
| 229 | + e.preventDefault(); |
243 | 230 | };
|
244 | 231 |
|
245 | 232 | this.initMultiButtons = function () {
|
|
248 | 235 | } else {
|
249 | 236 | uploadHandler.multiButtons.find('.file_upload_start:first')
|
250 | 237 | .button({icons: {primary: 'ui-icon-circle-arrow-e'}})
|
251 |
| - .click(function (e) { |
252 |
| - uploadHandler.uploadTable.find('.file_upload_start button:visible').click(); |
253 |
| - e.preventDefault(); |
254 |
| - }); |
| 238 | + .bind('click', {selector: '.file_upload_start'}, uploadHandler.multiButtonHandler); |
255 | 239 | }
|
256 | 240 | uploadHandler.multiButtons.find('.file_upload_cancel:first')
|
257 | 241 | .button({icons: {primary: 'ui-icon-cancel'}})
|
258 |
| - .click(function (e) { |
259 |
| - uploadHandler.uploadTable.find('.file_upload_cancel button:visible').click(); |
260 |
| - e.preventDefault(); |
261 |
| - }); |
| 242 | + .bind('click', {selector: '.file_upload_cancel'}, uploadHandler.multiButtonHandler); |
262 | 243 | uploadHandler.multiButtons.find('.file_download_delete:first')
|
263 | 244 | .button({icons: {primary: 'ui-icon-trash'}})
|
264 |
| - .click(function (e) { |
265 |
| - uploadHandler.downloadTable.find('.file_download_delete button:visible').click(); |
266 |
| - e.preventDefault(); |
267 |
| - }); |
| 245 | + .bind('click', {selector: '.file_download_delete'}, uploadHandler.multiButtonHandler); |
| 246 | + }; |
| 247 | + |
| 248 | + this.destroyMultiButtons = function () { |
| 249 | + uploadHandler.multiButtons.find( |
| 250 | + '.file_upload_start:first, .file_upload_cancel:first, .file_download_delete:first' |
| 251 | + ).unbind('click', uploadHandler.multiButtonHandler).button('destroy').show(); |
268 | 252 | };
|
269 | 253 |
|
270 | 254 | this.initExtended = function () {
|
271 |
| - uploadHandler.initDownloadHandler(); |
272 |
| - uploadHandler.initDeleteHandler(); |
| 255 | + uploadHandler.initEventHandlers(); |
273 | 256 | uploadHandler.initMultiButtons();
|
274 | 257 | };
|
275 | 258 |
|
276 | 259 | this.destroyExtended = function () {
|
277 |
| - uploadHandler.downloadTable.find('.file_download_delete button').die('click'); |
278 |
| - uploadHandler.multiButtons.find('.file_upload_start:first').button('destroy').show(); |
279 |
| - uploadHandler.multiButtons.find('.file_upload_cancel:first').button('destroy'); |
280 |
| - uploadHandler.multiButtons.find('.file_download_delete:first').button('destroy'); |
| 260 | + uploadHandler.destroyEventHandlers(); |
| 261 | + uploadHandler.destroyMultiButtons(); |
281 | 262 | };
|
282 | 263 |
|
283 | 264 | $.extend(this, options);
|
|
286 | 267 | methods = {
|
287 | 268 | init : function (options) {
|
288 | 269 | return this.each(function () {
|
289 |
| - $(this).fileUploadUI(new UploadHandler($(this), options)) |
290 |
| - .fileUploadUI('option', 'initExtended', undefined, options.namespace)(); |
| 270 | + $(this).fileUploadUI(new UploadHandler($(this), options)); |
291 | 271 | });
|
292 | 272 | },
|
293 | 273 |
|
|
302 | 282 |
|
303 | 283 | destroy : function (namespace) {
|
304 | 284 | return this.each(function () {
|
305 |
| - $(this).fileUploadUI('option', 'destroyExtended', undefined, namespace)(); |
306 | 285 | $(this).fileUploadUI('destroy', namespace);
|
307 | 286 | });
|
308 | 287 | },
|
|
0 commit comments