jquery-fileupload-rails 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +38 -16
  3. data/{vendor → app}/assets/images/loading.gif +0 -0
  4. data/{vendor → app}/assets/images/progressbar.gif +0 -0
  5. data/app/assets/javascripts/jquery-fileupload/angularjs.js +12 -0
  6. data/app/assets/javascripts/jquery-fileupload/basic-plus.js +11 -0
  7. data/app/assets/javascripts/jquery-fileupload/basic.js +3 -0
  8. data/{vendor → app}/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js +4 -4
  9. data/{vendor → app}/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js +1 -2
  10. data/app/assets/javascripts/jquery-fileupload/index.js +13 -0
  11. data/app/assets/javascripts/jquery-fileupload/jquery-ui.js +13 -0
  12. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-angular.js +429 -0
  13. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-audio.js +106 -0
  14. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-image.js +315 -0
  15. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-jquery-ui.js +152 -0
  16. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-process.js +172 -0
  17. data/{vendor → app}/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +178 -273
  18. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-validate.js +119 -0
  19. data/app/assets/javascripts/jquery-fileupload/jquery.fileupload-video.js +106 -0
  20. data/{vendor → app}/assets/javascripts/jquery-fileupload/jquery.fileupload.js +481 -188
  21. data/{vendor → app}/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js +43 -14
  22. data/{vendor → app}/assets/javascripts/jquery-fileupload/locale.js +0 -0
  23. data/{vendor → app}/assets/javascripts/jquery-fileupload/vendor/canvas-to-blob.js +9 -5
  24. data/{vendor → app}/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +72 -44
  25. data/app/assets/javascripts/jquery-fileupload/vendor/load-image.all.min.js +1 -0
  26. data/{vendor → app}/assets/javascripts/jquery-fileupload/vendor/tmpl.js +9 -8
  27. data/app/assets/stylesheets/jquery.fileupload-noscript.scss +22 -0
  28. data/app/assets/stylesheets/jquery.fileupload-ui-noscript.scss +17 -0
  29. data/app/assets/stylesheets/jquery.fileupload-ui.scss +57 -0
  30. data/app/assets/stylesheets/jquery.fileupload.scss +36 -0
  31. data/lib/jquery/fileupload/rails/version.rb +1 -1
  32. metadata +43 -39
  33. data/vendor/assets/javascripts/jquery-fileupload/basic.js +0 -4
  34. data/vendor/assets/javascripts/jquery-fileupload/index.js +0 -9
  35. data/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js +0 -223
  36. data/vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js +0 -121
  37. data/vendor/assets/stylesheets/jquery.fileupload-ui.scss +0 -84
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1371b3aeb9a281ebbb77cc9f3afc16e99598b77
4
+ data.tar.gz: 2bb1f4ab429a3e88c570d5d46a38df88e7557346
5
+ SHA512:
6
+ metadata.gz: 65eca9c49bca1f76e5d1a49e7255446c2f98c5bff0137b44581687a3043ee705fa06ece26d22a06538fad3d3864783304a92606eb1d8fa3f90f931704b681271
7
+ data.tar.gz: 3ca6ac7d6c4fc3498e3db0954d86decc131a760ae4b0eafeb75071f45e595da402934ecdc23f15b1e050ecbe8f2e2da11dd77ec98987623befeddd42c1498db8
data/README.md CHANGED
@@ -6,9 +6,9 @@ jquery-fileupload-rails is a library that integrates jQuery File Upload for Rail
6
6
 
7
7
  ## Plugin versions
8
8
 
9
- * jQuery File Upload User Interface Plugin 6.11
10
- * jQuery File Upload Plugin 5.19.3
11
- * jQuery UI Widget 1.9.1+amd
9
+ * jQuery File Upload User Interface Plugin 9.6.0
10
+ * jQuery File Upload Plugin 5.42.0
11
+ * jQuery UI Widget 1.11.1
12
12
 
13
13
  ## Installing Gem
14
14
 
@@ -22,32 +22,54 @@ Require jquery-fileupload in your app/assets/application.js file.
22
22
 
23
23
  The snippet above will add the following js files to the mainfest file.
24
24
 
25
- //=require jquery-fileupload/vendor/jquery.ui.widget
26
- //=require jquery-fileupload/vendor/load-image
27
- //=require jquery-fileupload/vendor/canvas-to-blob
28
- //=require jquery-fileupload/vendor/tmpl
29
- //=require jquery-fileupload/jquery.iframe-transport
30
- //=require jquery-fileupload/jquery.fileupload
31
- //=require jquery-fileupload/jquery.fileupload-fp
32
- //=require jquery-fileupload/jquery.fileupload-ui
33
- //=require jquery-fileupload/locale
25
+ //= require jquery-fileupload/vendor/jquery.ui.widget
26
+ //= require jquery-fileupload/vendor/tmpl
27
+ //= require jquery-fileupload/vendor/load-image
28
+ //= require jquery-fileupload/vendor/canvas-to-blob
29
+ //= require jquery-fileupload/jquery.iframe-transport
30
+ //= require jquery-fileupload/jquery.fileupload
31
+ //= require jquery-fileupload/jquery.fileupload-process
32
+ //= require jquery-fileupload/jquery.fileupload-image
33
+ //= require jquery-fileupload/jquery.fileupload-audio
34
+ //= require jquery-fileupload/jquery.fileupload-video
35
+ //= require jquery-fileupload/jquery.fileupload-validate
36
+ //= require jquery-fileupload/jquery.fileupload-ui
37
+ //= require jquery-fileupload/locale
38
+ //= require jquery-fileupload/jquery.fileupload-angular
39
+ //= require jquery-fileupload/jquery.fileupload-jquery-ui
40
+ //= require jquery-fileupload/cors/jquery.postmessage-transport
41
+ //= require jquery-fileupload/cors/jquery.xdr-transport
34
42
 
35
43
  If you only need the basic files, just add the code below to your application.js file. [Basic setup guide](https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin)
36
44
 
37
- //=require jquery-fileupload/basic
45
+ //= require jquery-fileupload/basic
38
46
 
39
47
  The basic setup only includes the following files:
40
48
 
41
- //=require jquery-fileupload/vendor/jquery.ui.widget
42
- //=require jquery-fileupload/jquery.iframe-transport
43
- //=require jquery-fileupload/jquery.fileupload
49
+ //= require jquery-fileupload/vendor/jquery.ui.widget
50
+ //= require jquery-fileupload/jquery.iframe-transport
51
+ //= require jquery-fileupload/jquery.fileupload
52
+
53
+ You can also require the following to get the js from the Basic-Plus, AngularJS and jQuery UI Examples:
54
+
55
+ //= require jquery-fileupload/basic-plus
56
+
57
+ //= require jquery-fileupload/angularjs
58
+
59
+ //= require jquery-fileupload/jquery-ui
44
60
 
45
61
  ## Using the stylesheet
46
62
 
47
63
  Require the stylesheet file to app/assets/stylesheets/application.css
48
64
 
65
+ *= require jquery.fileupload
49
66
  *= require jquery.fileupload-ui
50
67
 
68
+ There are also noscript styles for Browsers with Javascript disabled, to use them create a noscript.css and add it to your precompile-list and layout inside a noscript tag:
69
+
70
+ *= require jquery.fileupload-noscript
71
+ *= require jquery.fileupload-ui-noscript
72
+
51
73
  ## Using the middleware
52
74
 
53
75
  The `jquery.iframe-transport` fallback transport has some special caveats regarding the response data type, http status, and character encodings. `jquery-fileupload-rails` includes a middleware that handles these inconsistencies seamlessly. If you decide to use it, create an initializer that adds the middleware to your application's middleware stack.
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ //= require jquery-fileupload/vendor/jquery.ui.widget
2
+ //= require jquery-fileupload/vendor/load-image.all.min
3
+ //= require jquery-fileupload/vendor/canvas-to-blob
4
+ //= require jquery-fileupload/jquery.iframe-transport
5
+ //= require jquery-fileupload/jquery.fileupload
6
+ //= require jquery-fileupload/jquery.fileupload-process
7
+ //= require jquery-fileupload/jquery.fileupload-image
8
+ //= require jquery-fileupload/jquery.fileupload-audio
9
+ //= require jquery-fileupload/jquery.fileupload-video
10
+ //= require jquery-fileupload/jquery.fileupload-validate
11
+ //= require jquery-fileupload/jquery.fileupload-angular
12
+ //= require jquery-fileupload/locale
@@ -0,0 +1,11 @@
1
+ //= require jquery-fileupload/vendor/jquery.ui.widget
2
+ //= require jquery-fileupload/vendor/load-image.all.min
3
+ //= require jquery-fileupload/vendor/canvas-to-blob
4
+ //= require jquery-fileupload/jquery.iframe-transport
5
+ //= require jquery-fileupload/jquery.fileupload
6
+ //= require jquery-fileupload/jquery.fileupload-process
7
+ //= require jquery-fileupload/jquery.fileupload-image
8
+ //= require jquery-fileupload/jquery.fileupload-audio
9
+ //= require jquery-fileupload/jquery.fileupload-video
10
+ //= require jquery-fileupload/jquery.fileupload-validate
11
+ //= require jquery-fileupload/locale
@@ -0,0 +1,3 @@
1
+ //= require jquery-fileupload/vendor/jquery.ui.widget
2
+ //= require jquery-fileupload/jquery.iframe-transport
3
+ //= require jquery-fileupload/jquery.fileupload
@@ -1,5 +1,5 @@
1
1
  /*
2
- * jQuery postMessage Transport Plugin 1.1
2
+ * jQuery postMessage Transport Plugin 1.1.1
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
5
  * Copyright 2011, Sebastian Tschan
@@ -9,8 +9,7 @@
9
9
  * http://www.opensource.org/licenses/MIT
10
10
  */
11
11
 
12
- /*jslint unparam: true, nomen: true */
13
- /*global define, window, document */
12
+ /* global define, window, document */
14
13
 
15
14
  (function (factory) {
16
15
  'use strict';
@@ -64,8 +63,9 @@
64
63
  xhrUpload = options.xhr().upload;
65
64
  return {
66
65
  send: function (_, completeCallback) {
66
+ counter += 1;
67
67
  var message = {
68
- id: 'postmessage-transport-' + (counter += 1)
68
+ id: 'postmessage-transport-' + counter
69
69
  },
70
70
  eventName = 'message.' + message.id;
71
71
  iframe = $(
@@ -12,8 +12,7 @@
12
12
  * https://github.com/jaubourg/ajaxHooks/
13
13
  */
14
14
 
15
- /*jslint unparam: true */
16
- /*global define, window, XDomainRequest */
15
+ /* global define, window, XDomainRequest */
17
16
 
18
17
  (function (factory) {
19
18
  'use strict';
@@ -0,0 +1,13 @@
1
+ //= require jquery-fileupload/vendor/jquery.ui.widget
2
+ //= require jquery-fileupload/vendor/tmpl
3
+ //= require jquery-fileupload/vendor/load-image.all.min
4
+ //= require jquery-fileupload/vendor/canvas-to-blob
5
+ //= require jquery-fileupload/jquery.iframe-transport
6
+ //= require jquery-fileupload/jquery.fileupload
7
+ //= require jquery-fileupload/jquery.fileupload-process
8
+ //= require jquery-fileupload/jquery.fileupload-image
9
+ //= require jquery-fileupload/jquery.fileupload-audio
10
+ //= require jquery-fileupload/jquery.fileupload-video
11
+ //= require jquery-fileupload/jquery.fileupload-validate
12
+ //= require jquery-fileupload/jquery.fileupload-ui
13
+ //= require jquery-fileupload/locale
@@ -0,0 +1,13 @@
1
+ //= require jquery-fileupload/vendor/tmpl
2
+ //= require jquery-fileupload/vendor/load-image.all.min
3
+ //= require jquery-fileupload/vendor/canvas-to-blob
4
+ //= require jquery-fileupload/jquery.iframe-transport
5
+ //= require jquery-fileupload/jquery.fileupload
6
+ //= require jquery-fileupload/jquery.fileupload-process
7
+ //= require jquery-fileupload/jquery.fileupload-image
8
+ //= require jquery-fileupload/jquery.fileupload-audio
9
+ //= require jquery-fileupload/jquery.fileupload-video
10
+ //= require jquery-fileupload/jquery.fileupload-validate
11
+ //= require jquery-fileupload/jquery.fileupload-ui
12
+ //= require jquery-fileupload/jquery.fileupload-jquery-ui
13
+ //= require jquery-fileupload/locale
@@ -0,0 +1,429 @@
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
+ }));