jquery-file-upload 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ /*
2
+ * jQuery File Upload Audio Preview Plugin 1.0.4
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2013, 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, require, window, document */
14
+
15
+ if(<%= JqueryFileUpload.config.audio %>) {
16
+ (function (factory) {
17
+ 'use strict';
18
+ if (typeof define === 'function' && define.amd) {
19
+ // Register as an anonymous AMD module:
20
+ define([
21
+ 'jquery',
22
+ 'load-image',
23
+ './jquery.fileupload-process'
24
+ ], factory);
25
+ } else if (typeof exports === 'object') {
26
+ // Node/CommonJS:
27
+ factory(
28
+ require('jquery'),
29
+ require('load-image')
30
+ );
31
+ } else {
32
+ // Browser globals:
33
+ factory(
34
+ window.jQuery,
35
+ window.loadImage
36
+ );
37
+ }
38
+ }(function ($, loadImage) {
39
+ 'use strict';
40
+
41
+ // Prepend to the default processQueue:
42
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
43
+ {
44
+ action: 'loadAudio',
45
+ // Use the action as prefix for the "@" options:
46
+ prefix: true,
47
+ fileTypes: '@',
48
+ maxFileSize: '@',
49
+ disabled: '@disableAudioPreview'
50
+ },
51
+ {
52
+ action: 'setAudio',
53
+ name: '@audioPreviewName',
54
+ disabled: '@disableAudioPreview'
55
+ }
56
+ );
57
+
58
+ // The File Upload Audio Preview plugin extends the fileupload widget
59
+ // with audio preview functionality:
60
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
61
+
62
+ options: {
63
+ // The regular expression for the types of audio files to load,
64
+ // matched against the file type:
65
+ loadAudioFileTypes: /^audio\/.*$/
66
+ },
67
+
68
+ _audioElement: document.createElement('audio'),
69
+
70
+ processActions: {
71
+
72
+ // Loads the audio file given via data.files and data.index
73
+ // as audio element if the browser supports playing it.
74
+ // Accepts the options fileTypes (regular expression)
75
+ // and maxFileSize (integer) to limit the files to load:
76
+ loadAudio: function (data, options) {
77
+ if (options.disabled) {
78
+ return data;
79
+ }
80
+ var file = data.files[data.index],
81
+ url,
82
+ audio;
83
+ if (this._audioElement.canPlayType &&
84
+ this._audioElement.canPlayType(file.type) &&
85
+ ($.type(options.maxFileSize) !== 'number' ||
86
+ file.size <= options.maxFileSize) &&
87
+ (!options.fileTypes ||
88
+ options.fileTypes.test(file.type))) {
89
+ url = loadImage.createObjectURL(file);
90
+ if (url) {
91
+ audio = this._audioElement.cloneNode(false);
92
+ audio.src = url;
93
+ audio.controls = true;
94
+ data.audio = audio;
95
+ return data;
96
+ }
97
+ }
98
+ return data;
99
+ },
100
+
101
+ // Sets the audio element as a property of the file object:
102
+ setAudio: function (data, options) {
103
+ if (data.audio && !options.disabled) {
104
+ data.files[data.index][options.name || 'preview'] = data.audio;
105
+ }
106
+ return data;
107
+ }
108
+
109
+ }
110
+
111
+ });
112
+
113
+ }));
114
+ }
@@ -0,0 +1,114 @@
1
+ /*
2
+ * jQuery File Upload Video Preview Plugin 1.0.4
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2013, 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, require, window, document */
14
+
15
+ if(<%= JqueryFileUpload.config.video %>) {
16
+ (function (factory) {
17
+ 'use strict';
18
+ if (typeof define === 'function' && define.amd) {
19
+ // Register as an anonymous AMD module:
20
+ define([
21
+ 'jquery',
22
+ 'load-image',
23
+ './jquery.fileupload-process'
24
+ ], factory);
25
+ } else if (typeof exports === 'object') {
26
+ // Node/CommonJS:
27
+ factory(
28
+ require('jquery'),
29
+ require('load-image')
30
+ );
31
+ } else {
32
+ // Browser globals:
33
+ factory(
34
+ window.jQuery,
35
+ window.loadImage
36
+ );
37
+ }
38
+ }(function ($, loadImage) {
39
+ 'use strict';
40
+
41
+ // Prepend to the default processQueue:
42
+ $.blueimp.fileupload.prototype.options.processQueue.unshift(
43
+ {
44
+ action: 'loadVideo',
45
+ // Use the action as prefix for the "@" options:
46
+ prefix: true,
47
+ fileTypes: '@',
48
+ maxFileSize: '@',
49
+ disabled: '@disableVideoPreview'
50
+ },
51
+ {
52
+ action: 'setVideo',
53
+ name: '@videoPreviewName',
54
+ disabled: '@disableVideoPreview'
55
+ }
56
+ );
57
+
58
+ // The File Upload Video Preview plugin extends the fileupload widget
59
+ // with video preview functionality:
60
+ $.widget('blueimp.fileupload', $.blueimp.fileupload, {
61
+
62
+ options: {
63
+ // The regular expression for the types of video files to load,
64
+ // matched against the file type:
65
+ loadVideoFileTypes: /^video\/.*$/
66
+ },
67
+
68
+ _videoElement: document.createElement('video'),
69
+
70
+ processActions: {
71
+
72
+ // Loads the video file given via data.files and data.index
73
+ // as video element if the browser supports playing it.
74
+ // Accepts the options fileTypes (regular expression)
75
+ // and maxFileSize (integer) to limit the files to load:
76
+ loadVideo: function (data, options) {
77
+ if (options.disabled) {
78
+ return data;
79
+ }
80
+ var file = data.files[data.index],
81
+ url,
82
+ video;
83
+ if (this._videoElement.canPlayType &&
84
+ this._videoElement.canPlayType(file.type) &&
85
+ ($.type(options.maxFileSize) !== 'number' ||
86
+ file.size <= options.maxFileSize) &&
87
+ (!options.fileTypes ||
88
+ options.fileTypes.test(file.type))) {
89
+ url = loadImage.createObjectURL(file);
90
+ if (url) {
91
+ video = this._videoElement.cloneNode(false);
92
+ video.src = url;
93
+ video.controls = true;
94
+ data.video = video;
95
+ return data;
96
+ }
97
+ }
98
+ return data;
99
+ },
100
+
101
+ // Sets the video element as a property of the file object:
102
+ setVideo: function (data, options) {
103
+ if (data.video && !options.disabled) {
104
+ data.files[data.index][options.name || 'preview'] = data.video;
105
+ }
106
+ return data;
107
+ }
108
+
109
+ }
110
+
111
+ });
112
+
113
+ }));
114
+ }
@@ -1,12 +1,12 @@
1
1
  module JqueryFileUpload
2
2
  class Configuration
3
- attr_accessor :video_upload
4
- attr_accessor :audio_upload
3
+ attr_accessor :video
4
+ attr_accessor :audio
5
5
  attr_accessor :angular_js
6
6
 
7
7
  def initialize
8
- @video_upload = false
9
- @audio_upload = false
8
+ @video = false
9
+ @audio = false
10
10
  @angular_js = false
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module JqueryFileUpload
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-file-upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Stephens
@@ -39,6 +39,9 @@ files:
39
39
  - app/assets/javascripts/jquery-file-upload.js.coffee
40
40
  - app/assets/javascripts/jquery-file-upload/cors/jquery.postmessage-transport.js
41
41
  - app/assets/javascripts/jquery-file-upload/cors/jquery.xdr-transport.js
42
+ - app/assets/javascripts/jquery-file-upload/erb/jquery.fileupload-angular.js.erb
43
+ - app/assets/javascripts/jquery-file-upload/erb/jquery.fileupload-audio.js.erb
44
+ - app/assets/javascripts/jquery-file-upload/erb/jquery.fileupload-video.js.erb
42
45
  - app/assets/javascripts/jquery-file-upload/jquery.fileupload-image.js
43
46
  - app/assets/javascripts/jquery-file-upload/jquery.fileupload-jquery-ui.js
44
47
  - app/assets/javascripts/jquery-file-upload/jquery.fileupload-process.js
@@ -47,9 +50,6 @@ files:
47
50
  - app/assets/javascripts/jquery-file-upload/jquery.fileupload.js
48
51
  - app/assets/javascripts/jquery-file-upload/jquery.iframe-transport.js
49
52
  - app/assets/javascripts/jquery-file-upload/vendor/jquery.ui.widget.js
50
- - app/assets/javascripts/jquery.fileupload-angular.js
51
- - app/assets/javascripts/jquery.fileupload-audio.js
52
- - app/assets/javascripts/jquery.fileupload-video.js
53
53
  - app/assets/stylesheets/jquery-file-upload/jquery.fileupload-noscript.css
54
54
  - app/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui-noscript.css
55
55
  - app/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui.css
@@ -1,429 +0,0 @@
1
- /*
2
- * jQuery File Upload AngularJS Plugin 2.2.0
3
- * https://github.com/blueimp/jQuery-File-Upload
4
- *
5
- * Copyright 2013, 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, angular */
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
- 'angular',
22
- './jquery.fileupload-image',
23
- './jquery.fileupload-audio',
24
- './jquery.fileupload-video',
25
- './jquery.fileupload-validate'
26
- ], factory);
27
- } else {
28
- factory();
29
- }
30
- }(function () {
31
- 'use strict';
32
-
33
- angular.module('blueimp.fileupload', [])
34
-
35
- // The fileUpload service provides configuration options
36
- // for the fileUpload directive and default handlers for
37
- // File Upload events:
38
- .provider('fileUpload', function () {
39
- var scopeEvalAsync = function (expression) {
40
- var scope = angular.element(this)
41
- .fileupload('option', 'scope');
42
- // Schedule a new $digest cycle if not already inside of one
43
- // and evaluate the given expression:
44
- scope.$evalAsync(expression);
45
- },
46
- addFileMethods = function (scope, data) {
47
- var files = data.files,
48
- file = files[0];
49
- angular.forEach(files, function (file, index) {
50
- file._index = index;
51
- file.$state = function () {
52
- return data.state();
53
- };
54
- file.$processing = function () {
55
- return data.processing();
56
- };
57
- file.$progress = function () {
58
- return data.progress();
59
- };
60
- file.$response = function () {
61
- return data.response();
62
- };
63
- });
64
- file.$submit = function () {
65
- if (!file.error) {
66
- return data.submit();
67
- }
68
- };
69
- file.$cancel = function () {
70
- return data.abort();
71
- };
72
- },
73
- $config;
74
- $config = this.defaults = {
75
- handleResponse: function (e, data) {
76
- var files = data.result && data.result.files;
77
- if (files) {
78
- data.scope.replace(data.files, files);
79
- } else if (data.errorThrown ||
80
- data.textStatus === 'error') {
81
- data.files[0].error = data.errorThrown ||
82
- data.textStatus;
83
- }
84
- },
85
- add: function (e, data) {
86
- if (e.isDefaultPrevented()) {
87
- return false;
88
- }
89
- var scope = data.scope,
90
- filesCopy = [];
91
- angular.forEach(data.files, function (file) {
92
- filesCopy.push(file);
93
- });
94
- scope.$apply(function () {
95
- addFileMethods(scope, data);
96
- var method = scope.option('prependFiles') ?
97
- 'unshift' : 'push';
98
- Array.prototype[method].apply(scope.queue, data.files);
99
- });
100
- data.process(function () {
101
- return scope.process(data);
102
- }).always(function () {
103
- scope.$apply(function () {
104
- addFileMethods(scope, data);
105
- scope.replace(filesCopy, data.files);
106
- });
107
- }).then(function () {
108
- if ((scope.option('autoUpload') ||
109
- data.autoUpload) &&
110
- data.autoUpload !== false) {
111
- data.submit();
112
- }
113
- });
114
- },
115
- progress: function (e, data) {
116
- if (e.isDefaultPrevented()) {
117
- return false;
118
- }
119
- data.scope.$apply();
120
- },
121
- done: function (e, data) {
122
- if (e.isDefaultPrevented()) {
123
- return false;
124
- }
125
- var that = this;
126
- data.scope.$apply(function () {
127
- data.handleResponse.call(that, e, data);
128
- });
129
- },
130
- fail: function (e, data) {
131
- if (e.isDefaultPrevented()) {
132
- return false;
133
- }
134
- var that = this,
135
- scope = data.scope;
136
- if (data.errorThrown === 'abort') {
137
- scope.clear(data.files);
138
- return;
139
- }
140
- scope.$apply(function () {
141
- data.handleResponse.call(that, e, data);
142
- });
143
- },
144
- stop: scopeEvalAsync,
145
- processstart: scopeEvalAsync,
146
- processstop: scopeEvalAsync,
147
- getNumberOfFiles: function () {
148
- var scope = this.scope;
149
- return scope.queue.length - scope.processing();
150
- },
151
- dataType: 'json',
152
- autoUpload: false
153
- };
154
- this.$get = [
155
- function () {
156
- return {
157
- defaults: $config
158
- };
159
- }
160
- ];
161
- })
162
-
163
- // Format byte numbers to readable presentations:
164
- .provider('formatFileSizeFilter', function () {
165
- var $config = {
166
- // Byte units following the IEC format
167
- // http://en.wikipedia.org/wiki/Kilobyte
168
- units: [
169
- {size: 1000000000, suffix: ' GB'},
170
- {size: 1000000, suffix: ' MB'},
171
- {size: 1000, suffix: ' KB'}
172
- ]
173
- };
174
- this.defaults = $config;
175
- this.$get = function () {
176
- return function (bytes) {
177
- if (!angular.isNumber(bytes)) {
178
- return '';
179
- }
180
- var unit = true,
181
- i = 0,
182
- prefix,
183
- suffix;
184
- while (unit) {
185
- unit = $config.units[i];
186
- prefix = unit.prefix || '';
187
- suffix = unit.suffix || '';
188
- if (i === $config.units.length - 1 || bytes >= unit.size) {
189
- return prefix + (bytes / unit.size).toFixed(2) + suffix;
190
- }
191
- i += 1;
192
- }
193
- };
194
- };
195
- })
196
-
197
- // The FileUploadController initializes the fileupload widget and
198
- // provides scope methods to control the File Upload functionality:
199
- .controller('FileUploadController', [
200
- '$scope', '$element', '$attrs', '$window', 'fileUpload',
201
- function ($scope, $element, $attrs, $window, fileUpload) {
202
- var uploadMethods = {
203
- progress: function () {
204
- return $element.fileupload('progress');
205
- },
206
- active: function () {
207
- return $element.fileupload('active');
208
- },
209
- option: function (option, data) {
210
- if (arguments.length === 1) {
211
- return $element.fileupload('option', option);
212
- }
213
- $element.fileupload('option', option, data);
214
- },
215
- add: function (data) {
216
- return $element.fileupload('add', data);
217
- },
218
- send: function (data) {
219
- return $element.fileupload('send', data);
220
- },
221
- process: function (data) {
222
- return $element.fileupload('process', data);
223
- },
224
- processing: function (data) {
225
- return $element.fileupload('processing', data);
226
- }
227
- };
228
- $scope.disabled = !$window.jQuery.support.fileInput;
229
- $scope.queue = $scope.queue || [];
230
- $scope.clear = function (files) {
231
- var queue = this.queue,
232
- i = queue.length,
233
- file = files,
234
- length = 1;
235
- if (angular.isArray(files)) {
236
- file = files[0];
237
- length = files.length;
238
- }
239
- while (i) {
240
- i -= 1;
241
- if (queue[i] === file) {
242
- return queue.splice(i, length);
243
- }
244
- }
245
- };
246
- $scope.replace = function (oldFiles, newFiles) {
247
- var queue = this.queue,
248
- file = oldFiles[0],
249
- i,
250
- j;
251
- for (i = 0; i < queue.length; i += 1) {
252
- if (queue[i] === file) {
253
- for (j = 0; j < newFiles.length; j += 1) {
254
- queue[i + j] = newFiles[j];
255
- }
256
- return;
257
- }
258
- }
259
- };
260
- $scope.applyOnQueue = function (method) {
261
- var list = this.queue.slice(0),
262
- i,
263
- file;
264
- for (i = 0; i < list.length; i += 1) {
265
- file = list[i];
266
- if (file[method]) {
267
- file[method]();
268
- }
269
- }
270
- };
271
- $scope.submit = function () {
272
- this.applyOnQueue('$submit');
273
- };
274
- $scope.cancel = function () {
275
- this.applyOnQueue('$cancel');
276
- };
277
- // Add upload methods to the scope:
278
- angular.extend($scope, uploadMethods);
279
- // The fileupload widget will initialize with
280
- // the options provided via "data-"-parameters,
281
- // as well as those given via options object:
282
- $element.fileupload(angular.extend(
283
- {scope: $scope},
284
- fileUpload.defaults
285
- )).on('fileuploadadd', function (e, data) {
286
- data.scope = $scope;
287
- }).on('fileuploadfail', function (e, data) {
288
- if (data.errorThrown === 'abort') {
289
- return;
290
- }
291
- if (data.dataType &&
292
- data.dataType.indexOf('json') === data.dataType.length - 4) {
293
- try {
294
- data.result = angular.fromJson(data.jqXHR.responseText);
295
- } catch (ignore) {}
296
- }
297
- }).on([
298
- 'fileuploadadd',
299
- 'fileuploadsubmit',
300
- 'fileuploadsend',
301
- 'fileuploaddone',
302
- 'fileuploadfail',
303
- 'fileuploadalways',
304
- 'fileuploadprogress',
305
- 'fileuploadprogressall',
306
- 'fileuploadstart',
307
- 'fileuploadstop',
308
- 'fileuploadchange',
309
- 'fileuploadpaste',
310
- 'fileuploaddrop',
311
- 'fileuploaddragover',
312
- 'fileuploadchunksend',
313
- 'fileuploadchunkdone',
314
- 'fileuploadchunkfail',
315
- 'fileuploadchunkalways',
316
- 'fileuploadprocessstart',
317
- 'fileuploadprocess',
318
- 'fileuploadprocessdone',
319
- 'fileuploadprocessfail',
320
- 'fileuploadprocessalways',
321
- 'fileuploadprocessstop'
322
- ].join(' '), function (e, data) {
323
- if ($scope.$emit(e.type, data).defaultPrevented) {
324
- e.preventDefault();
325
- }
326
- }).on('remove', function () {
327
- // Remove upload methods from the scope,
328
- // when the widget is removed:
329
- var method;
330
- for (method in uploadMethods) {
331
- if (uploadMethods.hasOwnProperty(method)) {
332
- delete $scope[method];
333
- }
334
- }
335
- });
336
- // Observe option changes:
337
- $scope.$watch(
338
- $attrs.fileUpload,
339
- function (newOptions) {
340
- if (newOptions) {
341
- $element.fileupload('option', newOptions);
342
- }
343
- }
344
- );
345
- }
346
- ])
347
-
348
- // Provide File Upload progress feedback:
349
- .controller('FileUploadProgressController', [
350
- '$scope', '$attrs', '$parse',
351
- function ($scope, $attrs, $parse) {
352
- var fn = $parse($attrs.fileUploadProgress),
353
- update = function () {
354
- var progress = fn($scope);
355
- if (!progress || !progress.total) {
356
- return;
357
- }
358
- $scope.num = Math.floor(
359
- progress.loaded / progress.total * 100
360
- );
361
- };
362
- update();
363
- $scope.$watch(
364
- $attrs.fileUploadProgress + '.loaded',
365
- function (newValue, oldValue) {
366
- if (newValue !== oldValue) {
367
- update();
368
- }
369
- }
370
- );
371
- }
372
- ])
373
-
374
- // Display File Upload previews:
375
- .controller('FileUploadPreviewController', [
376
- '$scope', '$element', '$attrs',
377
- function ($scope, $element, $attrs) {
378
- $scope.$watch(
379
- $attrs.fileUploadPreview + '.preview',
380
- function (preview) {
381
- $element.empty();
382
- if (preview) {
383
- $element.append(preview);
384
- }
385
- }
386
- );
387
- }
388
- ])
389
-
390
- .directive('fileUpload', function () {
391
- return {
392
- controller: 'FileUploadController',
393
- scope: true
394
- };
395
- })
396
-
397
- .directive('fileUploadProgress', function () {
398
- return {
399
- controller: 'FileUploadProgressController',
400
- scope: true
401
- };
402
- })
403
-
404
- .directive('fileUploadPreview', function () {
405
- return {
406
- controller: 'FileUploadPreviewController'
407
- };
408
- })
409
-
410
- // Enhance the HTML5 download attribute to
411
- // allow drag&drop of files to the desktop:
412
- .directive('download', function () {
413
- return function (scope, elm) {
414
- elm.on('dragstart', function (e) {
415
- try {
416
- e.originalEvent.dataTransfer.setData(
417
- 'DownloadURL',
418
- [
419
- 'application/octet-stream',
420
- elm.prop('download'),
421
- elm.prop('href')
422
- ].join(':')
423
- );
424
- } catch (ignore) {}
425
- });
426
- };
427
- });
428
-
429
- }));