angularjs-file-upload-rails 1.1.6 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb70a719506f44ab6f69a15b0eaf560faa90cb9d
4
- data.tar.gz: cc88a54f125d537375f4b16988b1564d97728d3d
3
+ metadata.gz: 17f7752e748b20c72779c900f146721bd76fac0e
4
+ data.tar.gz: 1aa3fac0585665efa8512687bf12279e1d09f8f0
5
5
  SHA512:
6
- metadata.gz: f4161dab606fd0d2d9e05b4652d3bcbdf8e8433c4fc47c622efbf9d1be01b7f9215a4e7a078c029dade375c12184e6ece84605dbc2654908db38f0499a2d2620
7
- data.tar.gz: e41661d20c722e602ffed5ffd2124ab676e5774061251891e9774a3d12ece76c126511317996c5cb25ef444a2fcd8d703ec3d26fe164ed876b9a5c329420a96f
6
+ metadata.gz: 2df46552ecddcef4060b0ac1675f375c46ce9b8ca78b9c2318c88611e158376225accea377b01b72c241ba0472d84665052fb6479fb1866dfac874ab902fec90
7
+ data.tar.gz: 38029528f2b86ba26bc283d385d4a7e5ece30c58859ed582cfeb72be2504ba5ba43a28992f3a086339e51f3f856d27b9e9ab7721ae370ade6f505834e42a8daf
data/README.md CHANGED
@@ -9,7 +9,7 @@ A gem that uses [angular-file-upload](https://github.com/nervgh/angular-file-upl
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'angularjs-file-upload-rails', '~> 1.1.5'
12
+ gem 'angularjs-file-upload-rails', '~> 2.2.0'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -35,14 +35,14 @@ Include it in your JavaScript manifest (e.g. `application.js`)
35
35
 
36
36
  ## Read more
37
37
 
38
- read more about the options in [angular-file-upload-wiki](https://github.com/nervgh/angular-file-upload/wiki/Introduction)
38
+ read more about the options in [angular-file-upload-wiki](https://github.com/nervgh/angular-file-upload/wiki/Introduction)
39
39
 
40
- ## Basic example
40
+ ## Basic example
41
41
 
42
42
  \* *assuming that you have setup an ```angularjs``` correctly in your rails app
43
43
 
44
44
  ```ruby
45
- gem 'angularjs-file-upload-rails', '~> 1.1.5'
45
+ gem 'angularjs-file-upload-rails', '~> 2.2.0'
46
46
  gem 'carrierwave'
47
47
  gem 'rails', '4.1.5'
48
48
  ```
@@ -50,7 +50,7 @@ read more about the options in [angular-file-upload-wiki](https://github.com/ner
50
50
  Setup your carrierwave gem as discribed in the [carrierwave-readme](https://github.com/carrierwaveuploader/carrierwave)
51
51
 
52
52
  add ```angularjs-file-upload-rails``` to your gem file
53
- add
53
+ add
54
54
 
55
55
  ```javascript
56
56
  //= require angularjs-file-upload
@@ -17,6 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib", "app"]
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.3"
20
- spec.add_development_dependency "rails", "~> 3.1"
20
+ spec.add_development_dependency "rails", ">= 3.1"
21
21
  spec.add_development_dependency "rake"
22
22
  end
@@ -1,1332 +1,1999 @@
1
1
  /*
2
- angular-file-upload v1.1.5
2
+ angular-file-upload v2.2.0
3
3
  https://github.com/nervgh/angular-file-upload
4
4
  */
5
- (function(angular, factory) {
6
- if (typeof define === 'function' && define.amd) {
7
- define('angular-file-upload', ['angular'], function(angular) {
8
- return factory(angular);
9
- });
10
- } else {
11
- return factory(angular);
12
- }
13
- }(typeof angular === 'undefined' ? null : angular, function(angular) {
14
-
15
- var module = angular.module('angularFileUpload', []);
16
-
17
- 'use strict';
18
-
19
- /**
20
- * Classes
21
- *
22
- * FileUploader
23
- * FileUploader.FileLikeObject
24
- * FileUploader.FileItem
25
- * FileUploader.FileDirective
26
- * FileUploader.FileSelect
27
- * FileUploader.FileDrop
28
- * FileUploader.FileOver
29
- */
30
-
31
- module
32
-
33
-
34
- .value('fileUploaderOptions', {
35
- url: '/',
36
- alias: 'file',
37
- headers: {},
38
- queue: [],
39
- progress: 0,
40
- autoUpload: false,
41
- removeAfterUpload: false,
42
- method: 'POST',
43
- filters: [],
44
- formData: [],
45
- queueLimit: Number.MAX_VALUE,
46
- withCredentials: false
47
- })
48
-
49
-
50
- .factory('FileUploader', ['fileUploaderOptions', '$rootScope', '$http', '$window', '$compile',
51
- function(fileUploaderOptions, $rootScope, $http, $window, $compile) {
52
- /**
53
- * Creates an instance of FileUploader
54
- * @param {Object} [options]
55
- * @constructor
56
- */
57
- function FileUploader(options) {
58
- var settings = angular.copy(fileUploaderOptions);
59
- angular.extend(this, settings, options, {
60
- isUploading: false,
61
- _nextIndex: 0,
62
- _failFilterIndex: -1,
63
- _directives: {select: [], drop: [], over: []}
64
- });
65
-
66
- // add default filters
67
- this.filters.unshift({name: 'queueLimit', fn: this._queueLimitFilter});
68
- this.filters.unshift({name: 'folder', fn: this._folderFilter});
69
- }
70
- /**********************
71
- * PUBLIC
72
- **********************/
73
- /**
74
- * Checks a support the html5 uploader
75
- * @returns {Boolean}
76
- * @readonly
77
- */
78
- FileUploader.prototype.isHTML5 = !!($window.File && $window.FormData);
79
- /**
80
- * Adds items to the queue
81
- * @param {File|HTMLInputElement|Object|FileList|Array<Object>} files
82
- * @param {Object} [options]
83
- * @param {Array<Function>|String} filters
84
- */
85
- FileUploader.prototype.addToQueue = function(files, options, filters) {
86
- var list = this.isArrayLikeObject(files) ? files: [files];
87
- var arrayOfFilters = this._getFilters(filters);
88
- var count = this.queue.length;
89
- var addedFileItems = [];
90
-
91
- angular.forEach(list, function(some /*{File|HTMLInputElement|Object}*/) {
92
- var temp = new FileUploader.FileLikeObject(some);
93
-
94
- if (this._isValidFile(temp, arrayOfFilters, options)) {
95
- var fileItem = new FileUploader.FileItem(this, some, options);
96
- addedFileItems.push(fileItem);
97
- this.queue.push(fileItem);
98
- this._onAfterAddingFile(fileItem);
99
- } else {
100
- var filter = this.filters[this._failFilterIndex];
101
- this._onWhenAddingFileFailed(temp, filter, options);
102
- }
103
- }, this);
104
-
105
- if(this.queue.length !== count) {
106
- this._onAfterAddingAll(addedFileItems);
107
- this.progress = this._getTotalProgress();
108
- }
109
-
110
- this._render();
111
- if (this.autoUpload) this.uploadAll();
112
- };
113
- /**
114
- * Remove items from the queue. Remove last: index = -1
115
- * @param {FileItem|Number} value
116
- */
117
- FileUploader.prototype.removeFromQueue = function(value) {
118
- var index = this.getIndexOfItem(value);
119
- var item = this.queue[index];
120
- if (item.isUploading) item.cancel();
121
- this.queue.splice(index, 1);
122
- item._destroy();
123
- this.progress = this._getTotalProgress();
124
- };
125
- /**
126
- * Clears the queue
127
- */
128
- FileUploader.prototype.clearQueue = function() {
129
- while(this.queue.length) {
130
- this.queue[0].remove();
131
- }
132
- this.progress = 0;
133
- };
134
- /**
135
- * Uploads a item from the queue
136
- * @param {FileItem|Number} value
137
- */
138
- FileUploader.prototype.uploadItem = function(value) {
139
- var index = this.getIndexOfItem(value);
140
- var item = this.queue[index];
141
- var transport = this.isHTML5 ? '_xhrTransport' : '_iframeTransport';
142
-
143
- item._prepareToUploading();
144
- if(this.isUploading) return;
145
-
146
- this.isUploading = true;
147
- this[transport](item);
148
- };
149
- /**
150
- * Cancels uploading of item from the queue
151
- * @param {FileItem|Number} value
152
- */
153
- FileUploader.prototype.cancelItem = function(value) {
154
- var index = this.getIndexOfItem(value);
155
- var item = this.queue[index];
156
- var prop = this.isHTML5 ? '_xhr' : '_form';
157
- if (item && item.isUploading) item[prop].abort();
158
- };
159
- /**
160
- * Uploads all not uploaded items of queue
161
- */
162
- FileUploader.prototype.uploadAll = function() {
163
- var items = this.getNotUploadedItems().filter(function(item) {
164
- return !item.isUploading;
165
- });
166
- if (!items.length) return;
167
-
168
- angular.forEach(items, function(item) {
169
- item._prepareToUploading();
170
- });
171
- items[0].upload();
172
- };
173
- /**
174
- * Cancels all uploads
175
- */
176
- FileUploader.prototype.cancelAll = function() {
177
- var items = this.getNotUploadedItems();
178
- angular.forEach(items, function(item) {
179
- item.cancel();
180
- });
181
- };
182
- /**
183
- * Returns "true" if value an instance of File
184
- * @param {*} value
185
- * @returns {Boolean}
186
- * @private
187
- */
188
- FileUploader.prototype.isFile = function(value) {
189
- var fn = $window.File;
190
- return (fn && value instanceof fn);
191
- };
192
- /**
193
- * Returns "true" if value an instance of FileLikeObject
194
- * @param {*} value
195
- * @returns {Boolean}
196
- * @private
197
- */
198
- FileUploader.prototype.isFileLikeObject = function(value) {
199
- return value instanceof FileUploader.FileLikeObject;
200
- };
201
- /**
202
- * Returns "true" if value is array like object
203
- * @param {*} value
204
- * @returns {Boolean}
205
- */
206
- FileUploader.prototype.isArrayLikeObject = function(value) {
207
- return (angular.isObject(value) && 'length' in value);
208
- };
209
- /**
210
- * Returns a index of item from the queue
211
- * @param {Item|Number} value
212
- * @returns {Number}
213
- */
214
- FileUploader.prototype.getIndexOfItem = function(value) {
215
- return angular.isNumber(value) ? value : this.queue.indexOf(value);
216
- };
217
- /**
218
- * Returns not uploaded items
219
- * @returns {Array}
220
- */
221
- FileUploader.prototype.getNotUploadedItems = function() {
222
- return this.queue.filter(function(item) {
223
- return !item.isUploaded;
224
- });
225
- };
226
- /**
227
- * Returns items ready for upload
228
- * @returns {Array}
229
- */
230
- FileUploader.prototype.getReadyItems = function() {
231
- return this.queue
232
- .filter(function(item) {
233
- return (item.isReady && !item.isUploading);
234
- })
235
- .sort(function(item1, item2) {
236
- return item1.index - item2.index;
237
- });
238
- };
239
- /**
240
- * Destroys instance of FileUploader
241
- */
242
- FileUploader.prototype.destroy = function() {
243
- angular.forEach(this._directives, function(key) {
244
- angular.forEach(this._directives[key], function(object) {
245
- object.destroy();
246
- }, this);
247
- }, this);
248
- };
249
- /**
250
- * Callback
251
- * @param {Array} fileItems
252
- */
253
- FileUploader.prototype.onAfterAddingAll = function(fileItems) {};
254
- /**
255
- * Callback
256
- * @param {FileItem} fileItem
257
- */
258
- FileUploader.prototype.onAfterAddingFile = function(fileItem) {};
259
- /**
260
- * Callback
261
- * @param {File|Object} item
262
- * @param {Object} filter
263
- * @param {Object} options
264
- * @private
265
- */
266
- FileUploader.prototype.onWhenAddingFileFailed = function(item, filter, options) {};
267
- /**
268
- * Callback
269
- * @param {FileItem} fileItem
270
- */
271
- FileUploader.prototype.onBeforeUploadItem = function(fileItem) {};
272
- /**
273
- * Callback
274
- * @param {FileItem} fileItem
275
- * @param {Number} progress
276
- */
277
- FileUploader.prototype.onProgressItem = function(fileItem, progress) {};
278
- /**
279
- * Callback
280
- * @param {Number} progress
281
- */
282
- FileUploader.prototype.onProgressAll = function(progress) {};
283
- /**
284
- * Callback
285
- * @param {FileItem} item
286
- * @param {*} response
287
- * @param {Number} status
288
- * @param {Object} headers
289
- */
290
- FileUploader.prototype.onSuccessItem = function(item, response, status, headers) {};
291
- /**
292
- * Callback
293
- * @param {FileItem} item
294
- * @param {*} response
295
- * @param {Number} status
296
- * @param {Object} headers
297
- */
298
- FileUploader.prototype.onErrorItem = function(item, response, status, headers) {};
299
- /**
300
- * Callback
301
- * @param {FileItem} item
302
- * @param {*} response
303
- * @param {Number} status
304
- * @param {Object} headers
305
- */
306
- FileUploader.prototype.onCancelItem = function(item, response, status, headers) {};
307
- /**
308
- * Callback
309
- * @param {FileItem} item
310
- * @param {*} response
311
- * @param {Number} status
312
- * @param {Object} headers
313
- */
314
- FileUploader.prototype.onCompleteItem = function(item, response, status, headers) {};
315
- /**
316
- * Callback
317
- */
318
- FileUploader.prototype.onCompleteAll = function() {};
319
- /**********************
320
- * PRIVATE
321
- **********************/
322
- /**
323
- * Returns the total progress
324
- * @param {Number} [value]
325
- * @returns {Number}
326
- * @private
327
- */
328
- FileUploader.prototype._getTotalProgress = function(value) {
329
- if(this.removeAfterUpload) return value || 0;
330
-
331
- var notUploaded = this.getNotUploadedItems().length;
332
- var uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
333
- var ratio = 100 / this.queue.length;
334
- var current = (value || 0) * ratio / 100;
335
-
336
- return Math.round(uploaded * ratio + current);
337
- };
338
- /**
339
- * Returns array of filters
340
- * @param {Array<Function>|String} filters
341
- * @returns {Array<Function>}
342
- * @private
343
- */
344
- FileUploader.prototype._getFilters = function(filters) {
345
- if (angular.isUndefined(filters)) return this.filters;
346
- if (angular.isArray(filters)) return filters;
347
- var names = filters.match(/[^\s,]+/g);
348
- return this.filters.filter(function(filter) {
349
- return names.indexOf(filter.name) !== -1;
350
- }, this);
351
- };
352
- /**
353
- * Updates html
354
- * @private
355
- */
356
- FileUploader.prototype._render = function() {
357
- if (!$rootScope.$$phase) $rootScope.$apply();
358
- };
359
- /**
360
- * Returns "true" if item is a file (not folder)
361
- * @param {File|FileLikeObject} item
362
- * @returns {Boolean}
363
- * @private
364
- */
365
- FileUploader.prototype._folderFilter = function(item) {
366
- return !!(item.size || item.type);
367
- };
368
- /**
369
- * Returns "true" if the limit has not been reached
370
- * @returns {Boolean}
371
- * @private
372
- */
373
- FileUploader.prototype._queueLimitFilter = function() {
374
- return this.queue.length < this.queueLimit;
375
- };
376
- /**
377
- * Returns "true" if file pass all filters
378
- * @param {File|Object} file
379
- * @param {Array<Function>} filters
380
- * @param {Object} options
381
- * @returns {Boolean}
382
- * @private
383
- */
384
- FileUploader.prototype._isValidFile = function(file, filters, options) {
385
- this._failFilterIndex = -1;
386
- return !filters.length ? true : filters.every(function(filter) {
387
- this._failFilterIndex++;
388
- return filter.fn.call(this, file, options);
389
- }, this);
390
- };
391
- /**
392
- * Checks whether upload successful
393
- * @param {Number} status
394
- * @returns {Boolean}
395
- * @private
396
- */
397
- FileUploader.prototype._isSuccessCode = function(status) {
398
- return (status >= 200 && status < 300) || status === 304;
399
- };
400
- /**
401
- * Transforms the server response
402
- * @param {*} response
403
- * @param {Object} headers
404
- * @returns {*}
405
- * @private
406
- */
407
- FileUploader.prototype._transformResponse = function(response, headers) {
408
- var headersGetter = this._headersGetter(headers);
409
- angular.forEach($http.defaults.transformResponse, function(transformFn) {
410
- response = transformFn(response, headersGetter);
411
- });
412
- return response;
413
- };
414
- /**
415
- * Parsed response headers
416
- * @param headers
417
- * @returns {Object}
418
- * @see https://github.com/angular/angular.js/blob/master/src/ng/http.js
419
- * @private
420
- */
421
- FileUploader.prototype._parseHeaders = function(headers) {
422
- var parsed = {}, key, val, i;
423
-
424
- if (!headers) return parsed;
425
-
426
- angular.forEach(headers.split('\n'), function(line) {
427
- i = line.indexOf(':');
428
- key = line.slice(0, i).trim().toLowerCase();
429
- val = line.slice(i + 1).trim();
430
-
431
- if (key) {
432
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
433
- }
434
- });
435
-
436
- return parsed;
437
- };
438
- /**
439
- * Returns function that returns headers
440
- * @param {Object} parsedHeaders
441
- * @returns {Function}
442
- * @private
443
- */
444
- FileUploader.prototype._headersGetter = function(parsedHeaders) {
445
- return function(name) {
446
- if (name) {
447
- return parsedHeaders[name.toLowerCase()] || null;
448
- }
449
- return parsedHeaders;
450
- };
451
- };
452
- /**
453
- * The XMLHttpRequest transport
454
- * @param {FileItem} item
455
- * @private
456
- */
457
- FileUploader.prototype._xhrTransport = function(item) {
458
- var xhr = item._xhr = new XMLHttpRequest();
459
- var form = new FormData();
460
- var that = this;
461
-
462
- that._onBeforeUploadItem(item);
463
-
464
- angular.forEach(item.formData, function(obj) {
465
- angular.forEach(obj, function(value, key) {
466
- form.append(key, value);
467
- });
468
- });
469
-
470
- form.append(item.alias, item._file, item.file.name);
471
-
472
- xhr.upload.onprogress = function(event) {
473
- var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
474
- that._onProgressItem(item, progress);
475
- };
476
-
477
- xhr.onload = function() {
478
- var headers = that._parseHeaders(xhr.getAllResponseHeaders());
479
- var response = that._transformResponse(xhr.response, headers);
480
- var gist = that._isSuccessCode(xhr.status) ? 'Success' : 'Error';
481
- var method = '_on' + gist + 'Item';
482
- that[method](item, response, xhr.status, headers);
483
- that._onCompleteItem(item, response, xhr.status, headers);
484
- };
485
-
486
- xhr.onerror = function() {
487
- var headers = that._parseHeaders(xhr.getAllResponseHeaders());
488
- var response = that._transformResponse(xhr.response, headers);
489
- that._onErrorItem(item, response, xhr.status, headers);
490
- that._onCompleteItem(item, response, xhr.status, headers);
491
- };
492
-
493
- xhr.onabort = function() {
494
- var headers = that._parseHeaders(xhr.getAllResponseHeaders());
495
- var response = that._transformResponse(xhr.response, headers);
496
- that._onCancelItem(item, response, xhr.status, headers);
497
- that._onCompleteItem(item, response, xhr.status, headers);
498
- };
499
-
500
- xhr.open(item.method, item.url, true);
501
-
502
- xhr.withCredentials = item.withCredentials;
503
-
504
- angular.forEach(item.headers, function(value, name) {
505
- xhr.setRequestHeader(name, value);
506
- });
507
-
508
- xhr.send(form);
509
- this._render();
510
- };
511
- /**
512
- * The IFrame transport
513
- * @param {FileItem} item
514
- * @private
515
- */
516
- FileUploader.prototype._iframeTransport = function(item) {
517
- var form = angular.element('<form style="display: none;" />');
518
- var iframe = angular.element('<iframe name="iframeTransport' + Date.now() + '">');
519
- var input = item._input;
520
- var that = this;
521
-
522
- if (item._form) item._form.replaceWith(input); // remove old form
523
- item._form = form; // save link to new form
524
-
525
- that._onBeforeUploadItem(item);
526
-
527
- input.prop('name', item.alias);
528
-
529
- angular.forEach(item.formData, function(obj) {
530
- angular.forEach(obj, function(value, key) {
531
- var element = angular.element('<input type="hidden" name="' + key + '" />');
532
- element.val(value);
533
- form.append(element);
534
- });
535
- });
536
-
537
- form.prop({
538
- action: item.url,
539
- method: 'POST',
540
- target: iframe.prop('name'),
541
- enctype: 'multipart/form-data',
542
- encoding: 'multipart/form-data' // old IE
543
- });
544
-
545
- iframe.bind('load', function() {
546
- try {
547
- // Fix for legacy IE browsers that loads internal error page
548
- // when failed WS response received. In consequence iframe
549
- // content access denied error is thrown becouse trying to
550
- // access cross domain page. When such thing occurs notifying
551
- // with empty response object. See more info at:
552
- // http://stackoverflow.com/questions/151362/access-is-denied-error-on-accessing-iframe-document-object
553
- // Note that if non standard 4xx or 5xx error code returned
554
- // from WS then response content can be accessed without error
555
- // but 'XHR' status becomes 200. In order to avoid confusion
556
- // returning response via same 'success' event handler.
557
-
558
- // fixed angular.contents() for iframes
559
- var html = iframe[0].contentDocument.body.innerHTML;
560
- } catch (e) {}
561
-
562
- var xhr = {response: html, status: 200, dummy: true};
563
- var headers = {};
564
- var response = that._transformResponse(xhr.response, headers);
565
-
566
- that._onSuccessItem(item, response, xhr.status, headers);
567
- that._onCompleteItem(item, response, xhr.status, headers);
568
- });
569
-
570
- form.abort = function() {
571
- var xhr = {status: 0, dummy: true};
572
- var headers = {};
573
- var response;
574
-
575
- iframe.unbind('load').prop('src', 'javascript:false;');
576
- form.replaceWith(input);
577
-
578
- that._onCancelItem(item, response, xhr.status, headers);
579
- that._onCompleteItem(item, response, xhr.status, headers);
580
- };
581
-
582
- input.after(form);
583
- form.append(input).append(iframe);
584
-
585
- form[0].submit();
586
- this._render();
587
- };
588
- /**
589
- * Inner callback
590
- * @param {File|Object} item
591
- * @param {Object} filter
592
- * @param {Object} options
593
- * @private
594
- */
595
- FileUploader.prototype._onWhenAddingFileFailed = function(item, filter, options) {
596
- this.onWhenAddingFileFailed(item, filter, options);
597
- };
598
- /**
599
- * Inner callback
600
- * @param {FileItem} item
601
- */
602
- FileUploader.prototype._onAfterAddingFile = function(item) {
603
- this.onAfterAddingFile(item);
604
- };
605
- /**
606
- * Inner callback
607
- * @param {Array<FileItem>} items
608
- */
609
- FileUploader.prototype._onAfterAddingAll = function(items) {
610
- this.onAfterAddingAll(items);
611
- };
612
- /**
613
- * Inner callback
614
- * @param {FileItem} item
615
- * @private
616
- */
617
- FileUploader.prototype._onBeforeUploadItem = function(item) {
618
- item._onBeforeUpload();
619
- this.onBeforeUploadItem(item);
620
- };
621
- /**
622
- * Inner callback
623
- * @param {FileItem} item
624
- * @param {Number} progress
625
- * @private
626
- */
627
- FileUploader.prototype._onProgressItem = function(item, progress) {
628
- var total = this._getTotalProgress(progress);
629
- this.progress = total;
630
- item._onProgress(progress);
631
- this.onProgressItem(item, progress);
632
- this.onProgressAll(total);
633
- this._render();
634
- };
635
- /**
636
- * Inner callback
637
- * @param {FileItem} item
638
- * @param {*} response
639
- * @param {Number} status
640
- * @param {Object} headers
641
- * @private
642
- */
643
- FileUploader.prototype._onSuccessItem = function(item, response, status, headers) {
644
- item._onSuccess(response, status, headers);
645
- this.onSuccessItem(item, response, status, headers);
646
- };
647
- /**
648
- * Inner callback
649
- * @param {FileItem} item
650
- * @param {*} response
651
- * @param {Number} status
652
- * @param {Object} headers
653
- * @private
654
- */
655
- FileUploader.prototype._onErrorItem = function(item, response, status, headers) {
656
- item._onError(response, status, headers);
657
- this.onErrorItem(item, response, status, headers);
658
- };
659
- /**
660
- * Inner callback
661
- * @param {FileItem} item
662
- * @param {*} response
663
- * @param {Number} status
664
- * @param {Object} headers
665
- * @private
666
- */
667
- FileUploader.prototype._onCancelItem = function(item, response, status, headers) {
668
- item._onCancel(response, status, headers);
669
- this.onCancelItem(item, response, status, headers);
670
- };
671
- /**
672
- * Inner callback
673
- * @param {FileItem} item
674
- * @param {*} response
675
- * @param {Number} status
676
- * @param {Object} headers
677
- * @private
678
- */
679
- FileUploader.prototype._onCompleteItem = function(item, response, status, headers) {
680
- item._onComplete(response, status, headers);
681
- this.onCompleteItem(item, response, status, headers);
682
-
683
- var nextItem = this.getReadyItems()[0];
684
- this.isUploading = false;
685
-
686
- if(angular.isDefined(nextItem)) {
687
- nextItem.upload();
688
- return;
689
- }
690
-
691
- this.onCompleteAll();
692
- this.progress = this._getTotalProgress();
693
- this._render();
694
- };
695
- /**********************
696
- * STATIC
697
- **********************/
698
- /**
699
- * @borrows FileUploader.prototype.isFile
700
- */
701
- FileUploader.isFile = FileUploader.prototype.isFile;
702
- /**
703
- * @borrows FileUploader.prototype.isFileLikeObject
704
- */
705
- FileUploader.isFileLikeObject = FileUploader.prototype.isFileLikeObject;
706
- /**
707
- * @borrows FileUploader.prototype.isArrayLikeObject
708
- */
709
- FileUploader.isArrayLikeObject = FileUploader.prototype.isArrayLikeObject;
710
- /**
711
- * @borrows FileUploader.prototype.isHTML5
712
- */
713
- FileUploader.isHTML5 = FileUploader.prototype.isHTML5;
714
- /**
715
- * Inherits a target (Class_1) by a source (Class_2)
716
- * @param {Function} target
717
- * @param {Function} source
718
- */
719
- FileUploader.inherit = function(target, source) {
720
- target.prototype = Object.create(source.prototype);
721
- target.prototype.constructor = target;
722
- target.super_ = source;
723
- };
724
- FileUploader.FileLikeObject = FileLikeObject;
725
- FileUploader.FileItem = FileItem;
726
- FileUploader.FileDirective = FileDirective;
727
- FileUploader.FileSelect = FileSelect;
728
- FileUploader.FileDrop = FileDrop;
729
- FileUploader.FileOver = FileOver;
730
-
731
- // ---------------------------
732
-
733
- /**
734
- * Creates an instance of FileLikeObject
735
- * @param {File|HTMLInputElement|Object} fileOrInput
736
- * @constructor
737
- */
738
- function FileLikeObject(fileOrInput) {
739
- var isInput = angular.isElement(fileOrInput);
740
- var fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
741
- var postfix = angular.isString(fakePathOrObject) ? 'FakePath' : 'Object';
742
- var method = '_createFrom' + postfix;
743
- this[method](fakePathOrObject);
744
- }
745
-
746
- /**
747
- * Creates file like object from fake path string
748
- * @param {String} path
749
- * @private
750
- */
751
- FileLikeObject.prototype._createFromFakePath = function(path) {
752
- this.lastModifiedDate = null;
753
- this.size = null;
754
- this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
755
- this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
756
- };
757
- /**
758
- * Creates file like object from object
759
- * @param {File|FileLikeObject} object
760
- * @private
761
- */
762
- FileLikeObject.prototype._createFromObject = function(object) {
763
- this.lastModifiedDate = angular.copy(object.lastModifiedDate);
764
- this.size = object.size;
765
- this.type = object.type;
766
- this.name = object.name;
767
- };
768
-
769
- // ---------------------------
770
-
771
- /**
772
- * Creates an instance of FileItem
773
- * @param {FileUploader} uploader
774
- * @param {File|HTMLInputElement|Object} some
775
- * @param {Object} options
776
- * @constructor
777
- */
778
- function FileItem(uploader, some, options) {
779
- var isInput = angular.isElement(some);
780
- var input = isInput ? angular.element(some) : null;
781
- var file = !isInput ? some : null;
782
-
783
- angular.extend(this, {
784
- url: uploader.url,
785
- alias: uploader.alias,
786
- headers: angular.copy(uploader.headers),
787
- formData: angular.copy(uploader.formData),
788
- removeAfterUpload: uploader.removeAfterUpload,
789
- withCredentials: uploader.withCredentials,
790
- method: uploader.method
791
- }, options, {
792
- uploader: uploader,
793
- file: new FileUploader.FileLikeObject(some),
794
- isReady: false,
795
- isUploading: false,
796
- isUploaded: false,
797
- isSuccess: false,
798
- isCancel: false,
799
- isError: false,
800
- progress: 0,
801
- index: null,
802
- _file: file,
803
- _input: input
804
- });
805
-
806
- if (input) this._replaceNode(input);
807
- }
808
- /**********************
809
- * PUBLIC
810
- **********************/
811
- /**
812
- * Uploads a FileItem
813
- */
814
- FileItem.prototype.upload = function() {
815
- this.uploader.uploadItem(this);
816
- };
817
- /**
818
- * Cancels uploading of FileItem
819
- */
820
- FileItem.prototype.cancel = function() {
821
- this.uploader.cancelItem(this);
822
- };
823
- /**
824
- * Removes a FileItem
825
- */
826
- FileItem.prototype.remove = function() {
827
- this.uploader.removeFromQueue(this);
828
- };
829
- /**
830
- * Callback
831
- * @private
832
- */
833
- FileItem.prototype.onBeforeUpload = function() {};
834
- /**
835
- * Callback
836
- * @param {Number} progress
837
- * @private
838
- */
839
- FileItem.prototype.onProgress = function(progress) {};
840
- /**
841
- * Callback
842
- * @param {*} response
843
- * @param {Number} status
844
- * @param {Object} headers
845
- */
846
- FileItem.prototype.onSuccess = function(response, status, headers) {};
847
- /**
848
- * Callback
849
- * @param {*} response
850
- * @param {Number} status
851
- * @param {Object} headers
852
- */
853
- FileItem.prototype.onError = function(response, status, headers) {};
854
- /**
855
- * Callback
856
- * @param {*} response
857
- * @param {Number} status
858
- * @param {Object} headers
859
- */
860
- FileItem.prototype.onCancel = function(response, status, headers) {};
861
- /**
862
- * Callback
863
- * @param {*} response
864
- * @param {Number} status
865
- * @param {Object} headers
866
- */
867
- FileItem.prototype.onComplete = function(response, status, headers) {};
868
- /**********************
869
- * PRIVATE
870
- **********************/
871
- /**
872
- * Inner callback
873
- */
874
- FileItem.prototype._onBeforeUpload = function() {
875
- this.isReady = true;
876
- this.isUploading = true;
877
- this.isUploaded = false;
878
- this.isSuccess = false;
879
- this.isCancel = false;
880
- this.isError = false;
881
- this.progress = 0;
882
- this.onBeforeUpload();
883
- };
884
- /**
885
- * Inner callback
886
- * @param {Number} progress
887
- * @private
888
- */
889
- FileItem.prototype._onProgress = function(progress) {
890
- this.progress = progress;
891
- this.onProgress(progress);
892
- };
893
- /**
894
- * Inner callback
895
- * @param {*} response
896
- * @param {Number} status
897
- * @param {Object} headers
898
- * @private
899
- */
900
- FileItem.prototype._onSuccess = function(response, status, headers) {
901
- this.isReady = false;
902
- this.isUploading = false;
903
- this.isUploaded = true;
904
- this.isSuccess = true;
905
- this.isCancel = false;
906
- this.isError = false;
907
- this.progress = 100;
908
- this.index = null;
909
- this.onSuccess(response, status, headers);
910
- };
911
- /**
912
- * Inner callback
913
- * @param {*} response
914
- * @param {Number} status
915
- * @param {Object} headers
916
- * @private
917
- */
918
- FileItem.prototype._onError = function(response, status, headers) {
919
- this.isReady = false;
920
- this.isUploading = false;
921
- this.isUploaded = true;
922
- this.isSuccess = false;
923
- this.isCancel = false;
924
- this.isError = true;
925
- this.progress = 0;
926
- this.index = null;
927
- this.onError(response, status, headers);
928
- };
929
- /**
930
- * Inner callback
931
- * @param {*} response
932
- * @param {Number} status
933
- * @param {Object} headers
934
- * @private
935
- */
936
- FileItem.prototype._onCancel = function(response, status, headers) {
937
- this.isReady = false;
938
- this.isUploading = false;
939
- this.isUploaded = false;
940
- this.isSuccess = false;
941
- this.isCancel = true;
942
- this.isError = false;
943
- this.progress = 0;
944
- this.index = null;
945
- this.onCancel(response, status, headers);
946
- };
947
- /**
948
- * Inner callback
949
- * @param {*} response
950
- * @param {Number} status
951
- * @param {Object} headers
952
- * @private
953
- */
954
- FileItem.prototype._onComplete = function(response, status, headers) {
955
- this.onComplete(response, status, headers);
956
- if (this.removeAfterUpload) this.remove();
957
- };
958
- /**
959
- * Destroys a FileItem
960
- */
961
- FileItem.prototype._destroy = function() {
962
- if (this._input) this._input.remove();
963
- if (this._form) this._form.remove();
964
- delete this._form;
965
- delete this._input;
966
- };
967
- /**
968
- * Prepares to uploading
969
- * @private
970
- */
971
- FileItem.prototype._prepareToUploading = function() {
972
- this.index = this.index || ++this.uploader._nextIndex;
973
- this.isReady = true;
974
- };
975
- /**
976
- * Replaces input element on his clone
977
- * @param {JQLite|jQuery} input
978
- * @private
979
- */
980
- FileItem.prototype._replaceNode = function(input) {
981
- var clone = $compile(input.clone())(input.scope());
982
- clone.prop('value', null); // FF fix
983
- input.css('display', 'none');
984
- input.after(clone); // remove jquery dependency
985
- };
986
-
987
- // ---------------------------
988
-
989
- /**
990
- * Creates instance of {FileDirective} object
991
- * @param {Object} options
992
- * @param {Object} options.uploader
993
- * @param {HTMLElement} options.element
994
- * @param {Object} options.events
995
- * @param {String} options.prop
996
- * @constructor
997
- */
998
- function FileDirective(options) {
999
- angular.extend(this, options);
1000
- this.uploader._directives[this.prop].push(this);
1001
- this._saveLinks();
1002
- this.bind();
1003
- }
1004
- /**
1005
- * Map of events
1006
- * @type {Object}
1007
- */
1008
- FileDirective.prototype.events = {};
1009
- /**
1010
- * Binds events handles
1011
- */
1012
- FileDirective.prototype.bind = function() {
1013
- for(var key in this.events) {
1014
- var prop = this.events[key];
1015
- this.element.bind(key, this[prop]);
1016
- }
1017
- };
1018
- /**
1019
- * Unbinds events handles
1020
- */
1021
- FileDirective.prototype.unbind = function() {
1022
- for(var key in this.events) {
1023
- this.element.unbind(key, this.events[key]);
1024
- }
1025
- };
1026
- /**
1027
- * Destroys directive
1028
- */
1029
- FileDirective.prototype.destroy = function() {
1030
- var index = this.uploader._directives[this.prop].indexOf(this);
1031
- this.uploader._directives[this.prop].splice(index, 1);
1032
- this.unbind();
1033
- // this.element = null;
1034
- };
1035
- /**
1036
- * Saves links to functions
1037
- * @private
1038
- */
1039
- FileDirective.prototype._saveLinks = function() {
1040
- for(var key in this.events) {
1041
- var prop = this.events[key];
1042
- this[prop] = this[prop].bind(this);
1043
- }
1044
- };
1045
-
1046
- // ---------------------------
1047
-
1048
- FileUploader.inherit(FileSelect, FileDirective);
1049
-
1050
- /**
1051
- * Creates instance of {FileSelect} object
1052
- * @param {Object} options
1053
- * @constructor
1054
- */
1055
- function FileSelect(options) {
1056
- FileSelect.super_.apply(this, arguments);
1057
-
1058
- if(!this.uploader.isHTML5) {
1059
- this.element.removeAttr('multiple');
1060
- }
1061
- this.element.prop('value', null); // FF fix
1062
- }
1063
- /**
1064
- * Map of events
1065
- * @type {Object}
1066
- */
1067
- FileSelect.prototype.events = {
1068
- $destroy: 'destroy',
1069
- change: 'onChange'
1070
- };
1071
- /**
1072
- * Name of property inside uploader._directive object
1073
- * @type {String}
1074
- */
1075
- FileSelect.prototype.prop = 'select';
1076
- /**
1077
- * Returns options
1078
- * @return {Object|undefined}
1079
- */
1080
- FileSelect.prototype.getOptions = function() {};
1081
- /**
1082
- * Returns filters
1083
- * @return {Array<Function>|String|undefined}
1084
- */
1085
- FileSelect.prototype.getFilters = function() {};
1086
- /**
1087
- * If returns "true" then HTMLInputElement will be cleared
1088
- * @returns {Boolean}
1089
- */
1090
- FileSelect.prototype.isEmptyAfterSelection = function() {
1091
- return !!this.element.attr('multiple');
1092
- };
1093
- /**
1094
- * Event handler
1095
- */
1096
- FileSelect.prototype.onChange = function() {
1097
- var files = this.uploader.isHTML5 ? this.element[0].files : this.element[0];
1098
- var options = this.getOptions();
1099
- var filters = this.getFilters();
1100
-
1101
- if (!this.uploader.isHTML5) this.destroy();
1102
- this.uploader.addToQueue(files, options, filters);
1103
- if (this.isEmptyAfterSelection()) this.element.prop('value', null);
1104
- };
1105
-
1106
- // ---------------------------
1107
-
1108
- FileUploader.inherit(FileDrop, FileDirective);
1109
-
1110
- /**
1111
- * Creates instance of {FileDrop} object
1112
- * @param {Object} options
1113
- * @constructor
1114
- */
1115
- function FileDrop(options) {
1116
- FileDrop.super_.apply(this, arguments);
1117
- }
1118
- /**
1119
- * Map of events
1120
- * @type {Object}
1121
- */
1122
- FileDrop.prototype.events = {
1123
- $destroy: 'destroy',
1124
- drop: 'onDrop',
1125
- dragover: 'onDragOver',
1126
- dragleave: 'onDragLeave'
1127
- };
1128
- /**
1129
- * Name of property inside uploader._directive object
1130
- * @type {String}
1131
- */
1132
- FileDrop.prototype.prop = 'drop';
1133
- /**
1134
- * Returns options
1135
- * @return {Object|undefined}
1136
- */
1137
- FileDrop.prototype.getOptions = function() {};
1138
- /**
1139
- * Returns filters
1140
- * @return {Array<Function>|String|undefined}
1141
- */
1142
- FileDrop.prototype.getFilters = function() {};
1143
- /**
1144
- * Event handler
1145
- */
1146
- FileDrop.prototype.onDrop = function(event) {
1147
- var transfer = this._getTransfer(event);
1148
- if (!transfer) return;
1149
- var options = this.getOptions();
1150
- var filters = this.getFilters();
1151
- this._preventAndStop(event);
1152
- angular.forEach(this.uploader._directives.over, this._removeOverClass, this);
1153
- this.uploader.addToQueue(transfer.files, options, filters);
1154
- };
1155
- /**
1156
- * Event handler
1157
- */
1158
- FileDrop.prototype.onDragOver = function(event) {
1159
- var transfer = this._getTransfer(event);
1160
- if(!this._haveFiles(transfer.types)) return;
1161
- transfer.dropEffect = 'copy';
1162
- this._preventAndStop(event);
1163
- angular.forEach(this.uploader._directives.over, this._addOverClass, this);
1164
- };
1165
- /**
1166
- * Event handler
1167
- */
1168
- FileDrop.prototype.onDragLeave = function(event) {
1169
- if (event.currentTarget !== this.element[0]) return;
1170
- this._preventAndStop(event);
1171
- angular.forEach(this.uploader._directives.over, this._removeOverClass, this);
1172
- };
1173
- /**
1174
- * Helper
1175
- */
1176
- FileDrop.prototype._getTransfer = function(event) {
1177
- return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
1178
- };
1179
- /**
1180
- * Helper
1181
- */
1182
- FileDrop.prototype._preventAndStop = function(event) {
1183
- event.preventDefault();
1184
- event.stopPropagation();
1185
- };
1186
- /**
1187
- * Returns "true" if types contains files
1188
- * @param {Object} types
1189
- */
1190
- FileDrop.prototype._haveFiles = function(types) {
1191
- if (!types) return false;
1192
- if (types.indexOf) {
1193
- return types.indexOf('Files') !== -1;
1194
- } else if(types.contains) {
1195
- return types.contains('Files');
1196
- } else {
1197
- return false;
1198
- }
1199
- };
1200
- /**
1201
- * Callback
1202
- */
1203
- FileDrop.prototype._addOverClass = function(item) {
1204
- item.addOverClass();
1205
- };
1206
- /**
1207
- * Callback
1208
- */
1209
- FileDrop.prototype._removeOverClass = function(item) {
1210
- item.removeOverClass();
1211
- };
1212
-
1213
- // ---------------------------
1214
-
1215
- FileUploader.inherit(FileOver, FileDirective);
1216
-
1217
- /**
1218
- * Creates instance of {FileDrop} object
1219
- * @param {Object} options
1220
- * @constructor
1221
- */
1222
- function FileOver(options) {
1223
- FileOver.super_.apply(this, arguments);
1224
- }
1225
- /**
1226
- * Map of events
1227
- * @type {Object}
1228
- */
1229
- FileOver.prototype.events = {
1230
- $destroy: 'destroy'
1231
- };
1232
- /**
1233
- * Name of property inside uploader._directive object
1234
- * @type {String}
1235
- */
1236
- FileOver.prototype.prop = 'over';
1237
- /**
1238
- * Over class
1239
- * @type {string}
1240
- */
1241
- FileOver.prototype.overClass = 'nv-file-over';
1242
- /**
1243
- * Adds over class
1244
- */
1245
- FileOver.prototype.addOverClass = function() {
1246
- this.element.addClass(this.getOverClass());
1247
- };
1248
- /**
1249
- * Removes over class
1250
- */
1251
- FileOver.prototype.removeOverClass = function() {
1252
- this.element.removeClass(this.getOverClass());
1253
- };
1254
- /**
1255
- * Returns over class
1256
- * @returns {String}
1257
- */
1258
- FileOver.prototype.getOverClass = function() {
1259
- return this.overClass;
1260
- };
1261
-
1262
- return FileUploader;
1263
- }])
1264
-
1265
-
1266
- .directive('nvFileSelect', ['$parse', 'FileUploader', function($parse, FileUploader) {
1267
- return {
1268
- link: function(scope, element, attributes) {
1269
- var uploader = scope.$eval(attributes.uploader);
1270
-
1271
- if (!(uploader instanceof FileUploader)) {
1272
- throw new TypeError('"Uploader" must be an instance of FileUploader');
1273
- }
1274
-
1275
- var object = new FileUploader.FileSelect({
1276
- uploader: uploader,
1277
- element: element
1278
- });
1279
-
1280
- object.getOptions = $parse(attributes.options).bind(object, scope);
1281
- object.getFilters = function() {return attributes.filters;};
1282
- }
1283
- };
1284
- }])
1285
-
1286
-
1287
- .directive('nvFileDrop', ['$parse', 'FileUploader', function($parse, FileUploader) {
1288
- return {
1289
- link: function(scope, element, attributes) {
1290
- var uploader = scope.$eval(attributes.uploader);
1291
-
1292
- if (!(uploader instanceof FileUploader)) {
1293
- throw new TypeError('"Uploader" must be an instance of FileUploader');
1294
- }
1295
-
1296
- if (!uploader.isHTML5) return;
1297
-
1298
- var object = new FileUploader.FileDrop({
1299
- uploader: uploader,
1300
- element: element
1301
- });
1302
-
1303
- object.getOptions = $parse(attributes.options).bind(object, scope);
1304
- object.getFilters = function() {return attributes.filters;};
1305
- }
1306
- };
1307
- }])
1308
-
1309
-
1310
- .directive('nvFileOver', ['FileUploader', function(FileUploader) {
1311
- return {
1312
- link: function(scope, element, attributes) {
1313
- var uploader = scope.$eval(attributes.uploader);
1314
-
1315
- if (!(uploader instanceof FileUploader)) {
1316
- throw new TypeError('"Uploader" must be an instance of FileUploader');
1317
- }
1318
-
1319
- var object = new FileUploader.FileOver({
1320
- uploader: uploader,
1321
- element: element
1322
- });
1323
-
1324
- object.getOverClass = function() {
1325
- return attributes.overClass || this.overClass;
1326
- };
1327
- }
1328
- };
1329
- }])
1330
-
1331
- return module;
1332
- }));
5
+
6
+ (function webpackUniversalModuleDefinition(root, factory) {
7
+ if(typeof exports === 'object' && typeof module === 'object')
8
+ module.exports = factory();
9
+ else if(typeof define === 'function' && define.amd)
10
+ define([], factory);
11
+ else if(typeof exports === 'object')
12
+ exports["angular-file-upload"] = factory();
13
+ else
14
+ root["angular-file-upload"] = factory();
15
+ })(this, function() {
16
+ return /******/ (function(modules) { // webpackBootstrap
17
+ /******/ // The module cache
18
+ /******/ var installedModules = {};
19
+ /******/
20
+ /******/ // The require function
21
+ /******/ function __webpack_require__(moduleId) {
22
+ /******/
23
+ /******/ // Check if module is in cache
24
+ /******/ if(installedModules[moduleId])
25
+ /******/ return installedModules[moduleId].exports;
26
+ /******/
27
+ /******/ // Create a new module (and put it into the cache)
28
+ /******/ var module = installedModules[moduleId] = {
29
+ /******/ exports: {},
30
+ /******/ id: moduleId,
31
+ /******/ loaded: false
32
+ /******/ };
33
+ /******/
34
+ /******/ // Execute the module function
35
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
36
+ /******/
37
+ /******/ // Flag the module as loaded
38
+ /******/ module.loaded = true;
39
+ /******/
40
+ /******/ // Return the exports of the module
41
+ /******/ return module.exports;
42
+ /******/ }
43
+ /******/
44
+ /******/
45
+ /******/ // expose the modules object (__webpack_modules__)
46
+ /******/ __webpack_require__.m = modules;
47
+ /******/
48
+ /******/ // expose the module cache
49
+ /******/ __webpack_require__.c = installedModules;
50
+ /******/
51
+ /******/ // __webpack_public_path__
52
+ /******/ __webpack_require__.p = "";
53
+ /******/
54
+ /******/ // Load entry module and return exports
55
+ /******/ return __webpack_require__(0);
56
+ /******/ })
57
+ /************************************************************************/
58
+ /******/ ([
59
+ /* 0 */
60
+ /***/ function(module, exports, __webpack_require__) {
61
+
62
+ "use strict";
63
+
64
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
65
+
66
+ var CONFIG = _interopRequire(__webpack_require__(1));
67
+
68
+ var options = _interopRequire(__webpack_require__(2));
69
+
70
+ var serviceFileUploader = _interopRequire(__webpack_require__(3));
71
+
72
+ var serviceFileLikeObject = _interopRequire(__webpack_require__(4));
73
+
74
+ var serviceFileItem = _interopRequire(__webpack_require__(5));
75
+
76
+ var serviceFileDirective = _interopRequire(__webpack_require__(6));
77
+
78
+ var serviceFileSelect = _interopRequire(__webpack_require__(7));
79
+
80
+ var serviceFileDrop = _interopRequire(__webpack_require__(8));
81
+
82
+ var serviceFileOver = _interopRequire(__webpack_require__(9));
83
+
84
+ var directiveFileSelect = _interopRequire(__webpack_require__(10));
85
+
86
+ var directiveFileDrop = _interopRequire(__webpack_require__(11));
87
+
88
+ var directiveFileOver = _interopRequire(__webpack_require__(12));
89
+
90
+ angular.module(CONFIG.name, []).value("fileUploaderOptions", options).factory("FileUploader", serviceFileUploader).factory("FileLikeObject", serviceFileLikeObject).factory("FileItem", serviceFileItem).factory("FileDirective", serviceFileDirective).factory("FileSelect", serviceFileSelect).factory("FileDrop", serviceFileDrop).factory("FileOver", serviceFileOver).directive("nvFileSelect", directiveFileSelect).directive("nvFileDrop", directiveFileDrop).directive("nvFileOver", directiveFileOver).run(["FileUploader", "FileLikeObject", "FileItem", "FileDirective", "FileSelect", "FileDrop", "FileOver", function (FileUploader, FileLikeObject, FileItem, FileDirective, FileSelect, FileDrop, FileOver) {
91
+ // only for compatibility
92
+ FileUploader.FileLikeObject = FileLikeObject;
93
+ FileUploader.FileItem = FileItem;
94
+ FileUploader.FileDirective = FileDirective;
95
+ FileUploader.FileSelect = FileSelect;
96
+ FileUploader.FileDrop = FileDrop;
97
+ FileUploader.FileOver = FileOver;
98
+ }]);
99
+
100
+ /***/ },
101
+ /* 1 */
102
+ /***/ function(module, exports) {
103
+
104
+ module.exports = {
105
+ "name": "angularFileUpload"
106
+ };
107
+
108
+ /***/ },
109
+ /* 2 */
110
+ /***/ function(module, exports) {
111
+
112
+ "use strict";
113
+
114
+ module.exports = {
115
+ url: "/",
116
+ alias: "file",
117
+ headers: {},
118
+ queue: [],
119
+ progress: 0,
120
+ autoUpload: false,
121
+ removeAfterUpload: false,
122
+ method: "POST",
123
+ filters: [],
124
+ formData: [],
125
+ queueLimit: Number.MAX_VALUE,
126
+ withCredentials: false
127
+ };
128
+
129
+ /***/ },
130
+ /* 3 */
131
+ /***/ function(module, exports, __webpack_require__) {
132
+
133
+ "use strict";
134
+
135
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
136
+
137
+ var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
138
+
139
+ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
140
+
141
+ var CONFIG = _interopRequire(__webpack_require__(1));
142
+
143
+ var copy = angular.copy;
144
+ var extend = angular.extend;
145
+ var forEach = angular.forEach;
146
+ var isObject = angular.isObject;
147
+ var isNumber = angular.isNumber;
148
+ var isDefined = angular.isDefined;
149
+ var isArray = angular.isArray;
150
+ var element = angular.element;
151
+
152
+ module.exports = function (fileUploaderOptions, $rootScope, $http, $window, FileLikeObject, FileItem) {
153
+ var File = $window.File;
154
+ var FormData = $window.FormData;
155
+
156
+ var FileUploader = (function () {
157
+ /**********************
158
+ * PUBLIC
159
+ **********************/
160
+ /**
161
+ * Creates an instance of FileUploader
162
+ * @param {Object} [options]
163
+ * @constructor
164
+ */
165
+
166
+ function FileUploader(options) {
167
+ _classCallCheck(this, FileUploader);
168
+
169
+ var settings = copy(fileUploaderOptions);
170
+
171
+ extend(this, settings, options, {
172
+ isUploading: false,
173
+ _nextIndex: 0,
174
+ _failFilterIndex: -1,
175
+ _directives: { select: [], drop: [], over: [] }
176
+ });
177
+
178
+ // add default filters
179
+ this.filters.unshift({ name: "queueLimit", fn: this._queueLimitFilter });
180
+ this.filters.unshift({ name: "folder", fn: this._folderFilter });
181
+ }
182
+
183
+ _createClass(FileUploader, {
184
+ addToQueue: {
185
+ /**
186
+ * Adds items to the queue
187
+ * @param {File|HTMLInputElement|Object|FileList|Array<Object>} files
188
+ * @param {Object} [options]
189
+ * @param {Array<Function>|String} filters
190
+ */
191
+
192
+ value: function addToQueue(files, options, filters) {
193
+ var _this = this;
194
+
195
+ var list = this.isArrayLikeObject(files) ? files : [files];
196
+ var arrayOfFilters = this._getFilters(filters);
197
+ var count = this.queue.length;
198
+ var addedFileItems = [];
199
+
200
+ forEach(list, function (some /*{File|HTMLInputElement|Object}*/) {
201
+ var temp = new FileLikeObject(some);
202
+
203
+ if (_this._isValidFile(temp, arrayOfFilters, options)) {
204
+ var fileItem = new FileItem(_this, some, options);
205
+ addedFileItems.push(fileItem);
206
+ _this.queue.push(fileItem);
207
+ _this._onAfterAddingFile(fileItem);
208
+ } else {
209
+ var filter = arrayOfFilters[_this._failFilterIndex];
210
+ _this._onWhenAddingFileFailed(temp, filter, options);
211
+ }
212
+ });
213
+
214
+ if (this.queue.length !== count) {
215
+ this._onAfterAddingAll(addedFileItems);
216
+ this.progress = this._getTotalProgress();
217
+ }
218
+
219
+ this._render();
220
+ if (this.autoUpload) this.uploadAll();
221
+ }
222
+ },
223
+ removeFromQueue: {
224
+ /**
225
+ * Remove items from the queue. Remove last: index = -1
226
+ * @param {FileItem|Number} value
227
+ */
228
+
229
+ value: function removeFromQueue(value) {
230
+ var index = this.getIndexOfItem(value);
231
+ var item = this.queue[index];
232
+ if (item.isUploading) item.cancel();
233
+ this.queue.splice(index, 1);
234
+ item._destroy();
235
+ this.progress = this._getTotalProgress();
236
+ }
237
+ },
238
+ clearQueue: {
239
+ /**
240
+ * Clears the queue
241
+ */
242
+
243
+ value: function clearQueue() {
244
+ while (this.queue.length) {
245
+ this.queue[0].remove();
246
+ }
247
+ this.progress = 0;
248
+ }
249
+ },
250
+ uploadItem: {
251
+ /**
252
+ * Uploads a item from the queue
253
+ * @param {FileItem|Number} value
254
+ */
255
+
256
+ value: function uploadItem(value) {
257
+ var index = this.getIndexOfItem(value);
258
+ var item = this.queue[index];
259
+ var transport = this.isHTML5 ? "_xhrTransport" : "_iframeTransport";
260
+
261
+ item._prepareToUploading();
262
+ if (this.isUploading) {
263
+ return;
264
+ }this.isUploading = true;
265
+ this[transport](item);
266
+ }
267
+ },
268
+ cancelItem: {
269
+ /**
270
+ * Cancels uploading of item from the queue
271
+ * @param {FileItem|Number} value
272
+ */
273
+
274
+ value: function cancelItem(value) {
275
+ var index = this.getIndexOfItem(value);
276
+ var item = this.queue[index];
277
+ var prop = this.isHTML5 ? "_xhr" : "_form";
278
+ if (item && item.isUploading) item[prop].abort();
279
+ }
280
+ },
281
+ uploadAll: {
282
+ /**
283
+ * Uploads all not uploaded items of queue
284
+ */
285
+
286
+ value: function uploadAll() {
287
+ var items = this.getNotUploadedItems().filter(function (item) {
288
+ return !item.isUploading;
289
+ });
290
+ if (!items.length) {
291
+ return;
292
+ }forEach(items, function (item) {
293
+ return item._prepareToUploading();
294
+ });
295
+ items[0].upload();
296
+ }
297
+ },
298
+ cancelAll: {
299
+ /**
300
+ * Cancels all uploads
301
+ */
302
+
303
+ value: function cancelAll() {
304
+ var items = this.getNotUploadedItems();
305
+ forEach(items, function (item) {
306
+ return item.cancel();
307
+ });
308
+ }
309
+ },
310
+ isFile: {
311
+ /**
312
+ * Returns "true" if value an instance of File
313
+ * @param {*} value
314
+ * @returns {Boolean}
315
+ * @private
316
+ */
317
+
318
+ value: function isFile(value) {
319
+ return this.constructor.isFile(value);
320
+ }
321
+ },
322
+ isFileLikeObject: {
323
+ /**
324
+ * Returns "true" if value an instance of FileLikeObject
325
+ * @param {*} value
326
+ * @returns {Boolean}
327
+ * @private
328
+ */
329
+
330
+ value: function isFileLikeObject(value) {
331
+ return this.constructor.isFileLikeObject(value);
332
+ }
333
+ },
334
+ isArrayLikeObject: {
335
+ /**
336
+ * Returns "true" if value is array like object
337
+ * @param {*} value
338
+ * @returns {Boolean}
339
+ */
340
+
341
+ value: function isArrayLikeObject(value) {
342
+ return this.constructor.isArrayLikeObject(value);
343
+ }
344
+ },
345
+ getIndexOfItem: {
346
+ /**
347
+ * Returns a index of item from the queue
348
+ * @param {Item|Number} value
349
+ * @returns {Number}
350
+ */
351
+
352
+ value: function getIndexOfItem(value) {
353
+ return isNumber(value) ? value : this.queue.indexOf(value);
354
+ }
355
+ },
356
+ getNotUploadedItems: {
357
+ /**
358
+ * Returns not uploaded items
359
+ * @returns {Array}
360
+ */
361
+
362
+ value: function getNotUploadedItems() {
363
+ return this.queue.filter(function (item) {
364
+ return !item.isUploaded;
365
+ });
366
+ }
367
+ },
368
+ getReadyItems: {
369
+ /**
370
+ * Returns items ready for upload
371
+ * @returns {Array}
372
+ */
373
+
374
+ value: function getReadyItems() {
375
+ return this.queue.filter(function (item) {
376
+ return item.isReady && !item.isUploading;
377
+ }).sort(function (item1, item2) {
378
+ return item1.index - item2.index;
379
+ });
380
+ }
381
+ },
382
+ destroy: {
383
+ /**
384
+ * Destroys instance of FileUploader
385
+ */
386
+
387
+ value: function destroy() {
388
+ var _this = this;
389
+
390
+ forEach(this._directives, function (key) {
391
+ forEach(_this._directives[key], function (object) {
392
+ object.destroy();
393
+ });
394
+ });
395
+ }
396
+ },
397
+ onAfterAddingAll: {
398
+ /**
399
+ * Callback
400
+ * @param {Array} fileItems
401
+ */
402
+
403
+ value: function onAfterAddingAll(fileItems) {}
404
+ },
405
+ onAfterAddingFile: {
406
+ /**
407
+ * Callback
408
+ * @param {FileItem} fileItem
409
+ */
410
+
411
+ value: function onAfterAddingFile(fileItem) {}
412
+ },
413
+ onWhenAddingFileFailed: {
414
+ /**
415
+ * Callback
416
+ * @param {File|Object} item
417
+ * @param {Object} filter
418
+ * @param {Object} options
419
+ */
420
+
421
+ value: function onWhenAddingFileFailed(item, filter, options) {}
422
+ },
423
+ onBeforeUploadItem: {
424
+ /**
425
+ * Callback
426
+ * @param {FileItem} fileItem
427
+ */
428
+
429
+ value: function onBeforeUploadItem(fileItem) {}
430
+ },
431
+ onProgressItem: {
432
+ /**
433
+ * Callback
434
+ * @param {FileItem} fileItem
435
+ * @param {Number} progress
436
+ */
437
+
438
+ value: function onProgressItem(fileItem, progress) {}
439
+ },
440
+ onProgressAll: {
441
+ /**
442
+ * Callback
443
+ * @param {Number} progress
444
+ */
445
+
446
+ value: function onProgressAll(progress) {}
447
+ },
448
+ onSuccessItem: {
449
+ /**
450
+ * Callback
451
+ * @param {FileItem} item
452
+ * @param {*} response
453
+ * @param {Number} status
454
+ * @param {Object} headers
455
+ */
456
+
457
+ value: function onSuccessItem(item, response, status, headers) {}
458
+ },
459
+ onErrorItem: {
460
+ /**
461
+ * Callback
462
+ * @param {FileItem} item
463
+ * @param {*} response
464
+ * @param {Number} status
465
+ * @param {Object} headers
466
+ */
467
+
468
+ value: function onErrorItem(item, response, status, headers) {}
469
+ },
470
+ onCancelItem: {
471
+ /**
472
+ * Callback
473
+ * @param {FileItem} item
474
+ * @param {*} response
475
+ * @param {Number} status
476
+ * @param {Object} headers
477
+ */
478
+
479
+ value: function onCancelItem(item, response, status, headers) {}
480
+ },
481
+ onCompleteItem: {
482
+ /**
483
+ * Callback
484
+ * @param {FileItem} item
485
+ * @param {*} response
486
+ * @param {Number} status
487
+ * @param {Object} headers
488
+ */
489
+
490
+ value: function onCompleteItem(item, response, status, headers) {}
491
+ },
492
+ onCompleteAll: {
493
+ /**
494
+ * Callback
495
+ */
496
+
497
+ value: function onCompleteAll() {}
498
+ },
499
+ _getTotalProgress: {
500
+ /**********************
501
+ * PRIVATE
502
+ **********************/
503
+ /**
504
+ * Returns the total progress
505
+ * @param {Number} [value]
506
+ * @returns {Number}
507
+ * @private
508
+ */
509
+
510
+ value: function _getTotalProgress(value) {
511
+ if (this.removeAfterUpload) {
512
+ return value || 0;
513
+ }var notUploaded = this.getNotUploadedItems().length;
514
+ var uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
515
+ var ratio = 100 / this.queue.length;
516
+ var current = (value || 0) * ratio / 100;
517
+
518
+ return Math.round(uploaded * ratio + current);
519
+ }
520
+ },
521
+ _getFilters: {
522
+ /**
523
+ * Returns array of filters
524
+ * @param {Array<Function>|String} filters
525
+ * @returns {Array<Function>}
526
+ * @private
527
+ */
528
+
529
+ value: function _getFilters(filters) {
530
+ if (!filters) {
531
+ return this.filters;
532
+ }if (isArray(filters)) {
533
+ return filters;
534
+ }var names = filters.match(/[^\s,]+/g);
535
+ return this.filters.filter(function (filter) {
536
+ return names.indexOf(filter.name) !== -1;
537
+ });
538
+ }
539
+ },
540
+ _render: {
541
+ /**
542
+ * Updates html
543
+ * @private
544
+ */
545
+
546
+ value: function _render() {
547
+ if (!$rootScope.$$phase) $rootScope.$apply();
548
+ }
549
+ },
550
+ _folderFilter: {
551
+ /**
552
+ * Returns "true" if item is a file (not folder)
553
+ * @param {File|FileLikeObject} item
554
+ * @returns {Boolean}
555
+ * @private
556
+ */
557
+
558
+ value: function _folderFilter(item) {
559
+ return !!(item.size || item.type);
560
+ }
561
+ },
562
+ _queueLimitFilter: {
563
+ /**
564
+ * Returns "true" if the limit has not been reached
565
+ * @returns {Boolean}
566
+ * @private
567
+ */
568
+
569
+ value: function _queueLimitFilter() {
570
+ return this.queue.length < this.queueLimit;
571
+ }
572
+ },
573
+ _isValidFile: {
574
+ /**
575
+ * Returns "true" if file pass all filters
576
+ * @param {File|Object} file
577
+ * @param {Array<Function>} filters
578
+ * @param {Object} options
579
+ * @returns {Boolean}
580
+ * @private
581
+ */
582
+
583
+ value: function _isValidFile(file, filters, options) {
584
+ var _this = this;
585
+
586
+ this._failFilterIndex = -1;
587
+ return !filters.length ? true : filters.every(function (filter) {
588
+ _this._failFilterIndex++;
589
+ return filter.fn.call(_this, file, options);
590
+ });
591
+ }
592
+ },
593
+ _isSuccessCode: {
594
+ /**
595
+ * Checks whether upload successful
596
+ * @param {Number} status
597
+ * @returns {Boolean}
598
+ * @private
599
+ */
600
+
601
+ value: function _isSuccessCode(status) {
602
+ return status >= 200 && status < 300 || status === 304;
603
+ }
604
+ },
605
+ _transformResponse: {
606
+ /**
607
+ * Transforms the server response
608
+ * @param {*} response
609
+ * @param {Object} headers
610
+ * @returns {*}
611
+ * @private
612
+ */
613
+
614
+ value: function _transformResponse(response, headers) {
615
+ var headersGetter = this._headersGetter(headers);
616
+ forEach($http.defaults.transformResponse, function (transformFn) {
617
+ response = transformFn(response, headersGetter);
618
+ });
619
+ return response;
620
+ }
621
+ },
622
+ _parseHeaders: {
623
+ /**
624
+ * Parsed response headers
625
+ * @param headers
626
+ * @returns {Object}
627
+ * @see https://github.com/angular/angular.js/blob/master/src/ng/http.js
628
+ * @private
629
+ */
630
+
631
+ value: function _parseHeaders(headers) {
632
+ var parsed = {},
633
+ key,
634
+ val,
635
+ i;
636
+
637
+ if (!headers) {
638
+ return parsed;
639
+ }forEach(headers.split("\n"), function (line) {
640
+ i = line.indexOf(":");
641
+ key = line.slice(0, i).trim().toLowerCase();
642
+ val = line.slice(i + 1).trim();
643
+
644
+ if (key) {
645
+ parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
646
+ }
647
+ });
648
+
649
+ return parsed;
650
+ }
651
+ },
652
+ _headersGetter: {
653
+ /**
654
+ * Returns function that returns headers
655
+ * @param {Object} parsedHeaders
656
+ * @returns {Function}
657
+ * @private
658
+ */
659
+
660
+ value: function _headersGetter(parsedHeaders) {
661
+ return function (name) {
662
+ if (name) {
663
+ return parsedHeaders[name.toLowerCase()] || null;
664
+ }
665
+ return parsedHeaders;
666
+ };
667
+ }
668
+ },
669
+ _xhrTransport: {
670
+ /**
671
+ * The XMLHttpRequest transport
672
+ * @param {FileItem} item
673
+ * @private
674
+ */
675
+
676
+ value: function _xhrTransport(item) {
677
+ var _this = this;
678
+
679
+ var xhr = item._xhr = new XMLHttpRequest();
680
+ var form = new FormData();
681
+
682
+ this._onBeforeUploadItem(item);
683
+
684
+ forEach(item.formData, function (obj) {
685
+ forEach(obj, function (value, key) {
686
+ form.append(key, value);
687
+ });
688
+ });
689
+
690
+ if (typeof item._file.size != "number") {
691
+ throw new TypeError("The file specified is no longer valid");
692
+ }
693
+
694
+ form.append(item.alias, item._file, item.file.name);
695
+
696
+ xhr.upload.onprogress = function (event) {
697
+ var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
698
+ _this._onProgressItem(item, progress);
699
+ };
700
+
701
+ xhr.onload = function () {
702
+ var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
703
+ var response = _this._transformResponse(xhr.response, headers);
704
+ var gist = _this._isSuccessCode(xhr.status) ? "Success" : "Error";
705
+ var method = "_on" + gist + "Item";
706
+ _this[method](item, response, xhr.status, headers);
707
+ _this._onCompleteItem(item, response, xhr.status, headers);
708
+ };
709
+
710
+ xhr.onerror = function () {
711
+ var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
712
+ var response = _this._transformResponse(xhr.response, headers);
713
+ _this._onErrorItem(item, response, xhr.status, headers);
714
+ _this._onCompleteItem(item, response, xhr.status, headers);
715
+ };
716
+
717
+ xhr.onabort = function () {
718
+ var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
719
+ var response = _this._transformResponse(xhr.response, headers);
720
+ _this._onCancelItem(item, response, xhr.status, headers);
721
+ _this._onCompleteItem(item, response, xhr.status, headers);
722
+ };
723
+
724
+ xhr.open(item.method, item.url, true);
725
+
726
+ xhr.withCredentials = item.withCredentials;
727
+
728
+ forEach(item.headers, function (value, name) {
729
+ xhr.setRequestHeader(name, value);
730
+ });
731
+
732
+ xhr.send(form);
733
+ this._render();
734
+ }
735
+ },
736
+ _iframeTransport: {
737
+ /**
738
+ * The IFrame transport
739
+ * @param {FileItem} item
740
+ * @private
741
+ */
742
+
743
+ value: function _iframeTransport(item) {
744
+ var _this = this;
745
+
746
+ var form = element("<form style=\"display: none;\" />");
747
+ var iframe = element("<iframe name=\"iframeTransport" + Date.now() + "\">");
748
+ var input = item._input;
749
+
750
+ if (item._form) item._form.replaceWith(input); // remove old form
751
+ item._form = form; // save link to new form
752
+
753
+ this._onBeforeUploadItem(item);
754
+
755
+ input.prop("name", item.alias);
756
+
757
+ forEach(item.formData, function (obj) {
758
+ forEach(obj, function (value, key) {
759
+ var element_ = element("<input type=\"hidden\" name=\"" + key + "\" />");
760
+ element_.val(value);
761
+ form.append(element_);
762
+ });
763
+ });
764
+
765
+ form.prop({
766
+ action: item.url,
767
+ method: "POST",
768
+ target: iframe.prop("name"),
769
+ enctype: "multipart/form-data",
770
+ encoding: "multipart/form-data" // old IE
771
+ });
772
+
773
+ iframe.bind("load", function () {
774
+ var html = "";
775
+ var status = 200;
776
+
777
+ try {
778
+ // Fix for legacy IE browsers that loads internal error page
779
+ // when failed WS response received. In consequence iframe
780
+ // content access denied error is thrown becouse trying to
781
+ // access cross domain page. When such thing occurs notifying
782
+ // with empty response object. See more info at:
783
+ // http://stackoverflow.com/questions/151362/access-is-denied-error-on-accessing-iframe-document-object
784
+ // Note that if non standard 4xx or 5xx error code returned
785
+ // from WS then response content can be accessed without error
786
+ // but 'XHR' status becomes 200. In order to avoid confusion
787
+ // returning response via same 'success' event handler.
788
+
789
+ // fixed angular.contents() for iframes
790
+ html = iframe[0].contentDocument.body.innerHTML;
791
+ } catch (e) {
792
+ // in case we run into the access-is-denied error or we have another error on the server side
793
+ // (intentional 500,40... errors), we at least say 'something went wrong' -> 500
794
+ status = 500;
795
+ }
796
+
797
+ var xhr = { response: html, status: status, dummy: true };
798
+ var headers = {};
799
+ var response = _this._transformResponse(xhr.response, headers);
800
+
801
+ _this._onSuccessItem(item, response, xhr.status, headers);
802
+ _this._onCompleteItem(item, response, xhr.status, headers);
803
+ });
804
+
805
+ form.abort = function () {
806
+ var xhr = { status: 0, dummy: true };
807
+ var headers = {};
808
+ var response;
809
+
810
+ iframe.unbind("load").prop("src", "javascript:false;");
811
+ form.replaceWith(input);
812
+
813
+ _this._onCancelItem(item, response, xhr.status, headers);
814
+ _this._onCompleteItem(item, response, xhr.status, headers);
815
+ };
816
+
817
+ input.after(form);
818
+ form.append(input).append(iframe);
819
+
820
+ form[0].submit();
821
+ this._render();
822
+ }
823
+ },
824
+ _onWhenAddingFileFailed: {
825
+ /**
826
+ * Inner callback
827
+ * @param {File|Object} item
828
+ * @param {Object} filter
829
+ * @param {Object} options
830
+ * @private
831
+ */
832
+
833
+ value: function _onWhenAddingFileFailed(item, filter, options) {
834
+ this.onWhenAddingFileFailed(item, filter, options);
835
+ }
836
+ },
837
+ _onAfterAddingFile: {
838
+ /**
839
+ * Inner callback
840
+ * @param {FileItem} item
841
+ */
842
+
843
+ value: function _onAfterAddingFile(item) {
844
+ this.onAfterAddingFile(item);
845
+ }
846
+ },
847
+ _onAfterAddingAll: {
848
+ /**
849
+ * Inner callback
850
+ * @param {Array<FileItem>} items
851
+ */
852
+
853
+ value: function _onAfterAddingAll(items) {
854
+ this.onAfterAddingAll(items);
855
+ }
856
+ },
857
+ _onBeforeUploadItem: {
858
+ /**
859
+ * Inner callback
860
+ * @param {FileItem} item
861
+ * @private
862
+ */
863
+
864
+ value: function _onBeforeUploadItem(item) {
865
+ item._onBeforeUpload();
866
+ this.onBeforeUploadItem(item);
867
+ }
868
+ },
869
+ _onProgressItem: {
870
+ /**
871
+ * Inner callback
872
+ * @param {FileItem} item
873
+ * @param {Number} progress
874
+ * @private
875
+ */
876
+
877
+ value: function _onProgressItem(item, progress) {
878
+ var total = this._getTotalProgress(progress);
879
+ this.progress = total;
880
+ item._onProgress(progress);
881
+ this.onProgressItem(item, progress);
882
+ this.onProgressAll(total);
883
+ this._render();
884
+ }
885
+ },
886
+ _onSuccessItem: {
887
+ /**
888
+ * Inner callback
889
+ * @param {FileItem} item
890
+ * @param {*} response
891
+ * @param {Number} status
892
+ * @param {Object} headers
893
+ * @private
894
+ */
895
+
896
+ value: function _onSuccessItem(item, response, status, headers) {
897
+ item._onSuccess(response, status, headers);
898
+ this.onSuccessItem(item, response, status, headers);
899
+ }
900
+ },
901
+ _onErrorItem: {
902
+ /**
903
+ * Inner callback
904
+ * @param {FileItem} item
905
+ * @param {*} response
906
+ * @param {Number} status
907
+ * @param {Object} headers
908
+ * @private
909
+ */
910
+
911
+ value: function _onErrorItem(item, response, status, headers) {
912
+ item._onError(response, status, headers);
913
+ this.onErrorItem(item, response, status, headers);
914
+ }
915
+ },
916
+ _onCancelItem: {
917
+ /**
918
+ * Inner callback
919
+ * @param {FileItem} item
920
+ * @param {*} response
921
+ * @param {Number} status
922
+ * @param {Object} headers
923
+ * @private
924
+ */
925
+
926
+ value: function _onCancelItem(item, response, status, headers) {
927
+ item._onCancel(response, status, headers);
928
+ this.onCancelItem(item, response, status, headers);
929
+ }
930
+ },
931
+ _onCompleteItem: {
932
+ /**
933
+ * Inner callback
934
+ * @param {FileItem} item
935
+ * @param {*} response
936
+ * @param {Number} status
937
+ * @param {Object} headers
938
+ * @private
939
+ */
940
+
941
+ value: function _onCompleteItem(item, response, status, headers) {
942
+ item._onComplete(response, status, headers);
943
+ this.onCompleteItem(item, response, status, headers);
944
+
945
+ var nextItem = this.getReadyItems()[0];
946
+ this.isUploading = false;
947
+
948
+ if (isDefined(nextItem)) {
949
+ nextItem.upload();
950
+ return;
951
+ }
952
+
953
+ this.onCompleteAll();
954
+ this.progress = this._getTotalProgress();
955
+ this._render();
956
+ }
957
+ }
958
+ }, {
959
+ isFile: {
960
+ /**********************
961
+ * STATIC
962
+ **********************/
963
+ /**
964
+ * Returns "true" if value an instance of File
965
+ * @param {*} value
966
+ * @returns {Boolean}
967
+ * @private
968
+ */
969
+
970
+ value: function isFile(value) {
971
+ return File && value instanceof File;
972
+ }
973
+ },
974
+ isFileLikeObject: {
975
+ /**
976
+ * Returns "true" if value an instance of FileLikeObject
977
+ * @param {*} value
978
+ * @returns {Boolean}
979
+ * @private
980
+ */
981
+
982
+ value: function isFileLikeObject(value) {
983
+ return value instanceof FileLikeObject;
984
+ }
985
+ },
986
+ isArrayLikeObject: {
987
+ /**
988
+ * Returns "true" if value is array like object
989
+ * @param {*} value
990
+ * @returns {Boolean}
991
+ */
992
+
993
+ value: function isArrayLikeObject(value) {
994
+ return isObject(value) && "length" in value;
995
+ }
996
+ },
997
+ inherit: {
998
+ /**
999
+ * Inherits a target (Class_1) by a source (Class_2)
1000
+ * @param {Function} target
1001
+ * @param {Function} source
1002
+ */
1003
+
1004
+ value: function inherit(target, source) {
1005
+ target.prototype = Object.create(source.prototype);
1006
+ target.prototype.constructor = target;
1007
+ target.super_ = source;
1008
+ }
1009
+ }
1010
+ });
1011
+
1012
+ return FileUploader;
1013
+ })();
1014
+
1015
+ /**********************
1016
+ * PUBLIC
1017
+ **********************/
1018
+ /**
1019
+ * Checks a support the html5 uploader
1020
+ * @returns {Boolean}
1021
+ * @readonly
1022
+ */
1023
+ FileUploader.prototype.isHTML5 = !!(File && FormData);
1024
+ /**********************
1025
+ * STATIC
1026
+ **********************/
1027
+ /**
1028
+ * @borrows FileUploader.prototype.isHTML5
1029
+ */
1030
+ FileUploader.isHTML5 = FileUploader.prototype.isHTML5;
1031
+
1032
+ return FileUploader;
1033
+ };
1034
+
1035
+ module.exports.$inject = ["fileUploaderOptions", "$rootScope", "$http", "$window", "FileLikeObject", "FileItem"];
1036
+
1037
+ /***/ },
1038
+ /* 4 */
1039
+ /***/ function(module, exports, __webpack_require__) {
1040
+
1041
+ "use strict";
1042
+
1043
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1044
+
1045
+ var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
1046
+
1047
+ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
1048
+
1049
+ var CONFIG = _interopRequire(__webpack_require__(1));
1050
+
1051
+ var copy = angular.copy;
1052
+ var isElement = angular.isElement;
1053
+ var isString = angular.isString;
1054
+
1055
+ module.exports = function () {
1056
+ var FileLikeObject = (function () {
1057
+ /**
1058
+ * Creates an instance of FileLikeObject
1059
+ * @param {File|HTMLInputElement|Object} fileOrInput
1060
+ * @constructor
1061
+ */
1062
+
1063
+ function FileLikeObject(fileOrInput) {
1064
+ _classCallCheck(this, FileLikeObject);
1065
+
1066
+ var isInput = isElement(fileOrInput);
1067
+ var fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
1068
+ var postfix = isString(fakePathOrObject) ? "FakePath" : "Object";
1069
+ var method = "_createFrom" + postfix;
1070
+ this[method](fakePathOrObject);
1071
+ }
1072
+
1073
+ _createClass(FileLikeObject, {
1074
+ _createFromFakePath: {
1075
+ /**
1076
+ * Creates file like object from fake path string
1077
+ * @param {String} path
1078
+ * @private
1079
+ */
1080
+
1081
+ value: function _createFromFakePath(path) {
1082
+ this.lastModifiedDate = null;
1083
+ this.size = null;
1084
+ this.type = "like/" + path.slice(path.lastIndexOf(".") + 1).toLowerCase();
1085
+ this.name = path.slice(path.lastIndexOf("/") + path.lastIndexOf("\\") + 2);
1086
+ }
1087
+ },
1088
+ _createFromObject: {
1089
+ /**
1090
+ * Creates file like object from object
1091
+ * @param {File|FileLikeObject} object
1092
+ * @private
1093
+ */
1094
+
1095
+ value: function _createFromObject(object) {
1096
+ this.lastModifiedDate = copy(object.lastModifiedDate);
1097
+ this.size = object.size;
1098
+ this.type = object.type;
1099
+ this.name = object.name;
1100
+ }
1101
+ }
1102
+ });
1103
+
1104
+ return FileLikeObject;
1105
+ })();
1106
+
1107
+ return FileLikeObject;
1108
+ };
1109
+
1110
+ module.exports.$inject = [];
1111
+
1112
+ /***/ },
1113
+ /* 5 */
1114
+ /***/ function(module, exports, __webpack_require__) {
1115
+
1116
+ "use strict";
1117
+
1118
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1119
+
1120
+ var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
1121
+
1122
+ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
1123
+
1124
+ var CONFIG = _interopRequire(__webpack_require__(1));
1125
+
1126
+ var copy = angular.copy;
1127
+ var extend = angular.extend;
1128
+ var element = angular.element;
1129
+ var isElement = angular.isElement;
1130
+
1131
+ module.exports = function ($compile, FileLikeObject) {
1132
+ var FileItem = (function () {
1133
+ /**
1134
+ * Creates an instance of FileItem
1135
+ * @param {FileUploader} uploader
1136
+ * @param {File|HTMLInputElement|Object} some
1137
+ * @param {Object} options
1138
+ * @constructor
1139
+ */
1140
+
1141
+ function FileItem(uploader, some, options) {
1142
+ _classCallCheck(this, FileItem);
1143
+
1144
+ var isInput = isElement(some);
1145
+ var input = isInput ? element(some) : null;
1146
+ var file = !isInput ? some : null;
1147
+
1148
+ extend(this, {
1149
+ url: uploader.url,
1150
+ alias: uploader.alias,
1151
+ headers: copy(uploader.headers),
1152
+ formData: copy(uploader.formData),
1153
+ removeAfterUpload: uploader.removeAfterUpload,
1154
+ withCredentials: uploader.withCredentials,
1155
+ method: uploader.method
1156
+ }, options, {
1157
+ uploader: uploader,
1158
+ file: new FileLikeObject(some),
1159
+ isReady: false,
1160
+ isUploading: false,
1161
+ isUploaded: false,
1162
+ isSuccess: false,
1163
+ isCancel: false,
1164
+ isError: false,
1165
+ progress: 0,
1166
+ index: null,
1167
+ _file: file,
1168
+ _input: input
1169
+ });
1170
+
1171
+ if (input) this._replaceNode(input);
1172
+ }
1173
+
1174
+ _createClass(FileItem, {
1175
+ upload: {
1176
+ /**********************
1177
+ * PUBLIC
1178
+ **********************/
1179
+ /**
1180
+ * Uploads a FileItem
1181
+ */
1182
+
1183
+ value: function upload() {
1184
+ try {
1185
+ this.uploader.uploadItem(this);
1186
+ } catch (e) {
1187
+ this.uploader._onCompleteItem(this, "", 0, []);
1188
+ this.uploader._onErrorItem(this, "", 0, []);
1189
+ }
1190
+ }
1191
+ },
1192
+ cancel: {
1193
+ /**
1194
+ * Cancels uploading of FileItem
1195
+ */
1196
+
1197
+ value: function cancel() {
1198
+ this.uploader.cancelItem(this);
1199
+ }
1200
+ },
1201
+ remove: {
1202
+ /**
1203
+ * Removes a FileItem
1204
+ */
1205
+
1206
+ value: function remove() {
1207
+ this.uploader.removeFromQueue(this);
1208
+ }
1209
+ },
1210
+ onBeforeUpload: {
1211
+ /**
1212
+ * Callback
1213
+ * @private
1214
+ */
1215
+
1216
+ value: function onBeforeUpload() {}
1217
+ },
1218
+ onProgress: {
1219
+ /**
1220
+ * Callback
1221
+ * @param {Number} progress
1222
+ * @private
1223
+ */
1224
+
1225
+ value: function onProgress(progress) {}
1226
+ },
1227
+ onSuccess: {
1228
+ /**
1229
+ * Callback
1230
+ * @param {*} response
1231
+ * @param {Number} status
1232
+ * @param {Object} headers
1233
+ */
1234
+
1235
+ value: function onSuccess(response, status, headers) {}
1236
+ },
1237
+ onError: {
1238
+ /**
1239
+ * Callback
1240
+ * @param {*} response
1241
+ * @param {Number} status
1242
+ * @param {Object} headers
1243
+ */
1244
+
1245
+ value: function onError(response, status, headers) {}
1246
+ },
1247
+ onCancel: {
1248
+ /**
1249
+ * Callback
1250
+ * @param {*} response
1251
+ * @param {Number} status
1252
+ * @param {Object} headers
1253
+ */
1254
+
1255
+ value: function onCancel(response, status, headers) {}
1256
+ },
1257
+ onComplete: {
1258
+ /**
1259
+ * Callback
1260
+ * @param {*} response
1261
+ * @param {Number} status
1262
+ * @param {Object} headers
1263
+ */
1264
+
1265
+ value: function onComplete(response, status, headers) {}
1266
+ },
1267
+ _onBeforeUpload: {
1268
+ /**********************
1269
+ * PRIVATE
1270
+ **********************/
1271
+ /**
1272
+ * Inner callback
1273
+ */
1274
+
1275
+ value: function _onBeforeUpload() {
1276
+ this.isReady = true;
1277
+ this.isUploading = true;
1278
+ this.isUploaded = false;
1279
+ this.isSuccess = false;
1280
+ this.isCancel = false;
1281
+ this.isError = false;
1282
+ this.progress = 0;
1283
+ this.onBeforeUpload();
1284
+ }
1285
+ },
1286
+ _onProgress: {
1287
+ /**
1288
+ * Inner callback
1289
+ * @param {Number} progress
1290
+ * @private
1291
+ */
1292
+
1293
+ value: function _onProgress(progress) {
1294
+ this.progress = progress;
1295
+ this.onProgress(progress);
1296
+ }
1297
+ },
1298
+ _onSuccess: {
1299
+ /**
1300
+ * Inner callback
1301
+ * @param {*} response
1302
+ * @param {Number} status
1303
+ * @param {Object} headers
1304
+ * @private
1305
+ */
1306
+
1307
+ value: function _onSuccess(response, status, headers) {
1308
+ this.isReady = false;
1309
+ this.isUploading = false;
1310
+ this.isUploaded = true;
1311
+ this.isSuccess = true;
1312
+ this.isCancel = false;
1313
+ this.isError = false;
1314
+ this.progress = 100;
1315
+ this.index = null;
1316
+ this.onSuccess(response, status, headers);
1317
+ }
1318
+ },
1319
+ _onError: {
1320
+ /**
1321
+ * Inner callback
1322
+ * @param {*} response
1323
+ * @param {Number} status
1324
+ * @param {Object} headers
1325
+ * @private
1326
+ */
1327
+
1328
+ value: function _onError(response, status, headers) {
1329
+ this.isReady = false;
1330
+ this.isUploading = false;
1331
+ this.isUploaded = true;
1332
+ this.isSuccess = false;
1333
+ this.isCancel = false;
1334
+ this.isError = true;
1335
+ this.progress = 0;
1336
+ this.index = null;
1337
+ this.onError(response, status, headers);
1338
+ }
1339
+ },
1340
+ _onCancel: {
1341
+ /**
1342
+ * Inner callback
1343
+ * @param {*} response
1344
+ * @param {Number} status
1345
+ * @param {Object} headers
1346
+ * @private
1347
+ */
1348
+
1349
+ value: function _onCancel(response, status, headers) {
1350
+ this.isReady = false;
1351
+ this.isUploading = false;
1352
+ this.isUploaded = false;
1353
+ this.isSuccess = false;
1354
+ this.isCancel = true;
1355
+ this.isError = false;
1356
+ this.progress = 0;
1357
+ this.index = null;
1358
+ this.onCancel(response, status, headers);
1359
+ }
1360
+ },
1361
+ _onComplete: {
1362
+ /**
1363
+ * Inner callback
1364
+ * @param {*} response
1365
+ * @param {Number} status
1366
+ * @param {Object} headers
1367
+ * @private
1368
+ */
1369
+
1370
+ value: function _onComplete(response, status, headers) {
1371
+ this.onComplete(response, status, headers);
1372
+ if (this.removeAfterUpload) this.remove();
1373
+ }
1374
+ },
1375
+ _destroy: {
1376
+ /**
1377
+ * Destroys a FileItem
1378
+ */
1379
+
1380
+ value: function _destroy() {
1381
+ if (this._input) this._input.remove();
1382
+ if (this._form) this._form.remove();
1383
+ delete this._form;
1384
+ delete this._input;
1385
+ }
1386
+ },
1387
+ _prepareToUploading: {
1388
+ /**
1389
+ * Prepares to uploading
1390
+ * @private
1391
+ */
1392
+
1393
+ value: function _prepareToUploading() {
1394
+ this.index = this.index || ++this.uploader._nextIndex;
1395
+ this.isReady = true;
1396
+ }
1397
+ },
1398
+ _replaceNode: {
1399
+ /**
1400
+ * Replaces input element on his clone
1401
+ * @param {JQLite|jQuery} input
1402
+ * @private
1403
+ */
1404
+
1405
+ value: function _replaceNode(input) {
1406
+ var clone = $compile(input.clone())(input.scope());
1407
+ clone.prop("value", null); // FF fix
1408
+ input.css("display", "none");
1409
+ input.after(clone); // remove jquery dependency
1410
+ }
1411
+ }
1412
+ });
1413
+
1414
+ return FileItem;
1415
+ })();
1416
+
1417
+ return FileItem;
1418
+ };
1419
+
1420
+ module.exports.$inject = ["$compile", "FileLikeObject"];
1421
+
1422
+ /***/ },
1423
+ /* 6 */
1424
+ /***/ function(module, exports, __webpack_require__) {
1425
+
1426
+ "use strict";
1427
+
1428
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1429
+
1430
+ var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
1431
+
1432
+ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
1433
+
1434
+ var CONFIG = _interopRequire(__webpack_require__(1));
1435
+
1436
+ var extend = angular.extend;
1437
+
1438
+ module.exports = function () {
1439
+ var FileDirective = (function () {
1440
+ /**
1441
+ * Creates instance of {FileDirective} object
1442
+ * @param {Object} options
1443
+ * @param {Object} options.uploader
1444
+ * @param {HTMLElement} options.element
1445
+ * @param {Object} options.events
1446
+ * @param {String} options.prop
1447
+ * @constructor
1448
+ */
1449
+
1450
+ function FileDirective(options) {
1451
+ _classCallCheck(this, FileDirective);
1452
+
1453
+ extend(this, options);
1454
+ this.uploader._directives[this.prop].push(this);
1455
+ this._saveLinks();
1456
+ this.bind();
1457
+ }
1458
+
1459
+ _createClass(FileDirective, {
1460
+ bind: {
1461
+ /**
1462
+ * Binds events handles
1463
+ */
1464
+
1465
+ value: function bind() {
1466
+ for (var key in this.events) {
1467
+ var prop = this.events[key];
1468
+ this.element.bind(key, this[prop]);
1469
+ }
1470
+ }
1471
+ },
1472
+ unbind: {
1473
+ /**
1474
+ * Unbinds events handles
1475
+ */
1476
+
1477
+ value: function unbind() {
1478
+ for (var key in this.events) {
1479
+ this.element.unbind(key, this.events[key]);
1480
+ }
1481
+ }
1482
+ },
1483
+ destroy: {
1484
+ /**
1485
+ * Destroys directive
1486
+ */
1487
+
1488
+ value: function destroy() {
1489
+ var index = this.uploader._directives[this.prop].indexOf(this);
1490
+ this.uploader._directives[this.prop].splice(index, 1);
1491
+ this.unbind();
1492
+ // this.element = null;
1493
+ }
1494
+ },
1495
+ _saveLinks: {
1496
+ /**
1497
+ * Saves links to functions
1498
+ * @private
1499
+ */
1500
+
1501
+ value: function _saveLinks() {
1502
+ for (var key in this.events) {
1503
+ var prop = this.events[key];
1504
+ this[prop] = this[prop].bind(this);
1505
+ }
1506
+ }
1507
+ }
1508
+ });
1509
+
1510
+ return FileDirective;
1511
+ })();
1512
+
1513
+ /**
1514
+ * Map of events
1515
+ * @type {Object}
1516
+ */
1517
+ FileDirective.prototype.events = {};
1518
+
1519
+ return FileDirective;
1520
+ };
1521
+
1522
+ module.exports.$inject = [];
1523
+
1524
+ /***/ },
1525
+ /* 7 */
1526
+ /***/ function(module, exports, __webpack_require__) {
1527
+
1528
+ "use strict";
1529
+
1530
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1531
+
1532
+ var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
1533
+
1534
+ var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
1535
+
1536
+ var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
1537
+
1538
+ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
1539
+
1540
+ var CONFIG = _interopRequire(__webpack_require__(1));
1541
+
1542
+ var extend = angular.extend;
1543
+
1544
+ module.exports = function (FileDirective) {
1545
+ var FileSelect = (function (_FileDirective) {
1546
+ /**
1547
+ * Creates instance of {FileSelect} object
1548
+ * @param {Object} options
1549
+ * @constructor
1550
+ */
1551
+
1552
+ function FileSelect(options) {
1553
+ _classCallCheck(this, FileSelect);
1554
+
1555
+ var extendedOptions = extend(options, {
1556
+ // Map of events
1557
+ events: {
1558
+ $destroy: "destroy",
1559
+ change: "onChange"
1560
+ },
1561
+ // Name of property inside uploader._directive object
1562
+ prop: "select"
1563
+ });
1564
+
1565
+ _get(Object.getPrototypeOf(FileSelect.prototype), "constructor", this).call(this, extendedOptions);
1566
+
1567
+ if (!this.uploader.isHTML5) {
1568
+ this.element.removeAttr("multiple");
1569
+ }
1570
+ this.element.prop("value", null); // FF fix
1571
+ }
1572
+
1573
+ _inherits(FileSelect, _FileDirective);
1574
+
1575
+ _createClass(FileSelect, {
1576
+ getOptions: {
1577
+ /**
1578
+ * Returns options
1579
+ * @return {Object|undefined}
1580
+ */
1581
+
1582
+ value: function getOptions() {}
1583
+ },
1584
+ getFilters: {
1585
+ /**
1586
+ * Returns filters
1587
+ * @return {Array<Function>|String|undefined}
1588
+ */
1589
+
1590
+ value: function getFilters() {}
1591
+ },
1592
+ isEmptyAfterSelection: {
1593
+ /**
1594
+ * If returns "true" then HTMLInputElement will be cleared
1595
+ * @returns {Boolean}
1596
+ */
1597
+
1598
+ value: function isEmptyAfterSelection() {
1599
+ return !!this.element.attr("multiple");
1600
+ }
1601
+ },
1602
+ onChange: {
1603
+ /**
1604
+ * Event handler
1605
+ */
1606
+
1607
+ value: function onChange() {
1608
+ var files = this.uploader.isHTML5 ? this.element[0].files : this.element[0];
1609
+ var options = this.getOptions();
1610
+ var filters = this.getFilters();
1611
+
1612
+ if (!this.uploader.isHTML5) this.destroy();
1613
+ this.uploader.addToQueue(files, options, filters);
1614
+ if (this.isEmptyAfterSelection()) {
1615
+ this.element.prop("value", null);
1616
+ this.element.replaceWith(this.element = this.element.clone(true)); // IE fix
1617
+ }
1618
+ }
1619
+ }
1620
+ });
1621
+
1622
+ return FileSelect;
1623
+ })(FileDirective);
1624
+
1625
+ return FileSelect;
1626
+ };
1627
+
1628
+ module.exports.$inject = ["FileDirective"];
1629
+
1630
+ /***/ },
1631
+ /* 8 */
1632
+ /***/ function(module, exports, __webpack_require__) {
1633
+
1634
+ "use strict";
1635
+
1636
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1637
+
1638
+ var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
1639
+
1640
+ var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
1641
+
1642
+ var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
1643
+
1644
+ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
1645
+
1646
+ var CONFIG = _interopRequire(__webpack_require__(1));
1647
+
1648
+ var extend = angular.extend;
1649
+ var forEach = angular.forEach;
1650
+
1651
+ module.exports = function (FileDirective) {
1652
+ var FileDrop = (function (_FileDirective) {
1653
+ /**
1654
+ * Creates instance of {FileDrop} object
1655
+ * @param {Object} options
1656
+ * @constructor
1657
+ */
1658
+
1659
+ function FileDrop(options) {
1660
+ _classCallCheck(this, FileDrop);
1661
+
1662
+ var extendedOptions = extend(options, {
1663
+ // Map of events
1664
+ events: {
1665
+ $destroy: "destroy",
1666
+ drop: "onDrop",
1667
+ dragover: "onDragOver",
1668
+ dragleave: "onDragLeave"
1669
+ },
1670
+ // Name of property inside uploader._directive object
1671
+ prop: "drop"
1672
+ });
1673
+
1674
+ _get(Object.getPrototypeOf(FileDrop.prototype), "constructor", this).call(this, extendedOptions);
1675
+ }
1676
+
1677
+ _inherits(FileDrop, _FileDirective);
1678
+
1679
+ _createClass(FileDrop, {
1680
+ getOptions: {
1681
+ /**
1682
+ * Returns options
1683
+ * @return {Object|undefined}
1684
+ */
1685
+
1686
+ value: function getOptions() {}
1687
+ },
1688
+ getFilters: {
1689
+ /**
1690
+ * Returns filters
1691
+ * @return {Array<Function>|String|undefined}
1692
+ */
1693
+
1694
+ value: function getFilters() {}
1695
+ },
1696
+ onDrop: {
1697
+ /**
1698
+ * Event handler
1699
+ */
1700
+
1701
+ value: function onDrop(event) {
1702
+ var transfer = this._getTransfer(event);
1703
+ if (!transfer) {
1704
+ return;
1705
+ }var options = this.getOptions();
1706
+ var filters = this.getFilters();
1707
+ this._preventAndStop(event);
1708
+ forEach(this.uploader._directives.over, this._removeOverClass, this);
1709
+ this.uploader.addToQueue(transfer.files, options, filters);
1710
+ }
1711
+ },
1712
+ onDragOver: {
1713
+ /**
1714
+ * Event handler
1715
+ */
1716
+
1717
+ value: function onDragOver(event) {
1718
+ var transfer = this._getTransfer(event);
1719
+ if (!this._haveFiles(transfer.types)) {
1720
+ return;
1721
+ }transfer.dropEffect = "copy";
1722
+ this._preventAndStop(event);
1723
+ forEach(this.uploader._directives.over, this._addOverClass, this);
1724
+ }
1725
+ },
1726
+ onDragLeave: {
1727
+ /**
1728
+ * Event handler
1729
+ */
1730
+
1731
+ value: function onDragLeave(event) {
1732
+ if (event.currentTarget === this.element[0]) {
1733
+ return;
1734
+ }this._preventAndStop(event);
1735
+ forEach(this.uploader._directives.over, this._removeOverClass, this);
1736
+ }
1737
+ },
1738
+ _getTransfer: {
1739
+ /**
1740
+ * Helper
1741
+ */
1742
+
1743
+ value: function _getTransfer(event) {
1744
+ return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
1745
+ }
1746
+ },
1747
+ _preventAndStop: {
1748
+ /**
1749
+ * Helper
1750
+ */
1751
+
1752
+ value: function _preventAndStop(event) {
1753
+ event.preventDefault();
1754
+ event.stopPropagation();
1755
+ }
1756
+ },
1757
+ _haveFiles: {
1758
+ /**
1759
+ * Returns "true" if types contains files
1760
+ * @param {Object} types
1761
+ */
1762
+
1763
+ value: function _haveFiles(types) {
1764
+ if (!types) {
1765
+ return false;
1766
+ }if (types.indexOf) {
1767
+ return types.indexOf("Files") !== -1;
1768
+ } else if (types.contains) {
1769
+ return types.contains("Files");
1770
+ } else {
1771
+ return false;
1772
+ }
1773
+ }
1774
+ },
1775
+ _addOverClass: {
1776
+ /**
1777
+ * Callback
1778
+ */
1779
+
1780
+ value: function _addOverClass(item) {
1781
+ item.addOverClass();
1782
+ }
1783
+ },
1784
+ _removeOverClass: {
1785
+ /**
1786
+ * Callback
1787
+ */
1788
+
1789
+ value: function _removeOverClass(item) {
1790
+ item.removeOverClass();
1791
+ }
1792
+ }
1793
+ });
1794
+
1795
+ return FileDrop;
1796
+ })(FileDirective);
1797
+
1798
+ return FileDrop;
1799
+ };
1800
+
1801
+ module.exports.$inject = ["FileDirective"];
1802
+
1803
+ /***/ },
1804
+ /* 9 */
1805
+ /***/ function(module, exports, __webpack_require__) {
1806
+
1807
+ "use strict";
1808
+
1809
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1810
+
1811
+ var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
1812
+
1813
+ var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
1814
+
1815
+ var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
1816
+
1817
+ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
1818
+
1819
+ var CONFIG = _interopRequire(__webpack_require__(1));
1820
+
1821
+ var extend = angular.extend;
1822
+
1823
+ module.exports = function (FileDirective) {
1824
+ var FileOver = (function (_FileDirective) {
1825
+ /**
1826
+ * Creates instance of {FileDrop} object
1827
+ * @param {Object} options
1828
+ * @constructor
1829
+ */
1830
+
1831
+ function FileOver(options) {
1832
+ _classCallCheck(this, FileOver);
1833
+
1834
+ var extendedOptions = extend(options, {
1835
+ // Map of events
1836
+ events: {
1837
+ $destroy: "destroy"
1838
+ },
1839
+ // Name of property inside uploader._directive object
1840
+ prop: "over",
1841
+ // Over class
1842
+ overClass: "nv-file-over"
1843
+ });
1844
+
1845
+ _get(Object.getPrototypeOf(FileOver.prototype), "constructor", this).call(this, extendedOptions);
1846
+ }
1847
+
1848
+ _inherits(FileOver, _FileDirective);
1849
+
1850
+ _createClass(FileOver, {
1851
+ addOverClass: {
1852
+ /**
1853
+ * Adds over class
1854
+ */
1855
+
1856
+ value: function addOverClass() {
1857
+ this.element.addClass(this.getOverClass());
1858
+ }
1859
+ },
1860
+ removeOverClass: {
1861
+ /**
1862
+ * Removes over class
1863
+ */
1864
+
1865
+ value: function removeOverClass() {
1866
+ this.element.removeClass(this.getOverClass());
1867
+ }
1868
+ },
1869
+ getOverClass: {
1870
+ /**
1871
+ * Returns over class
1872
+ * @returns {String}
1873
+ */
1874
+
1875
+ value: function getOverClass() {
1876
+ return this.overClass;
1877
+ }
1878
+ }
1879
+ });
1880
+
1881
+ return FileOver;
1882
+ })(FileDirective);
1883
+
1884
+ return FileOver;
1885
+ };
1886
+
1887
+ module.exports.$inject = ["FileDirective"];
1888
+
1889
+ /***/ },
1890
+ /* 10 */
1891
+ /***/ function(module, exports, __webpack_require__) {
1892
+
1893
+ "use strict";
1894
+
1895
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1896
+
1897
+ var CONFIG = _interopRequire(__webpack_require__(1));
1898
+
1899
+ module.exports = function ($parse, FileUploader, FileSelect) {
1900
+
1901
+ return {
1902
+ link: function (scope, element, attributes) {
1903
+ var uploader = scope.$eval(attributes.uploader);
1904
+
1905
+ if (!(uploader instanceof FileUploader)) {
1906
+ throw new TypeError("\"Uploader\" must be an instance of FileUploader");
1907
+ }
1908
+
1909
+ var object = new FileSelect({
1910
+ uploader: uploader,
1911
+ element: element
1912
+ });
1913
+
1914
+ object.getOptions = $parse(attributes.options).bind(object, scope);
1915
+ object.getFilters = function () {
1916
+ return attributes.filters;
1917
+ };
1918
+ }
1919
+ };
1920
+ };
1921
+
1922
+ module.exports.$inject = ["$parse", "FileUploader", "FileSelect"];
1923
+
1924
+ /***/ },
1925
+ /* 11 */
1926
+ /***/ function(module, exports, __webpack_require__) {
1927
+
1928
+ "use strict";
1929
+
1930
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1931
+
1932
+ var CONFIG = _interopRequire(__webpack_require__(1));
1933
+
1934
+ module.exports = function ($parse, FileUploader, FileDrop) {
1935
+
1936
+ return {
1937
+ link: function (scope, element, attributes) {
1938
+ var uploader = scope.$eval(attributes.uploader);
1939
+
1940
+ if (!(uploader instanceof FileUploader)) {
1941
+ throw new TypeError("\"Uploader\" must be an instance of FileUploader");
1942
+ }
1943
+
1944
+ if (!uploader.isHTML5) return;
1945
+
1946
+ var object = new FileDrop({
1947
+ uploader: uploader,
1948
+ element: element
1949
+ });
1950
+
1951
+ object.getOptions = $parse(attributes.options).bind(object, scope);
1952
+ object.getFilters = function () {
1953
+ return attributes.filters;
1954
+ };
1955
+ }
1956
+ };
1957
+ };
1958
+
1959
+ module.exports.$inject = ["$parse", "FileUploader", "FileDrop"];
1960
+
1961
+ /***/ },
1962
+ /* 12 */
1963
+ /***/ function(module, exports, __webpack_require__) {
1964
+
1965
+ "use strict";
1966
+
1967
+ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
1968
+
1969
+ var CONFIG = _interopRequire(__webpack_require__(1));
1970
+
1971
+ module.exports = function (FileUploader, FileOver) {
1972
+
1973
+ return {
1974
+ link: function (scope, element, attributes) {
1975
+ var uploader = scope.$eval(attributes.uploader);
1976
+
1977
+ if (!(uploader instanceof FileUploader)) {
1978
+ throw new TypeError("\"Uploader\" must be an instance of FileUploader");
1979
+ }
1980
+
1981
+ var object = new FileOver({
1982
+ uploader: uploader,
1983
+ element: element
1984
+ });
1985
+
1986
+ object.getOverClass = function () {
1987
+ return attributes.overClass || object.overClass;
1988
+ };
1989
+ }
1990
+ };
1991
+ };
1992
+
1993
+ module.exports.$inject = ["FileUploader", "FileOver"];
1994
+
1995
+ /***/ }
1996
+ /******/ ])
1997
+ });
1998
+ ;
1999
+ //# sourceMappingURL=angular-file-upload.js.map