Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4576df9

Browse files
committed
Added functionality to define options via data attributes on the widget element.
Allow using query strings and document elements for the dropZone and fileInput options.
1 parent 8936a91 commit 4576df9

File tree

3 files changed

+53
-26
lines changed

3 files changed

+53
-26
lines changed

js/jquery.fileupload.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin 5.7
2+
* jQuery File Upload Plugin 5.8
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -767,44 +767,38 @@
767767
.unbind('change.' + ns, this._onChange);
768768
},
769769

770-
_beforeSetOption: function (key, value) {
771-
this._destroyEventHandlers();
772-
},
773-
774-
_afterSetOption: function (key, value) {
775-
var options = this.options;
776-
if (!options.fileInput) {
777-
options.fileInput = $();
778-
}
779-
if (!options.dropZone) {
780-
options.dropZone = $();
781-
}
782-
this._initEventHandlers();
783-
},
784-
785770
_setOption: function (key, value) {
786771
var refresh = $.inArray(key, this._refreshOptionsList) !== -1;
787772
if (refresh) {
788-
this._beforeSetOption(key, value);
773+
this._destroyEventHandlers();
789774
}
790775
$.Widget.prototype._setOption.call(this, key, value);
791776
if (refresh) {
792-
this._afterSetOption(key, value);
777+
this._initSpecialOptions();
778+
this._initEventHandlers();
793779
}
794780
},
795781

796-
_create: function () {
782+
_initSpecialOptions: function () {
797783
var options = this.options;
798-
options.namespace = options.namespace || this.widgetName;
799784
if (options.fileInput === undefined) {
800785
options.fileInput = this.element.is('input:file') ?
801786
this.element : this.element.find('input:file');
802-
} else if (!options.fileInput) {
803-
options.fileInput = $();
787+
} else if (!(options.fileInput instanceof $)) {
788+
options.fileInput = $(options.fileInput);
804789
}
805-
if (!options.dropZone) {
806-
options.dropZone = $();
790+
if (!(options.dropZone instanceof $)) {
791+
options.dropZone = $(options.dropZone);
807792
}
793+
},
794+
795+
_create: function () {
796+
var options = this.options,
797+
dataOpts = $.extend({}, this.element.data());
798+
dataOpts[this.widgetName] = undefined;
799+
$.extend(options, dataOpts);
800+
options.namespace = options.namespace || this.widgetName;
801+
this._initSpecialOptions();
808802
this._slots = [];
809803
this._sequence = this._getXHRPromise(true);
810804
this._sending = this._active = this._loaded = this._total = 0;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"dependencies": {
5050
"jquery": ">=1.6",
5151
"jquery.ui.widget": ">=1.8",
52-
"blueimp-tmpl": ">=1.0.2",
52+
"blueimp-tmpl": ">=2.1.0",
5353
"blueimp-load-image": ">=1.1.4",
5454
"blueimp-canvas-to-blob": ">=1.0.1"
5555
}

test/test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin Test 6.3
2+
* jQuery File Upload Plugin Test 6.4
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -61,6 +61,15 @@ $(function () {
6161
ok($('#fileupload').fileupload().data('fileupload'));
6262
});
6363

64+
test('Data attribute options', function () {
65+
$('#fileupload').attr('data-url', 'http://example.org');
66+
$('#fileupload').fileupload();
67+
strictEqual(
68+
$('#fileupload').fileupload('option', 'url'),
69+
'http://example.org'
70+
);
71+
});
72+
6473
test('File input initialization', function () {
6574
var fu = $('#fileupload').fileupload();
6675
ok(
@@ -217,6 +226,30 @@ $(function () {
217226
dropZone.data('events').dragover.length,
218227
'Adds dragover event listener after setting dropZone option'
219228
);
229+
fu.fileupload('option', 'dropZone', 'body');
230+
strictEqual(
231+
fu.fileupload('option', 'dropZone')[0],
232+
document.body,
233+
'Allow a query string as parameter for the dropZone option'
234+
);
235+
fu.fileupload('option', 'dropZone', document);
236+
strictEqual(
237+
fu.fileupload('option', 'dropZone')[0],
238+
document,
239+
'Allow a document element as parameter for the dropZone option'
240+
);
241+
fu.fileupload('option', 'fileInput', ':file');
242+
strictEqual(
243+
fu.fileupload('option', 'fileInput')[0],
244+
$(':file')[0],
245+
'Allow a query string as parameter for the fileInput option'
246+
);
247+
fu.fileupload('option', 'fileInput', $(':file')[0]);
248+
strictEqual(
249+
fu.fileupload('option', 'fileInput')[0],
250+
$(':file')[0],
251+
'Allow a document element as parameter for the fileInput option'
252+
);
220253
});
221254

222255
asyncTest('add', function () {

0 commit comments

Comments
 (0)