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