jquery.fileupload-rails 1.0.0.alpha → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/Rakefile +1 -1
  2. data/Readme.md +21 -11
  3. data/demo/.gitignore +15 -0
  4. data/demo/Gemfile +39 -0
  5. data/demo/README.rdoc +261 -0
  6. data/demo/Rakefile +7 -0
  7. data/demo/app/assets/images/rails.png +0 -0
  8. data/demo/app/assets/javascripts/application.js.coffee +9 -0
  9. data/demo/app/assets/stylesheets/application.css +13 -0
  10. data/demo/app/controllers/application_controller.rb +7 -0
  11. data/demo/app/helpers/application_helper.rb +2 -0
  12. data/demo/app/mailers/.gitkeep +0 -0
  13. data/demo/app/models/.gitkeep +0 -0
  14. data/demo/app/views/application/basic.html.erb +4 -0
  15. data/demo/app/views/application/create.html.erb +1 -0
  16. data/demo/app/views/application/ui.html.erb +1 -0
  17. data/demo/app/views/layouts/application.html.erb +14 -0
  18. data/demo/config.ru +4 -0
  19. data/demo/config/application.rb +62 -0
  20. data/demo/config/boot.rb +6 -0
  21. data/demo/config/database.yml +25 -0
  22. data/demo/config/environment.rb +5 -0
  23. data/demo/config/environments/development.rb +37 -0
  24. data/demo/config/environments/production.rb +67 -0
  25. data/demo/config/environments/test.rb +37 -0
  26. data/demo/config/initializers/backtrace_silencers.rb +7 -0
  27. data/demo/config/initializers/inflections.rb +15 -0
  28. data/demo/config/initializers/mime_types.rb +5 -0
  29. data/demo/config/initializers/secret_token.rb +7 -0
  30. data/demo/config/initializers/session_store.rb +8 -0
  31. data/demo/config/initializers/wrap_parameters.rb +14 -0
  32. data/demo/config/locales/en.yml +5 -0
  33. data/demo/config/routes.rb +6 -0
  34. data/demo/db/seeds.rb +7 -0
  35. data/demo/doc/README_FOR_APP +2 -0
  36. data/demo/lib/assets/.gitkeep +0 -0
  37. data/demo/lib/tasks/.gitkeep +0 -0
  38. data/demo/log/.gitkeep +0 -0
  39. data/demo/public/404.html +26 -0
  40. data/demo/public/422.html +26 -0
  41. data/demo/public/500.html +25 -0
  42. data/demo/public/favicon.ico +0 -0
  43. data/demo/public/robots.txt +5 -0
  44. data/demo/script/rails +6 -0
  45. data/demo/test/fixtures/.gitkeep +0 -0
  46. data/demo/test/functional/.gitkeep +0 -0
  47. data/demo/test/integration/.gitkeep +0 -0
  48. data/demo/test/performance/browsing_test.rb +12 -0
  49. data/demo/test/test_helper.rb +13 -0
  50. data/demo/test/unit/.gitkeep +0 -0
  51. data/demo/vendor/plugins/.gitkeep +0 -0
  52. data/lib/jquery.fileupload-rails.rb +3 -4
  53. data/lib/jquery.fileupload-rails/version.rb +1 -1
  54. data/vendor/assets/javascripts/jquery.fileupload.js +18 -10
  55. data/vendor/legacy_assets/javascripts/jquery.fileupload-fp.js +219 -0
  56. data/vendor/legacy_assets/javascripts/jquery.fileupload-ip.js +160 -0
  57. data/vendor/legacy_assets/javascripts/jquery.fileupload-ui.js +702 -0
  58. data/vendor/legacy_assets/javascripts/jquery.postmessage-transport.js +117 -0
  59. data/vendor/legacy_assets/javascripts/jquery.xdr-transport.js +85 -0
  60. data/vendor/legacy_assets/stylesheets/jquery.fileupload-ui.css +84 -0
  61. metadata +57 -2
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
data/demo/script/rails ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
File without changes
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+ require 'rails/performance_test_help'
3
+
4
+ class BrowsingTest < ActionDispatch::PerformanceTest
5
+ # Refer to the documentation for all available options
6
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
7
+ # :output => 'tmp/performance', :formats => [:flat] }
8
+
9
+ def test_homepage
10
+ get '/'
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
+ #
8
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
+ # -- they do not yet inherit this setting
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
File without changes
File without changes
@@ -1,11 +1,10 @@
1
1
  require "jquery.fileupload-rails/version"
2
+ require "jquery-ui-rails"
2
3
 
3
4
  module JqueryFileUpload
4
5
  module Rails
5
- if defined?(::Rails) and ::Rails.version >= "3.1"
6
- class Rails::Engine < ::Rails::Engine
7
- # this class enables the asset pipeline
8
- end
6
+ class Rails::Engine < ::Rails::Engine
7
+ paths['vendor/assets'] << 'vendor/legacy_assets'
9
8
  end
10
9
  end
11
10
  end
@@ -1,5 +1,5 @@
1
1
  module JqueryFileUpload
2
2
  module Rails
3
- VERSION = "1.0.0.alpha"
3
+ VERSION = "1.0.0.beta"
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@
2
2
  //= require jquery.iframe-transport
3
3
 
4
4
  /*
5
- * jQuery File Upload Plugin 5.17.2
5
+ * jQuery File Upload Plugin 5.17.6
6
6
  * https://github.com/blueimp/jQuery-File-Upload
7
7
  *
8
8
  * Copyright 2010, Sebastian Tschan
@@ -506,9 +506,7 @@
506
506
  fs = file.size,
507
507
  ub = options.uploadedBytes = options.uploadedBytes || 0,
508
508
  mcs = options.maxChunkSize || fs,
509
- // Use the Blob methods with the slice implementation
510
- // according to the W3C Blob API specification:
511
- slice = file.webkitSlice || file.mozSlice || file.slice,
509
+ slice = file.slice || file.webkitSlice || file.mozSlice,
512
510
  upload,
513
511
  n,
514
512
  jqXHR,
@@ -521,7 +519,7 @@
521
519
  return true;
522
520
  }
523
521
  if (ub >= fs) {
524
- file.error = 'uploadedBytes';
522
+ file.error = 'Uploaded bytes exceed file size';
525
523
  return this._getXHRPromise(
526
524
  false,
527
525
  options.context,
@@ -809,10 +807,16 @@
809
807
  dirReader;
810
808
  path = path || '';
811
809
  if (entry.isFile) {
812
- entry.file(function (file) {
813
- file.relativePath = path;
814
- dfd.resolve(file);
815
- }, errorHandler);
810
+ if (entry._file) {
811
+ // Workaround for Chrome bug #149735
812
+ entry._file.relativePath = path;
813
+ dfd.resolve(entry._file);
814
+ } else {
815
+ entry.file(function (file) {
816
+ file.relativePath = path;
817
+ dfd.resolve(file);
818
+ }, errorHandler);
819
+ }
816
820
  } else if (entry.isDirectory) {
817
821
  dirReader = entry.createReader();
818
822
  dirReader.readEntries(function (entries) {
@@ -853,8 +857,12 @@
853
857
  items[0].getAsEntry)) {
854
858
  return this._handleFileTreeEntries(
855
859
  $.map(items, function (item) {
860
+ var entry;
856
861
  if (item.webkitGetAsEntry) {
857
- return item.webkitGetAsEntry();
862
+ entry = item.webkitGetAsEntry();
863
+ // Workaround for Chrome bug #149735:
864
+ entry._file = item.getAsFile();
865
+ return entry;
858
866
  }
859
867
  return item.getAsEntry();
860
868
  })
@@ -0,0 +1,219 @@
1
+ /*
2
+ * jQuery File Upload File Processing Plugin 1.0
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2012, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint nomen: true, unparam: true, regexp: true */
13
+ /*global define, window, document */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'load-image',
22
+ 'canvas-to-blob',
23
+ './jquery.fileupload'
24
+ ], factory);
25
+ } else {
26
+ // Browser globals:
27
+ factory(
28
+ window.jQuery,
29
+ window.loadImage
30
+ );
31
+ }
32
+ }(function ($, loadImage) {
33
+ 'use strict';
34
+
35
+ // The File Upload IP version extends the basic fileupload widget
36
+ // with file processing functionality:
37
+ $.widget('blueimpFP.fileupload', $.blueimp.fileupload, {
38
+
39
+ options: {
40
+ // The list of file processing actions:
41
+ process: [
42
+ /*
43
+ {
44
+ action: 'load',
45
+ fileTypes: /^image\/(gif|jpeg|png)$/,
46
+ maxFileSize: 20000000 // 20MB
47
+ },
48
+ {
49
+ action: 'resize',
50
+ maxWidth: 1920,
51
+ maxHeight: 1200,
52
+ minWidth: 800,
53
+ minHeight: 600
54
+ },
55
+ {
56
+ action: 'save'
57
+ }
58
+ */
59
+ ],
60
+
61
+ // The add callback is invoked as soon as files are added to the
62
+ // fileupload widget (via file input selection, drag & drop or add
63
+ // API call). See the basic file upload widget for more information:
64
+ add: function (e, data) {
65
+ $(this).fileupload('process', data).done(function () {
66
+ data.submit();
67
+ });
68
+ }
69
+ },
70
+
71
+ processActions: {
72
+ // Loads the image given via data.files and data.index
73
+ // as canvas element.
74
+ // Accepts the options fileTypes (regular expression)
75
+ // and maxFileSize (integer) to limit the files to load:
76
+ load: function (data, options) {
77
+ var that = this,
78
+ file = data.files[data.index],
79
+ dfd = $.Deferred();
80
+ if (window.HTMLCanvasElement &&
81
+ window.HTMLCanvasElement.prototype.toBlob &&
82
+ ($.type(options.maxFileSize) !== 'number' ||
83
+ file.size < options.maxFileSize) &&
84
+ (!options.fileTypes ||
85
+ options.fileTypes.test(file.type))) {
86
+ loadImage(
87
+ file,
88
+ function (canvas) {
89
+ data.canvas = canvas;
90
+ dfd.resolveWith(that, [data]);
91
+ },
92
+ {canvas: true}
93
+ );
94
+ } else {
95
+ dfd.rejectWith(that, [data]);
96
+ }
97
+ return dfd.promise();
98
+ },
99
+ // Resizes the image given as data.canvas and updates
100
+ // data.canvas with the resized image.
101
+ // Accepts the options maxWidth, maxHeight, minWidth and
102
+ // minHeight to scale the given image:
103
+ resize: function (data, options) {
104
+ if (data.canvas) {
105
+ var canvas = loadImage.scale(data.canvas, options);
106
+ if (canvas.width !== data.canvas.width ||
107
+ canvas.height !== data.canvas.height) {
108
+ data.canvas = canvas;
109
+ data.processed = true;
110
+ }
111
+ }
112
+ return data;
113
+ },
114
+ // Saves the processed image given as data.canvas
115
+ // inplace at data.index of data.files:
116
+ save: function (data, options) {
117
+ // Do nothing if no processing has happened:
118
+ if (!data.canvas || !data.processed) {
119
+ return data;
120
+ }
121
+ var that = this,
122
+ file = data.files[data.index],
123
+ name = file.name,
124
+ dfd = $.Deferred(),
125
+ callback = function (blob) {
126
+ if (!blob.name) {
127
+ if (file.type === blob.type) {
128
+ blob.name = file.name;
129
+ } else if (file.name) {
130
+ blob.name = file.name.replace(
131
+ /\..+$/,
132
+ '.' + blob.type.substr(6)
133
+ );
134
+ }
135
+ }
136
+ // Store the created blob at the position
137
+ // of the original file in the files list:
138
+ data.files[data.index] = blob;
139
+ dfd.resolveWith(that, [data]);
140
+ };
141
+ // Use canvas.mozGetAsFile directly, to retain the filename, as
142
+ // Gecko doesn't support the filename option for FormData.append:
143
+ if (data.canvas.mozGetAsFile) {
144
+ callback(data.canvas.mozGetAsFile(
145
+ (/^image\/(jpeg|png)$/.test(file.type) && name) ||
146
+ ((name && name.replace(/\..+$/, '')) ||
147
+ 'blob') + '.png',
148
+ file.type
149
+ ));
150
+ } else {
151
+ data.canvas.toBlob(callback, file.type);
152
+ }
153
+ return dfd.promise();
154
+ }
155
+ },
156
+
157
+ // Resizes the file at the given index and stores the created blob at
158
+ // the original position of the files list, returns a Promise object:
159
+ _processFile: function (files, index, options) {
160
+ var that = this,
161
+ dfd = $.Deferred().resolveWith(that, [{
162
+ files: files,
163
+ index: index
164
+ }]),
165
+ chain = dfd.promise();
166
+ that._processing += 1;
167
+ $.each(options.process, function (i, settings) {
168
+ chain = chain.pipe(function (data) {
169
+ return that.processActions[settings.action]
170
+ .call(this, data, settings);
171
+ });
172
+ });
173
+ chain.always(function () {
174
+ that._processing -= 1;
175
+ if (that._processing === 0) {
176
+ that.element
177
+ .removeClass('fileupload-processing');
178
+ }
179
+ });
180
+ if (that._processing === 1) {
181
+ that.element.addClass('fileupload-processing');
182
+ }
183
+ return chain;
184
+ },
185
+
186
+ // Processes the files given as files property of the data parameter,
187
+ // returns a Promise object that allows to bind a done handler, which
188
+ // will be invoked after processing all files (inplace) is done:
189
+ process: function (data) {
190
+ var that = this,
191
+ options = $.extend({}, this.options, data);
192
+ if (options.process && options.process.length &&
193
+ this._isXHRUpload(options)) {
194
+ $.each(data.files, function (index, file) {
195
+ that._processingQueue = that._processingQueue.pipe(
196
+ function () {
197
+ var dfd = $.Deferred();
198
+ that._processFile(data.files, index, options)
199
+ .always(function () {
200
+ dfd.resolveWith(that);
201
+ });
202
+ return dfd.promise();
203
+ }
204
+ );
205
+ });
206
+ }
207
+ return this._processingQueue;
208
+ },
209
+
210
+ _create: function () {
211
+ $.blueimp.fileupload.prototype._create.call(this);
212
+ this._processing = 0;
213
+ this._processingQueue = $.Deferred().resolveWith(this)
214
+ .promise();
215
+ }
216
+
217
+ });
218
+
219
+ }));
@@ -0,0 +1,160 @@
1
+ /*
2
+ * jQuery File Upload Image Processing Plugin 1.0.6
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2012, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint nomen: true, unparam: true, regexp: true */
13
+ /*global define, window, document */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'load-image',
22
+ 'canvas-to-blob',
23
+ './jquery.fileupload'
24
+ ], factory);
25
+ } else {
26
+ // Browser globals:
27
+ factory(
28
+ window.jQuery,
29
+ window.loadImage,
30
+ window.canvasToBlob
31
+ );
32
+ }
33
+ }(function ($, loadImage, canvasToBlob) {
34
+ 'use strict';
35
+
36
+ // The File Upload IP version extends the basic fileupload widget
37
+ // with image processing functionality:
38
+ $.widget('blueimpIP.fileupload', $.blueimp.fileupload, {
39
+
40
+ options: {
41
+ // The regular expression to define which image files are to be
42
+ // resized, given that the browser supports the operation:
43
+ resizeSourceFileTypes: /^image\/(gif|jpeg|png)$/,
44
+ // The maximum file size of images that are to be resized:
45
+ resizeSourceMaxFileSize: 20000000, // 20MB
46
+ // The maximum width of the resized images:
47
+ resizeMaxWidth: undefined,
48
+ // The maximum height of the resized images:
49
+ resizeMaxHeight: undefined,
50
+ // The minimum width of the resized images:
51
+ resizeMinWidth: undefined,
52
+ // The minimum height of the resized images:
53
+ resizeMinHeight: undefined,
54
+
55
+ // The add callback is invoked as soon as files are added to the fileupload
56
+ // widget (via file input selection, drag & drop or add API call).
57
+ // See the basic file upload widget for more information:
58
+ add: function (e, data) {
59
+ $(this).fileupload('resize', data).done(function () {
60
+ data.submit();
61
+ });
62
+ }
63
+ },
64
+
65
+ // Resizes the image file at the given index and stores the created blob
66
+ // at the original position of the files list, returns a Promise object:
67
+ _resizeImage: function (files, index, options) {
68
+ var that = this,
69
+ file = files[index],
70
+ deferred = $.Deferred(),
71
+ canvas,
72
+ blob;
73
+ options = options || this.options;
74
+ loadImage(
75
+ file,
76
+ function (img) {
77
+ var width = img.width,
78
+ height = img.height;
79
+ canvas = loadImage.scale(img, {
80
+ maxWidth: options.resizeMaxWidth,
81
+ maxHeight: options.resizeMaxHeight,
82
+ minWidth: options.resizeMinWidth,
83
+ minHeight: options.resizeMinHeight,
84
+ canvas: true
85
+ });
86
+ if (width !== canvas.width || height !== canvas.height) {
87
+ canvasToBlob(canvas, function (blob) {
88
+ if (!blob.name) {
89
+ if (file.type === blob.type) {
90
+ blob.name = file.name;
91
+ } else if (file.name) {
92
+ blob.name = file.name.replace(
93
+ /\..+$/,
94
+ '.' + blob.type.substr(6)
95
+ );
96
+ }
97
+ }
98
+ files[index] = blob;
99
+ deferred.resolveWith(that);
100
+ }, file);
101
+ } else {
102
+ deferred.resolveWith(that);
103
+ }
104
+ }
105
+ );
106
+ return deferred.promise();
107
+ },
108
+
109
+ // Resizes the images given as files property of the data parameter,
110
+ // returns a Promise object that allows to bind a done handler, which
111
+ // will be invoked after processing all images is done:
112
+ resize: function (data) {
113
+ var that = this,
114
+ options = $.extend({}, this.options, data),
115
+ resizeAll = $.type(options.resizeSourceMaxFileSize) !== 'number',
116
+ isXHRUpload = this._isXHRUpload(options);
117
+ $.each(data.files, function (index, file) {
118
+ if (isXHRUpload && that._resizeSupport &&
119
+ (options.resizeMaxWidth || options.resizeMaxHeight ||
120
+ options.resizeMinWidth || options.resizeMinHeight) &&
121
+ (resizeAll || file.size < options.resizeSourceMaxFileSize) &&
122
+ options.resizeSourceFileTypes.test(file.type)) {
123
+ that._processing += 1;
124
+ if (that._processing === 1) {
125
+ that.element.addClass('fileupload-processing');
126
+ }
127
+ that._processingQueue = that._processingQueue.pipe(function () {
128
+ var deferred = $.Deferred();
129
+ that._resizeImage(
130
+ data.files,
131
+ index,
132
+ options
133
+ ).done(function () {
134
+ that._processing -= 1;
135
+ if (that._processing === 0) {
136
+ that.element
137
+ .removeClass('fileupload-processing');
138
+ }
139
+ deferred.resolveWith(that);
140
+ });
141
+ return deferred.promise();
142
+ });
143
+ }
144
+ });
145
+ return this._processingQueue;
146
+ },
147
+
148
+ _create: function () {
149
+ $.blueimp.fileupload.prototype._create.call(this);
150
+ this._processing = 0;
151
+ this._processingQueue = $.Deferred().resolveWith(this).promise();
152
+ this._resizeSupport = canvasToBlob && canvasToBlob(
153
+ document.createElement('canvas'),
154
+ $.noop
155
+ );
156
+ }
157
+
158
+ });
159
+
160
+ }));