jquery-fileupload-requirejs-rails 0.1.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.
- data/MIT-LICENSE +20 -0
- data/README.md +3 -0
- data/Rakefile +27 -0
- data/app/assets/images/loading.gif +0 -0
- data/app/assets/images/progressbar.gif +0 -0
- data/app/assets/javascripts/jquery-fileupload/basic.js +4 -0
- data/app/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js +111 -0
- data/app/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js +80 -0
- data/app/assets/javascripts/jquery-fileupload/index.js +9 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js +210 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +782 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.fileupload.js +1156 -0
- data/app/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +179 -0
- data/app/assets/javascripts/jquery-fileupload/locale.js +29 -0
- data/app/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +91 -0
- data/app/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +533 -0
- data/app/assets/javascripts/jquery-fileupload/vendor/load-image.js +121 -0
- data/app/assets/javascripts/jquery-fileupload/vendor/tmpl.js +86 -0
- data/app/assets/stylesheets/jquery.fileupload-ui.scss +84 -0
- data/lib/jquery-fileupload-requirejs-rails.rb +4 -0
- data/lib/jquery-fileupload-requirejs-rails/engine.rb +4 -0
- data/lib/jquery-fileupload-requirejs-rails/version.rb +3 -0
- data/lib/tasks/jquery-fileupload-requirejs-rails_tasks.rake +4 -0
- metadata +170 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Cre8 New Media Ltd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'JqueryFileuploadRequirejsRails'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
Binary file
|
Binary file
|
@@ -0,0 +1,111 @@
|
|
1
|
+
define(['jquery'], function ($) {
|
2
|
+
|
3
|
+
|
4
|
+
/*
|
5
|
+
* jQuery postMessage Transport Plugin 1.1
|
6
|
+
* https://github.com/blueimp/jQuery-File-Upload
|
7
|
+
*
|
8
|
+
* Copyright 2011, Sebastian Tschan
|
9
|
+
* https://blueimp.net
|
10
|
+
*
|
11
|
+
* Licensed under the MIT license:
|
12
|
+
* http://www.opensource.org/licenses/MIT
|
13
|
+
*/
|
14
|
+
|
15
|
+
/*jslint unparam: true, nomen: true */
|
16
|
+
/*global define, window, document */
|
17
|
+
|
18
|
+
'use strict';
|
19
|
+
|
20
|
+
var counter = 0,
|
21
|
+
names = [
|
22
|
+
'accepts',
|
23
|
+
'cache',
|
24
|
+
'contents',
|
25
|
+
'contentType',
|
26
|
+
'crossDomain',
|
27
|
+
'data',
|
28
|
+
'dataType',
|
29
|
+
'headers',
|
30
|
+
'ifModified',
|
31
|
+
'mimeType',
|
32
|
+
'password',
|
33
|
+
'processData',
|
34
|
+
'timeout',
|
35
|
+
'traditional',
|
36
|
+
'type',
|
37
|
+
'url',
|
38
|
+
'username'
|
39
|
+
],
|
40
|
+
convert = function (p) {
|
41
|
+
return p;
|
42
|
+
};
|
43
|
+
|
44
|
+
$.ajaxSetup({
|
45
|
+
converters: {
|
46
|
+
'postmessage text': convert,
|
47
|
+
'postmessage json': convert,
|
48
|
+
'postmessage html': convert
|
49
|
+
}
|
50
|
+
});
|
51
|
+
|
52
|
+
$.ajaxTransport('postmessage', function (options) {
|
53
|
+
if (options.postMessage && window.postMessage) {
|
54
|
+
var iframe,
|
55
|
+
loc = $('<a>').prop('href', options.postMessage)[0],
|
56
|
+
target = loc.protocol + '//' + loc.host,
|
57
|
+
xhrUpload = options.xhr().upload;
|
58
|
+
return {
|
59
|
+
send: function (_, completeCallback) {
|
60
|
+
var message = {
|
61
|
+
id: 'postmessage-transport-' + (counter += 1)
|
62
|
+
},
|
63
|
+
eventName = 'message.' + message.id;
|
64
|
+
iframe = $(
|
65
|
+
'<iframe style="display:none;" src="' +
|
66
|
+
options.postMessage + '" name="' +
|
67
|
+
message.id + '"></iframe>'
|
68
|
+
).bind('load',function () {
|
69
|
+
$.each(names, function (i, name) {
|
70
|
+
message[name] = options[name];
|
71
|
+
});
|
72
|
+
message.dataType = message.dataType.replace('postmessage ', '');
|
73
|
+
$(window).bind(eventName, function (e) {
|
74
|
+
e = e.originalEvent;
|
75
|
+
var data = e.data,
|
76
|
+
ev;
|
77
|
+
if (e.origin === target && data.id === message.id) {
|
78
|
+
if (data.type === 'progress') {
|
79
|
+
ev = document.createEvent('Event');
|
80
|
+
ev.initEvent(data.type, false, true);
|
81
|
+
$.extend(ev, data);
|
82
|
+
xhrUpload.dispatchEvent(ev);
|
83
|
+
} else {
|
84
|
+
completeCallback(
|
85
|
+
data.status,
|
86
|
+
data.statusText,
|
87
|
+
{postmessage: data.result},
|
88
|
+
data.headers
|
89
|
+
);
|
90
|
+
iframe.remove();
|
91
|
+
$(window).unbind(eventName);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
});
|
95
|
+
iframe[0].contentWindow.postMessage(
|
96
|
+
message,
|
97
|
+
target
|
98
|
+
);
|
99
|
+
}).appendTo(document.body);
|
100
|
+
},
|
101
|
+
abort: function () {
|
102
|
+
if (iframe) {
|
103
|
+
iframe.remove();
|
104
|
+
}
|
105
|
+
}
|
106
|
+
};
|
107
|
+
}
|
108
|
+
});
|
109
|
+
|
110
|
+
});
|
111
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
define(['jquery'], function ($) {
|
2
|
+
|
3
|
+
/*
|
4
|
+
* jQuery XDomainRequest Transport Plugin 1.1.3
|
5
|
+
* https://github.com/blueimp/jQuery-File-Upload
|
6
|
+
*
|
7
|
+
* Copyright 2011, Sebastian Tschan
|
8
|
+
* https://blueimp.net
|
9
|
+
*
|
10
|
+
* Licensed under the MIT license:
|
11
|
+
* http://www.opensource.org/licenses/MIT
|
12
|
+
*
|
13
|
+
* Based on Julian Aubourg's ajaxHooks xdr.js:
|
14
|
+
* https://github.com/jaubourg/ajaxHooks/
|
15
|
+
*/
|
16
|
+
|
17
|
+
/*jslint unparam: true */
|
18
|
+
/*global define, window, XDomainRequest */
|
19
|
+
|
20
|
+
|
21
|
+
'use strict';
|
22
|
+
if (window.XDomainRequest && !$.support.cors) {
|
23
|
+
$.ajaxTransport(function (s) {
|
24
|
+
if (s.crossDomain && s.async) {
|
25
|
+
if (s.timeout) {
|
26
|
+
s.xdrTimeout = s.timeout;
|
27
|
+
delete s.timeout;
|
28
|
+
}
|
29
|
+
var xdr;
|
30
|
+
return {
|
31
|
+
send: function (headers, completeCallback) {
|
32
|
+
var addParamChar = /\?/.test(s.url) ? '&' : '?';
|
33
|
+
function callback(status, statusText, responses, responseHeaders) {
|
34
|
+
xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
|
35
|
+
xdr = null;
|
36
|
+
completeCallback(status, statusText, responses, responseHeaders);
|
37
|
+
}
|
38
|
+
xdr = new XDomainRequest();
|
39
|
+
// XDomainRequest only supports GET and POST:
|
40
|
+
if (s.type === 'DELETE') {
|
41
|
+
s.url = s.url + addParamChar + '_method=DELETE';
|
42
|
+
s.type = 'POST';
|
43
|
+
} else if (s.type === 'PUT') {
|
44
|
+
s.url = s.url + addParamChar + '_method=PUT';
|
45
|
+
s.type = 'POST';
|
46
|
+
} else if (s.type === 'PATCH') {
|
47
|
+
s.url = s.url + addParamChar + '_method=PATCH';
|
48
|
+
s.type = 'POST';
|
49
|
+
}
|
50
|
+
xdr.open(s.type, s.url);
|
51
|
+
xdr.onload = function () {
|
52
|
+
callback(
|
53
|
+
200,
|
54
|
+
'OK',
|
55
|
+
{text: xdr.responseText},
|
56
|
+
'Content-Type: ' + xdr.contentType
|
57
|
+
);
|
58
|
+
};
|
59
|
+
xdr.onerror = function () {
|
60
|
+
callback(404, 'Not Found');
|
61
|
+
};
|
62
|
+
if (s.xdrTimeout) {
|
63
|
+
xdr.ontimeout = function () {
|
64
|
+
callback(0, 'timeout');
|
65
|
+
};
|
66
|
+
xdr.timeout = s.xdrTimeout;
|
67
|
+
}
|
68
|
+
xdr.send((s.hasContent && s.data) || null);
|
69
|
+
},
|
70
|
+
abort: function () {
|
71
|
+
if (xdr) {
|
72
|
+
xdr.onerror = $.noop();
|
73
|
+
xdr.abort();
|
74
|
+
}
|
75
|
+
}
|
76
|
+
};
|
77
|
+
}
|
78
|
+
});
|
79
|
+
}
|
80
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
//=require jquery-fileupload/vendor/jquery.ui.widget
|
2
|
+
//=require jquery-fileupload/vendor/load-image
|
3
|
+
//=require jquery-fileupload/vendor/canvas-to-blob
|
4
|
+
//=require jquery-fileupload/vendor/tmpl
|
5
|
+
//=require jquery-fileupload/jquery.iframe-transport
|
6
|
+
//=require jquery-fileupload/jquery.fileupload
|
7
|
+
//=require jquery-fileupload/jquery.fileupload-fp
|
8
|
+
//=require jquery-fileupload/jquery.fileupload-ui
|
9
|
+
//=require jquery-fileupload/locale
|
@@ -0,0 +1,210 @@
|
|
1
|
+
define(['jquery', './vendor/load-image', './vendor/canvas-to-blob', './jquery.fileupload'], function ($, loadImage) {
|
2
|
+
|
3
|
+
|
4
|
+
/*
|
5
|
+
* jQuery File Upload File Processing Plugin 1.2.1
|
6
|
+
* https://github.com/blueimp/jQuery-File-Upload
|
7
|
+
*
|
8
|
+
* Copyright 2012, Sebastian Tschan
|
9
|
+
* https://blueimp.net
|
10
|
+
*
|
11
|
+
* Licensed under the MIT license:
|
12
|
+
* http://www.opensource.org/licenses/MIT
|
13
|
+
*/
|
14
|
+
|
15
|
+
/*jslint nomen: true, unparam: true, regexp: true */
|
16
|
+
/*global define, window, document */
|
17
|
+
|
18
|
+
'use strict';
|
19
|
+
|
20
|
+
// The File Upload FP version extends the fileupload widget
|
21
|
+
// with file processing functionality:
|
22
|
+
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
|
23
|
+
|
24
|
+
options: {
|
25
|
+
// The list of file processing actions:
|
26
|
+
process: [
|
27
|
+
/*
|
28
|
+
{
|
29
|
+
action: 'load',
|
30
|
+
fileTypes: /^image\/(gif|jpeg|png)$/,
|
31
|
+
maxFileSize: 20000000 // 20MB
|
32
|
+
},
|
33
|
+
{
|
34
|
+
action: 'resize',
|
35
|
+
maxWidth: 1920,
|
36
|
+
maxHeight: 1200,
|
37
|
+
minWidth: 800,
|
38
|
+
minHeight: 600
|
39
|
+
},
|
40
|
+
{
|
41
|
+
action: 'save'
|
42
|
+
}
|
43
|
+
*/
|
44
|
+
],
|
45
|
+
|
46
|
+
// The add callback is invoked as soon as files are added to the
|
47
|
+
// fileupload widget (via file input selection, drag & drop or add
|
48
|
+
// API call). See the basic file upload widget for more information:
|
49
|
+
add: function (e, data) {
|
50
|
+
$(this).fileupload('process', data).done(function () {
|
51
|
+
data.submit();
|
52
|
+
});
|
53
|
+
}
|
54
|
+
},
|
55
|
+
|
56
|
+
processActions: {
|
57
|
+
// Loads the image given via data.files and data.index
|
58
|
+
// as img element if the browser supports canvas.
|
59
|
+
// Accepts the options fileTypes (regular expression)
|
60
|
+
// and maxFileSize (integer) to limit the files to load:
|
61
|
+
load: function (data, options) {
|
62
|
+
var that = this,
|
63
|
+
file = data.files[data.index],
|
64
|
+
dfd = $.Deferred();
|
65
|
+
if (window.HTMLCanvasElement &&
|
66
|
+
window.HTMLCanvasElement.prototype.toBlob &&
|
67
|
+
($.type(options.maxFileSize) !== 'number' ||
|
68
|
+
file.size < options.maxFileSize) &&
|
69
|
+
(!options.fileTypes ||
|
70
|
+
options.fileTypes.test(file.type))) {
|
71
|
+
loadImage(
|
72
|
+
file,
|
73
|
+
function (img) {
|
74
|
+
if (!img.src) {
|
75
|
+
return dfd.rejectWith(that, [data]);
|
76
|
+
}
|
77
|
+
data.img = img;
|
78
|
+
dfd.resolveWith(that, [data]);
|
79
|
+
}
|
80
|
+
);
|
81
|
+
} else {
|
82
|
+
dfd.rejectWith(that, [data]);
|
83
|
+
}
|
84
|
+
return dfd.promise();
|
85
|
+
},
|
86
|
+
// Resizes the image given as data.img and updates
|
87
|
+
// data.canvas with the resized image as canvas element.
|
88
|
+
// Accepts the options maxWidth, maxHeight, minWidth and
|
89
|
+
// minHeight to scale the given image:
|
90
|
+
resize: function (data, options) {
|
91
|
+
var img = data.img,
|
92
|
+
canvas;
|
93
|
+
options = $.extend({canvas: true}, options);
|
94
|
+
if (img) {
|
95
|
+
canvas = loadImage.scale(img, options);
|
96
|
+
if (canvas.width !== img.width ||
|
97
|
+
canvas.height !== img.height) {
|
98
|
+
data.canvas = canvas;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
return data;
|
102
|
+
},
|
103
|
+
// Saves the processed image given as data.canvas
|
104
|
+
// inplace at data.index of data.files:
|
105
|
+
save: function (data, options) {
|
106
|
+
// Do nothing if no processing has happened:
|
107
|
+
if (!data.canvas) {
|
108
|
+
return data;
|
109
|
+
}
|
110
|
+
var that = this,
|
111
|
+
file = data.files[data.index],
|
112
|
+
name = file.name,
|
113
|
+
dfd = $.Deferred(),
|
114
|
+
callback = function (blob) {
|
115
|
+
if (!blob.name) {
|
116
|
+
if (file.type === blob.type) {
|
117
|
+
blob.name = file.name;
|
118
|
+
} else if (file.name) {
|
119
|
+
blob.name = file.name.replace(
|
120
|
+
/\..+$/,
|
121
|
+
'.' + blob.type.substr(6)
|
122
|
+
);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
// Store the created blob at the position
|
126
|
+
// of the original file in the files list:
|
127
|
+
data.files[data.index] = blob;
|
128
|
+
dfd.resolveWith(that, [data]);
|
129
|
+
};
|
130
|
+
// Use canvas.mozGetAsFile directly, to retain the filename, as
|
131
|
+
// Gecko doesn't support the filename option for FormData.append:
|
132
|
+
if (data.canvas.mozGetAsFile) {
|
133
|
+
callback(data.canvas.mozGetAsFile(
|
134
|
+
(/^image\/(jpeg|png)$/.test(file.type) && name) ||
|
135
|
+
((name && name.replace(/\..+$/, '')) ||
|
136
|
+
'blob') + '.png',
|
137
|
+
file.type
|
138
|
+
));
|
139
|
+
} else {
|
140
|
+
data.canvas.toBlob(callback, file.type);
|
141
|
+
}
|
142
|
+
return dfd.promise();
|
143
|
+
}
|
144
|
+
},
|
145
|
+
|
146
|
+
// Resizes the file at the given index and stores the created blob at
|
147
|
+
// the original position of the files list, returns a Promise object:
|
148
|
+
_processFile: function (files, index, options) {
|
149
|
+
var that = this,
|
150
|
+
dfd = $.Deferred().resolveWith(that, [
|
151
|
+
{
|
152
|
+
files: files,
|
153
|
+
index: index
|
154
|
+
}
|
155
|
+
]),
|
156
|
+
chain = dfd.promise();
|
157
|
+
that._processing += 1;
|
158
|
+
$.each(options.process, function (i, settings) {
|
159
|
+
chain = chain.pipe(function (data) {
|
160
|
+
return that.processActions[settings.action]
|
161
|
+
.call(this, data, settings);
|
162
|
+
});
|
163
|
+
});
|
164
|
+
chain.always(function () {
|
165
|
+
that._processing -= 1;
|
166
|
+
if (that._processing === 0) {
|
167
|
+
that.element
|
168
|
+
.removeClass('fileupload-processing');
|
169
|
+
}
|
170
|
+
});
|
171
|
+
if (that._processing === 1) {
|
172
|
+
that.element.addClass('fileupload-processing');
|
173
|
+
}
|
174
|
+
return chain;
|
175
|
+
},
|
176
|
+
|
177
|
+
// Processes the files given as files property of the data parameter,
|
178
|
+
// returns a Promise object that allows to bind a done handler, which
|
179
|
+
// will be invoked after processing all files (inplace) is done:
|
180
|
+
process: function (data) {
|
181
|
+
var that = this,
|
182
|
+
options = $.extend({}, this.options, data);
|
183
|
+
if (options.process && options.process.length &&
|
184
|
+
this._isXHRUpload(options)) {
|
185
|
+
$.each(data.files, function (index, file) {
|
186
|
+
that._processingQueue = that._processingQueue.pipe(
|
187
|
+
function () {
|
188
|
+
var dfd = $.Deferred();
|
189
|
+
that._processFile(data.files, index, options)
|
190
|
+
.always(function () {
|
191
|
+
dfd.resolveWith(that);
|
192
|
+
});
|
193
|
+
return dfd.promise();
|
194
|
+
}
|
195
|
+
);
|
196
|
+
});
|
197
|
+
}
|
198
|
+
return this._processingQueue;
|
199
|
+
},
|
200
|
+
|
201
|
+
_create: function () {
|
202
|
+
this._super();
|
203
|
+
this._processing = 0;
|
204
|
+
this._processingQueue = $.Deferred().resolveWith(this)
|
205
|
+
.promise();
|
206
|
+
}
|
207
|
+
|
208
|
+
});
|
209
|
+
|
210
|
+
});
|