jquery-file-upload-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +55 -0
  4. data/Rakefile +32 -0
  5. data/app/views/jquery_file_upload/basic_plus_ui/_download.html.erb +43 -0
  6. data/app/views/jquery_file_upload/basic_plus_ui/_form.html.haml +35 -0
  7. data/app/views/jquery_file_upload/basic_plus_ui/_upload.html.erb +32 -0
  8. data/config/locales/jquery_file_upload.cs.yml +16 -0
  9. data/config/locales/jquery_file_upload.en.yml +16 -0
  10. data/lib/jquery-file-upload-rails.rb +1 -0
  11. data/lib/jquery_file_upload/rails.rb +6 -0
  12. data/lib/jquery_file_upload/rails/version.rb +5 -0
  13. data/test/dummy/README.rdoc +28 -0
  14. data/test/dummy/app/assets/javascripts/application.js +13 -0
  15. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/test/dummy/app/controllers/application_controller.rb +5 -0
  17. data/test/dummy/app/helpers/application_helper.rb +2 -0
  18. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/test/dummy/bin/bundle +3 -0
  20. data/test/dummy/bin/rails +4 -0
  21. data/test/dummy/bin/rake +4 -0
  22. data/test/dummy/config.ru +4 -0
  23. data/test/dummy/config/application.rb +22 -0
  24. data/test/dummy/config/boot.rb +5 -0
  25. data/test/dummy/config/database.yml +25 -0
  26. data/test/dummy/config/environment.rb +5 -0
  27. data/test/dummy/config/environments/development.rb +29 -0
  28. data/test/dummy/config/environments/production.rb +80 -0
  29. data/test/dummy/config/environments/test.rb +36 -0
  30. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  31. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  32. data/test/dummy/config/initializers/inflections.rb +16 -0
  33. data/test/dummy/config/initializers/mime_types.rb +5 -0
  34. data/test/dummy/config/initializers/secret_token.rb +12 -0
  35. data/test/dummy/config/initializers/session_store.rb +3 -0
  36. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  37. data/test/dummy/config/locales/en.yml +23 -0
  38. data/test/dummy/config/routes.rb +56 -0
  39. data/test/dummy/db/test.sqlite3 +0 -0
  40. data/test/jquery_file_upload_rails_test.rb +7 -0
  41. data/test/test_helper.rb +15 -0
  42. data/vendor/assets/images/jquery-file-upload/loading.gif +0 -0
  43. data/vendor/assets/images/jquery-file-upload/progressbar.gif +0 -0
  44. data/vendor/assets/javascripts/jquery-file-upload/app.js +101 -0
  45. data/vendor/assets/javascripts/jquery-file-upload/basic-plus-ui-no-widget.js.coffee +35 -0
  46. data/vendor/assets/javascripts/jquery-file-upload/basic-plus-ui.js.coffee +38 -0
  47. data/vendor/assets/javascripts/jquery-file-upload/cors/jquery.postmessage-transport.js +118 -0
  48. data/vendor/assets/javascripts/jquery-file-upload/cors/jquery.xdr-transport.js +87 -0
  49. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-angular.js +428 -0
  50. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-audio.js +106 -0
  51. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-image.js +295 -0
  52. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-jquery-ui.js +144 -0
  53. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-process.js +172 -0
  54. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-ui.js +699 -0
  55. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-validate.js +120 -0
  56. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-video.js +106 -0
  57. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload.js +1416 -0
  58. data/vendor/assets/javascripts/jquery-file-upload/jquery.iframe-transport.js +210 -0
  59. data/vendor/assets/javascripts/jquery-file-upload/main.js.coffee +4 -0
  60. data/vendor/assets/javascripts/jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob.js +95 -0
  61. data/vendor/assets/javascripts/jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob.min.js +1 -0
  62. data/vendor/assets/javascripts/jquery-file-upload/vendor/jquery.ui.widget.js +530 -0
  63. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/demo.js +138 -0
  64. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-exif-map.js +384 -0
  65. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-exif.js +299 -0
  66. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-ios.js +181 -0
  67. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-meta.js +137 -0
  68. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-orientation.js +159 -0
  69. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image.js +276 -0
  70. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image.min.js +1 -0
  71. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/vendor/jquery.Jcrop.js +1694 -0
  72. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/compile.js +84 -0
  73. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/demo.js +48 -0
  74. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/runtime.js +47 -0
  75. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/tmpl.js +87 -0
  76. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/tmpl.min.js +1 -0
  77. data/vendor/assets/stylesheets/jquery-file-upload/demo-ie8.css +21 -0
  78. data/vendor/assets/stylesheets/jquery-file-upload/demo.css +67 -0
  79. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-noscript.css +22 -0
  80. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui-noscript.css +17 -0
  81. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui.css.scss +57 -0
  82. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload.css +36 -0
  83. data/vendor/assets/stylesheets/jquery-file-upload/style.css +15 -0
  84. metadata +196 -0
@@ -0,0 +1,35 @@
1
+ # The Templates plugin is included to render the upload/download listings
2
+ #= require jquery-file-upload/vendor/templates/tmpl
3
+
4
+ # The Load Image plugin is included for the preview images and image resizing functionality
5
+ #= require jquery-file-upload/vendor/load-image/load-image.min
6
+
7
+ # The Canvas to Blob plugin is included for image resizing functionality
8
+ #= require jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob
9
+
10
+ # The Iframe Transport is required for browsers without support for XHR file uploads
11
+ #= require "jquery-file-upload/jquery.iframe-transport"
12
+
13
+ # The basic File Upload plugin
14
+ #= require "jquery-file-upload/jquery.fileupload"
15
+
16
+ # The File Upload processing plugin
17
+ #= require "jquery-file-upload/jquery.fileupload-process"
18
+
19
+ # The File Upload image preview & resize plugin
20
+ #= require "jquery-file-upload/jquery.fileupload-image"
21
+
22
+ # The File Upload audio preview plugin
23
+ #= require "jquery-file-upload/jquery.fileupload-audio"
24
+
25
+ # The File Upload video preview plugin
26
+ #= require "jquery-file-upload/jquery.fileupload-video"
27
+
28
+ # The File Upload validation plugin
29
+ #= require "jquery-file-upload/jquery.fileupload-validate"
30
+
31
+ # The File Upload user interface plugin
32
+ #= require "jquery-file-upload/jquery.fileupload-ui"
33
+
34
+ # The main application script
35
+ #= require "jquery-file-upload/main"
@@ -0,0 +1,38 @@
1
+ # The jQuery UI widget factory, can be omitted if jQuery UI is already included
2
+ #= require "jquery-file-upload/vendor/jquery.ui.widget"
3
+
4
+ # The Templates plugin is included to render the upload/download listings
5
+ #= require jquery-file-upload/vendor/templates/tmpl
6
+
7
+ # The Load Image plugin is included for the preview images and image resizing functionality
8
+ #= require jquery-file-upload/vendor/load-image/load-image.min
9
+
10
+ # The Canvas to Blob plugin is included for image resizing functionality
11
+ #= require jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob
12
+
13
+ # The Iframe Transport is required for browsers without support for XHR file uploads
14
+ #= require "jquery-file-upload/jquery.iframe-transport"
15
+
16
+ # The basic File Upload plugin
17
+ #= require "jquery-file-upload/jquery.fileupload"
18
+
19
+ # The File Upload processing plugin
20
+ #= require "jquery-file-upload/jquery.fileupload-process"
21
+
22
+ # The File Upload image preview & resize plugin
23
+ #= require "jquery-file-upload/jquery.fileupload-image"
24
+
25
+ # The File Upload audio preview plugin
26
+ #= require "jquery-file-upload/jquery.fileupload-audio"
27
+
28
+ # The File Upload video preview plugin
29
+ #= require "jquery-file-upload/jquery.fileupload-video"
30
+
31
+ # The File Upload validation plugin
32
+ #= require "jquery-file-upload/jquery.fileupload-validate"
33
+
34
+ # The File Upload user interface plugin
35
+ #= require "jquery-file-upload/jquery.fileupload-ui"
36
+
37
+ # The main application script
38
+ #= require "jquery-file-upload/main"
@@ -0,0 +1,118 @@
1
+ /*
2
+ * jQuery postMessage Transport Plugin 1.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
+ counter += 1;
68
+ var message = {
69
+ id: 'postmessage-transport-' + counter
70
+ },
71
+ eventName = 'message.' + message.id;
72
+ iframe = $(
73
+ '<iframe style="display:none;" src="' +
74
+ options.postMessage + '" name="' +
75
+ message.id + '"></iframe>'
76
+ ).bind('load', function () {
77
+ $.each(names, function (i, name) {
78
+ message[name] = options[name];
79
+ });
80
+ message.dataType = message.dataType.replace('postmessage ', '');
81
+ $(window).bind(eventName, function (e) {
82
+ e = e.originalEvent;
83
+ var data = e.data,
84
+ ev;
85
+ if (e.origin === target && data.id === message.id) {
86
+ if (data.type === 'progress') {
87
+ ev = document.createEvent('Event');
88
+ ev.initEvent(data.type, false, true);
89
+ $.extend(ev, data);
90
+ xhrUpload.dispatchEvent(ev);
91
+ } else {
92
+ completeCallback(
93
+ data.status,
94
+ data.statusText,
95
+ {postmessage: data.result},
96
+ data.headers
97
+ );
98
+ iframe.remove();
99
+ $(window).unbind(eventName);
100
+ }
101
+ }
102
+ });
103
+ iframe[0].contentWindow.postMessage(
104
+ message,
105
+ target
106
+ );
107
+ }).appendTo(document.body);
108
+ },
109
+ abort: function () {
110
+ if (iframe) {
111
+ iframe.remove();
112
+ }
113
+ }
114
+ };
115
+ }
116
+ });
117
+
118
+ }));
@@ -0,0 +1,87 @@
1
+ /*
2
+ * jQuery XDomainRequest Transport Plugin 1.1.3
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
+ var addParamChar = /\?/.test(s.url) ? '&' : '?';
40
+ function callback(status, statusText, responses, responseHeaders) {
41
+ xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
42
+ xdr = null;
43
+ completeCallback(status, statusText, responses, responseHeaders);
44
+ }
45
+ xdr = new XDomainRequest();
46
+ // XDomainRequest only supports GET and POST:
47
+ if (s.type === 'DELETE') {
48
+ s.url = s.url + addParamChar + '_method=DELETE';
49
+ s.type = 'POST';
50
+ } else if (s.type === 'PUT') {
51
+ s.url = s.url + addParamChar + '_method=PUT';
52
+ s.type = 'POST';
53
+ } else if (s.type === 'PATCH') {
54
+ s.url = s.url + addParamChar + '_method=PATCH';
55
+ s.type = 'POST';
56
+ }
57
+ xdr.open(s.type, s.url);
58
+ xdr.onload = function () {
59
+ callback(
60
+ 200,
61
+ 'OK',
62
+ {text: xdr.responseText},
63
+ 'Content-Type: ' + xdr.contentType
64
+ );
65
+ };
66
+ xdr.onerror = function () {
67
+ callback(404, 'Not Found');
68
+ };
69
+ if (s.xdrTimeout) {
70
+ xdr.ontimeout = function () {
71
+ callback(0, 'timeout');
72
+ };
73
+ xdr.timeout = s.xdrTimeout;
74
+ }
75
+ xdr.send((s.hasContent && s.data) || null);
76
+ },
77
+ abort: function () {
78
+ if (xdr) {
79
+ xdr.onerror = $.noop();
80
+ xdr.abort();
81
+ }
82
+ }
83
+ };
84
+ }
85
+ });
86
+ }
87
+ }));
@@ -0,0 +1,428 @@
1
+ /*
2
+ * jQuery File Upload AngularJS Plugin 2.0.1
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
+ /*jslint nomen: true, unparam: true */
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 scopeApply = function () {
40
+ var scope = angular.element(this)
41
+ .fileupload('option', 'scope')(),
42
+ $timeout = angular.injector(['ng'])
43
+ .get('$timeout');
44
+ // Safe apply, makes sure $apply is called
45
+ // asynchronously outside of the $digest cycle:
46
+ $timeout(function () {
47
+ scope.$apply();
48
+ });
49
+ },
50
+ addFileMethods = function (scope, data) {
51
+ var files = data.files,
52
+ file = files[0];
53
+ angular.forEach(files, function (file, index) {
54
+ file._index = index;
55
+ file.$state = function () {
56
+ return data.state();
57
+ };
58
+ file.$processing = function () {
59
+ return data.processing();
60
+ };
61
+ file.$progress = function () {
62
+ return data.progress();
63
+ };
64
+ file.$response = function () {
65
+ return data.response();
66
+ };
67
+ });
68
+ file.$submit = function () {
69
+ return data.submit();
70
+ };
71
+ file.$cancel = function () {
72
+ scope.clear(files);
73
+ return data.abort();
74
+ };
75
+ },
76
+ $config;
77
+ $config = this.defaults = {
78
+ handleResponse: function (e, data) {
79
+ var files = data.result && data.result.files;
80
+ if (files) {
81
+ data.scope().replace(data.files, files);
82
+ } else if (data.errorThrown ||
83
+ data.textStatus === 'error') {
84
+ data.files[0].error = data.errorThrown ||
85
+ data.textStatus;
86
+ }
87
+ },
88
+ add: function (e, data) {
89
+ if (e.isDefaultPrevented()) {
90
+ return false;
91
+ }
92
+ var scope = data.scope(),
93
+ filesCopy = [];
94
+ angular.forEach(data.files, function (file) {
95
+ filesCopy.push(file);
96
+ });
97
+ scope.$apply(function () {
98
+ addFileMethods(scope, data);
99
+ var method = scope.option('prependFiles') ?
100
+ 'unshift' : 'push';
101
+ Array.prototype[method].apply(scope.queue, data.files);
102
+ });
103
+ data.process(function () {
104
+ return scope.process(data);
105
+ }).always(function () {
106
+ scope.$apply(function () {
107
+ addFileMethods(scope, data);
108
+ scope.replace(filesCopy, data.files);
109
+ });
110
+ }).then(function () {
111
+ if ((scope.option('autoUpload') ||
112
+ data.autoUpload) &&
113
+ data.autoUpload !== false) {
114
+ data.submit();
115
+ }
116
+ });
117
+ },
118
+ progress: function (e, data) {
119
+ if (e.isDefaultPrevented()) {
120
+ return false;
121
+ }
122
+ data.scope().$apply();
123
+ },
124
+ done: function (e, data) {
125
+ if (e.isDefaultPrevented()) {
126
+ return false;
127
+ }
128
+ var that = this;
129
+ data.scope().$apply(function () {
130
+ data.handleResponse.call(that, e, data);
131
+ });
132
+ },
133
+ fail: function (e, data) {
134
+ if (e.isDefaultPrevented()) {
135
+ return false;
136
+ }
137
+ var that = this;
138
+ if (data.errorThrown === 'abort') {
139
+ return;
140
+ }
141
+ data.scope().$apply(function () {
142
+ data.handleResponse.call(that, e, data);
143
+ });
144
+ },
145
+ stop: scopeApply,
146
+ processstart: scopeApply,
147
+ processstop: scopeApply,
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
+ return $element.fileupload('option', option, data);
212
+ },
213
+ add: function (data) {
214
+ return $element.fileupload('add', data);
215
+ },
216
+ send: function (data) {
217
+ return $element.fileupload('send', data);
218
+ },
219
+ process: function (data) {
220
+ return $element.fileupload('process', data);
221
+ },
222
+ processing: function (data) {
223
+ return $element.fileupload('processing', data);
224
+ }
225
+ };
226
+ $scope.disabled = !$window.jQuery.support.fileInput;
227
+ $scope.queue = $scope.queue || [];
228
+ $scope.clear = function (files) {
229
+ var queue = this.queue,
230
+ i = queue.length,
231
+ file = files,
232
+ length = 1;
233
+ if (angular.isArray(files)) {
234
+ file = files[0];
235
+ length = files.length;
236
+ }
237
+ while (i) {
238
+ i -= 1;
239
+ if (queue[i] === file) {
240
+ return queue.splice(i, length);
241
+ }
242
+ }
243
+ };
244
+ $scope.replace = function (oldFiles, newFiles) {
245
+ var queue = this.queue,
246
+ file = oldFiles[0],
247
+ i,
248
+ j;
249
+ for (i = 0; i < queue.length; i += 1) {
250
+ if (queue[i] === file) {
251
+ for (j = 0; j < newFiles.length; j += 1) {
252
+ queue[i + j] = newFiles[j];
253
+ }
254
+ return;
255
+ }
256
+ }
257
+ };
258
+ $scope.applyOnQueue = function (method) {
259
+ var list = this.queue.slice(0),
260
+ i,
261
+ file;
262
+ for (i = 0; i < list.length; i += 1) {
263
+ file = list[i];
264
+ if (file[method]) {
265
+ file[method]();
266
+ }
267
+ }
268
+ };
269
+ $scope.submit = function () {
270
+ this.applyOnQueue('$submit');
271
+ };
272
+ $scope.cancel = function () {
273
+ this.applyOnQueue('$cancel');
274
+ };
275
+ // Add upload methods to the scope:
276
+ angular.extend($scope, uploadMethods);
277
+ // The fileupload widget will initialize with
278
+ // the options provided via "data-"-parameters,
279
+ // as well as those given via options object:
280
+ $element.fileupload(angular.extend(
281
+ {scope: function () {
282
+ return $scope;
283
+ }},
284
+ fileUpload.defaults
285
+ )).on('fileuploadadd', function (e, data) {
286
+ data.scope = $scope.option('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
+ if (preview) {
382
+ $element.empty().append(preview);
383
+ }
384
+ }
385
+ );
386
+ }
387
+ ])
388
+
389
+ .directive('fileUpload', function () {
390
+ return {
391
+ controller: 'FileUploadController',
392
+ scope: true
393
+ };
394
+ })
395
+
396
+ .directive('fileUploadProgress', function () {
397
+ return {
398
+ controller: 'FileUploadProgressController',
399
+ scope: true
400
+ };
401
+ })
402
+
403
+ .directive('fileUploadPreview', function () {
404
+ return {
405
+ controller: 'FileUploadPreviewController'
406
+ };
407
+ })
408
+
409
+ // Enhance the HTML5 download attribute to
410
+ // allow drag&drop of files to the desktop:
411
+ .directive('download', function () {
412
+ return function (scope, elm) {
413
+ elm.on('dragstart', function (e) {
414
+ try {
415
+ e.originalEvent.dataTransfer.setData(
416
+ 'DownloadURL',
417
+ [
418
+ 'application/octet-stream',
419
+ elm.prop('download'),
420
+ elm.prop('href')
421
+ ].join(':')
422
+ );
423
+ } catch (ignore) {}
424
+ });
425
+ };
426
+ });
427
+
428
+ }));