Skip to content

Commit

Permalink
Fixed #456 #451 #467
Browse files Browse the repository at this point in the history
  • Loading branch information
Danial Farid authored and Danial Farid committed Jan 6, 2015
1 parent 9f99650 commit 44db8a8
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 179 deletions.
2 changes: 1 addition & 1 deletion demo/war/WEB-INF/appengine-web.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>angular-file-upload</application>
<version>2-0-3</version>
<version>2-1-0</version>

<!--
Allows App Engine to send multiple requests to one instance in parallel:
Expand Down
3 changes: 2 additions & 1 deletion demo/war/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ <h3>
<span class="progress" ng-show="f.progress >= 0">
<div style="width:{{f.progress}}%">{{f.progress}}%</div>
</span>
<button class="button" ng-click="f.upload.abort()" ng-show="f.upload != null && f.progress < 100">Abort</button>
<button class="button" ng-click="f.upload.abort();f.upload.aborted=true"
ng-show="f.upload != null && f.progress < 100 && !f.upload.aborted">Abort</button>
{{f.name}} - size: {{f.size}}B - type: {{f.type}}
<a ng-show="f.result" href="javascript:void(0)" ng-click="f.showDetail = !f.showDetail">details</a>
<div ng-show="f.showDetail">
Expand Down
16 changes: 9 additions & 7 deletions demo/war/js/FileAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -3696,13 +3696,15 @@
if( !file.__info ){
var defer = file.__info = api.defer();

flash.cmd(file, 'getFileInfo', {
id: file.id
, callback: _wrap(function _(err, info){
_unwrap(_);
defer.resolve(err, file.info = info);
})
});
// flash.cmd(file, 'getFileInfo', {
// id: file.id
// , callback: _wrap(function _(err, info){
// _unwrap(_);
// defer.resolve(err, file.info = info);
// })
// });
defer.resolve(null, file.info = null);

}

file.__info.then(fn);
Expand Down
2 changes: 1 addition & 1 deletion demo/war/js/FileAPI.min.js

Large diffs are not rendered by default.

91 changes: 50 additions & 41 deletions demo/war/js/angular-file-upload-all.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
* AngularJS file upload/drop directive with progress and abort
* @author Danial <[email protected]>
* @version 2.1.0
* @version 2.1.1
*/
(function() {

Expand All @@ -26,7 +26,7 @@ if (window.XMLHttpRequest && !window.XMLHttpRequest.__isFileAPIShim) {
}

var angularFileUpload = angular.module('angularFileUpload', []);
angularFileUpload.version = '2.1.0';
angularFileUpload.version = '2.1.1';
angularFileUpload.service('$upload', ['$http', '$q', '$timeout', function($http, $q, $timeout) {
function sendHttp(config) {
config.method = config.method || 'POST';
Expand Down Expand Up @@ -161,15 +161,15 @@ angularFileUpload.service('$upload', ['$http', '$q', '$timeout', function($http,
};
}]);

angularFileUpload.directive('ngFileSelect', [ '$parse', '$timeout', function($parse, $timeout) { return {
angularFileUpload.directive('ngFileSelect', [ '$parse', '$timeout', '$compile', function($parse, $timeout, $compile) { return {
restrict: 'AEC',
require:'?ngModel',
link: function(scope, elem, attr, ngModel) {
handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout);
handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile);
}
}}]);

function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout) {
function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile) {
if (attr.ngMultiple && $parse(attr.ngMultiple)(scope)) {
elem.attr('multiple', 'true');
attr['multiple'] = 'true';
Expand All @@ -188,55 +188,64 @@ function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout) {
elem.append(fileElem);
elem.__afu_fileClickDelegate__ = function() {
fileElem[0].click();
};
};
elem.bind('click', elem.__afu_fileClickDelegate__);
elem.css('overflow', 'hidden');
var origElem = elem;
elem = fileElem;
}
var changeFn = $parse(attr.ngFileChange);
if ($parse(attr.resetOnClick)(scope) != false) {
elem.bind('click', function(evt) {
if (elem[0].value) {
updateModel([], attr, ngModel, changeFn, scope, evt);
}
elem[0].value = null;
});
}
if (ngModel) {
scope.$parent.$watch(attr['ngModel'], function(val) {
if (val == null) {
if (navigator.appVersion.indexOf("MSIE 10") !== -1) {
// fix for IE10 cannot set the value of the input to null programmatically by replacing input
var replaceElem = function(evt) {
var inputFile = elem.clone();
inputFile.val('');
elem.replaceWith(inputFile);
$compile(inputFile)(scope);
fileElem = inputFile;
elem = inputFile;
elem.bind('change', onChangeFn);
elem.unbind('click');
elem[0].click();
elem.bind('click', replaceElem);
evt.preventDefault();
evt.stopPropagation();
};
elem.bind('click', replaceElem);
} else {
elem.bind('click', function(evt) {
elem[0].value = null;
}
});
}
if (attr['ngFileSelect'] != '') {
attr.ngFileChange = attr.ngFileSelect;
});
}
}
elem.bind('change', function(evt) {
var onChangeFn = function(evt) {
var files = [], fileList, i;
fileList = evt.__files_ || evt.target.files;
updateModel(fileList, attr, ngModel, changeFn, scope, evt);
});
};
elem.bind('change', onChangeFn);
if (attr['ngFileSelect'] != '') {
attr.ngFileChange = attr.ngFileSelect;
}

function updateModel(fileList, attr, ngModel, change, scope, evt) {
$timeout(function() {
var files = [];
for (var i = 0; i < fileList.length; i++) {
files.push(fileList.item(i));
}
if (ngModel) {
scope[attr.ngModel] ? scope[attr.ngModel].value = files : scope[attr.ngModel] = files;
ngModel && ngModel.$setViewValue(files != null && files.length == 0 ? '' : files);
}
if (change) {
$timeout(function() {
change(scope, {
$files : files,
$event : evt
});
var files = [];
for (var i = 0; i < fileList.length; i++) {
files.push(fileList.item(i));
}
if (ngModel) {
scope[attr.ngModel] ? scope[attr.ngModel].value = files : scope[attr.ngModel] = files;
ngModel && ngModel.$setViewValue(files != null && files.length == 0 ? '' : files);
}
if (change) {
$timeout(function() {
change(scope, {
$files : files,
$event : evt
});
}
});
});
}
}
}

Expand Down Expand Up @@ -493,7 +502,7 @@ function globStringToRegex(str) {
* AngularJS file upload/drop directive with progress and abort
* FileAPI Flash shim for old browsers not supporting FormData
* @author Danial <[email protected]>
* @version 2.1.0
* @version 2.1.1
*/

(function() {
Expand Down
85 changes: 47 additions & 38 deletions demo/war/js/angular-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ angularFileUpload.service('$upload', ['$http', '$q', '$timeout', function($http,
};
}]);

angularFileUpload.directive('ngFileSelect', [ '$parse', '$timeout', function($parse, $timeout) { return {
angularFileUpload.directive('ngFileSelect', [ '$parse', '$timeout', '$compile', function($parse, $timeout, $compile) { return {
restrict: 'AEC',
require:'?ngModel',
link: function(scope, elem, attr, ngModel) {
handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout);
handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile);
}
}}]);

function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout) {
function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout, $compile) {
if (attr.ngMultiple && $parse(attr.ngMultiple)(scope)) {
elem.attr('multiple', 'true');
attr['multiple'] = 'true';
Expand All @@ -188,55 +188,64 @@ function handleFileSelect(scope, elem, attr, ngModel, $parse, $timeout) {
elem.append(fileElem);
elem.__afu_fileClickDelegate__ = function() {
fileElem[0].click();
};
};
elem.bind('click', elem.__afu_fileClickDelegate__);
elem.css('overflow', 'hidden');
var origElem = elem;
elem = fileElem;
}
var changeFn = $parse(attr.ngFileChange);
if ($parse(attr.resetOnClick)(scope) != false) {
elem.bind('click', function(evt) {
if (elem[0].value) {
updateModel([], attr, ngModel, changeFn, scope, evt);
}
elem[0].value = null;
});
}
if (ngModel) {
scope.$parent.$watch(attr['ngModel'], function(val) {
if (val == null) {
if (navigator.appVersion.indexOf("MSIE 10") !== -1) {
// fix for IE10 cannot set the value of the input to null programmatically by replacing input
var replaceElem = function(evt) {
var inputFile = elem.clone();
inputFile.val('');
elem.replaceWith(inputFile);
$compile(inputFile)(scope);
fileElem = inputFile;
elem = inputFile;
elem.bind('change', onChangeFn);
elem.unbind('click');
elem[0].click();
elem.bind('click', replaceElem);
evt.preventDefault();
evt.stopPropagation();
};
elem.bind('click', replaceElem);
} else {
elem.bind('click', function(evt) {
elem[0].value = null;
}
});
}
if (attr['ngFileSelect'] != '') {
attr.ngFileChange = attr.ngFileSelect;
});
}
}
elem.bind('change', function(evt) {
var onChangeFn = function(evt) {
var files = [], fileList, i;
fileList = evt.__files_ || evt.target.files;
updateModel(fileList, attr, ngModel, changeFn, scope, evt);
});
};
elem.bind('change', onChangeFn);
if (attr['ngFileSelect'] != '') {
attr.ngFileChange = attr.ngFileSelect;
}

function updateModel(fileList, attr, ngModel, change, scope, evt) {
$timeout(function() {
var files = [];
for (var i = 0; i < fileList.length; i++) {
files.push(fileList.item(i));
}
if (ngModel) {
scope[attr.ngModel] ? scope[attr.ngModel].value = files : scope[attr.ngModel] = files;
ngModel && ngModel.$setViewValue(files != null && files.length == 0 ? '' : files);
}
if (change) {
$timeout(function() {
change(scope, {
$files : files,
$event : evt
});
var files = [];
for (var i = 0; i < fileList.length; i++) {
files.push(fileList.item(i));
}
if (ngModel) {
scope[attr.ngModel] ? scope[attr.ngModel].value = files : scope[attr.ngModel] = files;
ngModel && ngModel.$setViewValue(files != null && files.length == 0 ? '' : files);
}
if (change) {
$timeout(function() {
change(scope, {
$files : files,
$event : evt
});
}
});
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/FileAPI.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 44db8a8

Please sign in to comment.