jquery-fileupload-rails 0.4.1 → 0.4.2
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/README.md +38 -16
- data/{vendor → app}/assets/images/loading.gif +0 -0
- data/{vendor → app}/assets/images/progressbar.gif +0 -0
- data/app/assets/javascripts/jquery-fileupload/angularjs.js +12 -0
- data/app/assets/javascripts/jquery-fileupload/basic-plus.js +11 -0
- data/app/assets/javascripts/jquery-fileupload/basic.js +3 -0
- data/{vendor → app}/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js +4 -4
- data/{vendor → app}/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js +1 -2
- data/app/assets/javascripts/jquery-fileupload/index.js +13 -0
- data/app/assets/javascripts/jquery-fileupload/jquery-ui.js +13 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js +429 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-audio.js +106 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-image.js +315 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-jquery-ui.js +152 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js +172 -0
- data/{vendor → app}/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +178 -273
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js +119 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-video.js +106 -0
- data/{vendor → app}/assets/javascripts/jquery-fileupload/jquery.fileupload.js +481 -188
- data/{vendor → app}/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +43 -14
- data/{vendor → app}/assets/javascripts/jquery-fileupload/locale.js +0 -0
- data/{vendor → app}/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +9 -5
- data/{vendor → app}/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +72 -44
- data/app/assets/javascripts/jquery-fileupload/vendor/load-image.all.min.js +1 -0
- data/{vendor → app}/assets/javascripts/jquery-fileupload/vendor/tmpl.js +9 -8
- data/app/assets/stylesheets/jquery.fileupload-noscript.scss +22 -0
- data/app/assets/stylesheets/jquery.fileupload-ui-noscript.scss +17 -0
- data/app/assets/stylesheets/jquery.fileupload-ui.scss +57 -0
- data/app/assets/stylesheets/jquery.fileupload.scss +36 -0
- data/lib/jquery/fileupload/rails/version.rb +1 -1
- metadata +43 -39
- data/vendor/assets/javascripts/jquery-fileupload/basic.js +0 -4
- data/vendor/assets/javascripts/jquery-fileupload/index.js +0 -9
- data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js +0 -223
- data/vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js +0 -121
- data/vendor/assets/stylesheets/jquery.fileupload-ui.scss +0 -84
@@ -0,0 +1,172 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery File Upload Processing Plugin 1.3.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
|
+
/* jshint nomen:false */
|
13
|
+
/* global define, window */
|
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
|
+
'./jquery.fileupload'
|
22
|
+
], factory);
|
23
|
+
} else {
|
24
|
+
// Browser globals:
|
25
|
+
factory(
|
26
|
+
window.jQuery
|
27
|
+
);
|
28
|
+
}
|
29
|
+
}(function ($) {
|
30
|
+
'use strict';
|
31
|
+
|
32
|
+
var originalAdd = $.blueimp.fileupload.prototype.options.add;
|
33
|
+
|
34
|
+
// The File Upload Processing plugin extends the fileupload widget
|
35
|
+
// with file processing functionality:
|
36
|
+
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
|
37
|
+
|
38
|
+
options: {
|
39
|
+
// The list of processing actions:
|
40
|
+
processQueue: [
|
41
|
+
/*
|
42
|
+
{
|
43
|
+
action: 'log',
|
44
|
+
type: 'debug'
|
45
|
+
}
|
46
|
+
*/
|
47
|
+
],
|
48
|
+
add: function (e, data) {
|
49
|
+
var $this = $(this);
|
50
|
+
data.process(function () {
|
51
|
+
return $this.fileupload('process', data);
|
52
|
+
});
|
53
|
+
originalAdd.call(this, e, data);
|
54
|
+
}
|
55
|
+
},
|
56
|
+
|
57
|
+
processActions: {
|
58
|
+
/*
|
59
|
+
log: function (data, options) {
|
60
|
+
console[options.type](
|
61
|
+
'Processing "' + data.files[data.index].name + '"'
|
62
|
+
);
|
63
|
+
}
|
64
|
+
*/
|
65
|
+
},
|
66
|
+
|
67
|
+
_processFile: function (data, originalData) {
|
68
|
+
var that = this,
|
69
|
+
dfd = $.Deferred().resolveWith(that, [data]),
|
70
|
+
chain = dfd.promise();
|
71
|
+
this._trigger('process', null, data);
|
72
|
+
$.each(data.processQueue, function (i, settings) {
|
73
|
+
var func = function (data) {
|
74
|
+
if (originalData.errorThrown) {
|
75
|
+
return $.Deferred()
|
76
|
+
.rejectWith(that, [originalData]).promise();
|
77
|
+
}
|
78
|
+
return that.processActions[settings.action].call(
|
79
|
+
that,
|
80
|
+
data,
|
81
|
+
settings
|
82
|
+
);
|
83
|
+
};
|
84
|
+
chain = chain.pipe(func, settings.always && func);
|
85
|
+
});
|
86
|
+
chain
|
87
|
+
.done(function () {
|
88
|
+
that._trigger('processdone', null, data);
|
89
|
+
that._trigger('processalways', null, data);
|
90
|
+
})
|
91
|
+
.fail(function () {
|
92
|
+
that._trigger('processfail', null, data);
|
93
|
+
that._trigger('processalways', null, data);
|
94
|
+
});
|
95
|
+
return chain;
|
96
|
+
},
|
97
|
+
|
98
|
+
// Replaces the settings of each processQueue item that
|
99
|
+
// are strings starting with an "@", using the remaining
|
100
|
+
// substring as key for the option map,
|
101
|
+
// e.g. "@autoUpload" is replaced with options.autoUpload:
|
102
|
+
_transformProcessQueue: function (options) {
|
103
|
+
var processQueue = [];
|
104
|
+
$.each(options.processQueue, function () {
|
105
|
+
var settings = {},
|
106
|
+
action = this.action,
|
107
|
+
prefix = this.prefix === true ? action : this.prefix;
|
108
|
+
$.each(this, function (key, value) {
|
109
|
+
if ($.type(value) === 'string' &&
|
110
|
+
value.charAt(0) === '@') {
|
111
|
+
settings[key] = options[
|
112
|
+
value.slice(1) || (prefix ? prefix +
|
113
|
+
key.charAt(0).toUpperCase() + key.slice(1) : key)
|
114
|
+
];
|
115
|
+
} else {
|
116
|
+
settings[key] = value;
|
117
|
+
}
|
118
|
+
|
119
|
+
});
|
120
|
+
processQueue.push(settings);
|
121
|
+
});
|
122
|
+
options.processQueue = processQueue;
|
123
|
+
},
|
124
|
+
|
125
|
+
// Returns the number of files currently in the processsing queue:
|
126
|
+
processing: function () {
|
127
|
+
return this._processing;
|
128
|
+
},
|
129
|
+
|
130
|
+
// Processes the files given as files property of the data parameter,
|
131
|
+
// returns a Promise object that allows to bind callbacks:
|
132
|
+
process: function (data) {
|
133
|
+
var that = this,
|
134
|
+
options = $.extend({}, this.options, data);
|
135
|
+
if (options.processQueue && options.processQueue.length) {
|
136
|
+
this._transformProcessQueue(options);
|
137
|
+
if (this._processing === 0) {
|
138
|
+
this._trigger('processstart');
|
139
|
+
}
|
140
|
+
$.each(data.files, function (index) {
|
141
|
+
var opts = index ? $.extend({}, options) : options,
|
142
|
+
func = function () {
|
143
|
+
if (data.errorThrown) {
|
144
|
+
return $.Deferred()
|
145
|
+
.rejectWith(that, [data]).promise();
|
146
|
+
}
|
147
|
+
return that._processFile(opts, data);
|
148
|
+
};
|
149
|
+
opts.index = index;
|
150
|
+
that._processing += 1;
|
151
|
+
that._processingQueue = that._processingQueue.pipe(func, func)
|
152
|
+
.always(function () {
|
153
|
+
that._processing -= 1;
|
154
|
+
if (that._processing === 0) {
|
155
|
+
that._trigger('processstop');
|
156
|
+
}
|
157
|
+
});
|
158
|
+
});
|
159
|
+
}
|
160
|
+
return this._processingQueue;
|
161
|
+
},
|
162
|
+
|
163
|
+
_create: function () {
|
164
|
+
this._super();
|
165
|
+
this._processing = 0;
|
166
|
+
this._processingQueue = $.Deferred().resolveWith(this)
|
167
|
+
.promise();
|
168
|
+
}
|
169
|
+
|
170
|
+
});
|
171
|
+
|
172
|
+
}));
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* jQuery File Upload User Interface Plugin
|
2
|
+
* jQuery File Upload User Interface Plugin 9.6.0
|
3
3
|
* https://github.com/blueimp/jQuery-File-Upload
|
4
4
|
*
|
5
5
|
* Copyright 2010, Sebastian Tschan
|
@@ -9,8 +9,8 @@
|
|
9
9
|
* http://www.opensource.org/licenses/MIT
|
10
10
|
*/
|
11
11
|
|
12
|
-
/*
|
13
|
-
/*global define, window
|
12
|
+
/* jshint nomen:false */
|
13
|
+
/* global define, window */
|
14
14
|
|
15
15
|
(function (factory) {
|
16
16
|
'use strict';
|
@@ -19,20 +19,27 @@
|
|
19
19
|
define([
|
20
20
|
'jquery',
|
21
21
|
'tmpl',
|
22
|
-
'
|
23
|
-
'./jquery.fileupload-
|
22
|
+
'./jquery.fileupload-image',
|
23
|
+
'./jquery.fileupload-audio',
|
24
|
+
'./jquery.fileupload-video',
|
25
|
+
'./jquery.fileupload-validate'
|
24
26
|
], factory);
|
25
27
|
} else {
|
26
28
|
// Browser globals:
|
27
29
|
factory(
|
28
30
|
window.jQuery,
|
29
|
-
window.tmpl
|
30
|
-
window.loadImage
|
31
|
+
window.tmpl
|
31
32
|
);
|
32
33
|
}
|
33
|
-
}(function ($, tmpl
|
34
|
+
}(function ($, tmpl) {
|
34
35
|
'use strict';
|
35
36
|
|
37
|
+
$.blueimp.fileupload.prototype._specialOptions.push(
|
38
|
+
'filesContainer',
|
39
|
+
'uploadTemplateId',
|
40
|
+
'downloadTemplateId'
|
41
|
+
);
|
42
|
+
|
36
43
|
// The UI version extends the file upload widget
|
37
44
|
// and adds complete user interface interaction:
|
38
45
|
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
|
@@ -42,29 +49,6 @@
|
|
42
49
|
// as the user clicks on the start buttons. To enable automatic
|
43
50
|
// uploads, set the following option to true:
|
44
51
|
autoUpload: false,
|
45
|
-
// The following option limits the number of files that are
|
46
|
-
// allowed to be uploaded using this widget:
|
47
|
-
maxNumberOfFiles: undefined,
|
48
|
-
// The maximum allowed file size:
|
49
|
-
maxFileSize: undefined,
|
50
|
-
// The minimum allowed file size:
|
51
|
-
minFileSize: undefined,
|
52
|
-
// The regular expression for allowed file types, matches
|
53
|
-
// against either file type or file name:
|
54
|
-
acceptFileTypes: /.+$/i,
|
55
|
-
// The regular expression to define for which files a preview
|
56
|
-
// image is shown, matched against the file type:
|
57
|
-
previewSourceFileTypes: /^image\/(gif|jpeg|png)$/,
|
58
|
-
// The maximum file size of images that are to be displayed as preview:
|
59
|
-
previewSourceMaxFileSize: 5000000, // 5MB
|
60
|
-
// The maximum width of the preview images:
|
61
|
-
previewMaxWidth: 80,
|
62
|
-
// The maximum height of the preview images:
|
63
|
-
previewMaxHeight: 80,
|
64
|
-
// By default, preview images are displayed as canvas elements
|
65
|
-
// if supported by the browser. Set the following option to false
|
66
|
-
// to always display preview images as img elements:
|
67
|
-
previewAsCanvas: true,
|
68
52
|
// The ID of the upload template:
|
69
53
|
uploadTemplateId: 'template-upload',
|
70
54
|
// The ID of the download template:
|
@@ -79,48 +63,79 @@
|
|
79
63
|
// option of the $.ajax upload requests:
|
80
64
|
dataType: 'json',
|
81
65
|
|
66
|
+
// Error and info messages:
|
67
|
+
messages: {
|
68
|
+
unknownError: 'Unknown error'
|
69
|
+
},
|
70
|
+
|
71
|
+
// Function returning the current number of files,
|
72
|
+
// used by the maxNumberOfFiles validation:
|
73
|
+
getNumberOfFiles: function () {
|
74
|
+
return this.filesContainer.children()
|
75
|
+
.not('.processing').length;
|
76
|
+
},
|
77
|
+
|
78
|
+
// Callback to retrieve the list of files from the server response:
|
79
|
+
getFilesFromResponse: function (data) {
|
80
|
+
if (data.result && $.isArray(data.result.files)) {
|
81
|
+
return data.result.files;
|
82
|
+
}
|
83
|
+
return [];
|
84
|
+
},
|
85
|
+
|
82
86
|
// The add callback is invoked as soon as files are added to the fileupload
|
83
87
|
// widget (via file input selection, drag & drop or add API call).
|
84
88
|
// See the basic file upload widget for more information:
|
85
89
|
add: function (e, data) {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
90
|
+
if (e.isDefaultPrevented()) {
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
var $this = $(this),
|
94
|
+
that = $this.data('blueimp-fileupload') ||
|
95
|
+
$this.data('fileupload'),
|
96
|
+
options = that.options;
|
97
|
+
data.context = that._renderUpload(data.files)
|
98
|
+
.data('data', data)
|
99
|
+
.addClass('processing');
|
100
|
+
options.filesContainer[
|
101
|
+
options.prependFiles ? 'prepend' : 'append'
|
102
|
+
](data.context);
|
103
|
+
that._forceReflow(data.context);
|
104
|
+
that._transition(data.context);
|
105
|
+
data.process(function () {
|
106
|
+
return $this.fileupload('process', data);
|
107
|
+
}).always(function () {
|
108
|
+
data.context.each(function (index) {
|
109
|
+
$(this).find('.size').text(
|
110
|
+
that._formatFileSize(data.files[index].size)
|
111
|
+
);
|
112
|
+
}).removeClass('processing');
|
98
113
|
that._renderPreviews(data);
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
114
|
+
}).done(function () {
|
115
|
+
data.context.find('.start').prop('disabled', false);
|
116
|
+
if ((that._trigger('added', e, data) !== false) &&
|
117
|
+
(options.autoUpload || data.autoUpload) &&
|
118
|
+
data.autoUpload !== false) {
|
119
|
+
data.submit();
|
120
|
+
}
|
121
|
+
}).fail(function () {
|
122
|
+
if (data.files.error) {
|
123
|
+
data.context.each(function (index) {
|
124
|
+
var error = data.files[index].error;
|
125
|
+
if (error) {
|
126
|
+
$(this).find('.error').text(error);
|
106
127
|
}
|
107
|
-
}
|
108
|
-
|
128
|
+
});
|
129
|
+
}
|
109
130
|
});
|
110
131
|
},
|
111
132
|
// Callback for the start of each file upload request:
|
112
133
|
send: function (e, data) {
|
134
|
+
if (e.isDefaultPrevented()) {
|
135
|
+
return false;
|
136
|
+
}
|
113
137
|
var that = $(this).data('blueimp-fileupload') ||
|
114
138
|
$(this).data('fileupload');
|
115
|
-
if (!data.isValidated) {
|
116
|
-
if (!data.maxNumberOfFilesAdjusted) {
|
117
|
-
that._adjustMaxNumberOfFiles(-data.files.length);
|
118
|
-
data.maxNumberOfFilesAdjusted = true;
|
119
|
-
}
|
120
|
-
if (!that._validate(data.files)) {
|
121
|
-
return false;
|
122
|
-
}
|
123
|
-
}
|
124
139
|
if (data.context && data.dataType &&
|
125
140
|
data.dataType.substr(0, 6) === 'iframe') {
|
126
141
|
// Iframe Transport does not support progress events.
|
@@ -131,7 +146,7 @@
|
|
131
146
|
!$.support.transition && 'progress-animated'
|
132
147
|
)
|
133
148
|
.attr('aria-valuenow', 100)
|
134
|
-
.
|
149
|
+
.children().first().css(
|
135
150
|
'width',
|
136
151
|
'100%'
|
137
152
|
);
|
@@ -140,19 +155,21 @@
|
|
140
155
|
},
|
141
156
|
// Callback for successful uploads:
|
142
157
|
done: function (e, data) {
|
158
|
+
if (e.isDefaultPrevented()) {
|
159
|
+
return false;
|
160
|
+
}
|
143
161
|
var that = $(this).data('blueimp-fileupload') ||
|
144
162
|
$(this).data('fileupload'),
|
145
|
-
|
163
|
+
getFilesFromResponse = data.getFilesFromResponse ||
|
164
|
+
that.options.getFilesFromResponse,
|
165
|
+
files = getFilesFromResponse(data),
|
146
166
|
template,
|
147
167
|
deferred;
|
148
168
|
if (data.context) {
|
149
169
|
data.context.each(function (index) {
|
150
170
|
var file = files[index] ||
|
151
|
-
{error: 'Empty file upload result'}
|
152
|
-
|
153
|
-
if (file.error) {
|
154
|
-
that._adjustMaxNumberOfFiles(1);
|
155
|
-
}
|
171
|
+
{error: 'Empty file upload result'};
|
172
|
+
deferred = that._addFinishedDeferreds();
|
156
173
|
that._transition($(this)).done(
|
157
174
|
function () {
|
158
175
|
var node = $(this);
|
@@ -171,19 +188,9 @@
|
|
171
188
|
);
|
172
189
|
});
|
173
190
|
} else {
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
that._adjustMaxNumberOfFiles(1);
|
178
|
-
} else if (!data.maxNumberOfFilesAdjusted &&
|
179
|
-
!file.error) {
|
180
|
-
that._adjustMaxNumberOfFiles(-1);
|
181
|
-
}
|
182
|
-
});
|
183
|
-
data.maxNumberOfFilesAdjusted = true;
|
184
|
-
}
|
185
|
-
template = that._renderDownload(files)
|
186
|
-
.appendTo(that.options.filesContainer);
|
191
|
+
template = that._renderDownload(files)[
|
192
|
+
that.options.prependFiles ? 'prependTo' : 'appendTo'
|
193
|
+
](that.options.filesContainer);
|
187
194
|
that._forceReflow(template);
|
188
195
|
deferred = that._addFinishedDeferreds();
|
189
196
|
that._transition(template).done(
|
@@ -198,19 +205,19 @@
|
|
198
205
|
},
|
199
206
|
// Callback for failed (abort or error) uploads:
|
200
207
|
fail: function (e, data) {
|
208
|
+
if (e.isDefaultPrevented()) {
|
209
|
+
return false;
|
210
|
+
}
|
201
211
|
var that = $(this).data('blueimp-fileupload') ||
|
202
212
|
$(this).data('fileupload'),
|
203
213
|
template,
|
204
214
|
deferred;
|
205
|
-
if (data.maxNumberOfFilesAdjusted) {
|
206
|
-
that._adjustMaxNumberOfFiles(data.files.length);
|
207
|
-
}
|
208
215
|
if (data.context) {
|
209
216
|
data.context.each(function (index) {
|
210
217
|
if (data.errorThrown !== 'abort') {
|
211
218
|
var file = data.files[index];
|
212
219
|
file.error = file.error || data.errorThrown ||
|
213
|
-
|
220
|
+
data.i18n('unknownError');
|
214
221
|
deferred = that._addFinishedDeferreds();
|
215
222
|
that._transition($(this)).done(
|
216
223
|
function () {
|
@@ -241,8 +248,9 @@
|
|
241
248
|
}
|
242
249
|
});
|
243
250
|
} else if (data.errorThrown !== 'abort') {
|
244
|
-
data.context = that._renderUpload(data.files)
|
245
|
-
|
251
|
+
data.context = that._renderUpload(data.files)[
|
252
|
+
that.options.prependFiles ? 'prependTo' : 'appendTo'
|
253
|
+
](that.options.filesContainer)
|
246
254
|
.data('data', data);
|
247
255
|
that._forceReflow(data.context);
|
248
256
|
deferred = that._addFinishedDeferreds();
|
@@ -262,20 +270,28 @@
|
|
262
270
|
},
|
263
271
|
// Callback for upload progress events:
|
264
272
|
progress: function (e, data) {
|
273
|
+
if (e.isDefaultPrevented()) {
|
274
|
+
return false;
|
275
|
+
}
|
276
|
+
var progress = Math.floor(data.loaded / data.total * 100);
|
265
277
|
if (data.context) {
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
278
|
+
data.context.each(function () {
|
279
|
+
$(this).find('.progress')
|
280
|
+
.attr('aria-valuenow', progress)
|
281
|
+
.children().first().css(
|
282
|
+
'width',
|
283
|
+
progress + '%'
|
284
|
+
);
|
285
|
+
});
|
273
286
|
}
|
274
287
|
},
|
275
288
|
// Callback for global upload progress events:
|
276
289
|
progressall: function (e, data) {
|
290
|
+
if (e.isDefaultPrevented()) {
|
291
|
+
return false;
|
292
|
+
}
|
277
293
|
var $this = $(this),
|
278
|
-
progress =
|
294
|
+
progress = Math.floor(data.loaded / data.total * 100),
|
279
295
|
globalProgressNode = $this.find('.fileupload-progress'),
|
280
296
|
extendedProgressNode = globalProgressNode
|
281
297
|
.find('.progress-extended');
|
@@ -288,13 +304,16 @@
|
|
288
304
|
globalProgressNode
|
289
305
|
.find('.progress')
|
290
306
|
.attr('aria-valuenow', progress)
|
291
|
-
.
|
307
|
+
.children().first().css(
|
292
308
|
'width',
|
293
309
|
progress + '%'
|
294
310
|
);
|
295
311
|
},
|
296
312
|
// Callback for uploads start, equivalent to the global ajaxStart event:
|
297
313
|
start: function (e) {
|
314
|
+
if (e.isDefaultPrevented()) {
|
315
|
+
return false;
|
316
|
+
}
|
298
317
|
var that = $(this).data('blueimp-fileupload') ||
|
299
318
|
$(this).data('fileupload');
|
300
319
|
that._resetFinishedDeferreds();
|
@@ -306,6 +325,9 @@
|
|
306
325
|
},
|
307
326
|
// Callback for uploads stop, equivalent to the global ajaxStop event:
|
308
327
|
stop: function (e) {
|
328
|
+
if (e.isDefaultPrevented()) {
|
329
|
+
return false;
|
330
|
+
}
|
309
331
|
var that = $(this).data('blueimp-fileupload') ||
|
310
332
|
$(this).data('fileupload'),
|
311
333
|
deferred = that._addFinishedDeferreds();
|
@@ -317,26 +339,47 @@
|
|
317
339
|
function () {
|
318
340
|
$(this).find('.progress')
|
319
341
|
.attr('aria-valuenow', '0')
|
320
|
-
.
|
342
|
+
.children().first().css('width', '0%');
|
321
343
|
$(this).find('.progress-extended').html(' ');
|
322
344
|
deferred.resolve();
|
323
345
|
}
|
324
346
|
);
|
325
347
|
},
|
348
|
+
processstart: function (e) {
|
349
|
+
if (e.isDefaultPrevented()) {
|
350
|
+
return false;
|
351
|
+
}
|
352
|
+
$(this).addClass('fileupload-processing');
|
353
|
+
},
|
354
|
+
processstop: function (e) {
|
355
|
+
if (e.isDefaultPrevented()) {
|
356
|
+
return false;
|
357
|
+
}
|
358
|
+
$(this).removeClass('fileupload-processing');
|
359
|
+
},
|
326
360
|
// Callback for file deletion:
|
327
361
|
destroy: function (e, data) {
|
362
|
+
if (e.isDefaultPrevented()) {
|
363
|
+
return false;
|
364
|
+
}
|
328
365
|
var that = $(this).data('blueimp-fileupload') ||
|
329
|
-
$(this).data('fileupload')
|
366
|
+
$(this).data('fileupload'),
|
367
|
+
removeNode = function () {
|
368
|
+
that._transition(data.context).done(
|
369
|
+
function () {
|
370
|
+
$(this).remove();
|
371
|
+
that._trigger('destroyed', e, data);
|
372
|
+
}
|
373
|
+
);
|
374
|
+
};
|
330
375
|
if (data.url) {
|
331
|
-
|
332
|
-
|
376
|
+
data.dataType = data.dataType || that.options.dataType;
|
377
|
+
$.ajax(data).done(removeNode).fail(function () {
|
378
|
+
that._trigger('destroyfailed', e, data);
|
379
|
+
});
|
380
|
+
} else {
|
381
|
+
removeNode();
|
333
382
|
}
|
334
|
-
that._transition(data.context).done(
|
335
|
-
function () {
|
336
|
-
$(this).remove();
|
337
|
-
that._trigger('destroyed', e, data);
|
338
|
-
}
|
339
|
-
);
|
340
383
|
}
|
341
384
|
},
|
342
385
|
|
@@ -356,13 +399,6 @@
|
|
356
399
|
return this._finishedUploads;
|
357
400
|
},
|
358
401
|
|
359
|
-
_getFilesFromResponse: function (data) {
|
360
|
-
if (data.result && $.isArray(data.result.files)) {
|
361
|
-
return data.result.files;
|
362
|
-
}
|
363
|
-
return [];
|
364
|
-
},
|
365
|
-
|
366
402
|
// Link handler, that allows to download files
|
367
403
|
// by drag & drop of the links to the desktop:
|
368
404
|
_enableDragToDesktop: function () {
|
@@ -376,21 +412,10 @@
|
|
376
412
|
'DownloadURL',
|
377
413
|
[type, name, url].join(':')
|
378
414
|
);
|
379
|
-
} catch (
|
415
|
+
} catch (ignore) {}
|
380
416
|
});
|
381
417
|
},
|
382
418
|
|
383
|
-
_adjustMaxNumberOfFiles: function (operand) {
|
384
|
-
if (typeof this.options.maxNumberOfFiles === 'number') {
|
385
|
-
this.options.maxNumberOfFiles += operand;
|
386
|
-
if (this.options.maxNumberOfFiles < 1) {
|
387
|
-
this._disableFileInputButton();
|
388
|
-
} else {
|
389
|
-
this._enableFileInputButton();
|
390
|
-
}
|
391
|
-
}
|
392
|
-
},
|
393
|
-
|
394
419
|
_formatFileSize: function (bytes) {
|
395
420
|
if (typeof bytes !== 'number') {
|
396
421
|
return '';
|
@@ -422,7 +447,7 @@
|
|
422
447
|
|
423
448
|
_formatTime: function (seconds) {
|
424
449
|
var date = new Date(seconds * 1000),
|
425
|
-
days =
|
450
|
+
days = Math.floor(seconds / 86400);
|
426
451
|
days = days ? days + 'd ' : '';
|
427
452
|
return days +
|
428
453
|
('0' + date.getUTCHours()).slice(-2) + ':' +
|
@@ -446,46 +471,6 @@
|
|
446
471
|
this._formatFileSize(data.total);
|
447
472
|
},
|
448
473
|
|
449
|
-
_hasError: function (file) {
|
450
|
-
if (file.error) {
|
451
|
-
return file.error;
|
452
|
-
}
|
453
|
-
// The number of added files is subtracted from
|
454
|
-
// maxNumberOfFiles before validation, so we check if
|
455
|
-
// maxNumberOfFiles is below 0 (instead of below 1):
|
456
|
-
if (this.options.maxNumberOfFiles < 0) {
|
457
|
-
return 'Maximum number of files exceeded';
|
458
|
-
}
|
459
|
-
// Files are accepted if either the file type or the file name
|
460
|
-
// matches against the acceptFileTypes regular expression, as
|
461
|
-
// only browsers with support for the File API report the type:
|
462
|
-
if (!(this.options.acceptFileTypes.test(file.type) ||
|
463
|
-
this.options.acceptFileTypes.test(file.name))) {
|
464
|
-
return 'Filetype not allowed';
|
465
|
-
}
|
466
|
-
if (this.options.maxFileSize &&
|
467
|
-
file.size > this.options.maxFileSize) {
|
468
|
-
return 'File is too big';
|
469
|
-
}
|
470
|
-
if (typeof file.size === 'number' &&
|
471
|
-
file.size < this.options.minFileSize) {
|
472
|
-
return 'File is too small';
|
473
|
-
}
|
474
|
-
return null;
|
475
|
-
},
|
476
|
-
|
477
|
-
_validate: function (files) {
|
478
|
-
var that = this,
|
479
|
-
valid = !!files.length;
|
480
|
-
$.each(files, function (index, file) {
|
481
|
-
file.error = that._hasError(file);
|
482
|
-
if (file.error) {
|
483
|
-
valid = false;
|
484
|
-
}
|
485
|
-
});
|
486
|
-
return valid;
|
487
|
-
},
|
488
|
-
|
489
474
|
_renderTemplate: function (func, files) {
|
490
475
|
if (!func) {
|
491
476
|
return $();
|
@@ -501,57 +486,10 @@
|
|
501
486
|
return $(this.options.templatesContainer).html(result).children();
|
502
487
|
},
|
503
488
|
|
504
|
-
_renderPreview: function (file, node) {
|
505
|
-
var that = this,
|
506
|
-
options = this.options,
|
507
|
-
dfd = $.Deferred();
|
508
|
-
return ((loadImage && loadImage(
|
509
|
-
file,
|
510
|
-
function (img) {
|
511
|
-
node.append(img);
|
512
|
-
that._forceReflow(node);
|
513
|
-
that._transition(node).done(function () {
|
514
|
-
dfd.resolveWith(node);
|
515
|
-
});
|
516
|
-
if (!$.contains(that.document[0].body, node[0])) {
|
517
|
-
// If the element is not part of the DOM,
|
518
|
-
// transition events are not triggered,
|
519
|
-
// so we have to resolve manually:
|
520
|
-
dfd.resolveWith(node);
|
521
|
-
}
|
522
|
-
},
|
523
|
-
{
|
524
|
-
maxWidth: options.previewMaxWidth,
|
525
|
-
maxHeight: options.previewMaxHeight,
|
526
|
-
canvas: options.previewAsCanvas
|
527
|
-
}
|
528
|
-
)) || dfd.resolveWith(node)) && dfd;
|
529
|
-
},
|
530
|
-
|
531
489
|
_renderPreviews: function (data) {
|
532
|
-
|
533
|
-
|
534
|
-
data.context.find('.preview span').each(function (index, element) {
|
535
|
-
var file = data.files[index];
|
536
|
-
if (options.previewSourceFileTypes.test(file.type) &&
|
537
|
-
($.type(options.previewSourceMaxFileSize) !== 'number' ||
|
538
|
-
file.size < options.previewSourceMaxFileSize)) {
|
539
|
-
that._processingQueue = that._processingQueue.pipe(function () {
|
540
|
-
var dfd = $.Deferred(),
|
541
|
-
ev = $.Event('previewdone', {
|
542
|
-
target: element
|
543
|
-
});
|
544
|
-
that._renderPreview(file, $(element)).done(
|
545
|
-
function () {
|
546
|
-
that._trigger(ev.type, ev, data);
|
547
|
-
dfd.resolveWith(that);
|
548
|
-
}
|
549
|
-
);
|
550
|
-
return dfd.promise();
|
551
|
-
});
|
552
|
-
}
|
490
|
+
data.context.find('.preview').each(function (index, elm) {
|
491
|
+
$(elm).append(data.files[index].preview);
|
553
492
|
});
|
554
|
-
return this._processingQueue;
|
555
493
|
},
|
556
494
|
|
557
495
|
_renderUpload: function (files) {
|
@@ -573,20 +511,23 @@
|
|
573
511
|
var button = $(e.currentTarget),
|
574
512
|
template = button.closest('.template-upload'),
|
575
513
|
data = template.data('data');
|
576
|
-
|
577
|
-
|
514
|
+
button.prop('disabled', true);
|
515
|
+
if (data && data.submit) {
|
516
|
+
data.submit();
|
578
517
|
}
|
579
518
|
},
|
580
519
|
|
581
520
|
_cancelHandler: function (e) {
|
582
521
|
e.preventDefault();
|
583
|
-
var template = $(e.currentTarget)
|
522
|
+
var template = $(e.currentTarget)
|
523
|
+
.closest('.template-upload,.template-download'),
|
584
524
|
data = template.data('data') || {};
|
585
|
-
|
525
|
+
data.context = data.context || template;
|
526
|
+
if (data.abort) {
|
527
|
+
data.abort();
|
528
|
+
} else {
|
586
529
|
data.errorThrown = 'abort';
|
587
530
|
this._trigger('fail', e, data);
|
588
|
-
} else {
|
589
|
-
data.jqXHR.abort();
|
590
531
|
}
|
591
532
|
},
|
592
533
|
|
@@ -595,8 +536,7 @@
|
|
595
536
|
var button = $(e.currentTarget);
|
596
537
|
this._trigger('destroy', e, $.extend({
|
597
538
|
context: button.closest('.template-download'),
|
598
|
-
type: 'DELETE'
|
599
|
-
dataType: this.options.dataType
|
539
|
+
type: 'DELETE'
|
600
540
|
}, button.data()));
|
601
541
|
},
|
602
542
|
|
@@ -607,7 +547,7 @@
|
|
607
547
|
|
608
548
|
_transition: function (node) {
|
609
549
|
var dfd = $.Deferred();
|
610
|
-
if ($.support.transition && node.hasClass('fade')) {
|
550
|
+
if ($.support.transition && node.hasClass('fade') && node.is(':visible')) {
|
611
551
|
node.bind(
|
612
552
|
$.support.transition.end,
|
613
553
|
function (e) {
|
@@ -632,27 +572,28 @@
|
|
632
572
|
this._on(fileUploadButtonBar.find('.start'), {
|
633
573
|
click: function (e) {
|
634
574
|
e.preventDefault();
|
635
|
-
filesList.find('.start
|
575
|
+
filesList.find('.start').click();
|
636
576
|
}
|
637
577
|
});
|
638
578
|
this._on(fileUploadButtonBar.find('.cancel'), {
|
639
579
|
click: function (e) {
|
640
580
|
e.preventDefault();
|
641
|
-
filesList.find('.cancel
|
581
|
+
filesList.find('.cancel').click();
|
642
582
|
}
|
643
583
|
});
|
644
584
|
this._on(fileUploadButtonBar.find('.delete'), {
|
645
585
|
click: function (e) {
|
646
586
|
e.preventDefault();
|
647
|
-
filesList.find('.
|
648
|
-
.
|
587
|
+
filesList.find('.toggle:checked')
|
588
|
+
.closest('.template-download')
|
589
|
+
.find('.delete').click();
|
649
590
|
fileUploadButtonBar.find('.toggle')
|
650
591
|
.prop('checked', false);
|
651
592
|
}
|
652
593
|
});
|
653
594
|
this._on(fileUploadButtonBar.find('.toggle'), {
|
654
595
|
change: function (e) {
|
655
|
-
filesList.find('.
|
596
|
+
filesList.find('.toggle').prop(
|
656
597
|
'checked',
|
657
598
|
$(e.currentTarget).is(':checked')
|
658
599
|
);
|
@@ -662,7 +603,8 @@
|
|
662
603
|
|
663
604
|
_destroyButtonBarEventHandlers: function () {
|
664
605
|
this._off(
|
665
|
-
this.element.find('.fileupload-buttonbar
|
606
|
+
this.element.find('.fileupload-buttonbar')
|
607
|
+
.find('.start, .cancel, .delete'),
|
666
608
|
'click'
|
667
609
|
);
|
668
610
|
this._off(
|
@@ -674,9 +616,9 @@
|
|
674
616
|
_initEventHandlers: function () {
|
675
617
|
this._super();
|
676
618
|
this._on(this.options.filesContainer, {
|
677
|
-
'click .start
|
678
|
-
'click .cancel
|
679
|
-
'click .delete
|
619
|
+
'click .start': this._startHandler,
|
620
|
+
'click .cancel': this._cancelHandler,
|
621
|
+
'click .delete': this._deleteHandler
|
680
622
|
});
|
681
623
|
this._initButtonBarEventHandlers();
|
682
624
|
},
|
@@ -723,55 +665,18 @@
|
|
723
665
|
}
|
724
666
|
},
|
725
667
|
|
726
|
-
_stringToRegExp: function (str) {
|
727
|
-
var parts = str.split('/'),
|
728
|
-
modifiers = parts.pop();
|
729
|
-
parts.shift();
|
730
|
-
return new RegExp(parts.join('/'), modifiers);
|
731
|
-
},
|
732
|
-
|
733
|
-
_initRegExpOptions: function () {
|
734
|
-
var options = this.options;
|
735
|
-
if ($.type(options.acceptFileTypes) === 'string') {
|
736
|
-
options.acceptFileTypes = this._stringToRegExp(
|
737
|
-
options.acceptFileTypes
|
738
|
-
);
|
739
|
-
}
|
740
|
-
if ($.type(options.previewSourceFileTypes) === 'string') {
|
741
|
-
options.previewSourceFileTypes = this._stringToRegExp(
|
742
|
-
options.previewSourceFileTypes
|
743
|
-
);
|
744
|
-
}
|
745
|
-
},
|
746
|
-
|
747
668
|
_initSpecialOptions: function () {
|
748
669
|
this._super();
|
749
670
|
this._initFilesContainer();
|
750
671
|
this._initTemplates();
|
751
|
-
this._initRegExpOptions();
|
752
|
-
},
|
753
|
-
|
754
|
-
_setOption: function (key, value) {
|
755
|
-
this._super(key, value);
|
756
|
-
if (key === 'maxNumberOfFiles') {
|
757
|
-
this._adjustMaxNumberOfFiles(0);
|
758
|
-
}
|
759
672
|
},
|
760
673
|
|
761
674
|
_create: function () {
|
762
675
|
this._super();
|
763
|
-
this._refreshOptionsList.push(
|
764
|
-
'filesContainer',
|
765
|
-
'uploadTemplateId',
|
766
|
-
'downloadTemplateId'
|
767
|
-
);
|
768
|
-
if (!this._processingQueue) {
|
769
|
-
this._processingQueue = $.Deferred().resolveWith(this).promise();
|
770
|
-
this.process = function () {
|
771
|
-
return this._processingQueue;
|
772
|
-
};
|
773
|
-
}
|
774
676
|
this._resetFinishedDeferreds();
|
677
|
+
if (!$.support.fileInput) {
|
678
|
+
this._disableFileInputButton();
|
679
|
+
}
|
775
680
|
},
|
776
681
|
|
777
682
|
enable: function () {
|