jquery.fileupload-rails-ui-6 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.gitmodules +3 -0
- data/Gemfile +4 -0
- data/Rakefile +40 -0
- data/Readme.md +93 -0
- data/demo/.gitignore +3 -0
- data/demo/Gemfile +8 -0
- data/demo/Rakefile +2 -0
- data/demo/Readme.md +12 -0
- data/demo/app/assets/javascripts/application.js.coffee +9 -0
- data/demo/app/controllers/application_controller.rb +7 -0
- data/demo/app/views/application/basic.html.erb +12 -0
- data/demo/app/views/application/create.html.erb +1 -0
- data/demo/app/views/application/ui.html.erb +1 -0
- data/demo/app/views/layouts/application.html.erb +13 -0
- data/demo/bin/bundle +3 -0
- data/demo/bin/rails +4 -0
- data/demo/bin/rake +4 -0
- data/demo/config/application.rb +21 -0
- data/demo/config/boot.rb +6 -0
- data/demo/config/environment.rb +5 -0
- data/demo/config/routes.rb +6 -0
- data/demo/config.ru +4 -0
- data/demo/log/.gitkeep +0 -0
- data/dependencies.json +4 -0
- data/jquery.fileupload-rails-ui-6.gemspec +17 -0
- data/lib/jquery.fileupload-rails.rb +9 -0
- data/vendor/assets/javascripts/jquery.fileupload.js +1460 -0
- data/vendor/assets/javascripts/jquery.iframe-transport.js +214 -0
- data/vendor/legacy_assets/javascripts/jquery.fileupload-fp.js +219 -0
- data/vendor/legacy_assets/javascripts/jquery.fileupload-ip.js +160 -0
- data/vendor/legacy_assets/javascripts/jquery.fileupload-ui.js +702 -0
- data/vendor/legacy_assets/javascripts/jquery.postmessage-transport.js +117 -0
- data/vendor/legacy_assets/javascripts/jquery.xdr-transport.js +85 -0
- data/vendor/legacy_assets/stylesheets/jquery.fileupload-ui.css +84 -0
- metadata +106 -0
@@ -0,0 +1,214 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery Iframe Transport Plugin 1.8.2
|
3
|
+
* https://github.com/blueimp/jQuery-File-Upload
|
4
|
+
*
|
5
|
+
* Copyright 2011, Sebastian Tschan
|
6
|
+
* https://blueimp.net
|
7
|
+
*
|
8
|
+
* Licensed under the MIT license:
|
9
|
+
* http://www.opensource.org/licenses/MIT
|
10
|
+
*/
|
11
|
+
|
12
|
+
/* global define, window, document */
|
13
|
+
|
14
|
+
(function (factory) {
|
15
|
+
'use strict';
|
16
|
+
if (typeof define === 'function' && define.amd) {
|
17
|
+
// Register as an anonymous AMD module:
|
18
|
+
define(['jquery'], factory);
|
19
|
+
} else {
|
20
|
+
// Browser globals:
|
21
|
+
factory(window.jQuery);
|
22
|
+
}
|
23
|
+
}(function ($) {
|
24
|
+
'use strict';
|
25
|
+
|
26
|
+
// Helper variable to create unique names for the transport iframes:
|
27
|
+
var counter = 0;
|
28
|
+
|
29
|
+
// The iframe transport accepts four additional options:
|
30
|
+
// options.fileInput: a jQuery collection of file input fields
|
31
|
+
// options.paramName: the parameter name for the file form data,
|
32
|
+
// overrides the name property of the file input field(s),
|
33
|
+
// can be a string or an array of strings.
|
34
|
+
// options.formData: an array of objects with name and value properties,
|
35
|
+
// equivalent to the return data of .serializeArray(), e.g.:
|
36
|
+
// [{name: 'a', value: 1}, {name: 'b', value: 2}]
|
37
|
+
// options.initialIframeSrc: the URL of the initial iframe src,
|
38
|
+
// by default set to "javascript:false;"
|
39
|
+
$.ajaxTransport('iframe', function (options) {
|
40
|
+
if (options.async) {
|
41
|
+
// javascript:false as initial iframe src
|
42
|
+
// prevents warning popups on HTTPS in IE6:
|
43
|
+
/*jshint scripturl: true */
|
44
|
+
var initialIframeSrc = options.initialIframeSrc || 'javascript:false;',
|
45
|
+
/*jshint scripturl: false */
|
46
|
+
form,
|
47
|
+
iframe,
|
48
|
+
addParamChar;
|
49
|
+
return {
|
50
|
+
send: function (_, completeCallback) {
|
51
|
+
form = $('<form style="display:none;"></form>');
|
52
|
+
form.attr('accept-charset', options.formAcceptCharset);
|
53
|
+
addParamChar = /\?/.test(options.url) ? '&' : '?';
|
54
|
+
// XDomainRequest only supports GET and POST:
|
55
|
+
if (options.type === 'DELETE') {
|
56
|
+
options.url = options.url + addParamChar + '_method=DELETE';
|
57
|
+
options.type = 'POST';
|
58
|
+
} else if (options.type === 'PUT') {
|
59
|
+
options.url = options.url + addParamChar + '_method=PUT';
|
60
|
+
options.type = 'POST';
|
61
|
+
} else if (options.type === 'PATCH') {
|
62
|
+
options.url = options.url + addParamChar + '_method=PATCH';
|
63
|
+
options.type = 'POST';
|
64
|
+
}
|
65
|
+
// IE versions below IE8 cannot set the name property of
|
66
|
+
// elements that have already been added to the DOM,
|
67
|
+
// so we set the name along with the iframe HTML markup:
|
68
|
+
counter += 1;
|
69
|
+
iframe = $(
|
70
|
+
'<iframe src="' + initialIframeSrc +
|
71
|
+
'" name="iframe-transport-' + counter + '"></iframe>'
|
72
|
+
).bind('load', function () {
|
73
|
+
var fileInputClones,
|
74
|
+
paramNames = $.isArray(options.paramName) ?
|
75
|
+
options.paramName : [options.paramName];
|
76
|
+
iframe
|
77
|
+
.unbind('load')
|
78
|
+
.bind('load', function () {
|
79
|
+
var response;
|
80
|
+
// Wrap in a try/catch block to catch exceptions thrown
|
81
|
+
// when trying to access cross-domain iframe contents:
|
82
|
+
try {
|
83
|
+
response = iframe.contents();
|
84
|
+
// Google Chrome and Firefox do not throw an
|
85
|
+
// exception when calling iframe.contents() on
|
86
|
+
// cross-domain requests, so we unify the response:
|
87
|
+
if (!response.length || !response[0].firstChild) {
|
88
|
+
throw new Error();
|
89
|
+
}
|
90
|
+
} catch (e) {
|
91
|
+
response = undefined;
|
92
|
+
}
|
93
|
+
// The complete callback returns the
|
94
|
+
// iframe content document as response object:
|
95
|
+
completeCallback(
|
96
|
+
200,
|
97
|
+
'success',
|
98
|
+
{'iframe': response}
|
99
|
+
);
|
100
|
+
// Fix for IE endless progress bar activity bug
|
101
|
+
// (happens on form submits to iframe targets):
|
102
|
+
$('<iframe src="' + initialIframeSrc + '"></iframe>')
|
103
|
+
.appendTo(form);
|
104
|
+
window.setTimeout(function () {
|
105
|
+
// Removing the form in a setTimeout call
|
106
|
+
// allows Chrome's developer tools to display
|
107
|
+
// the response result
|
108
|
+
form.remove();
|
109
|
+
}, 0);
|
110
|
+
});
|
111
|
+
form
|
112
|
+
.prop('target', iframe.prop('name'))
|
113
|
+
.prop('action', options.url)
|
114
|
+
.prop('method', options.type);
|
115
|
+
if (options.formData) {
|
116
|
+
$.each(options.formData, function (index, field) {
|
117
|
+
$('<input type="hidden"/>')
|
118
|
+
.prop('name', field.name)
|
119
|
+
.val(field.value)
|
120
|
+
.appendTo(form);
|
121
|
+
});
|
122
|
+
}
|
123
|
+
if (options.fileInput && options.fileInput.length &&
|
124
|
+
options.type === 'POST') {
|
125
|
+
fileInputClones = options.fileInput.clone();
|
126
|
+
// Insert a clone for each file input field:
|
127
|
+
options.fileInput.after(function (index) {
|
128
|
+
return fileInputClones[index];
|
129
|
+
});
|
130
|
+
if (options.paramName) {
|
131
|
+
options.fileInput.each(function (index) {
|
132
|
+
$(this).prop(
|
133
|
+
'name',
|
134
|
+
paramNames[index] || options.paramName
|
135
|
+
);
|
136
|
+
});
|
137
|
+
}
|
138
|
+
// Appending the file input fields to the hidden form
|
139
|
+
// removes them from their original location:
|
140
|
+
form
|
141
|
+
.append(options.fileInput)
|
142
|
+
.prop('enctype', 'multipart/form-data')
|
143
|
+
// enctype must be set as encoding for IE:
|
144
|
+
.prop('encoding', 'multipart/form-data');
|
145
|
+
// Remove the HTML5 form attribute from the input(s):
|
146
|
+
options.fileInput.removeAttr('form');
|
147
|
+
}
|
148
|
+
form.submit();
|
149
|
+
// Insert the file input fields at their original location
|
150
|
+
// by replacing the clones with the originals:
|
151
|
+
if (fileInputClones && fileInputClones.length) {
|
152
|
+
options.fileInput.each(function (index, input) {
|
153
|
+
var clone = $(fileInputClones[index]);
|
154
|
+
// Restore the original name and form properties:
|
155
|
+
$(input)
|
156
|
+
.prop('name', clone.prop('name'))
|
157
|
+
.attr('form', clone.attr('form'));
|
158
|
+
clone.replaceWith(input);
|
159
|
+
});
|
160
|
+
}
|
161
|
+
});
|
162
|
+
form.append(iframe).appendTo(document.body);
|
163
|
+
},
|
164
|
+
abort: function () {
|
165
|
+
if (iframe) {
|
166
|
+
// javascript:false as iframe src aborts the request
|
167
|
+
// and prevents warning popups on HTTPS in IE6.
|
168
|
+
// concat is used to avoid the "Script URL" JSLint error:
|
169
|
+
iframe
|
170
|
+
.unbind('load')
|
171
|
+
.prop('src', initialIframeSrc);
|
172
|
+
}
|
173
|
+
if (form) {
|
174
|
+
form.remove();
|
175
|
+
}
|
176
|
+
}
|
177
|
+
};
|
178
|
+
}
|
179
|
+
});
|
180
|
+
|
181
|
+
// The iframe transport returns the iframe content document as response.
|
182
|
+
// The following adds converters from iframe to text, json, html, xml
|
183
|
+
// and script.
|
184
|
+
// Please note that the Content-Type for JSON responses has to be text/plain
|
185
|
+
// or text/html, if the browser doesn't include application/json in the
|
186
|
+
// Accept header, else IE will show a download dialog.
|
187
|
+
// The Content-Type for XML responses on the other hand has to be always
|
188
|
+
// application/xml or text/xml, so IE properly parses the XML response.
|
189
|
+
// See also
|
190
|
+
// https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
|
191
|
+
$.ajaxSetup({
|
192
|
+
converters: {
|
193
|
+
'iframe text': function (iframe) {
|
194
|
+
return iframe && $(iframe[0].body).text();
|
195
|
+
},
|
196
|
+
'iframe json': function (iframe) {
|
197
|
+
return iframe && $.parseJSON($(iframe[0].body).text());
|
198
|
+
},
|
199
|
+
'iframe html': function (iframe) {
|
200
|
+
return iframe && $(iframe[0].body).html();
|
201
|
+
},
|
202
|
+
'iframe xml': function (iframe) {
|
203
|
+
var xmlDoc = iframe && iframe[0];
|
204
|
+
return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
|
205
|
+
$.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
|
206
|
+
$(xmlDoc.body).html());
|
207
|
+
},
|
208
|
+
'iframe script': function (iframe) {
|
209
|
+
return iframe && $.globalEval($(iframe[0].body).text());
|
210
|
+
}
|
211
|
+
}
|
212
|
+
});
|
213
|
+
|
214
|
+
}));
|
@@ -0,0 +1,219 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery File Upload File Processing Plugin 1.0
|
3
|
+
* https://github.com/blueimp/jQuery-File-Upload
|
4
|
+
*
|
5
|
+
* Copyright 2012, Sebastian Tschan
|
6
|
+
* https://blueimp.net
|
7
|
+
*
|
8
|
+
* Licensed under the MIT license:
|
9
|
+
* http://www.opensource.org/licenses/MIT
|
10
|
+
*/
|
11
|
+
|
12
|
+
/*jslint nomen: true, unparam: true, regexp: true */
|
13
|
+
/*global define, window, document */
|
14
|
+
|
15
|
+
(function (factory) {
|
16
|
+
'use strict';
|
17
|
+
if (typeof define === 'function' && define.amd) {
|
18
|
+
// Register as an anonymous AMD module:
|
19
|
+
define([
|
20
|
+
'jquery',
|
21
|
+
'load-image',
|
22
|
+
'canvas-to-blob',
|
23
|
+
'./jquery.fileupload'
|
24
|
+
], factory);
|
25
|
+
} else {
|
26
|
+
// Browser globals:
|
27
|
+
factory(
|
28
|
+
window.jQuery,
|
29
|
+
window.loadImage
|
30
|
+
);
|
31
|
+
}
|
32
|
+
}(function ($, loadImage) {
|
33
|
+
'use strict';
|
34
|
+
|
35
|
+
// The File Upload IP version extends the basic fileupload widget
|
36
|
+
// with file processing functionality:
|
37
|
+
$.widget('blueimpFP.fileupload', $.blueimp.fileupload, {
|
38
|
+
|
39
|
+
options: {
|
40
|
+
// The list of file processing actions:
|
41
|
+
process: [
|
42
|
+
/*
|
43
|
+
{
|
44
|
+
action: 'load',
|
45
|
+
fileTypes: /^image\/(gif|jpeg|png)$/,
|
46
|
+
maxFileSize: 20000000 // 20MB
|
47
|
+
},
|
48
|
+
{
|
49
|
+
action: 'resize',
|
50
|
+
maxWidth: 1920,
|
51
|
+
maxHeight: 1200,
|
52
|
+
minWidth: 800,
|
53
|
+
minHeight: 600
|
54
|
+
},
|
55
|
+
{
|
56
|
+
action: 'save'
|
57
|
+
}
|
58
|
+
*/
|
59
|
+
],
|
60
|
+
|
61
|
+
// The add callback is invoked as soon as files are added to the
|
62
|
+
// fileupload widget (via file input selection, drag & drop or add
|
63
|
+
// API call). See the basic file upload widget for more information:
|
64
|
+
add: function (e, data) {
|
65
|
+
$(this).fileupload('process', data).done(function () {
|
66
|
+
data.submit();
|
67
|
+
});
|
68
|
+
}
|
69
|
+
},
|
70
|
+
|
71
|
+
processActions: {
|
72
|
+
// Loads the image given via data.files and data.index
|
73
|
+
// as canvas element.
|
74
|
+
// Accepts the options fileTypes (regular expression)
|
75
|
+
// and maxFileSize (integer) to limit the files to load:
|
76
|
+
load: function (data, options) {
|
77
|
+
var that = this,
|
78
|
+
file = data.files[data.index],
|
79
|
+
dfd = $.Deferred();
|
80
|
+
if (window.HTMLCanvasElement &&
|
81
|
+
window.HTMLCanvasElement.prototype.toBlob &&
|
82
|
+
($.type(options.maxFileSize) !== 'number' ||
|
83
|
+
file.size < options.maxFileSize) &&
|
84
|
+
(!options.fileTypes ||
|
85
|
+
options.fileTypes.test(file.type))) {
|
86
|
+
loadImage(
|
87
|
+
file,
|
88
|
+
function (canvas) {
|
89
|
+
data.canvas = canvas;
|
90
|
+
dfd.resolveWith(that, [data]);
|
91
|
+
},
|
92
|
+
{canvas: true}
|
93
|
+
);
|
94
|
+
} else {
|
95
|
+
dfd.rejectWith(that, [data]);
|
96
|
+
}
|
97
|
+
return dfd.promise();
|
98
|
+
},
|
99
|
+
// Resizes the image given as data.canvas and updates
|
100
|
+
// data.canvas with the resized image.
|
101
|
+
// Accepts the options maxWidth, maxHeight, minWidth and
|
102
|
+
// minHeight to scale the given image:
|
103
|
+
resize: function (data, options) {
|
104
|
+
if (data.canvas) {
|
105
|
+
var canvas = loadImage.scale(data.canvas, options);
|
106
|
+
if (canvas.width !== data.canvas.width ||
|
107
|
+
canvas.height !== data.canvas.height) {
|
108
|
+
data.canvas = canvas;
|
109
|
+
data.processed = true;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
return data;
|
113
|
+
},
|
114
|
+
// Saves the processed image given as data.canvas
|
115
|
+
// inplace at data.index of data.files:
|
116
|
+
save: function (data, options) {
|
117
|
+
// Do nothing if no processing has happened:
|
118
|
+
if (!data.canvas || !data.processed) {
|
119
|
+
return data;
|
120
|
+
}
|
121
|
+
var that = this,
|
122
|
+
file = data.files[data.index],
|
123
|
+
name = file.name,
|
124
|
+
dfd = $.Deferred(),
|
125
|
+
callback = function (blob) {
|
126
|
+
if (!blob.name) {
|
127
|
+
if (file.type === blob.type) {
|
128
|
+
blob.name = file.name;
|
129
|
+
} else if (file.name) {
|
130
|
+
blob.name = file.name.replace(
|
131
|
+
/\..+$/,
|
132
|
+
'.' + blob.type.substr(6)
|
133
|
+
);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
// Store the created blob at the position
|
137
|
+
// of the original file in the files list:
|
138
|
+
data.files[data.index] = blob;
|
139
|
+
dfd.resolveWith(that, [data]);
|
140
|
+
};
|
141
|
+
// Use canvas.mozGetAsFile directly, to retain the filename, as
|
142
|
+
// Gecko doesn't support the filename option for FormData.append:
|
143
|
+
if (data.canvas.mozGetAsFile) {
|
144
|
+
callback(data.canvas.mozGetAsFile(
|
145
|
+
(/^image\/(jpeg|png)$/.test(file.type) && name) ||
|
146
|
+
((name && name.replace(/\..+$/, '')) ||
|
147
|
+
'blob') + '.png',
|
148
|
+
file.type
|
149
|
+
));
|
150
|
+
} else {
|
151
|
+
data.canvas.toBlob(callback, file.type);
|
152
|
+
}
|
153
|
+
return dfd.promise();
|
154
|
+
}
|
155
|
+
},
|
156
|
+
|
157
|
+
// Resizes the file at the given index and stores the created blob at
|
158
|
+
// the original position of the files list, returns a Promise object:
|
159
|
+
_processFile: function (files, index, options) {
|
160
|
+
var that = this,
|
161
|
+
dfd = $.Deferred().resolveWith(that, [{
|
162
|
+
files: files,
|
163
|
+
index: index
|
164
|
+
}]),
|
165
|
+
chain = dfd.promise();
|
166
|
+
that._processing += 1;
|
167
|
+
$.each(options.process, function (i, settings) {
|
168
|
+
chain = chain.pipe(function (data) {
|
169
|
+
return that.processActions[settings.action]
|
170
|
+
.call(this, data, settings);
|
171
|
+
});
|
172
|
+
});
|
173
|
+
chain.always(function () {
|
174
|
+
that._processing -= 1;
|
175
|
+
if (that._processing === 0) {
|
176
|
+
that.element
|
177
|
+
.removeClass('fileupload-processing');
|
178
|
+
}
|
179
|
+
});
|
180
|
+
if (that._processing === 1) {
|
181
|
+
that.element.addClass('fileupload-processing');
|
182
|
+
}
|
183
|
+
return chain;
|
184
|
+
},
|
185
|
+
|
186
|
+
// Processes the files given as files property of the data parameter,
|
187
|
+
// returns a Promise object that allows to bind a done handler, which
|
188
|
+
// will be invoked after processing all files (inplace) is done:
|
189
|
+
process: function (data) {
|
190
|
+
var that = this,
|
191
|
+
options = $.extend({}, this.options, data);
|
192
|
+
if (options.process && options.process.length &&
|
193
|
+
this._isXHRUpload(options)) {
|
194
|
+
$.each(data.files, function (index, file) {
|
195
|
+
that._processingQueue = that._processingQueue.pipe(
|
196
|
+
function () {
|
197
|
+
var dfd = $.Deferred();
|
198
|
+
that._processFile(data.files, index, options)
|
199
|
+
.always(function () {
|
200
|
+
dfd.resolveWith(that);
|
201
|
+
});
|
202
|
+
return dfd.promise();
|
203
|
+
}
|
204
|
+
);
|
205
|
+
});
|
206
|
+
}
|
207
|
+
return this._processingQueue;
|
208
|
+
},
|
209
|
+
|
210
|
+
_create: function () {
|
211
|
+
$.blueimp.fileupload.prototype._create.call(this);
|
212
|
+
this._processing = 0;
|
213
|
+
this._processingQueue = $.Deferred().resolveWith(this)
|
214
|
+
.promise();
|
215
|
+
}
|
216
|
+
|
217
|
+
});
|
218
|
+
|
219
|
+
}));
|
@@ -0,0 +1,160 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery File Upload Image Processing Plugin 1.0.6
|
3
|
+
* https://github.com/blueimp/jQuery-File-Upload
|
4
|
+
*
|
5
|
+
* Copyright 2012, Sebastian Tschan
|
6
|
+
* https://blueimp.net
|
7
|
+
*
|
8
|
+
* Licensed under the MIT license:
|
9
|
+
* http://www.opensource.org/licenses/MIT
|
10
|
+
*/
|
11
|
+
|
12
|
+
/*jslint nomen: true, unparam: true, regexp: true */
|
13
|
+
/*global define, window, document */
|
14
|
+
|
15
|
+
(function (factory) {
|
16
|
+
'use strict';
|
17
|
+
if (typeof define === 'function' && define.amd) {
|
18
|
+
// Register as an anonymous AMD module:
|
19
|
+
define([
|
20
|
+
'jquery',
|
21
|
+
'load-image',
|
22
|
+
'canvas-to-blob',
|
23
|
+
'./jquery.fileupload'
|
24
|
+
], factory);
|
25
|
+
} else {
|
26
|
+
// Browser globals:
|
27
|
+
factory(
|
28
|
+
window.jQuery,
|
29
|
+
window.loadImage,
|
30
|
+
window.canvasToBlob
|
31
|
+
);
|
32
|
+
}
|
33
|
+
}(function ($, loadImage, canvasToBlob) {
|
34
|
+
'use strict';
|
35
|
+
|
36
|
+
// The File Upload IP version extends the basic fileupload widget
|
37
|
+
// with image processing functionality:
|
38
|
+
$.widget('blueimpIP.fileupload', $.blueimp.fileupload, {
|
39
|
+
|
40
|
+
options: {
|
41
|
+
// The regular expression to define which image files are to be
|
42
|
+
// resized, given that the browser supports the operation:
|
43
|
+
resizeSourceFileTypes: /^image\/(gif|jpeg|png)$/,
|
44
|
+
// The maximum file size of images that are to be resized:
|
45
|
+
resizeSourceMaxFileSize: 20000000, // 20MB
|
46
|
+
// The maximum width of the resized images:
|
47
|
+
resizeMaxWidth: undefined,
|
48
|
+
// The maximum height of the resized images:
|
49
|
+
resizeMaxHeight: undefined,
|
50
|
+
// The minimum width of the resized images:
|
51
|
+
resizeMinWidth: undefined,
|
52
|
+
// The minimum height of the resized images:
|
53
|
+
resizeMinHeight: undefined,
|
54
|
+
|
55
|
+
// The add callback is invoked as soon as files are added to the fileupload
|
56
|
+
// widget (via file input selection, drag & drop or add API call).
|
57
|
+
// See the basic file upload widget for more information:
|
58
|
+
add: function (e, data) {
|
59
|
+
$(this).fileupload('resize', data).done(function () {
|
60
|
+
data.submit();
|
61
|
+
});
|
62
|
+
}
|
63
|
+
},
|
64
|
+
|
65
|
+
// Resizes the image file at the given index and stores the created blob
|
66
|
+
// at the original position of the files list, returns a Promise object:
|
67
|
+
_resizeImage: function (files, index, options) {
|
68
|
+
var that = this,
|
69
|
+
file = files[index],
|
70
|
+
deferred = $.Deferred(),
|
71
|
+
canvas,
|
72
|
+
blob;
|
73
|
+
options = options || this.options;
|
74
|
+
loadImage(
|
75
|
+
file,
|
76
|
+
function (img) {
|
77
|
+
var width = img.width,
|
78
|
+
height = img.height;
|
79
|
+
canvas = loadImage.scale(img, {
|
80
|
+
maxWidth: options.resizeMaxWidth,
|
81
|
+
maxHeight: options.resizeMaxHeight,
|
82
|
+
minWidth: options.resizeMinWidth,
|
83
|
+
minHeight: options.resizeMinHeight,
|
84
|
+
canvas: true
|
85
|
+
});
|
86
|
+
if (width !== canvas.width || height !== canvas.height) {
|
87
|
+
canvasToBlob(canvas, function (blob) {
|
88
|
+
if (!blob.name) {
|
89
|
+
if (file.type === blob.type) {
|
90
|
+
blob.name = file.name;
|
91
|
+
} else if (file.name) {
|
92
|
+
blob.name = file.name.replace(
|
93
|
+
/\..+$/,
|
94
|
+
'.' + blob.type.substr(6)
|
95
|
+
);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
files[index] = blob;
|
99
|
+
deferred.resolveWith(that);
|
100
|
+
}, file);
|
101
|
+
} else {
|
102
|
+
deferred.resolveWith(that);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
);
|
106
|
+
return deferred.promise();
|
107
|
+
},
|
108
|
+
|
109
|
+
// Resizes the images given as files property of the data parameter,
|
110
|
+
// returns a Promise object that allows to bind a done handler, which
|
111
|
+
// will be invoked after processing all images is done:
|
112
|
+
resize: function (data) {
|
113
|
+
var that = this,
|
114
|
+
options = $.extend({}, this.options, data),
|
115
|
+
resizeAll = $.type(options.resizeSourceMaxFileSize) !== 'number',
|
116
|
+
isXHRUpload = this._isXHRUpload(options);
|
117
|
+
$.each(data.files, function (index, file) {
|
118
|
+
if (isXHRUpload && that._resizeSupport &&
|
119
|
+
(options.resizeMaxWidth || options.resizeMaxHeight ||
|
120
|
+
options.resizeMinWidth || options.resizeMinHeight) &&
|
121
|
+
(resizeAll || file.size < options.resizeSourceMaxFileSize) &&
|
122
|
+
options.resizeSourceFileTypes.test(file.type)) {
|
123
|
+
that._processing += 1;
|
124
|
+
if (that._processing === 1) {
|
125
|
+
that.element.addClass('fileupload-processing');
|
126
|
+
}
|
127
|
+
that._processingQueue = that._processingQueue.pipe(function () {
|
128
|
+
var deferred = $.Deferred();
|
129
|
+
that._resizeImage(
|
130
|
+
data.files,
|
131
|
+
index,
|
132
|
+
options
|
133
|
+
).done(function () {
|
134
|
+
that._processing -= 1;
|
135
|
+
if (that._processing === 0) {
|
136
|
+
that.element
|
137
|
+
.removeClass('fileupload-processing');
|
138
|
+
}
|
139
|
+
deferred.resolveWith(that);
|
140
|
+
});
|
141
|
+
return deferred.promise();
|
142
|
+
});
|
143
|
+
}
|
144
|
+
});
|
145
|
+
return this._processingQueue;
|
146
|
+
},
|
147
|
+
|
148
|
+
_create: function () {
|
149
|
+
$.blueimp.fileupload.prototype._create.call(this);
|
150
|
+
this._processing = 0;
|
151
|
+
this._processingQueue = $.Deferred().resolveWith(this).promise();
|
152
|
+
this._resizeSupport = canvasToBlob && canvasToBlob(
|
153
|
+
document.createElement('canvas'),
|
154
|
+
$.noop
|
155
|
+
);
|
156
|
+
}
|
157
|
+
|
158
|
+
});
|
159
|
+
|
160
|
+
}));
|