fileupload-rails 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fileupload-rails.gemspec
4
+ gemspec
data/INSTALL.sh ADDED
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+
3
+ SRC="../jQuery-File-Upload"
4
+ DEST="vendor/assets"
5
+
6
+ mkdir -p $DEST/images
7
+ mkdir -p $DEST/javascripts
8
+ mkdir -p $DEST/stylesheets
9
+
10
+ cp $SRC/css/* $DEST/stylesheets
11
+ cp $SRC/img/* $DEST/images
12
+ cp -R $SRC/js/* $DEST/javascripts
13
+
14
+ # We already have jquery.ui.widget.js.
15
+ rm -rf $DEST/javascripts/vendor
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Michael Schmitz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Fileupload::Rails
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fileupload-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fileupload-rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/fileupload-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Michael Schmitz"]
6
+ gem.email = ["lydianblues@gmail.com"]
7
+ gem.description = %q{jQuery-File-Upload for Rails}
8
+ gem.summary = %q{Package the jQuery-File-Upload javasscripts for Rails}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "fileupload-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Fileupload::Rails::VERSION
17
+ end
@@ -0,0 +1,8 @@
1
+ require "fileupload-rails/version"
2
+ require "fileupload-rails/rails"
3
+
4
+ module FileUpload
5
+ module Rails
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module FileUpload
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Fileupload
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
Binary file
@@ -0,0 +1,117 @@
1
+ /*
2
+ * jQuery postMessage Transport Plugin 1.1
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
+ /*jslint unparam: true, nomen: 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(['jquery'], factory);
20
+ } else {
21
+ // Browser globals:
22
+ factory(window.jQuery);
23
+ }
24
+ }(function ($) {
25
+ 'use strict';
26
+
27
+ var counter = 0,
28
+ names = [
29
+ 'accepts',
30
+ 'cache',
31
+ 'contents',
32
+ 'contentType',
33
+ 'crossDomain',
34
+ 'data',
35
+ 'dataType',
36
+ 'headers',
37
+ 'ifModified',
38
+ 'mimeType',
39
+ 'password',
40
+ 'processData',
41
+ 'timeout',
42
+ 'traditional',
43
+ 'type',
44
+ 'url',
45
+ 'username'
46
+ ],
47
+ convert = function (p) {
48
+ return p;
49
+ };
50
+
51
+ $.ajaxSetup({
52
+ converters: {
53
+ 'postmessage text': convert,
54
+ 'postmessage json': convert,
55
+ 'postmessage html': convert
56
+ }
57
+ });
58
+
59
+ $.ajaxTransport('postmessage', function (options) {
60
+ if (options.postMessage && window.postMessage) {
61
+ var iframe,
62
+ loc = $('<a>').prop('href', options.postMessage)[0],
63
+ target = loc.protocol + '//' + loc.host,
64
+ xhrUpload = options.xhr().upload;
65
+ return {
66
+ send: function (_, completeCallback) {
67
+ var message = {
68
+ id: 'postmessage-transport-' + (counter += 1)
69
+ },
70
+ eventName = 'message.' + message.id;
71
+ iframe = $(
72
+ '<iframe style="display:none;" src="' +
73
+ options.postMessage + '" name="' +
74
+ message.id + '"></iframe>'
75
+ ).bind('load', function () {
76
+ $.each(names, function (i, name) {
77
+ message[name] = options[name];
78
+ });
79
+ message.dataType = message.dataType.replace('postmessage ', '');
80
+ $(window).bind(eventName, function (e) {
81
+ e = e.originalEvent;
82
+ var data = e.data,
83
+ ev;
84
+ if (e.origin === target && data.id === message.id) {
85
+ if (data.type === 'progress') {
86
+ ev = document.createEvent('Event');
87
+ ev.initEvent(data.type, false, true);
88
+ $.extend(ev, data);
89
+ xhrUpload.dispatchEvent(ev);
90
+ } else {
91
+ completeCallback(
92
+ data.status,
93
+ data.statusText,
94
+ {postmessage: data.result},
95
+ data.headers
96
+ );
97
+ iframe.remove();
98
+ $(window).unbind(eventName);
99
+ }
100
+ }
101
+ });
102
+ iframe[0].contentWindow.postMessage(
103
+ message,
104
+ target
105
+ );
106
+ }).appendTo(document.body);
107
+ },
108
+ abort: function () {
109
+ if (iframe) {
110
+ iframe.remove();
111
+ }
112
+ }
113
+ };
114
+ }
115
+ });
116
+
117
+ }));
@@ -0,0 +1,85 @@
1
+ /*
2
+ * jQuery XDomainRequest Transport Plugin 1.1.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
+ * Based on Julian Aubourg's ajaxHooks xdr.js:
12
+ * https://github.com/jaubourg/ajaxHooks/
13
+ */
14
+
15
+ /*jslint unparam: true */
16
+ /*global define, window, XDomainRequest */
17
+
18
+ (function (factory) {
19
+ 'use strict';
20
+ if (typeof define === 'function' && define.amd) {
21
+ // Register as an anonymous AMD module:
22
+ define(['jquery'], factory);
23
+ } else {
24
+ // Browser globals:
25
+ factory(window.jQuery);
26
+ }
27
+ }(function ($) {
28
+ 'use strict';
29
+ if (window.XDomainRequest && !$.support.cors) {
30
+ $.ajaxTransport(function (s) {
31
+ if (s.crossDomain && s.async) {
32
+ if (s.timeout) {
33
+ s.xdrTimeout = s.timeout;
34
+ delete s.timeout;
35
+ }
36
+ var xdr;
37
+ return {
38
+ send: function (headers, completeCallback) {
39
+ function callback(status, statusText, responses, responseHeaders) {
40
+ xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
41
+ xdr = null;
42
+ completeCallback(status, statusText, responses, responseHeaders);
43
+ }
44
+ xdr = new XDomainRequest();
45
+ // XDomainRequest only supports GET and POST:
46
+ if (s.type === 'DELETE') {
47
+ s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
48
+ '_method=DELETE';
49
+ s.type = 'POST';
50
+ } else if (s.type === 'PUT') {
51
+ s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
52
+ '_method=PUT';
53
+ s.type = 'POST';
54
+ }
55
+ xdr.open(s.type, s.url);
56
+ xdr.onload = function () {
57
+ callback(
58
+ 200,
59
+ 'OK',
60
+ {text: xdr.responseText},
61
+ 'Content-Type: ' + xdr.contentType
62
+ );
63
+ };
64
+ xdr.onerror = function () {
65
+ callback(404, 'Not Found');
66
+ };
67
+ if (s.xdrTimeout) {
68
+ xdr.ontimeout = function () {
69
+ callback(0, 'timeout');
70
+ };
71
+ xdr.timeout = s.xdrTimeout;
72
+ }
73
+ xdr.send((s.hasContent && s.data) || null);
74
+ },
75
+ abort: function () {
76
+ if (xdr) {
77
+ xdr.onerror = $.noop();
78
+ xdr.abort();
79
+ }
80
+ }
81
+ };
82
+ }
83
+ });
84
+ }
85
+ }));
@@ -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
+ }));