jquery-file-upload-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +55 -0
- data/Rakefile +32 -0
- data/app/views/jquery_file_upload/basic_plus_ui/_download.html.erb +43 -0
- data/app/views/jquery_file_upload/basic_plus_ui/_form.html.haml +35 -0
- data/app/views/jquery_file_upload/basic_plus_ui/_upload.html.erb +32 -0
- data/config/locales/jquery_file_upload.cs.yml +16 -0
- data/config/locales/jquery_file_upload.en.yml +16 -0
- data/lib/jquery-file-upload-rails.rb +1 -0
- data/lib/jquery_file_upload/rails.rb +6 -0
- data/lib/jquery_file_upload/rails/version.rb +5 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +22 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/jquery_file_upload_rails_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/vendor/assets/images/jquery-file-upload/loading.gif +0 -0
- data/vendor/assets/images/jquery-file-upload/progressbar.gif +0 -0
- data/vendor/assets/javascripts/jquery-file-upload/app.js +101 -0
- data/vendor/assets/javascripts/jquery-file-upload/basic-plus-ui-no-widget.js.coffee +35 -0
- data/vendor/assets/javascripts/jquery-file-upload/basic-plus-ui.js.coffee +38 -0
- data/vendor/assets/javascripts/jquery-file-upload/cors/jquery.postmessage-transport.js +118 -0
- data/vendor/assets/javascripts/jquery-file-upload/cors/jquery.xdr-transport.js +87 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-angular.js +428 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-audio.js +106 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-image.js +295 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-jquery-ui.js +144 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-process.js +172 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-ui.js +699 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-validate.js +120 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-video.js +106 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload.js +1416 -0
- data/vendor/assets/javascripts/jquery-file-upload/jquery.iframe-transport.js +210 -0
- data/vendor/assets/javascripts/jquery-file-upload/main.js.coffee +4 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob.js +95 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob.min.js +1 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/jquery.ui.widget.js +530 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/demo.js +138 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-exif-map.js +384 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-exif.js +299 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-ios.js +181 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-meta.js +137 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-orientation.js +159 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image.js +276 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image.min.js +1 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/vendor/jquery.Jcrop.js +1694 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/compile.js +84 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/demo.js +48 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/runtime.js +47 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/tmpl.js +87 -0
- data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/tmpl.min.js +1 -0
- data/vendor/assets/stylesheets/jquery-file-upload/demo-ie8.css +21 -0
- data/vendor/assets/stylesheets/jquery-file-upload/demo.css +67 -0
- data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-noscript.css +22 -0
- data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui-noscript.css +17 -0
- data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui.css.scss +57 -0
- data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload.css +36 -0
- data/vendor/assets/stylesheets/jquery-file-upload/style.css +15 -0
- metadata +196 -0
@@ -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
|
+
/*jslint nomen: true, unparam: true */
|
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
|
+
}));
|
@@ -0,0 +1,699 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery File Upload User Interface Plugin 9.0.0
|
3
|
+
* https://github.com/blueimp/jQuery-File-Upload
|
4
|
+
*
|
5
|
+
* Copyright 2010, 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, URL, webkitURL, FileReader */
|
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
|
+
'tmpl',
|
22
|
+
'./jquery.fileupload-image',
|
23
|
+
'./jquery.fileupload-audio',
|
24
|
+
'./jquery.fileupload-video',
|
25
|
+
'./jquery.fileupload-validate'
|
26
|
+
], factory);
|
27
|
+
} else {
|
28
|
+
// Browser globals:
|
29
|
+
factory(
|
30
|
+
window.jQuery,
|
31
|
+
window.tmpl
|
32
|
+
);
|
33
|
+
}
|
34
|
+
}(function ($, tmpl, loadImage) {
|
35
|
+
'use strict';
|
36
|
+
|
37
|
+
$.blueimp.fileupload.prototype._specialOptions.push(
|
38
|
+
'filesContainer',
|
39
|
+
'uploadTemplateId',
|
40
|
+
'downloadTemplateId'
|
41
|
+
);
|
42
|
+
|
43
|
+
// The UI version extends the file upload widget
|
44
|
+
// and adds complete user interface interaction:
|
45
|
+
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
|
46
|
+
|
47
|
+
options: {
|
48
|
+
// By default, files added to the widget are uploaded as soon
|
49
|
+
// as the user clicks on the start buttons. To enable automatic
|
50
|
+
// uploads, set the following option to true:
|
51
|
+
autoUpload: false,
|
52
|
+
// The ID of the upload template:
|
53
|
+
uploadTemplateId: 'template-upload',
|
54
|
+
// The ID of the download template:
|
55
|
+
downloadTemplateId: 'template-download',
|
56
|
+
// The container for the list of files. If undefined, it is set to
|
57
|
+
// an element with class "files" inside of the widget element:
|
58
|
+
filesContainer: undefined,
|
59
|
+
// By default, files are appended to the files container.
|
60
|
+
// Set the following option to true, to prepend files instead:
|
61
|
+
prependFiles: false,
|
62
|
+
// The expected data type of the upload response, sets the dataType
|
63
|
+
// option of the $.ajax upload requests:
|
64
|
+
dataType: 'json',
|
65
|
+
|
66
|
+
// Function returning the current number of files,
|
67
|
+
// used by the maxNumberOfFiles validation:
|
68
|
+
getNumberOfFiles: function () {
|
69
|
+
return this.filesContainer.children()
|
70
|
+
.not('.processing').length;
|
71
|
+
},
|
72
|
+
|
73
|
+
// Callback to retrieve the list of files from the server response:
|
74
|
+
getFilesFromResponse: function (data) {
|
75
|
+
if (data.result && $.isArray(data.result.files)) {
|
76
|
+
return data.result.files;
|
77
|
+
}
|
78
|
+
return [];
|
79
|
+
},
|
80
|
+
|
81
|
+
// The add callback is invoked as soon as files are added to the fileupload
|
82
|
+
// widget (via file input selection, drag & drop or add API call).
|
83
|
+
// See the basic file upload widget for more information:
|
84
|
+
add: function (e, data) {
|
85
|
+
if (e.isDefaultPrevented()) {
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
var $this = $(this),
|
89
|
+
that = $this.data('blueimp-fileupload') ||
|
90
|
+
$this.data('fileupload'),
|
91
|
+
options = that.options;
|
92
|
+
data.context = that._renderUpload(data.files)
|
93
|
+
.data('data', data)
|
94
|
+
.addClass('processing');
|
95
|
+
options.filesContainer[
|
96
|
+
options.prependFiles ? 'prepend' : 'append'
|
97
|
+
](data.context);
|
98
|
+
that._forceReflow(data.context);
|
99
|
+
$.when(
|
100
|
+
that._transition(data.context),
|
101
|
+
data.process(function () {
|
102
|
+
return $this.fileupload('process', data);
|
103
|
+
})
|
104
|
+
).always(function () {
|
105
|
+
data.context.each(function (index) {
|
106
|
+
$(this).find('.size').text(
|
107
|
+
that._formatFileSize(data.files[index].size)
|
108
|
+
);
|
109
|
+
}).removeClass('processing');
|
110
|
+
that._renderPreviews(data);
|
111
|
+
}).done(function () {
|
112
|
+
data.context.find('.start').prop('disabled', false);
|
113
|
+
if ((that._trigger('added', e, data) !== false) &&
|
114
|
+
(options.autoUpload || data.autoUpload) &&
|
115
|
+
data.autoUpload !== false) {
|
116
|
+
data.submit();
|
117
|
+
}
|
118
|
+
}).fail(function () {
|
119
|
+
if (data.files.error) {
|
120
|
+
data.context.each(function (index) {
|
121
|
+
var error = data.files[index].error;
|
122
|
+
if (error) {
|
123
|
+
$(this).find('.error').text(error);
|
124
|
+
}
|
125
|
+
});
|
126
|
+
}
|
127
|
+
});
|
128
|
+
},
|
129
|
+
// Callback for the start of each file upload request:
|
130
|
+
send: function (e, data) {
|
131
|
+
if (e.isDefaultPrevented()) {
|
132
|
+
return false;
|
133
|
+
}
|
134
|
+
var that = $(this).data('blueimp-fileupload') ||
|
135
|
+
$(this).data('fileupload');
|
136
|
+
if (data.context && data.dataType &&
|
137
|
+
data.dataType.substr(0, 6) === 'iframe') {
|
138
|
+
// Iframe Transport does not support progress events.
|
139
|
+
// In lack of an indeterminate progress bar, we set
|
140
|
+
// the progress to 100%, showing the full animated bar:
|
141
|
+
data.context
|
142
|
+
.find('.progress').addClass(
|
143
|
+
!$.support.transition && 'progress-animated'
|
144
|
+
)
|
145
|
+
.attr('aria-valuenow', 100)
|
146
|
+
.children().first().css(
|
147
|
+
'width',
|
148
|
+
'100%'
|
149
|
+
);
|
150
|
+
}
|
151
|
+
return that._trigger('sent', e, data);
|
152
|
+
},
|
153
|
+
// Callback for successful uploads:
|
154
|
+
done: function (e, data) {
|
155
|
+
if (e.isDefaultPrevented()) {
|
156
|
+
return false;
|
157
|
+
}
|
158
|
+
var that = $(this).data('blueimp-fileupload') ||
|
159
|
+
$(this).data('fileupload'),
|
160
|
+
getFilesFromResponse = data.getFilesFromResponse ||
|
161
|
+
that.options.getFilesFromResponse,
|
162
|
+
files = getFilesFromResponse(data),
|
163
|
+
template,
|
164
|
+
deferred;
|
165
|
+
if (data.context) {
|
166
|
+
data.context.each(function (index) {
|
167
|
+
var file = files[index] ||
|
168
|
+
{error: 'Empty file upload result'};
|
169
|
+
deferred = that._addFinishedDeferreds();
|
170
|
+
that._transition($(this)).done(
|
171
|
+
function () {
|
172
|
+
var node = $(this);
|
173
|
+
template = that._renderDownload([file])
|
174
|
+
.replaceAll(node);
|
175
|
+
that._forceReflow(template);
|
176
|
+
that._transition(template).done(
|
177
|
+
function () {
|
178
|
+
data.context = $(this);
|
179
|
+
that._trigger('completed', e, data);
|
180
|
+
that._trigger('finished', e, data);
|
181
|
+
deferred.resolve();
|
182
|
+
}
|
183
|
+
);
|
184
|
+
}
|
185
|
+
);
|
186
|
+
});
|
187
|
+
} else {
|
188
|
+
template = that._renderDownload(files)[
|
189
|
+
that.options.prependFiles ? 'prependTo' : 'appendTo'
|
190
|
+
](that.options.filesContainer);
|
191
|
+
that._forceReflow(template);
|
192
|
+
deferred = that._addFinishedDeferreds();
|
193
|
+
that._transition(template).done(
|
194
|
+
function () {
|
195
|
+
data.context = $(this);
|
196
|
+
that._trigger('completed', e, data);
|
197
|
+
that._trigger('finished', e, data);
|
198
|
+
deferred.resolve();
|
199
|
+
}
|
200
|
+
);
|
201
|
+
}
|
202
|
+
},
|
203
|
+
// Callback for failed (abort or error) uploads:
|
204
|
+
fail: function (e, data) {
|
205
|
+
if (e.isDefaultPrevented()) {
|
206
|
+
return false;
|
207
|
+
}
|
208
|
+
var that = $(this).data('blueimp-fileupload') ||
|
209
|
+
$(this).data('fileupload'),
|
210
|
+
template,
|
211
|
+
deferred;
|
212
|
+
if (data.context) {
|
213
|
+
data.context.each(function (index) {
|
214
|
+
if (data.errorThrown !== 'abort') {
|
215
|
+
var file = data.files[index];
|
216
|
+
file.error = file.error || data.errorThrown ||
|
217
|
+
true;
|
218
|
+
deferred = that._addFinishedDeferreds();
|
219
|
+
that._transition($(this)).done(
|
220
|
+
function () {
|
221
|
+
var node = $(this);
|
222
|
+
template = that._renderDownload([file])
|
223
|
+
.replaceAll(node);
|
224
|
+
that._forceReflow(template);
|
225
|
+
that._transition(template).done(
|
226
|
+
function () {
|
227
|
+
data.context = $(this);
|
228
|
+
that._trigger('failed', e, data);
|
229
|
+
that._trigger('finished', e, data);
|
230
|
+
deferred.resolve();
|
231
|
+
}
|
232
|
+
);
|
233
|
+
}
|
234
|
+
);
|
235
|
+
} else {
|
236
|
+
deferred = that._addFinishedDeferreds();
|
237
|
+
that._transition($(this)).done(
|
238
|
+
function () {
|
239
|
+
$(this).remove();
|
240
|
+
that._trigger('failed', e, data);
|
241
|
+
that._trigger('finished', e, data);
|
242
|
+
deferred.resolve();
|
243
|
+
}
|
244
|
+
);
|
245
|
+
}
|
246
|
+
});
|
247
|
+
} else if (data.errorThrown !== 'abort') {
|
248
|
+
data.context = that._renderUpload(data.files)[
|
249
|
+
that.options.prependFiles ? 'prependTo' : 'appendTo'
|
250
|
+
](that.options.filesContainer)
|
251
|
+
.data('data', data);
|
252
|
+
that._forceReflow(data.context);
|
253
|
+
deferred = that._addFinishedDeferreds();
|
254
|
+
that._transition(data.context).done(
|
255
|
+
function () {
|
256
|
+
data.context = $(this);
|
257
|
+
that._trigger('failed', e, data);
|
258
|
+
that._trigger('finished', e, data);
|
259
|
+
deferred.resolve();
|
260
|
+
}
|
261
|
+
);
|
262
|
+
} else {
|
263
|
+
that._trigger('failed', e, data);
|
264
|
+
that._trigger('finished', e, data);
|
265
|
+
that._addFinishedDeferreds().resolve();
|
266
|
+
}
|
267
|
+
},
|
268
|
+
// Callback for upload progress events:
|
269
|
+
progress: function (e, data) {
|
270
|
+
if (e.isDefaultPrevented()) {
|
271
|
+
return false;
|
272
|
+
}
|
273
|
+
var progress = Math.floor(data.loaded / data.total * 100);
|
274
|
+
if (data.context) {
|
275
|
+
data.context.each(function () {
|
276
|
+
$(this).find('.progress')
|
277
|
+
.attr('aria-valuenow', progress)
|
278
|
+
.children().first().css(
|
279
|
+
'width',
|
280
|
+
progress + '%'
|
281
|
+
);
|
282
|
+
});
|
283
|
+
}
|
284
|
+
},
|
285
|
+
// Callback for global upload progress events:
|
286
|
+
progressall: function (e, data) {
|
287
|
+
if (e.isDefaultPrevented()) {
|
288
|
+
return false;
|
289
|
+
}
|
290
|
+
var $this = $(this),
|
291
|
+
progress = Math.floor(data.loaded / data.total * 100),
|
292
|
+
globalProgressNode = $this.find('.fileupload-progress'),
|
293
|
+
extendedProgressNode = globalProgressNode
|
294
|
+
.find('.progress-extended');
|
295
|
+
if (extendedProgressNode.length) {
|
296
|
+
extendedProgressNode.html(
|
297
|
+
($this.data('blueimp-fileupload') || $this.data('fileupload'))
|
298
|
+
._renderExtendedProgress(data)
|
299
|
+
);
|
300
|
+
}
|
301
|
+
globalProgressNode
|
302
|
+
.find('.progress')
|
303
|
+
.attr('aria-valuenow', progress)
|
304
|
+
.children().first().css(
|
305
|
+
'width',
|
306
|
+
progress + '%'
|
307
|
+
);
|
308
|
+
},
|
309
|
+
// Callback for uploads start, equivalent to the global ajaxStart event:
|
310
|
+
start: function (e) {
|
311
|
+
if (e.isDefaultPrevented()) {
|
312
|
+
return false;
|
313
|
+
}
|
314
|
+
var that = $(this).data('blueimp-fileupload') ||
|
315
|
+
$(this).data('fileupload');
|
316
|
+
that._resetFinishedDeferreds();
|
317
|
+
that._transition($(this).find('.fileupload-progress')).done(
|
318
|
+
function () {
|
319
|
+
that._trigger('started', e);
|
320
|
+
}
|
321
|
+
);
|
322
|
+
},
|
323
|
+
// Callback for uploads stop, equivalent to the global ajaxStop event:
|
324
|
+
stop: function (e) {
|
325
|
+
if (e.isDefaultPrevented()) {
|
326
|
+
return false;
|
327
|
+
}
|
328
|
+
var that = $(this).data('blueimp-fileupload') ||
|
329
|
+
$(this).data('fileupload'),
|
330
|
+
deferred = that._addFinishedDeferreds();
|
331
|
+
$.when.apply($, that._getFinishedDeferreds())
|
332
|
+
.done(function () {
|
333
|
+
that._trigger('stopped', e);
|
334
|
+
});
|
335
|
+
that._transition($(this).find('.fileupload-progress')).done(
|
336
|
+
function () {
|
337
|
+
$(this).find('.progress')
|
338
|
+
.attr('aria-valuenow', '0')
|
339
|
+
.children().first().css('width', '0%');
|
340
|
+
$(this).find('.progress-extended').html(' ');
|
341
|
+
deferred.resolve();
|
342
|
+
}
|
343
|
+
);
|
344
|
+
},
|
345
|
+
processstart: function (e) {
|
346
|
+
if (e.isDefaultPrevented()) {
|
347
|
+
return false;
|
348
|
+
}
|
349
|
+
$(this).addClass('fileupload-processing');
|
350
|
+
},
|
351
|
+
processstop: function (e) {
|
352
|
+
if (e.isDefaultPrevented()) {
|
353
|
+
return false;
|
354
|
+
}
|
355
|
+
$(this).removeClass('fileupload-processing');
|
356
|
+
},
|
357
|
+
// Callback for file deletion:
|
358
|
+
destroy: function (e, data) {
|
359
|
+
if (e.isDefaultPrevented()) {
|
360
|
+
return false;
|
361
|
+
}
|
362
|
+
var that = $(this).data('blueimp-fileupload') ||
|
363
|
+
$(this).data('fileupload'),
|
364
|
+
removeNode = function () {
|
365
|
+
that._transition(data.context).done(
|
366
|
+
function () {
|
367
|
+
$(this).remove();
|
368
|
+
that._trigger('destroyed', e, data);
|
369
|
+
}
|
370
|
+
);
|
371
|
+
};
|
372
|
+
if (data.url) {
|
373
|
+
data.dataType = data.dataType || that.options.dataType;
|
374
|
+
$.ajax(data).done(removeNode);
|
375
|
+
} else {
|
376
|
+
removeNode();
|
377
|
+
}
|
378
|
+
}
|
379
|
+
},
|
380
|
+
|
381
|
+
_resetFinishedDeferreds: function () {
|
382
|
+
this._finishedUploads = [];
|
383
|
+
},
|
384
|
+
|
385
|
+
_addFinishedDeferreds: function (deferred) {
|
386
|
+
if (!deferred) {
|
387
|
+
deferred = $.Deferred();
|
388
|
+
}
|
389
|
+
this._finishedUploads.push(deferred);
|
390
|
+
return deferred;
|
391
|
+
},
|
392
|
+
|
393
|
+
_getFinishedDeferreds: function () {
|
394
|
+
return this._finishedUploads;
|
395
|
+
},
|
396
|
+
|
397
|
+
// Link handler, that allows to download files
|
398
|
+
// by drag & drop of the links to the desktop:
|
399
|
+
_enableDragToDesktop: function () {
|
400
|
+
var link = $(this),
|
401
|
+
url = link.prop('href'),
|
402
|
+
name = link.prop('download'),
|
403
|
+
type = 'application/octet-stream';
|
404
|
+
link.bind('dragstart', function (e) {
|
405
|
+
try {
|
406
|
+
e.originalEvent.dataTransfer.setData(
|
407
|
+
'DownloadURL',
|
408
|
+
[type, name, url].join(':')
|
409
|
+
);
|
410
|
+
} catch (ignore) {}
|
411
|
+
});
|
412
|
+
},
|
413
|
+
|
414
|
+
_formatFileSize: function (bytes) {
|
415
|
+
if (typeof bytes !== 'number') {
|
416
|
+
return '';
|
417
|
+
}
|
418
|
+
if (bytes >= 1000000000) {
|
419
|
+
return (bytes / 1000000000).toFixed(2) + ' GB';
|
420
|
+
}
|
421
|
+
if (bytes >= 1000000) {
|
422
|
+
return (bytes / 1000000).toFixed(2) + ' MB';
|
423
|
+
}
|
424
|
+
return (bytes / 1000).toFixed(2) + ' KB';
|
425
|
+
},
|
426
|
+
|
427
|
+
_formatBitrate: function (bits) {
|
428
|
+
if (typeof bits !== 'number') {
|
429
|
+
return '';
|
430
|
+
}
|
431
|
+
if (bits >= 1000000000) {
|
432
|
+
return (bits / 1000000000).toFixed(2) + ' Gbit/s';
|
433
|
+
}
|
434
|
+
if (bits >= 1000000) {
|
435
|
+
return (bits / 1000000).toFixed(2) + ' Mbit/s';
|
436
|
+
}
|
437
|
+
if (bits >= 1000) {
|
438
|
+
return (bits / 1000).toFixed(2) + ' kbit/s';
|
439
|
+
}
|
440
|
+
return bits.toFixed(2) + ' bit/s';
|
441
|
+
},
|
442
|
+
|
443
|
+
_formatTime: function (seconds) {
|
444
|
+
var date = new Date(seconds * 1000),
|
445
|
+
days = Math.floor(seconds / 86400);
|
446
|
+
days = days ? days + 'd ' : '';
|
447
|
+
return days +
|
448
|
+
('0' + date.getUTCHours()).slice(-2) + ':' +
|
449
|
+
('0' + date.getUTCMinutes()).slice(-2) + ':' +
|
450
|
+
('0' + date.getUTCSeconds()).slice(-2);
|
451
|
+
},
|
452
|
+
|
453
|
+
_formatPercentage: function (floatValue) {
|
454
|
+
return (floatValue * 100).toFixed(2) + ' %';
|
455
|
+
},
|
456
|
+
|
457
|
+
_renderExtendedProgress: function (data) {
|
458
|
+
return this._formatBitrate(data.bitrate) + ' | ' +
|
459
|
+
this._formatTime(
|
460
|
+
(data.total - data.loaded) * 8 / data.bitrate
|
461
|
+
) + ' | ' +
|
462
|
+
this._formatPercentage(
|
463
|
+
data.loaded / data.total
|
464
|
+
) + ' | ' +
|
465
|
+
this._formatFileSize(data.loaded) + ' / ' +
|
466
|
+
this._formatFileSize(data.total);
|
467
|
+
},
|
468
|
+
|
469
|
+
_renderTemplate: function (func, files) {
|
470
|
+
if (!func) {
|
471
|
+
return $();
|
472
|
+
}
|
473
|
+
var result = func({
|
474
|
+
files: files,
|
475
|
+
formatFileSize: this._formatFileSize,
|
476
|
+
options: this.options
|
477
|
+
});
|
478
|
+
if (result instanceof $) {
|
479
|
+
return result;
|
480
|
+
}
|
481
|
+
return $(this.options.templatesContainer).html(result).children();
|
482
|
+
},
|
483
|
+
|
484
|
+
_renderPreviews: function (data) {
|
485
|
+
data.context.find('.preview').each(function (index, elm) {
|
486
|
+
$(elm).append(data.files[index].preview);
|
487
|
+
});
|
488
|
+
},
|
489
|
+
|
490
|
+
_renderUpload: function (files) {
|
491
|
+
return this._renderTemplate(
|
492
|
+
this.options.uploadTemplate,
|
493
|
+
files
|
494
|
+
);
|
495
|
+
},
|
496
|
+
|
497
|
+
_renderDownload: function (files) {
|
498
|
+
return this._renderTemplate(
|
499
|
+
this.options.downloadTemplate,
|
500
|
+
files
|
501
|
+
).find('a[download]').each(this._enableDragToDesktop).end();
|
502
|
+
},
|
503
|
+
|
504
|
+
_startHandler: function (e) {
|
505
|
+
e.preventDefault();
|
506
|
+
var button = $(e.currentTarget),
|
507
|
+
template = button.closest('.template-upload'),
|
508
|
+
data = template.data('data');
|
509
|
+
button.prop('disabled', true);
|
510
|
+
if (data && data.submit) {
|
511
|
+
data.submit();
|
512
|
+
}
|
513
|
+
},
|
514
|
+
|
515
|
+
_cancelHandler: function (e) {
|
516
|
+
e.preventDefault();
|
517
|
+
var template = $(e.currentTarget)
|
518
|
+
.closest('.template-upload,.template-download'),
|
519
|
+
data = template.data('data') || {};
|
520
|
+
if (!data.jqXHR) {
|
521
|
+
data.context = data.context || template;
|
522
|
+
data.errorThrown = 'abort';
|
523
|
+
this._trigger('fail', e, data);
|
524
|
+
} else {
|
525
|
+
data.jqXHR.abort();
|
526
|
+
}
|
527
|
+
},
|
528
|
+
|
529
|
+
_deleteHandler: function (e) {
|
530
|
+
e.preventDefault();
|
531
|
+
var button = $(e.currentTarget);
|
532
|
+
this._trigger('destroy', e, $.extend({
|
533
|
+
context: button.closest('.template-download'),
|
534
|
+
type: 'DELETE'
|
535
|
+
}, button.data()));
|
536
|
+
},
|
537
|
+
|
538
|
+
_forceReflow: function (node) {
|
539
|
+
return $.support.transition && node.length &&
|
540
|
+
node[0].offsetWidth;
|
541
|
+
},
|
542
|
+
|
543
|
+
_transition: function (node) {
|
544
|
+
var dfd = $.Deferred();
|
545
|
+
if ($.support.transition && node.hasClass('fade') && node.is(':visible')) {
|
546
|
+
node.bind(
|
547
|
+
$.support.transition.end,
|
548
|
+
function (e) {
|
549
|
+
// Make sure we don't respond to other transitions events
|
550
|
+
// in the container element, e.g. from button elements:
|
551
|
+
if (e.target === node[0]) {
|
552
|
+
node.unbind($.support.transition.end);
|
553
|
+
dfd.resolveWith(node);
|
554
|
+
}
|
555
|
+
}
|
556
|
+
).toggleClass('in');
|
557
|
+
} else {
|
558
|
+
node.toggleClass('in');
|
559
|
+
dfd.resolveWith(node);
|
560
|
+
}
|
561
|
+
return dfd;
|
562
|
+
},
|
563
|
+
|
564
|
+
_initButtonBarEventHandlers: function () {
|
565
|
+
var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
|
566
|
+
filesList = this.options.filesContainer;
|
567
|
+
this._on(fileUploadButtonBar.find('.start'), {
|
568
|
+
click: function (e) {
|
569
|
+
e.preventDefault();
|
570
|
+
filesList.find('.start').click();
|
571
|
+
}
|
572
|
+
});
|
573
|
+
this._on(fileUploadButtonBar.find('.cancel'), {
|
574
|
+
click: function (e) {
|
575
|
+
e.preventDefault();
|
576
|
+
filesList.find('.cancel').click();
|
577
|
+
}
|
578
|
+
});
|
579
|
+
this._on(fileUploadButtonBar.find('.delete'), {
|
580
|
+
click: function (e) {
|
581
|
+
e.preventDefault();
|
582
|
+
filesList.find('.toggle:checked')
|
583
|
+
.closest('.template-download')
|
584
|
+
.find('.delete').click();
|
585
|
+
fileUploadButtonBar.find('.toggle')
|
586
|
+
.prop('checked', false);
|
587
|
+
}
|
588
|
+
});
|
589
|
+
this._on(fileUploadButtonBar.find('.toggle'), {
|
590
|
+
change: function (e) {
|
591
|
+
filesList.find('.toggle').prop(
|
592
|
+
'checked',
|
593
|
+
$(e.currentTarget).is(':checked')
|
594
|
+
);
|
595
|
+
}
|
596
|
+
});
|
597
|
+
},
|
598
|
+
|
599
|
+
_destroyButtonBarEventHandlers: function () {
|
600
|
+
this._off(
|
601
|
+
this.element.find('.fileupload-buttonbar')
|
602
|
+
.find('.start, .cancel, .delete'),
|
603
|
+
'click'
|
604
|
+
);
|
605
|
+
this._off(
|
606
|
+
this.element.find('.fileupload-buttonbar .toggle'),
|
607
|
+
'change.'
|
608
|
+
);
|
609
|
+
},
|
610
|
+
|
611
|
+
_initEventHandlers: function () {
|
612
|
+
this._super();
|
613
|
+
this._on(this.options.filesContainer, {
|
614
|
+
'click .start': this._startHandler,
|
615
|
+
'click .cancel': this._cancelHandler,
|
616
|
+
'click .delete': this._deleteHandler
|
617
|
+
});
|
618
|
+
this._initButtonBarEventHandlers();
|
619
|
+
},
|
620
|
+
|
621
|
+
_destroyEventHandlers: function () {
|
622
|
+
this._destroyButtonBarEventHandlers();
|
623
|
+
this._off(this.options.filesContainer, 'click');
|
624
|
+
this._super();
|
625
|
+
},
|
626
|
+
|
627
|
+
_enableFileInputButton: function () {
|
628
|
+
this.element.find('.fileinput-button input')
|
629
|
+
.prop('disabled', false)
|
630
|
+
.parent().removeClass('disabled');
|
631
|
+
},
|
632
|
+
|
633
|
+
_disableFileInputButton: function () {
|
634
|
+
this.element.find('.fileinput-button input')
|
635
|
+
.prop('disabled', true)
|
636
|
+
.parent().addClass('disabled');
|
637
|
+
},
|
638
|
+
|
639
|
+
_initTemplates: function () {
|
640
|
+
var options = this.options;
|
641
|
+
options.templatesContainer = this.document[0].createElement(
|
642
|
+
options.filesContainer.prop('nodeName')
|
643
|
+
);
|
644
|
+
if (tmpl) {
|
645
|
+
if (options.uploadTemplateId) {
|
646
|
+
options.uploadTemplate = tmpl(options.uploadTemplateId);
|
647
|
+
}
|
648
|
+
if (options.downloadTemplateId) {
|
649
|
+
options.downloadTemplate = tmpl(options.downloadTemplateId);
|
650
|
+
}
|
651
|
+
}
|
652
|
+
},
|
653
|
+
|
654
|
+
_initFilesContainer: function () {
|
655
|
+
var options = this.options;
|
656
|
+
if (options.filesContainer === undefined) {
|
657
|
+
options.filesContainer = this.element.find('.files');
|
658
|
+
} else if (!(options.filesContainer instanceof $)) {
|
659
|
+
options.filesContainer = $(options.filesContainer);
|
660
|
+
}
|
661
|
+
},
|
662
|
+
|
663
|
+
_initSpecialOptions: function () {
|
664
|
+
this._super();
|
665
|
+
this._initFilesContainer();
|
666
|
+
this._initTemplates();
|
667
|
+
},
|
668
|
+
|
669
|
+
_create: function () {
|
670
|
+
this._super();
|
671
|
+
this._resetFinishedDeferreds();
|
672
|
+
if (!$.support.fileInput) {
|
673
|
+
this._disableFileInputButton();
|
674
|
+
}
|
675
|
+
},
|
676
|
+
|
677
|
+
enable: function () {
|
678
|
+
var wasDisabled = false;
|
679
|
+
if (this.options.disabled) {
|
680
|
+
wasDisabled = true;
|
681
|
+
}
|
682
|
+
this._super();
|
683
|
+
if (wasDisabled) {
|
684
|
+
this.element.find('input, button').prop('disabled', false);
|
685
|
+
this._enableFileInputButton();
|
686
|
+
}
|
687
|
+
},
|
688
|
+
|
689
|
+
disable: function () {
|
690
|
+
if (!this.options.disabled) {
|
691
|
+
this.element.find('input, button').prop('disabled', true);
|
692
|
+
this._disableFileInputButton();
|
693
|
+
}
|
694
|
+
this._super();
|
695
|
+
}
|
696
|
+
|
697
|
+
});
|
698
|
+
|
699
|
+
}));
|