Skip to content

Commit c1ebb1b

Browse files
committed
Updated jQuery Widget Factory to version 1.9.0.
Refactoring to make use of the new Widget API.
1 parent 40ec680 commit c1ebb1b

File tree

6 files changed

+438
-256
lines changed

6 files changed

+438
-256
lines changed

js/jquery.fileupload-fp.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload File Processing Plugin 1.1
2+
* jQuery File Upload File Processing Plugin 1.2
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2012, Sebastian Tschan
@@ -32,9 +32,9 @@
3232
}(function ($, loadImage) {
3333
'use strict';
3434

35-
// The File Upload IP version extends the basic fileupload widget
35+
// The File Upload FP version extends the fileupload widget
3636
// with file processing functionality:
37-
$.widget('blueimpFP.fileupload', $.blueimp.fileupload, {
37+
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
3838

3939
options: {
4040
// The list of file processing actions:
@@ -209,7 +209,7 @@
209209
},
210210

211211
_create: function () {
212-
$.blueimp.fileupload.prototype._create.call(this);
212+
this._super();
213213
this._processing = 0;
214214
this._processingQueue = $.Deferred().resolveWith(this)
215215
.promise();

js/jquery.fileupload-ui.js

Lines changed: 52 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload User Interface Plugin 6.9.7
2+
* jQuery File Upload User Interface Plugin 6.10
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -10,7 +10,7 @@
1010
*/
1111

1212
/*jslint nomen: true, unparam: true, regexp: true */
13-
/*global define, window, document, URL, webkitURL, FileReader */
13+
/*global define, window, URL, webkitURL, FileReader */
1414

1515
(function (factory) {
1616
'use strict';
@@ -33,10 +33,9 @@
3333
}(function ($, tmpl, loadImage) {
3434
'use strict';
3535

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, {
4039

4140
options: {
4241
// By default, files added to the widget are uploaded as soon
@@ -458,7 +457,7 @@
458457
that._transition(node).done(function () {
459458
dfd.resolveWith(node);
460459
});
461-
if (!$.contains(document.body, node[0])) {
460+
if (!$.contains(this.document[0].body, node[0])) {
462461
// If the element is not part of the DOM,
463462
// transition events are not triggered,
464463
// so we have to resolve manually:
@@ -511,7 +510,7 @@
511510

512511
_startHandler: function (e) {
513512
e.preventDefault();
514-
var button = $(this),
513+
var button = $(e.currentTarget),
515514
template = button.closest('.template-upload'),
516515
data = template.data('data');
517516
if (data && data.submit && !data.jqXHR && data.submit()) {
@@ -521,24 +520,24 @@
521520

522521
_cancelHandler: function (e) {
523522
e.preventDefault();
524-
var template = $(this).closest('.template-upload'),
523+
var template = $(e.currentTarget).closest('.template-upload'),
525524
data = template.data('data') || {};
526525
if (!data.jqXHR) {
527526
data.errorThrown = 'abort';
528-
e.data.fileupload._trigger('fail', e, data);
527+
this._trigger('fail', e, data);
529528
} else {
530529
data.jqXHR.abort();
531530
}
532531
},
533532

534533
_deleteHandler: function (e) {
535534
e.preventDefault();
536-
var button = $(this);
537-
e.data.fileupload._trigger('destroy', e, {
535+
var button = $(e.currentTarget);
536+
this._trigger('destroy', e, {
538537
context: button.closest('.template-download'),
539538
url: button.attr('data-url'),
540539
type: button.attr('data-type') || 'DELETE',
541-
dataType: e.data.fileupload.options.dataType
540+
dataType: this.options.dataType
542541
});
543542
},
544543

@@ -570,75 +569,63 @@
570569

571570
_initButtonBarEventHandlers: function () {
572571
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) {
577575
e.preventDefault();
578576
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) {
582581
e.preventDefault();
583582
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) {
587587
e.preventDefault();
588588
filesList.find('.delete input:checked')
589589
.siblings('button').click();
590590
fileUploadButtonBar.find('.toggle')
591591
.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) {
595596
filesList.find('.delete input').prop(
596597
'checked',
597-
$(this).is(':checked')
598+
$(e.currentTarget).is(':checked')
598599
);
599-
});
600+
}
601+
});
600602
},
601603

602604
_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+
);
607613
},
608614

609615
_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+
});
631622
this._initButtonBarEventHandlers();
632623
},
633624

634625
_destroyEventHandlers: function () {
635-
var options = this.options;
636626
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();
642629
},
643630

644631
_enableFileInputButton: function () {
@@ -655,7 +642,7 @@
655642

656643
_initTemplates: function () {
657644
var options = this.options;
658-
options.templatesContainer = document.createElement(
645+
options.templatesContainer = this.document[0].createElement(
659646
options.filesContainer.prop('nodeName')
660647
);
661648
if (tmpl) {
@@ -699,20 +686,20 @@
699686
},
700687

701688
_initSpecialOptions: function () {
702-
parentWidget.prototype._initSpecialOptions.call(this);
689+
this._super();
703690
this._initFilesContainer();
704691
this._initTemplates();
705692
this._initRegExpOptions();
706693
},
707694

708695
_create: function () {
709-
parentWidget.prototype._create.call(this);
696+
this._super();
710697
this._refreshOptionsList.push(
711698
'filesContainer',
712699
'uploadTemplateId',
713700
'downloadTemplateId'
714701
);
715-
if (!$.blueimpFP) {
702+
if (!this._processingQueue) {
716703
this._processingQueue = $.Deferred().resolveWith(this).promise();
717704
this.process = function () {
718705
return this._processingQueue;
@@ -725,7 +712,7 @@
725712
if (this.options.disabled) {
726713
wasDisabled = true;
727714
}
728-
parentWidget.prototype.enable.call(this);
715+
this._super();
729716
if (wasDisabled) {
730717
this.element.find('input, button').prop('disabled', false);
731718
this._enableFileInputButton();
@@ -737,7 +724,7 @@
737724
this.element.find('input, button').prop('disabled', true);
738725
this._disableFileInputButton();
739726
}
740-
parentWidget.prototype.disable.call(this);
727+
this._super();
741728
}
742729

743730
});

0 commit comments

Comments
 (0)