Skip to content

Commit 44d54ea

Browse files
author
nerv
committed
Added: more comments
1 parent 6663a07 commit 44d54ea

File tree

10 files changed

+183
-29
lines changed

10 files changed

+183
-29
lines changed

angular-file-upload.js

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Angular File Upload v0.3.2
2+
Angular File Upload v0.3.3.1
33
https://github.com/nervgh/angular-file-upload
44
*/
55
(function(angular, factory) {
@@ -82,6 +82,11 @@ app.directive('ngFileSelect', [ '$fileUploader', function ($fileUploader) {
8282
app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', function ($compile, $rootScope, $http, $window) {
8383
'use strict';
8484

85+
/**
86+
* Creates a uploader
87+
* @param {Object} params
88+
* @constructor
89+
*/
8590
function Uploader(params) {
8691
angular.extend(this, {
8792
scope: $rootScope,
@@ -119,11 +124,16 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
119124
}
120125

121126
Uploader.prototype = {
127+
/**
128+
* Link to the constructor
129+
*/
130+
constructor: Uploader,
122131

123132
/**
124133
* The base filter. If returns "true" an item will be added to the queue
125134
* @param {File|Input} item
126135
* @returns {boolean}
136+
* @private
127137
*/
128138
_filter: function (item) {
129139
return angular.isElement(item) ? true : !!item.size;
@@ -152,6 +162,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
152162
/**
153163
* Checks a support the html5 uploader
154164
* @returns {Boolean}
165+
* @readonly
155166
*/
156167
isHTML5: !!($window.File && $window.FormData),
157168

@@ -273,7 +284,6 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
273284
this[ transport ](item);
274285
},
275286

276-
277287
/**
278288
* Cancels uploading of item from the queue
279289
* @param {Item|Number} value
@@ -285,7 +295,6 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
285295
item[prop] && item[prop].abort();
286296
},
287297

288-
289298
/**
290299
* Uploads all not uploaded items of queue
291300
*/
@@ -300,7 +309,6 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
300309
items.length && this.uploadItem(items[ 0 ]);
301310
},
302311

303-
304312
/**
305313
* Cancels all uploads
306314
*/
@@ -310,7 +318,6 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
310318
}, this);
311319
},
312320

313-
314321
/**
315322
* Updates angular scope
316323
* @private
@@ -319,11 +326,11 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
319326
this.scope.$$phase || this.scope.$digest();
320327
},
321328

322-
323329
/**
324330
* Returns the total progress
325331
* @param {Number} [value]
326332
* @returns {Number}
333+
* @private
327334
*/
328335
_getTotalProgress: function (value) {
329336
if (this.removeAfterUpload) {
@@ -340,6 +347,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
340347

341348
/**
342349
* The 'in:progress' handler
350+
* @private
343351
*/
344352
_progress: function (event, item, progress) {
345353
var result = this._getTotalProgress(progress);
@@ -350,6 +358,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
350358

351359
/**
352360
* The 'in:complete' handler
361+
* @private
353362
*/
354363
_complete: function () {
355364
var item = this.getReadyItems()[ 0 ];
@@ -367,6 +376,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
367376

368377
/**
369378
* The XMLHttpRequest transport
379+
* @private
370380
*/
371381
_xhrTransport: function (item) {
372382
var xhr = item._xhr = new XMLHttpRequest();
@@ -416,6 +426,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
416426

417427
/**
418428
* The IFrame transport
429+
* @private
419430
*/
420431
_iframeTransport: function (item) {
421432
var form = angular.element('<form style="display: none;" />');
@@ -446,7 +457,7 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
446457

447458
iframe.bind('load', function () {
448459
// 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;
450461
var xhr = { response: html, status: 200, dummy: true };
451462
var response = that._transformResponse(xhr.response);
452463
that.trigger('in:success', xhr, item, response);
@@ -467,21 +478,21 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
467478
form[ 0 ].submit();
468479
},
469480

470-
471481
/**
472482
* Checks whether upload successful
473483
* @param {Number} status
474484
* @returns {Boolean}
485+
* @private
475486
*/
476487
_isSuccessCode: function(status) {
477488
return (status >= 200 && status < 300) || status === 304;
478489
},
479490

480-
481491
/**
482492
* Transforms the server response
483493
* @param {*} response
484494
* @returns {*}
495+
* @private
485496
*/
486497
_transformResponse: function (response) {
487498
$http.defaults.transformResponse.forEach(function (transformFn) {
@@ -492,7 +503,11 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
492503
};
493504

494505

495-
// item of queue
506+
/**
507+
* Create a item
508+
* @param {Object} params
509+
* @constructor
510+
*/
496511
function Item(params) {
497512
// fix for old browsers
498513
if (!Uploader.prototype.isHTML5) {
@@ -524,22 +539,46 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
524539
}, params);
525540
}
526541

542+
527543
Item.prototype = {
544+
/**
545+
* Link to the constructor
546+
*/
547+
constructor: Item,
548+
/**
549+
* Removes a item
550+
*/
528551
remove: function () {
529552
this.uploader.removeFromQueue(this);
530553
},
554+
/**
555+
* Uploads a item
556+
*/
531557
upload: function () {
532558
this.uploader.uploadItem(this);
533559
},
560+
/**
561+
* Cancels uploading
562+
*/
534563
cancel: function() {
535564
this.uploader.cancelItem(this);
536565
},
566+
/**
567+
* Destroys form and input
568+
* @private
569+
*/
537570
_destroy: function() {
538571
this._form && this._form.remove();
539572
this._input && this._input.remove();
540573
delete this._form;
541574
delete this._input;
542575
},
576+
/**
577+
* The 'beforeupload' handler
578+
* @param {Object} event
579+
* @param {Item} item
580+
* @private
581+
*/
543582
_beforeupload: function (event, item) {
544583
item.isReady = true;
545584
item.isUploading = true;
@@ -549,10 +588,25 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
549588
item.isError = false;
550589
item.progress = 0;
551590
},
591+
/**
592+
* The 'in:progress' handler
593+
* @param {Object} event
594+
* @param {Item} item
595+
* @param {Number} progress
596+
* @private
597+
*/
552598
_progress: function (event, item, progress) {
553599
item.progress = progress;
554600
item.uploader.trigger('progress', item, progress);
555601
},
602+
/**
603+
* The 'in:success' handler
604+
* @param {Object} event
605+
* @param {XMLHttpRequest} xhr
606+
* @param {Item} item
607+
* @param {*} response
608+
* @private
609+
*/
556610
_success: function (event, xhr, item, response) {
557611
item.isReady = false;
558612
item.isUploading = false;
@@ -564,6 +618,13 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
564618
item.index = null;
565619
item.uploader.trigger('success', xhr, item, response);
566620
},
621+
/**
622+
* The 'in:cancel' handler
623+
* @param {Object} event
624+
* @param {XMLHttpRequest} xhr
625+
* @param {Item} item
626+
* @private
627+
*/
567628
_cancel: function(event, xhr, item) {
568629
item.isReady = false;
569630
item.isUploading = false;
@@ -575,6 +636,14 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
575636
item.index = null;
576637
item.uploader.trigger('cancel', xhr, item);
577638
},
639+
/**
640+
* The 'in:error' handler
641+
* @param {Object} event
642+
* @param {XMLHttpRequest} xhr
643+
* @param {Item} item
644+
* @param {*} response
645+
* @private
646+
*/
578647
_error: function (event, xhr, item, response) {
579648
item.isReady = false;
580649
item.isUploading = false;
@@ -586,6 +655,14 @@ app.factory('$fileUploader', [ '$compile', '$rootScope', '$http', '$window', fun
586655
item.index = null;
587656
item.uploader.trigger('error', xhr, item, response);
588657
},
658+
/**
659+
* The 'in:complete' handler
660+
* @param {Object} event
661+
* @param {XMLHttpRequest} xhr
662+
* @param {Item} item
663+
* @param {*} response
664+
* @private
665+
*/
589666
_complete: function (event, xhr, item, response) {
590667
item.uploader.trigger('complete', xhr, item, response);
591668
item.removeAfterUpload && item.remove();

angular-file-upload.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular-file-upload.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-file-upload",
3-
"version": "0.3.2",
3+
"version": "0.3.3.1",
44
"main": "angular-file-upload.js",
55
"homepage": "https://github.com/nervgh/angular-file-upload",
66
"ignore": [],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Angular File Upload",
3-
"version": "0.3.2",
3+
"version": "0.3.3.1",
44
"homepage": "https://github.com/nervgh/angular-file-upload",
55
"description": "Angular File Upload is a module for the AngularJS framework",
66
"author": {

src/scripts/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* The angular file upload module
33
* @author: nerv
4-
* @version: 0.3.3, 2014-02-18
4+
* @version: 0.3.3.1, 2014-02-28
55
*/
66
var app = angular.module('angularFileUpload', []);

src/scripts/directives/ngFileDrop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* The angular file upload module
33
* @author: nerv
4-
* @version: 0.3.3, 2014-02-18
4+
* @version: 0.3.3.1, 2014-02-28
55
*/
66

77
// It is attached to an element that catches the event drop file

src/scripts/directives/ngFileOver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* The angular file upload module
33
* @author: nerv
4-
* @version: 0.3.3, 2014-02-18
4+
* @version: 0.3.3.1, 2014-02-28
55
*/
66

77
// It is attached to an element which will be assigned to a class "ng-file-over" or ng-file-over="className"

src/scripts/directives/ngFileSelect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* The angular file upload module
33
* @author: nerv
4-
* @version: 0.3.3, 2014-02-18
4+
* @version: 0.3.3.1, 2014-02-28
55
*/
66

77
// It is attached to <input type="file"> element like <ng-file-select="options">

0 commit comments

Comments
 (0)