|
1 | 1 | /*
|
2 |
| - * jQuery File Upload User Interface Plugin 6.9.4 |
| 2 | + * jQuery File Upload User Interface Plugin 6.11 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
10 | 10 | */
|
11 | 11 |
|
12 | 12 | /*jslint nomen: true, unparam: true, regexp: true */
|
13 |
| -/*global define, window, document, URL, webkitURL, FileReader */ |
| 13 | +/*global define, window, URL, webkitURL, FileReader */ |
14 | 14 |
|
15 | 15 | (function (factory) {
|
16 | 16 | 'use strict';
|
|
33 | 33 | }(function ($, tmpl, loadImage) {
|
34 | 34 | 'use strict';
|
35 | 35 |
|
36 |
| - // The UI version extends the FP (file processing) version or the basic |
37 |
| - // file upload widget and adds complete user interface interaction: |
38 |
| - var parentWidget = ($.blueimpFP || $.blueimp).fileupload; |
39 |
| - $.widget('blueimpUI.fileupload', parentWidget, { |
| 36 | + // The UI version extends the file upload widget |
| 37 | + // and adds complete user interface interaction: |
| 38 | + $.widget('blueimp.fileupload', $.blueimp.fileupload, { |
40 | 39 |
|
41 | 40 | options: {
|
42 | 41 | // By default, files added to the widget are uploaded as soon
|
|
144 | 143 | if (data.context) {
|
145 | 144 | data.context.each(function (index) {
|
146 | 145 | var file = ($.isArray(data.result) &&
|
147 |
| - data.result[index]) || {error: 'emptyResult'}; |
| 146 | + data.result[index]) || |
| 147 | + {error: 'Empty file upload result'}; |
148 | 148 | if (file.error) {
|
149 | 149 | that._adjustMaxNumberOfFiles(1);
|
150 | 150 | }
|
|
398 | 398 | // maxNumberOfFiles before validation, so we check if
|
399 | 399 | // maxNumberOfFiles is below 0 (instead of below 1):
|
400 | 400 | if (this.options.maxNumberOfFiles < 0) {
|
401 |
| - return 'maxNumberOfFiles'; |
| 401 | + return 'Maximum number of files exceeded'; |
402 | 402 | }
|
403 | 403 | // Files are accepted if either the file type or the file name
|
404 | 404 | // matches against the acceptFileTypes regular expression, as
|
405 | 405 | // only browsers with support for the File API report the type:
|
406 | 406 | if (!(this.options.acceptFileTypes.test(file.type) ||
|
407 | 407 | this.options.acceptFileTypes.test(file.name))) {
|
408 |
| - return 'acceptFileTypes'; |
| 408 | + return 'Filetype not allowed'; |
409 | 409 | }
|
410 | 410 | if (this.options.maxFileSize &&
|
411 | 411 | file.size > this.options.maxFileSize) {
|
412 |
| - return 'maxFileSize'; |
| 412 | + return 'File is too big'; |
413 | 413 | }
|
414 | 414 | if (typeof file.size === 'number' &&
|
415 | 415 | file.size < this.options.minFileSize) {
|
416 |
| - return 'minFileSize'; |
| 416 | + return 'File is too small'; |
417 | 417 | }
|
418 | 418 | return null;
|
419 | 419 | },
|
|
457 | 457 | that._transition(node).done(function () {
|
458 | 458 | dfd.resolveWith(node);
|
459 | 459 | });
|
460 |
| - if (!$.contains(document.body, node[0])) { |
| 460 | + if (!$.contains(that.document[0].body, node[0])) { |
461 | 461 | // If the element is not part of the DOM,
|
462 | 462 | // transition events are not triggered,
|
463 | 463 | // so we have to resolve manually:
|
|
510 | 510 |
|
511 | 511 | _startHandler: function (e) {
|
512 | 512 | e.preventDefault();
|
513 |
| - var button = $(this), |
| 513 | + var button = $(e.currentTarget), |
514 | 514 | template = button.closest('.template-upload'),
|
515 | 515 | data = template.data('data');
|
516 | 516 | if (data && data.submit && !data.jqXHR && data.submit()) {
|
|
520 | 520 |
|
521 | 521 | _cancelHandler: function (e) {
|
522 | 522 | e.preventDefault();
|
523 |
| - var template = $(this).closest('.template-upload'), |
| 523 | + var template = $(e.currentTarget).closest('.template-upload'), |
524 | 524 | data = template.data('data') || {};
|
525 | 525 | if (!data.jqXHR) {
|
526 | 526 | data.errorThrown = 'abort';
|
527 |
| - e.data.fileupload._trigger('fail', e, data); |
| 527 | + this._trigger('fail', e, data); |
528 | 528 | } else {
|
529 | 529 | data.jqXHR.abort();
|
530 | 530 | }
|
531 | 531 | },
|
532 | 532 |
|
533 | 533 | _deleteHandler: function (e) {
|
534 | 534 | e.preventDefault();
|
535 |
| - var button = $(this); |
536 |
| - e.data.fileupload._trigger('destroy', e, { |
| 535 | + var button = $(e.currentTarget); |
| 536 | + this._trigger('destroy', e, $.extend({ |
537 | 537 | context: button.closest('.template-download'),
|
538 |
| - url: button.attr('data-url'), |
539 |
| - type: button.attr('data-type') || 'DELETE', |
540 |
| - dataType: e.data.fileupload.options.dataType |
541 |
| - }); |
| 538 | + type: 'DELETE', |
| 539 | + dataType: this.options.dataType |
| 540 | + }, button.data())); |
542 | 541 | },
|
543 | 542 |
|
544 | 543 | _forceReflow: function (node) {
|
|
569 | 568 |
|
570 | 569 | _initButtonBarEventHandlers: function () {
|
571 | 570 | var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
|
572 |
| - filesList = this.options.filesContainer, |
573 |
| - ns = this.options.namespace; |
574 |
| - fileUploadButtonBar.find('.start') |
575 |
| - .bind('click.' + ns, function (e) { |
| 571 | + filesList = this.options.filesContainer; |
| 572 | + this._on(fileUploadButtonBar.find('.start'), { |
| 573 | + click: function (e) { |
576 | 574 | e.preventDefault();
|
577 | 575 | filesList.find('.start button').click();
|
578 |
| - }); |
579 |
| - fileUploadButtonBar.find('.cancel') |
580 |
| - .bind('click.' + ns, function (e) { |
| 576 | + } |
| 577 | + }); |
| 578 | + this._on(fileUploadButtonBar.find('.cancel'), { |
| 579 | + click: function (e) { |
581 | 580 | e.preventDefault();
|
582 | 581 | filesList.find('.cancel button').click();
|
583 |
| - }); |
584 |
| - fileUploadButtonBar.find('.delete') |
585 |
| - .bind('click.' + ns, function (e) { |
| 582 | + } |
| 583 | + }); |
| 584 | + this._on(fileUploadButtonBar.find('.delete'), { |
| 585 | + click: function (e) { |
586 | 586 | e.preventDefault();
|
587 | 587 | filesList.find('.delete input:checked')
|
588 | 588 | .siblings('button').click();
|
589 | 589 | fileUploadButtonBar.find('.toggle')
|
590 | 590 | .prop('checked', false);
|
591 |
| - }); |
592 |
| - fileUploadButtonBar.find('.toggle') |
593 |
| - .bind('change.' + ns, function (e) { |
| 591 | + } |
| 592 | + }); |
| 593 | + this._on(fileUploadButtonBar.find('.toggle'), { |
| 594 | + change: function (e) { |
594 | 595 | filesList.find('.delete input').prop(
|
595 | 596 | 'checked',
|
596 |
| - $(this).is(':checked') |
| 597 | + $(e.currentTarget).is(':checked') |
597 | 598 | );
|
598 |
| - }); |
| 599 | + } |
| 600 | + }); |
599 | 601 | },
|
600 | 602 |
|
601 | 603 | _destroyButtonBarEventHandlers: function () {
|
602 |
| - this.element.find('.fileupload-buttonbar button') |
603 |
| - .unbind('click.' + this.options.namespace); |
604 |
| - this.element.find('.fileupload-buttonbar .toggle') |
605 |
| - .unbind('change.' + this.options.namespace); |
| 604 | + this._off( |
| 605 | + this.element.find('.fileupload-buttonbar button'), |
| 606 | + 'click' |
| 607 | + ); |
| 608 | + this._off( |
| 609 | + this.element.find('.fileupload-buttonbar .toggle'), |
| 610 | + 'change.' |
| 611 | + ); |
606 | 612 | },
|
607 | 613 |
|
608 | 614 | _initEventHandlers: function () {
|
609 |
| - parentWidget.prototype._initEventHandlers.call(this); |
610 |
| - var eventData = {fileupload: this}; |
611 |
| - this.options.filesContainer |
612 |
| - .delegate( |
613 |
| - '.start button', |
614 |
| - 'click.' + this.options.namespace, |
615 |
| - eventData, |
616 |
| - this._startHandler |
617 |
| - ) |
618 |
| - .delegate( |
619 |
| - '.cancel button', |
620 |
| - 'click.' + this.options.namespace, |
621 |
| - eventData, |
622 |
| - this._cancelHandler |
623 |
| - ) |
624 |
| - .delegate( |
625 |
| - '.delete button', |
626 |
| - 'click.' + this.options.namespace, |
627 |
| - eventData, |
628 |
| - this._deleteHandler |
629 |
| - ); |
| 615 | + this._super(); |
| 616 | + this._on(this.options.filesContainer, { |
| 617 | + 'click .start button': this._startHandler, |
| 618 | + 'click .cancel button': this._cancelHandler, |
| 619 | + 'click .delete button': this._deleteHandler |
| 620 | + }); |
630 | 621 | this._initButtonBarEventHandlers();
|
631 | 622 | },
|
632 | 623 |
|
633 | 624 | _destroyEventHandlers: function () {
|
634 |
| - var options = this.options; |
635 | 625 | this._destroyButtonBarEventHandlers();
|
636 |
| - options.filesContainer |
637 |
| - .undelegate('.start button', 'click.' + options.namespace) |
638 |
| - .undelegate('.cancel button', 'click.' + options.namespace) |
639 |
| - .undelegate('.delete button', 'click.' + options.namespace); |
640 |
| - parentWidget.prototype._destroyEventHandlers.call(this); |
| 626 | + this._off(this.options.filesContainer, 'click'); |
| 627 | + this._super(); |
641 | 628 | },
|
642 | 629 |
|
643 | 630 | _enableFileInputButton: function () {
|
|
654 | 641 |
|
655 | 642 | _initTemplates: function () {
|
656 | 643 | var options = this.options;
|
657 |
| - options.templatesContainer = document.createElement( |
| 644 | + options.templatesContainer = this.document[0].createElement( |
658 | 645 | options.filesContainer.prop('nodeName')
|
659 | 646 | );
|
660 | 647 | if (tmpl) {
|
|
698 | 685 | },
|
699 | 686 |
|
700 | 687 | _initSpecialOptions: function () {
|
701 |
| - parentWidget.prototype._initSpecialOptions.call(this); |
| 688 | + this._super(); |
702 | 689 | this._initFilesContainer();
|
703 | 690 | this._initTemplates();
|
704 | 691 | this._initRegExpOptions();
|
705 | 692 | },
|
706 | 693 |
|
707 | 694 | _create: function () {
|
708 |
| - parentWidget.prototype._create.call(this); |
| 695 | + this._super(); |
709 | 696 | this._refreshOptionsList.push(
|
710 | 697 | 'filesContainer',
|
711 | 698 | 'uploadTemplateId',
|
712 | 699 | 'downloadTemplateId'
|
713 | 700 | );
|
714 |
| - if (!$.blueimpFP) { |
| 701 | + if (!this._processingQueue) { |
715 | 702 | this._processingQueue = $.Deferred().resolveWith(this).promise();
|
716 | 703 | this.process = function () {
|
717 | 704 | return this._processingQueue;
|
|
720 | 707 | },
|
721 | 708 |
|
722 | 709 | enable: function () {
|
723 |
| - parentWidget.prototype.enable.call(this); |
724 |
| - this.element.find('input, button').prop('disabled', false); |
725 |
| - this._enableFileInputButton(); |
| 710 | + var wasDisabled = false; |
| 711 | + if (this.options.disabled) { |
| 712 | + wasDisabled = true; |
| 713 | + } |
| 714 | + this._super(); |
| 715 | + if (wasDisabled) { |
| 716 | + this.element.find('input, button').prop('disabled', false); |
| 717 | + this._enableFileInputButton(); |
| 718 | + } |
726 | 719 | },
|
727 | 720 |
|
728 | 721 | disable: function () {
|
729 |
| - this.element.find('input, button').prop('disabled', true); |
730 |
| - this._disableFileInputButton(); |
731 |
| - parentWidget.prototype.disable.call(this); |
| 722 | + if (!this.options.disabled) { |
| 723 | + this.element.find('input, button').prop('disabled', true); |
| 724 | + this._disableFileInputButton(); |
| 725 | + } |
| 726 | + this._super(); |
732 | 727 | }
|
733 | 728 |
|
734 | 729 | });
|
|
0 commit comments