1
1
/*
2
- Angular File Upload v0.3.2
2
+ Angular File Upload v0.3.3.1
3
3
https://github.com/nervgh/angular-file-upload
4
4
*/
5
5
( function ( angular , factory ) {
@@ -82,6 +82,11 @@ app.directive('ngFileSelect', [ '$fileUploader', function ($fileUploader) {
82
82
app . factory ( '$fileUploader' , [ '$compile' , '$rootScope' , '$http' , '$window' , function ( $compile , $rootScope , $http , $window ) {
83
83
'use strict' ;
84
84
85
+ /**
86
+ * Creates a uploader
87
+ * @param {Object } params
88
+ * @constructor
89
+ */
85
90
function Uploader ( params ) {
86
91
angular . extend ( this , {
87
92
scope : $rootScope ,
@@ -119,11 +124,16 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
119
124
}
120
125
121
126
Uploader . prototype = {
127
+ /**
128
+ * Link to the constructor
129
+ */
130
+ constructor : Uploader ,
122
131
123
132
/**
124
133
* The base filter. If returns "true" an item will be added to the queue
125
134
* @param {File|Input } item
126
135
* @returns {boolean }
136
+ * @private
127
137
*/
128
138
_filter : function ( item ) {
129
139
return angular . isElement ( item ) ? true : ! ! item . size ;
@@ -152,6 +162,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
152
162
/**
153
163
* Checks a support the html5 uploader
154
164
* @returns {Boolean }
165
+ * @readonly
155
166
*/
156
167
isHTML5 : ! ! ( $window . File && $window . FormData ) ,
157
168
@@ -273,7 +284,6 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
273
284
this [ transport ] ( item ) ;
274
285
} ,
275
286
276
-
277
287
/**
278
288
* Cancels uploading of item from the queue
279
289
* @param {Item|Number } value
@@ -285,7 +295,6 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
285
295
item [ prop ] && item [ prop ] . abort ( ) ;
286
296
} ,
287
297
288
-
289
298
/**
290
299
* Uploads all not uploaded items of queue
291
300
*/
@@ -300,7 +309,6 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
300
309
items . length && this . uploadItem ( items [ 0 ] ) ;
301
310
} ,
302
311
303
-
304
312
/**
305
313
* Cancels all uploads
306
314
*/
@@ -310,7 +318,6 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
310
318
} , this ) ;
311
319
} ,
312
320
313
-
314
321
/**
315
322
* Updates angular scope
316
323
* @private
@@ -319,11 +326,11 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
319
326
this . scope . $$phase || this . scope . $digest ( ) ;
320
327
} ,
321
328
322
-
323
329
/**
324
330
* Returns the total progress
325
331
* @param {Number } [value]
326
332
* @returns {Number }
333
+ * @private
327
334
*/
328
335
_getTotalProgress : function ( value ) {
329
336
if ( this . removeAfterUpload ) {
@@ -340,6 +347,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
340
347
341
348
/**
342
349
* The 'in:progress' handler
350
+ * @private
343
351
*/
344
352
_progress : function ( event , item , progress ) {
345
353
var result = this . _getTotalProgress ( progress ) ;
@@ -350,6 +358,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
350
358
351
359
/**
352
360
* The 'in:complete' handler
361
+ * @private
353
362
*/
354
363
_complete : function ( ) {
355
364
var item = this . getReadyItems ( ) [ 0 ] ;
@@ -367,6 +376,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
367
376
368
377
/**
369
378
* The XMLHttpRequest transport
379
+ * @private
370
380
*/
371
381
_xhrTransport : function ( item ) {
372
382
var xhr = item . _xhr = new XMLHttpRequest ( ) ;
@@ -416,6 +426,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
416
426
417
427
/**
418
428
* The IFrame transport
429
+ * @private
419
430
*/
420
431
_iframeTransport : function ( item ) {
421
432
var form = angular . element ( '<form style="display: none;" />' ) ;
@@ -446,7 +457,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
446
457
447
458
iframe . bind ( 'load' , function ( ) {
448
459
// fixed angular.contents() for iframes
449
- var html = ( iframe [ 0 ] . contentDocument || iframe [ 0 ] . contentWindow . document ) . body . innerHTML ;
460
+ var html = iframe [ 0 ] . contentDocument . body . innerHTML ;
450
461
var xhr = { response : html , status : 200 , dummy : true } ;
451
462
var response = that . _transformResponse ( xhr . response ) ;
452
463
that . trigger ( 'in:success' , xhr , item , response ) ;
@@ -467,21 +478,21 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
467
478
form [ 0 ] . submit ( ) ;
468
479
} ,
469
480
470
-
471
481
/**
472
482
* Checks whether upload successful
473
483
* @param {Number } status
474
484
* @returns {Boolean }
485
+ * @private
475
486
*/
476
487
_isSuccessCode : function ( status ) {
477
488
return ( status >= 200 && status < 300 ) || status === 304 ;
478
489
} ,
479
490
480
-
481
491
/**
482
492
* Transforms the server response
483
493
* @param {* } response
484
494
* @returns {* }
495
+ * @private
485
496
*/
486
497
_transformResponse : function ( response ) {
487
498
$http . defaults . transformResponse . forEach ( function ( transformFn ) {
@@ -492,7 +503,11 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
492
503
} ;
493
504
494
505
495
- // item of queue
506
+ /**
507
+ * Create a item
508
+ * @param {Object } params
509
+ * @constructor
510
+ */
496
511
function Item ( params ) {
497
512
// fix for old browsers
498
513
if ( ! Uploader . prototype . isHTML5 ) {
@@ -524,22 +539,46 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
524
539
} , params ) ;
525
540
}
526
541
542
+
527
543
Item . prototype = {
544
+ /**
545
+ * Link to the constructor
546
+ */
547
+ constructor : Item ,
548
+ /**
549
+ * Removes a item
550
+ */
528
551
remove : function ( ) {
529
552
this . uploader . removeFromQueue ( this ) ;
530
553
} ,
554
+ /**
555
+ * Uploads a item
556
+ */
531
557
upload : function ( ) {
532
558
this . uploader . uploadItem ( this ) ;
533
559
} ,
560
+ /**
561
+ * Cancels uploading
562
+ */
534
563
cancel : function ( ) {
535
564
this . uploader . cancelItem ( this ) ;
536
565
} ,
566
+ /**
567
+ * Destroys form and input
568
+ * @private
569
+ */
537
570
_destroy : function ( ) {
538
571
this . _form && this . _form . remove ( ) ;
539
572
this . _input && this . _input . remove ( ) ;
540
573
delete this . _form ;
541
574
delete this . _input ;
542
575
} ,
576
+ /**
577
+ * The 'beforeupload' handler
578
+ * @param {Object } event
579
+ * @param {Item } item
580
+ * @private
581
+ */
543
582
_beforeupload : function ( event , item ) {
544
583
item . isReady = true ;
545
584
item . isUploading = true ;
@@ -549,10 +588,25 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
549
588
item . isError = false ;
550
589
item . progress = 0 ;
551
590
} ,
591
+ /**
592
+ * The 'in:progress' handler
593
+ * @param {Object } event
594
+ * @param {Item } item
595
+ * @param {Number } progress
596
+ * @private
597
+ */
552
598
_progress : function ( event , item , progress ) {
553
599
item . progress = progress ;
554
600
item . uploader . trigger ( 'progress' , item , progress ) ;
555
601
} ,
602
+ /**
603
+ * The 'in:success' handler
604
+ * @param {Object } event
605
+ * @param {XMLHttpRequest } xhr
606
+ * @param {Item } item
607
+ * @param {* } response
608
+ * @private
609
+ */
556
610
_success : function ( event , xhr , item , response ) {
557
611
item . isReady = false ;
558
612
item . isUploading = false ;
@@ -564,6 +618,13 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
564
618
item . index = null ;
565
619
item . uploader . trigger ( 'success' , xhr , item , response ) ;
566
620
} ,
621
+ /**
622
+ * The 'in:cancel' handler
623
+ * @param {Object } event
624
+ * @param {XMLHttpRequest } xhr
625
+ * @param {Item } item
626
+ * @private
627
+ */
567
628
_cancel : function ( event , xhr , item ) {
568
629
item . isReady = false ;
569
630
item . isUploading = false ;
@@ -575,6 +636,14 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
575
636
item . index = null ;
576
637
item . uploader . trigger ( 'cancel' , xhr , item ) ;
577
638
} ,
639
+ /**
640
+ * The 'in:error' handler
641
+ * @param {Object } event
642
+ * @param {XMLHttpRequest } xhr
643
+ * @param {Item } item
644
+ * @param {* } response
645
+ * @private
646
+ */
578
647
_error : function ( event , xhr , item , response ) {
579
648
item . isReady = false ;
580
649
item . isUploading = false ;
@@ -586,6 +655,14 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
586
655
item . index = null ;
587
656
item . uploader . trigger ( 'error' , xhr , item , response ) ;
588
657
} ,
658
+ /**
659
+ * The 'in:complete' handler
660
+ * @param {Object } event
661
+ * @param {XMLHttpRequest } xhr
662
+ * @param {Item } item
663
+ * @param {* } response
664
+ * @private
665
+ */
589
666
_complete : function ( event , xhr , item , response ) {
590
667
item . uploader . trigger ( 'complete' , xhr , item , response ) ;
591
668
item . removeAfterUpload && item . remove ( ) ;
0 commit comments