|
1 | 1 | /*
|
2 |
| - * jQuery File Upload User Interface Plugin 6.5.5 |
| 2 | + * jQuery File Upload User Interface Plugin 6.6 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
33 | 33 | }(function ($, tmpl, loadImage) {
|
34 | 34 | 'use strict';
|
35 | 35 |
|
36 |
| - // The UI version extends the IP (image processing) version and adds |
37 |
| - // complete user interface interaction: |
38 |
| - $.widget('blueimpUI.fileupload', $.blueimpIP.fileupload, { |
| 36 | + // The UI version extends the IP (image processing) version or the basic |
| 37 | + // file upload widget and adds complete user interface interaction: |
| 38 | + var parentWidget = ($.blueimpIP || $.blueimp).fileupload; |
| 39 | + $.widget('blueimpUI.fileupload', parentWidget, { |
39 | 40 |
|
40 | 41 | options: {
|
41 | 42 | // By default, files added to the widget are uploaded as soon
|
|
85 | 86 | $(this).fileupload('resize', data).done(data, function () {
|
86 | 87 | data.files.valid = data.isValidated = that._validate(files);
|
87 | 88 | data.context = that._renderUpload(files)
|
88 |
| - .appendTo(that._files) |
| 89 | + .appendTo(options.filesContainer) |
89 | 90 | .data('data', data);
|
90 | 91 | that._renderPreviews(files, data.context);
|
91 |
| - // Force reflow: |
92 |
| - that._reflow = $.support.transition && data.context[0].offsetWidth; |
| 92 | + that._forceReflow(data.context); |
93 | 93 | that._transition(data.context).done(
|
94 | 94 | function () {
|
95 | 95 | if ((that._trigger('added', e, data) !== false) &&
|
|
146 | 146 | template = that._renderDownload([file])
|
147 | 147 | .css('height', node.height())
|
148 | 148 | .replaceAll(node);
|
149 |
| - // Force reflow: |
150 |
| - that._reflow = $.support.transition && |
151 |
| - template[0].offsetWidth; |
| 149 | + that._forceReflow(template); |
152 | 150 | that._transition(template).done(
|
153 | 151 | function () {
|
154 | 152 | data.context = $(this);
|
|
160 | 158 | });
|
161 | 159 | } else {
|
162 | 160 | template = that._renderDownload(data.result)
|
163 |
| - .appendTo(that._files); |
164 |
| - // Force reflow: |
165 |
| - that._reflow = $.support.transition && template[0].offsetWidth; |
| 161 | + .appendTo(that.options.filesContainer); |
| 162 | + that._forceReflow(template); |
166 | 163 | that._transition(template).done(
|
167 | 164 | function () {
|
168 | 165 | data.context = $(this);
|
|
187 | 184 | var node = $(this);
|
188 | 185 | template = that._renderDownload([file])
|
189 | 186 | .replaceAll(node);
|
190 |
| - // Force reflow: |
191 |
| - that._reflow = $.support.transition && |
192 |
| - template[0].offsetWidth; |
| 187 | + that._forceReflow(template); |
193 | 188 | that._transition(template).done(
|
194 | 189 | function () {
|
195 | 190 | data.context = $(this);
|
|
210 | 205 | } else if (data.errorThrown !== 'abort') {
|
211 | 206 | that._adjustMaxNumberOfFiles(-data.files.length);
|
212 | 207 | data.context = that._renderUpload(data.files)
|
213 |
| - .appendTo(that._files) |
| 208 | + .appendTo(that.options.filesContainer) |
214 | 209 | .data('data', data);
|
215 |
| - // Force reflow: |
216 |
| - that._reflow = $.support.transition && data.context[0].offsetWidth; |
| 210 | + that._forceReflow(data.context); |
217 | 211 | that._transition(data.context).done(
|
218 | 212 | function () {
|
219 | 213 | data.context = $(this);
|
|
357 | 351 | },
|
358 | 352 |
|
359 | 353 | _renderTemplate: function (func, files) {
|
360 |
| - return $(this.options.templateContainer).html(func({ |
| 354 | + if (!func) { |
| 355 | + return $(); |
| 356 | + } |
| 357 | + var result = func({ |
361 | 358 | files: files,
|
362 | 359 | formatFileSize: this._formatFileSize,
|
363 | 360 | options: this.options
|
364 |
| - })).children(); |
| 361 | + }); |
| 362 | + if (result instanceof $) { |
| 363 | + return result; |
| 364 | + } |
| 365 | + return $(this.options.templatesContainer).html(result).children(); |
365 | 366 | },
|
366 | 367 |
|
367 | 368 | _renderPreview: function (file, node) {
|
368 | 369 | var that = this,
|
369 | 370 | options = this.options,
|
370 | 371 | deferred = $.Deferred();
|
371 |
| - return (loadImage( |
| 372 | + return ((loadImage && loadImage( |
372 | 373 | file,
|
373 | 374 | function (img) {
|
374 | 375 | node.append(img);
|
375 |
| - // Force reflow: |
376 |
| - that._reflow = $.support.transition && |
377 |
| - node[0].offsetWidth; |
| 376 | + that._forceReflow(node); |
378 | 377 | that._transition(node).done(function () {
|
379 | 378 | deferred.resolveWith(node);
|
380 | 379 | });
|
|
384 | 383 | maxHeight: options.previewMaxHeight,
|
385 | 384 | canvas: options.previewAsCanvas
|
386 | 385 | }
|
387 |
| - ) || deferred.resolveWith(node)) && deferred; |
| 386 | + )) || deferred.resolveWith(node)) && deferred; |
388 | 387 | },
|
389 | 388 |
|
390 | 389 | _renderPreviews: function (files, nodes) {
|
|
451 | 450 | e.data.fileupload._trigger('destroy', e, {
|
452 | 451 | context: button.closest('.template-download'),
|
453 | 452 | url: button.attr('data-url'),
|
454 |
| - type: button.attr('data-type'), |
| 453 | + type: button.attr('data-type') || 'DELETE', |
455 | 454 | dataType: e.data.fileupload.options.dataType
|
456 | 455 | });
|
457 | 456 | },
|
458 | 457 |
|
| 458 | + _forceReflow: function (node) { |
| 459 | + this._reflow = $.support.transition && |
| 460 | + node.length && node[0].offsetWidth; |
| 461 | + }, |
| 462 | + |
459 | 463 | _transition: function (node) {
|
460 | 464 | var that = this,
|
461 | 465 | deferred = $.Deferred();
|
|
480 | 484 |
|
481 | 485 | _initButtonBarEventHandlers: function () {
|
482 | 486 | var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
|
483 |
| - filesList = this._files, |
| 487 | + filesList = this.options.filesContainer, |
484 | 488 | ns = this.options.namespace;
|
485 | 489 | fileUploadButtonBar.find('.start')
|
486 | 490 | .bind('click.' + ns, function (e) {
|
|
517 | 521 | },
|
518 | 522 |
|
519 | 523 | _initEventHandlers: function () {
|
520 |
| - $.blueimpIP.fileupload.prototype._initEventHandlers.call(this); |
| 524 | + parentWidget.prototype._initEventHandlers.call(this); |
521 | 525 | var eventData = {fileupload: this};
|
522 |
| - this._files |
| 526 | + this.options.filesContainer |
523 | 527 | .delegate(
|
524 | 528 | '.start button',
|
525 | 529 | 'click.' + this.options.namespace,
|
|
542 | 546 | },
|
543 | 547 |
|
544 | 548 | _destroyEventHandlers: function () {
|
| 549 | + var options = this.options; |
545 | 550 | this._destroyButtonBarEventHandlers();
|
546 |
| - this._files |
547 |
| - .undelegate('.start button', 'click.' + this.options.namespace) |
548 |
| - .undelegate('.cancel button', 'click.' + this.options.namespace) |
549 |
| - .undelegate('.delete button', 'click.' + this.options.namespace); |
550 |
| - $.blueimpIP.fileupload.prototype._destroyEventHandlers.call(this); |
| 551 | + options.filesContainer |
| 552 | + .undelegate('.start button', 'click.' + options.namespace) |
| 553 | + .undelegate('.cancel button', 'click.' + options.namespace) |
| 554 | + .undelegate('.delete button', 'click.' + options.namespace); |
| 555 | + parentWidget.prototype._destroyEventHandlers.call(this); |
551 | 556 | },
|
552 | 557 |
|
553 | 558 | _enableFileInputButton: function () {
|
|
564 | 569 |
|
565 | 570 | _initTemplates: function () {
|
566 | 571 | var options = this.options;
|
567 |
| - options.templateContainer = document.createElement( |
568 |
| - this._files.prop('nodeName') |
| 572 | + options.templatesContainer = document.createElement( |
| 573 | + options.filesContainer.prop('nodeName') |
569 | 574 | );
|
570 |
| - options.uploadTemplate = tmpl(options.uploadTemplateId); |
571 |
| - options.downloadTemplate = tmpl(options.downloadTemplateId); |
| 575 | + if (tmpl) { |
| 576 | + options.uploadTemplate = tmpl(options.uploadTemplateId); |
| 577 | + options.downloadTemplate = tmpl(options.downloadTemplateId); |
| 578 | + } |
572 | 579 | },
|
573 | 580 |
|
574 |
| - _initFiles: function () { |
575 |
| - this._files = this.element.find('.files'); |
| 581 | + _initFilesContainer: function () { |
| 582 | + if (!this.options.filesContainer) { |
| 583 | + this.options.filesContainer = this.element.find('.files'); |
| 584 | + } |
576 | 585 | },
|
577 | 586 |
|
578 |
| - _create: function () { |
579 |
| - this._initFiles(); |
580 |
| - $.blueimpIP.fileupload.prototype._create.call(this); |
| 587 | + _initSpecialOptions: function () { |
| 588 | + parentWidget.prototype._initSpecialOptions.call(this); |
581 | 589 | this._initTemplates();
|
582 | 590 | },
|
583 | 591 |
|
| 592 | + _create: function () { |
| 593 | + this._initFilesContainer(); |
| 594 | + parentWidget.prototype._create.call(this); |
| 595 | + this._refreshOptionsList.push( |
| 596 | + 'filesContainer', |
| 597 | + 'uploadTemplateId', |
| 598 | + 'downloadTemplateId' |
| 599 | + ); |
| 600 | + if (!$.blueimpIP) { |
| 601 | + this._processingQueue = $.Deferred().resolveWith(this).promise(); |
| 602 | + this.resize = function () { |
| 603 | + return this._processingQueue; |
| 604 | + }; |
| 605 | + } |
| 606 | + }, |
| 607 | + |
584 | 608 | enable: function () {
|
585 |
| - $.blueimpIP.fileupload.prototype.enable.call(this); |
| 609 | + parentWidget.prototype.enable.call(this); |
586 | 610 | this.element.find('input, button').prop('disabled', false);
|
587 | 611 | this._enableFileInputButton();
|
588 | 612 | },
|
589 | 613 |
|
590 | 614 | disable: function () {
|
591 | 615 | this.element.find('input, button').prop('disabled', true);
|
592 | 616 | this._disableFileInputButton();
|
593 |
| - $.blueimpIP.fileupload.prototype.disable.call(this); |
| 617 | + parentWidget.prototype.disable.call(this); |
594 | 618 | }
|
595 | 619 |
|
596 | 620 | });
|
|
0 commit comments