Skip to content

Commit a746d3a

Browse files
committed
Merge pull request #3 from HenryYan2012/release/v1.1.5
upgrade to v1.1.5
2 parents 948f551 + 74c8bb3 commit a746d3a

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A gem that uses [angular-file-upload](https://github.com/nervgh/angular-file-upl
99
Add this line to your application's Gemfile:
1010

1111
```ruby
12-
gem 'angularjs-file-upload-rails', '~> 1.1.0'
12+
gem 'angularjs-file-upload-rails', '~> 1.1.5'
1313
```
1414

1515
And then execute:
@@ -42,7 +42,7 @@ read more about the options in [angular-file-upload-wiki](https://github.com/ner
4242
\* *assuming that you have setup an ```angularjs``` correctly in your rails app
4343

4444
```ruby
45-
gem 'angularjs-file-upload-rails', '~> 1.1.0'
45+
gem 'angularjs-file-upload-rails', '~> 1.1.5'
4646
gem 'carrierwave'
4747
gem 'rails', '4.1.5'
4848
```

app/assets/javascripts/angularjs-file-upload.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
angular-file-upload v1.1.0
2+
angular-file-upload v1.1.5
33
https://github.com/nervgh/angular-file-upload
44
*/
55
(function(angular, factory) {
@@ -344,7 +344,7 @@ module
344344
FileUploader.prototype._getFilters = function(filters) {
345345
if (angular.isUndefined(filters)) return this.filters;
346346
if (angular.isArray(filters)) return filters;
347-
var names = filters.split(/\s*,/);
347+
var names = filters.match(/[^\s,]+/g);
348348
return this.filters.filter(function(filter) {
349349
return names.indexOf(filter.name) !== -1;
350350
}, this);
@@ -400,12 +400,14 @@ module
400400
/**
401401
* Transforms the server response
402402
* @param {*} response
403+
* @param {Object} headers
403404
* @returns {*}
404405
* @private
405406
*/
406-
FileUploader.prototype._transformResponse = function(response) {
407+
FileUploader.prototype._transformResponse = function(response, headers) {
408+
var headersGetter = this._headersGetter(headers);
407409
angular.forEach($http.defaults.transformResponse, function(transformFn) {
408-
response = transformFn(response);
410+
response = transformFn(response, headersGetter);
409411
});
410412
return response;
411413
};
@@ -421,17 +423,10 @@ module
421423

422424
if (!headers) return parsed;
423425

424-
function trim(string) {
425-
return string.replace(/^\s+/, '').replace(/\s+$/, '');
426-
}
427-
function lowercase(string) {
428-
return string.toLowerCase();
429-
}
430-
431426
angular.forEach(headers.split('\n'), function(line) {
432427
i = line.indexOf(':');
433-
key = lowercase(trim(line.substr(0, i)));
434-
val = trim(line.substr(i + 1));
428+
key = line.slice(0, i).trim().toLowerCase();
429+
val = line.slice(i + 1).trim();
435430

436431
if (key) {
437432
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
@@ -440,6 +435,20 @@ module
440435

441436
return parsed;
442437
};
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+
};
443452
/**
444453
* The XMLHttpRequest transport
445454
* @param {FileItem} item
@@ -458,7 +467,7 @@ module
458467
});
459468
});
460469

461-
form.append(item.alias, item._file);
470+
form.append(item.alias, item._file, item.file.name);
462471

463472
xhr.upload.onprogress = function(event) {
464473
var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
@@ -467,7 +476,7 @@ module
467476

468477
xhr.onload = function() {
469478
var headers = that._parseHeaders(xhr.getAllResponseHeaders());
470-
var response = that._transformResponse(xhr.response);
479+
var response = that._transformResponse(xhr.response, headers);
471480
var gist = that._isSuccessCode(xhr.status) ? 'Success' : 'Error';
472481
var method = '_on' + gist + 'Item';
473482
that[method](item, response, xhr.status, headers);
@@ -476,14 +485,14 @@ module
476485

477486
xhr.onerror = function() {
478487
var headers = that._parseHeaders(xhr.getAllResponseHeaders());
479-
var response = that._transformResponse(xhr.response);
488+
var response = that._transformResponse(xhr.response, headers);
480489
that._onErrorItem(item, response, xhr.status, headers);
481490
that._onCompleteItem(item, response, xhr.status, headers);
482491
};
483492

484493
xhr.onabort = function() {
485494
var headers = that._parseHeaders(xhr.getAllResponseHeaders());
486-
var response = that._transformResponse(xhr.response);
495+
var response = that._transformResponse(xhr.response, headers);
487496
that._onCancelItem(item, response, xhr.status, headers);
488497
that._onCompleteItem(item, response, xhr.status, headers);
489498
};
@@ -519,7 +528,9 @@ module
519528

520529
angular.forEach(item.formData, function(obj) {
521530
angular.forEach(obj, function(value, key) {
522-
form.append(angular.element('<input type="hidden" name="' + key + '" value="' + value + '" />'));
531+
var element = angular.element('<input type="hidden" name="' + key + '" />');
532+
element.val(value);
533+
form.append(element);
523534
});
524535
});
525536

@@ -549,8 +560,8 @@ module
549560
} catch (e) {}
550561

551562
var xhr = {response: html, status: 200, dummy: true};
552-
var response = that._transformResponse(xhr.response);
553563
var headers = {};
564+
var response = that._transformResponse(xhr.response, headers);
554565

555566
that._onSuccessItem(item, response, xhr.status, headers);
556567
that._onCompleteItem(item, response, xhr.status, headers);
@@ -1155,7 +1166,7 @@ module
11551166
* Event handler
11561167
*/
11571168
FileDrop.prototype.onDragLeave = function(event) {
1158-
if (event.target !== this.element[0]) return;
1169+
if (event.currentTarget !== this.element[0]) return;
11591170
this._preventAndStop(event);
11601171
angular.forEach(this.uploader._directives.over, this._removeOverClass, this);
11611172
};
@@ -1316,5 +1327,6 @@ module
13161327
}
13171328
};
13181329
}])
1330+
13191331
return module;
1320-
}));
1332+
}));

lib/angularjs-file-upload/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module AngularjsFileUpload
2-
VERSION = '1.1.0'
2+
VERSION = '1.1.5'
33
end

0 commit comments

Comments
 (0)