|
1 | 1 | /*
|
2 |
| - * jQuery File Upload AngularJS Plugin 1.2 |
| 2 | + * jQuery File Upload AngularJS Plugin 1.2.1 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2013, Sebastian Tschan
|
|
170 | 170 | .controller('FileUploadController', [
|
171 | 171 | '$scope', '$element', '$attrs', 'fileUpload',
|
172 | 172 | function ($scope, $element, $attrs, fileUpload) {
|
| 173 | + var uploadMethods = { |
| 174 | + progress: function () { |
| 175 | + return $element.fileupload('progress'); |
| 176 | + }, |
| 177 | + active: function () { |
| 178 | + return $element.fileupload('active'); |
| 179 | + }, |
| 180 | + option: function (option, data) { |
| 181 | + return $element.fileupload('option', option, data); |
| 182 | + }, |
| 183 | + add: function (data) { |
| 184 | + return $element.fileupload('add', data); |
| 185 | + }, |
| 186 | + send: function (data) { |
| 187 | + return $element.fileupload('send', data); |
| 188 | + }, |
| 189 | + process: function (data) { |
| 190 | + return $element.fileupload('process', data); |
| 191 | + }, |
| 192 | + processing: function (data) { |
| 193 | + return $element.fileupload('processing', data); |
| 194 | + } |
| 195 | + }; |
173 | 196 | $scope.disabled = angular.element('<input type="file">')
|
174 | 197 | .prop('disabled');
|
175 | 198 | $scope.queue = $scope.queue || [];
|
|
202 | 225 | }
|
203 | 226 | }
|
204 | 227 | };
|
205 |
| - $scope.progress = function () { |
206 |
| - return $element.fileupload('progress'); |
207 |
| - }; |
208 |
| - $scope.active = function () { |
209 |
| - return $element.fileupload('active'); |
210 |
| - }; |
211 |
| - $scope.option = function (option, data) { |
212 |
| - return $element.fileupload('option', option, data); |
213 |
| - }; |
214 |
| - $scope.add = function (data) { |
215 |
| - return $element.fileupload('add', data); |
216 |
| - }; |
217 |
| - $scope.send = function (data) { |
218 |
| - return $element.fileupload('send', data); |
219 |
| - }; |
220 |
| - $scope.process = function (data) { |
221 |
| - return $element.fileupload('process', data); |
222 |
| - }; |
223 |
| - $scope.processing = function (data) { |
224 |
| - return $element.fileupload('processing', data); |
225 |
| - }; |
226 | 228 | $scope.applyOnQueue = function (method) {
|
227 | 229 | var list = this.queue.slice(0),
|
228 | 230 | i,
|
|
240 | 242 | $scope.cancel = function () {
|
241 | 243 | this.applyOnQueue('$cancel');
|
242 | 244 | };
|
| 245 | + // Add upload methods to the scope: |
| 246 | + angular.extend($scope, uploadMethods); |
243 | 247 | // The fileupload widget will initialize with
|
244 | 248 | // the options provided via "data-"-parameters,
|
245 | 249 | // as well as those given via options object:
|
|
277 | 281 | 'fileuploadprocessstop'
|
278 | 282 | ].join(' '), function (e, data) {
|
279 | 283 | $scope.$emit(e.type, data);
|
| 284 | + }).on('remove', function () { |
| 285 | + // Remove upload methods from the scope, |
| 286 | + // when the widget is removed: |
| 287 | + var method; |
| 288 | + for (method in uploadMethods) { |
| 289 | + if (uploadMethods.hasOwnProperty(method)) { |
| 290 | + delete $scope[method]; |
| 291 | + } |
| 292 | + } |
280 | 293 | });
|
281 | 294 | // Observe option changes:
|
282 | 295 | $scope.$watch(
|
|
0 commit comments