|
1 | 1 | /*
|
2 |
| - * jQuery File Upload User Interface Plugin 6.9.7 |
| 2 | + * jQuery File Upload User Interface Plugin 6.10 |
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
|
|
458 | 457 | that._transition(node).done(function () {
|
459 | 458 | dfd.resolveWith(node);
|
460 | 459 | });
|
461 |
| - if (!$.contains(document.body, node[0])) { |
| 460 | + if (!$.contains(this.document[0].body, node[0])) { |
462 | 461 | // If the element is not part of the DOM,
|
463 | 462 | // transition events are not triggered,
|
464 | 463 | // so we have to resolve manually:
|
|
511 | 510 |
|
512 | 511 | _startHandler: function (e) {
|
513 | 512 | e.preventDefault();
|
514 |
| - var button = $(this), |
| 513 | + var button = $(e.currentTarget), |
515 | 514 | template = button.closest('.template-upload'),
|
516 | 515 | data = template.data('data');
|
517 | 516 | if (data && data.submit && !data.jqXHR && data.submit()) {
|
|
521 | 520 |
|
522 | 521 | _cancelHandler: function (e) {
|
523 | 522 | e.preventDefault();
|
524 |
| - var template = $(this).closest('.template-upload'), |
| 523 | + var template = $(e.currentTarget).closest('.template-upload'), |
525 | 524 | data = template.data('data') || {};
|
526 | 525 | if (!data.jqXHR) {
|
527 | 526 | data.errorThrown = 'abort';
|
528 |
| - e.data.fileupload._trigger('fail', e, data); |
| 527 | + this._trigger('fail', e, data); |
529 | 528 | } else {
|
530 | 529 | data.jqXHR.abort();
|
531 | 530 | }
|
532 | 531 | },
|
533 | 532 |
|
534 | 533 | _deleteHandler: function (e) {
|
535 | 534 | e.preventDefault();
|
536 |
| - var button = $(this); |
537 |
| - e.data.fileupload._trigger('destroy', e, { |
| 535 | + var button = $(e.currentTarget); |
| 536 | + this._trigger('destroy', e, { |
538 | 537 | context: button.closest('.template-download'),
|
539 | 538 | url: button.attr('data-url'),
|
540 | 539 | type: button.attr('data-type') || 'DELETE',
|
541 |
| - dataType: e.data.fileupload.options.dataType |
| 540 | + dataType: this.options.dataType |
542 | 541 | });
|
543 | 542 | },
|
544 | 543 |
|
|
570 | 569 |
|
571 | 570 | _initButtonBarEventHandlers: function () {
|
572 | 571 | var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
|
573 |
| - filesList = this.options.filesContainer, |
574 |
| - ns = this.options.namespace; |
575 |
| - fileUploadButtonBar.find('.start') |
576 |
| - .bind('click.' + ns, function (e) { |
| 572 | + filesList = this.options.filesContainer; |
| 573 | + this._on(fileUploadButtonBar.find('.start'), { |
| 574 | + click: function (e) { |
577 | 575 | e.preventDefault();
|
578 | 576 | filesList.find('.start button').click();
|
579 |
| - }); |
580 |
| - fileUploadButtonBar.find('.cancel') |
581 |
| - .bind('click.' + ns, function (e) { |
| 577 | + } |
| 578 | + }); |
| 579 | + this._on(fileUploadButtonBar.find('.cancel'), { |
| 580 | + click: function (e) { |
582 | 581 | e.preventDefault();
|
583 | 582 | filesList.find('.cancel button').click();
|
584 |
| - }); |
585 |
| - fileUploadButtonBar.find('.delete') |
586 |
| - .bind('click.' + ns, function (e) { |
| 583 | + } |
| 584 | + }); |
| 585 | + this._on(fileUploadButtonBar.find('.delete'), { |
| 586 | + click: function (e) { |
587 | 587 | e.preventDefault();
|
588 | 588 | filesList.find('.delete input:checked')
|
589 | 589 | .siblings('button').click();
|
590 | 590 | fileUploadButtonBar.find('.toggle')
|
591 | 591 | .prop('checked', false);
|
592 |
| - }); |
593 |
| - fileUploadButtonBar.find('.toggle') |
594 |
| - .bind('change.' + ns, function (e) { |
| 592 | + } |
| 593 | + }); |
| 594 | + this._on(fileUploadButtonBar.find('.toggle'), { |
| 595 | + change: function (e) { |
595 | 596 | filesList.find('.delete input').prop(
|
596 | 597 | 'checked',
|
597 |
| - $(this).is(':checked') |
| 598 | + $(e.currentTarget).is(':checked') |
598 | 599 | );
|
599 |
| - }); |
| 600 | + } |
| 601 | + }); |
600 | 602 | },
|
601 | 603 |
|
602 | 604 | _destroyButtonBarEventHandlers: function () {
|
603 |
| - this.element.find('.fileupload-buttonbar button') |
604 |
| - .unbind('click.' + this.options.namespace); |
605 |
| - this.element.find('.fileupload-buttonbar .toggle') |
606 |
| - .unbind('change.' + this.options.namespace); |
| 605 | + this._off( |
| 606 | + this.element.find('.fileupload-buttonbar button'), |
| 607 | + 'click' |
| 608 | + ); |
| 609 | + this._off( |
| 610 | + this.element.find('.fileupload-buttonbar .toggle'), |
| 611 | + 'change.' |
| 612 | + ); |
607 | 613 | },
|
608 | 614 |
|
609 | 615 | _initEventHandlers: function () {
|
610 |
| - parentWidget.prototype._initEventHandlers.call(this); |
611 |
| - var eventData = {fileupload: this}; |
612 |
| - this.options.filesContainer |
613 |
| - .delegate( |
614 |
| - '.start button', |
615 |
| - 'click.' + this.options.namespace, |
616 |
| - eventData, |
617 |
| - this._startHandler |
618 |
| - ) |
619 |
| - .delegate( |
620 |
| - '.cancel button', |
621 |
| - 'click.' + this.options.namespace, |
622 |
| - eventData, |
623 |
| - this._cancelHandler |
624 |
| - ) |
625 |
| - .delegate( |
626 |
| - '.delete button', |
627 |
| - 'click.' + this.options.namespace, |
628 |
| - eventData, |
629 |
| - this._deleteHandler |
630 |
| - ); |
| 616 | + this._super(); |
| 617 | + this._on(this.options.filesContainer, { |
| 618 | + 'click .start button': this._startHandler, |
| 619 | + 'click .cancel button': this._cancelHandler, |
| 620 | + 'click .delete button': this._deleteHandler |
| 621 | + }); |
631 | 622 | this._initButtonBarEventHandlers();
|
632 | 623 | },
|
633 | 624 |
|
634 | 625 | _destroyEventHandlers: function () {
|
635 |
| - var options = this.options; |
636 | 626 | this._destroyButtonBarEventHandlers();
|
637 |
| - options.filesContainer |
638 |
| - .undelegate('.start button', 'click.' + options.namespace) |
639 |
| - .undelegate('.cancel button', 'click.' + options.namespace) |
640 |
| - .undelegate('.delete button', 'click.' + options.namespace); |
641 |
| - parentWidget.prototype._destroyEventHandlers.call(this); |
| 627 | + this._off(this.options.filesContainer, 'click'); |
| 628 | + this._super(); |
642 | 629 | },
|
643 | 630 |
|
644 | 631 | _enableFileInputButton: function () {
|
|
655 | 642 |
|
656 | 643 | _initTemplates: function () {
|
657 | 644 | var options = this.options;
|
658 |
| - options.templatesContainer = document.createElement( |
| 645 | + options.templatesContainer = this.document[0].createElement( |
659 | 646 | options.filesContainer.prop('nodeName')
|
660 | 647 | );
|
661 | 648 | if (tmpl) {
|
|
699 | 686 | },
|
700 | 687 |
|
701 | 688 | _initSpecialOptions: function () {
|
702 |
| - parentWidget.prototype._initSpecialOptions.call(this); |
| 689 | + this._super(); |
703 | 690 | this._initFilesContainer();
|
704 | 691 | this._initTemplates();
|
705 | 692 | this._initRegExpOptions();
|
706 | 693 | },
|
707 | 694 |
|
708 | 695 | _create: function () {
|
709 |
| - parentWidget.prototype._create.call(this); |
| 696 | + this._super(); |
710 | 697 | this._refreshOptionsList.push(
|
711 | 698 | 'filesContainer',
|
712 | 699 | 'uploadTemplateId',
|
713 | 700 | 'downloadTemplateId'
|
714 | 701 | );
|
715 |
| - if (!$.blueimpFP) { |
| 702 | + if (!this._processingQueue) { |
716 | 703 | this._processingQueue = $.Deferred().resolveWith(this).promise();
|
717 | 704 | this.process = function () {
|
718 | 705 | return this._processingQueue;
|
|
725 | 712 | if (this.options.disabled) {
|
726 | 713 | wasDisabled = true;
|
727 | 714 | }
|
728 |
| - parentWidget.prototype.enable.call(this); |
| 715 | + this._super(); |
729 | 716 | if (wasDisabled) {
|
730 | 717 | this.element.find('input, button').prop('disabled', false);
|
731 | 718 | this._enableFileInputButton();
|
|
737 | 724 | this.element.find('input, button').prop('disabled', true);
|
738 | 725 | this._disableFileInputButton();
|
739 | 726 | }
|
740 |
| - parentWidget.prototype.disable.call(this); |
| 727 | + this._super(); |
741 | 728 | }
|
742 | 729 |
|
743 | 730 | });
|
|
0 commit comments