From 51161222dae4c46a6a33cba068f4b28989ebb484 Mon Sep 17 00:00:00 2001 From: Danial Farid Date: Sun, 27 Jul 2014 12:19:09 -0400 Subject: [PATCH] fixed #276 #277 --- CHANGELOG.md | 88 ------------------- .../com/df/angularfileupload/CORSFilter.java | 4 +- demo/war/WEB-INF/appengine-web.xml | 4 +- demo/war/index.html | 9 +- demo/war/js/angular-file-upload-shim.js | 19 ++-- demo/war/js/angular-file-upload.js | 6 +- demo/war/js/upload.js | 2 +- dist/angular-file-upload-html5-shim.js | 2 +- dist/angular-file-upload-html5-shim.min.js | 2 +- dist/angular-file-upload-shim.js | 21 +++-- dist/angular-file-upload-shim.min.js | 4 +- dist/angular-file-upload.js | 8 +- dist/angular-file-upload.min.js | 4 +- nuget/Package.nuspec | 2 +- package.json | 2 +- 15 files changed, 49 insertions(+), 128 deletions(-) delete mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index dfc3d424..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,88 +0,0 @@ -# Changelog - -##1.2.8 -Fixed #138 #133 #114 #130 #128 -fixed progress end for ie8 - -##1.2.7 -Fixed #122 -Added request headers to the demo page - -##1.2.6 -Fixed bower main js files - -##1.2.5 -Fixed #109 Angular 1.2.8 Data returned in success callback is null/undefined - -##1.2.4 -Fixed #100 Custom names when uploading multiple files - -##1.2.3 -fixed #90 - -##1.2.2 -fixed #89 - -##1.2.1 -Fixed progress event for older angular version < 1.2.0 - -##1.2.0 -Fixed #88 #87 -Added $upload.http service method to be able to send a normal POST/PUT and listen to progress event. -File binary content can be send as data to the server like this. - -##1.1.11 -Added support for multiple files upload with the same call for HTML5 only browsers. -Fixed #69 - -## 1.1.10 -Fixed #68 #70 #65 #62 #64 #58 - - -## 1.1.9 2013-11-27 -Directory structure changes and adding Grunt to build. -Fixed #57 - -## 1.1.8 2013-11-21 -Fixed #54 - -## 1.1.7 2013-11-19 -Fixed #51 - -## 1.1.6 2013-11-18 -Fixed #50 firefox progress event not firing at the end. - -## 1.1.5 2013-11-08 -Fixed #46 #40 #38, moved demo to a separate folder - -## 1.1.4 2013-11-08 -Fixed #38 #40 - -## 1.1.3 2013-11-07 -Fixed #37 #39 - -## 1.1.2 - 2013-11-05 -upload.abort() to cancel the upload in progress. -issue #34 -issue #35 -issue #36 - -## 1.1.1 - 2013-10-28 -Fixed progress bar to work with the latest angular 1.2.0-rc.3. -Added fileFormDataName to set the name of the Content-Disposition formData. -You can now upload the same file twice: pull request #27 - -## 1.1.0 - 2013-10-28 -upload is now done with regular angular $http.post for HTML5 browsers so all angular $http features are available. -Added $upload as an angular service. -All the code for non HTML5 browsers and upload progress are moved to a separate shim file, the actual directive just uses html5 code. So if you only suppost HTML5 browsers you don't need to load shim js file. -angular-file-upload-shim.js needs to be loaded before angular.js if you need to support upload progress or browsers not supporting HTML5 FormData. -progress event is part of the upload config params instead of promise call. - -## 1.0.1 - 2013-10-16 -- Added fileFormDataName to config to be able to set the Content-Disposition formData name for the uploaded file - -## 1.0.0 - 2013-10-15 -- file upload progress support -- file drag and drop support - diff --git a/demo/src/com/df/angularfileupload/CORSFilter.java b/demo/src/com/df/angularfileupload/CORSFilter.java index 5ae6802b..3e82f89f 100644 --- a/demo/src/com/df/angularfileupload/CORSFilter.java +++ b/demo/src/com/df/angularfileupload/CORSFilter.java @@ -19,11 +19,11 @@ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain HttpServletResponse httpResp = (HttpServletResponse) resp; HttpServletRequest httpReq = (HttpServletRequest) req; - httpResp.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, OPTION"); + httpResp.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS"); httpResp.setHeader("Access-Control-Allow-Origin", "*"); if (httpReq.getMethod().equalsIgnoreCase("OPTIONS")) { httpResp.setHeader("Access-Control-Allow-Headers", - ((HttpServletRequest) req).getHeader("Access-Control-Request-Headers")); + httpReq.getHeader("Access-Control-Request-Headers")); } chain.doFilter(req, resp); } diff --git a/demo/war/WEB-INF/appengine-web.xml b/demo/war/WEB-INF/appengine-web.xml index 47372ef0..17dc7d06 100644 --- a/demo/war/WEB-INF/appengine-web.xml +++ b/demo/war/WEB-INF/appengine-web.xml @@ -1,7 +1,7 @@ - angular-file-upload - 1-6-0 + angular-file-upload-cors-srv + 1-6-1
or drop files
here
+ ng-file-drag-over-class="dragOverClass($event)" ng-file-drag-over-delay="100">or drop files
here
HTML5 Drop File is not supported on this browser

Upload right away diff --git a/demo/war/js/angular-file-upload-shim.js b/demo/war/js/angular-file-upload-shim.js index 7c022f80..14541230 100644 --- a/demo/war/js/angular-file-upload-shim.js +++ b/demo/war/js/angular-file-upload-shim.js @@ -161,14 +161,17 @@ if (!window.FormData || (window.FileAPI && FileAPI.forceLoad)) { } var el = angular.element(elem); if (!el.hasClass('js-fileapi-wrapper') && (elem.getAttribute('ng-file-select') != null || elem.getAttribute('data-ng-file-select') != null)) { -// var wrap = document.createElement('div'); -// wrap.innerHTML = '
'; -// wrap = wrap.firstChild; -// var parent = elem.parentNode; -// parent.insertBefore(wrap, elem); -// parent.removeChild(elem); -// wrap.appendChild(elem); - el.addClass('js-fileapi-wrapper'); + if (FileAPI.wrapInsideDiv) { + var wrap = document.createElement('div'); + wrap.innerHTML = '
'; + wrap = wrap.firstChild; + var parent = elem.parentNode; + parent.insertBefore(wrap, elem); + parent.removeChild(elem); + wrap.appendChild(elem); + } else { + el.addClass('js-fileapi-wrapper'); + } } }; var changeFnWrapper = function(fn) { diff --git a/demo/war/js/angular-file-upload.js b/demo/war/js/angular-file-upload.js index c77379cf..4dc3b0c3 100644 --- a/demo/war/js/angular-file-upload.js +++ b/demo/war/js/angular-file-upload.js @@ -209,8 +209,8 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f evt.preventDefault(); $timeout.cancel(leaveTimeout); if (!elem[0].__drag_over_class_) { - var dragOverClassFn = $parse(attr['ngFileDragOverClass']); - if (dragOverClassFn instanceof Function) { + if (attr['ngFileDragOverClass'].search(/\) *$/) > -1) { + dragOverClassFn = $parse(attr['ngFileDragOverClass']); var dragOverClass = dragOverClassFn(scope, { $event : evt }); @@ -229,7 +229,7 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f leaveTimeout = $timeout(function() { elem.removeClass(elem[0].__drag_over_class_); elem[0].__drag_over_class_ = null; - }); + }, attr['ngFileDragOverDelay'] || 1); }, false); var fn = $parse(attr['ngFileDrop']); elem[0].addEventListener("drop", function(evt) { diff --git a/demo/war/js/upload.js b/demo/war/js/upload.js index 885bedf5..9e7c95cc 100644 --- a/demo/war/js/upload.js +++ b/demo/war/js/upload.js @@ -3,7 +3,7 @@ angular.module('fileUpload', [ 'angularFileUpload' ]); -var uploadUrl = 'http://angular-file-upload-cors-srv.appspot.com/upload'; +//var uploadUrl = 'http://angular-file-upload-cors-srv.appspot.com/upload'; window.uploadUrl = window.uploadUrl || 'upload'; var MyCtrl = [ '$scope', '$http', '$timeout', '$upload', function($scope, $http, $timeout, $upload) { diff --git a/dist/angular-file-upload-html5-shim.js b/dist/angular-file-upload-html5-shim.js index 9872637d..dd012104 100644 --- a/dist/angular-file-upload-html5-shim.js +++ b/dist/angular-file-upload-html5-shim.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload shim for angular XHR HTML5 browsers * @author Danial - * @version 1.6.1 + * @version 1.6.2 */ if (window.XMLHttpRequest) { if (window.FormData) { diff --git a/dist/angular-file-upload-html5-shim.min.js b/dist/angular-file-upload-html5-shim.min.js index 4d6fbc4c..ec363d5f 100644 --- a/dist/angular-file-upload-html5-shim.min.js +++ b/dist/angular-file-upload-html5-shim.min.js @@ -1,2 +1,2 @@ -/*! 1.6.1 */ +/*! 1.6.2 */ window.XMLHttpRequest&&window.FormData&&(XMLHttpRequest=function(a){return function(){var b=new a;return b.setRequestHeader=function(a){return function(c,d){if("__setXHR_"===c){var e=d(b);e instanceof Function&&e(b)}else a.apply(b,arguments)}}(b.setRequestHeader),b}}(XMLHttpRequest),window.XMLHttpRequest.__isShim=!0); \ No newline at end of file diff --git a/dist/angular-file-upload-shim.js b/dist/angular-file-upload-shim.js index 3a5d3c3d..71304d94 100644 --- a/dist/angular-file-upload-shim.js +++ b/dist/angular-file-upload-shim.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload shim for HTML5 FormData * @author Danial - * @version 1.6.1 + * @version 1.6.2 */ (function() { @@ -161,14 +161,17 @@ if (!window.FormData || (window.FileAPI && FileAPI.forceLoad)) { } var el = angular.element(elem); if (!el.hasClass('js-fileapi-wrapper') && (elem.getAttribute('ng-file-select') != null || elem.getAttribute('data-ng-file-select') != null)) { -// var wrap = document.createElement('div'); -// wrap.innerHTML = '
'; -// wrap = wrap.firstChild; -// var parent = elem.parentNode; -// parent.insertBefore(wrap, elem); -// parent.removeChild(elem); -// wrap.appendChild(elem); - el.addClass('js-fileapi-wrapper'); + if (FileAPI.wrapInsideDiv) { + var wrap = document.createElement('div'); + wrap.innerHTML = '
'; + wrap = wrap.firstChild; + var parent = elem.parentNode; + parent.insertBefore(wrap, elem); + parent.removeChild(elem); + wrap.appendChild(elem); + } else { + el.addClass('js-fileapi-wrapper'); + } } }; var changeFnWrapper = function(fn) { diff --git a/dist/angular-file-upload-shim.min.js b/dist/angular-file-upload-shim.min.js index ded56b71..9bdf7e51 100644 --- a/dist/angular-file-upload-shim.min.js +++ b/dist/angular-file-upload-shim.min.js @@ -1,2 +1,2 @@ -/*! 1.6.1 */ -!function(){function a(a){if(!a.__listeners){a.upload||(a.upload={}),a.__listeners=[];var b=a.upload.addEventListener;a.upload.addEventListener=function(c,d){a.__listeners[c]=d,b&&b.apply(this,arguments)}}}var b=function(){try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if(a)return!0}catch(b){if(void 0!=navigator.mimeTypes["application/x-shockwave-flash"])return!0}return!1},c=function(a,b){window.XMLHttpRequest.prototype[a]=b(window.XMLHttpRequest.prototype[a])};if(window.XMLHttpRequest&&(!window.FormData||window.FileAPI&&FileAPI.forceLoad?(c("open",function(b){return function(c,d,e){a(this),this.__url=d;try{b.apply(this,[c,d,e])}catch(f){f.message.indexOf("Access is denied")>-1&&b.apply(this,[c,"_fix_for_ie_crossdomain__",e])}}}),c("getResponseHeader",function(a){return function(b){return this.__fileApiXHR?this.__fileApiXHR.getResponseHeader(b):a.apply(this,[b])}}),c("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),c("abort",function(a){return function(){return this.__fileApiXHR?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),c("setRequestHeader",function(b){return function(c,d){if("__setXHR_"===c){a(this);var e=d(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[c]=d,b.apply(this,arguments)}}),c("send",function(a){return function(){var c=this;if(arguments[0]&&arguments[0].__isShim){var d=arguments[0],e={url:c.__url,complete:function(a,b){!a&&c.__listeners.load&&c.__listeners.load({type:"load",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),!a&&c.__listeners.loadend&&c.__listeners.loadend({type:"loadend",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),"abort"===a&&c.__listeners.abort&&c.__listeners.abort({type:"abort",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),void 0!==b.status&&Object.defineProperty(c,"status",{get:function(){return b.status}}),void 0!==b.statusText&&Object.defineProperty(c,"statusText",{get:function(){return b.statusText}}),Object.defineProperty(c,"readyState",{get:function(){return 4}}),void 0!==b.response&&Object.defineProperty(c,"response",{get:function(){return b.response}}),Object.defineProperty(c,"responseText",{get:function(){return b.responseText}}),Object.defineProperty(c,"response",{get:function(){return b.responseText}}),c.__fileApiXHR=b,c.onreadystatechange()},fileprogress:function(a){a.target=c,c.__listeners.progress&&c.__listeners.progress(a),c.__total=a.total,c.__loaded=a.loaded},headers:c.__requestHeaders};e.data={},e.files={};for(var f=0;f-1){c=f.substring(0,e);break}null==FileAPI.staticPath&&(FileAPI.staticPath=c),g.setAttribute("src",a||c+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(g),FileAPI.hasFlash=b()}}()}window.FileReader||(window.FileReader=function(){function a(a,c){var d={type:a,target:b,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d}var b=this,c=!1;this.listeners={},this.addEventListener=function(a,c){b.listeners[a]=b.listeners[a]||[],b.listeners[a].push(c)},this.removeEventListener=function(a,c){b.listeners[a]&&b.listeners[a].splice(b.listeners[a].indexOf(c),1)},this.dispatchEvent=function(a){var c=b.listeners[a.type];if(c)for(var d=0;d-1&&b.apply(this,[c,"_fix_for_ie_crossdomain__",e])}}}),c("getResponseHeader",function(a){return function(b){return this.__fileApiXHR?this.__fileApiXHR.getResponseHeader(b):a.apply(this,[b])}}),c("getAllResponseHeaders",function(a){return function(){return this.__fileApiXHR?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),c("abort",function(a){return function(){return this.__fileApiXHR?this.__fileApiXHR.abort():null==a?null:a.apply(this)}}),c("setRequestHeader",function(b){return function(c,d){if("__setXHR_"===c){a(this);var e=d(this);e instanceof Function&&e(this)}else this.__requestHeaders=this.__requestHeaders||{},this.__requestHeaders[c]=d,b.apply(this,arguments)}}),c("send",function(a){return function(){var c=this;if(arguments[0]&&arguments[0].__isShim){var d=arguments[0],e={url:c.__url,complete:function(a,b){!a&&c.__listeners.load&&c.__listeners.load({type:"load",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),!a&&c.__listeners.loadend&&c.__listeners.loadend({type:"loadend",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),"abort"===a&&c.__listeners.abort&&c.__listeners.abort({type:"abort",loaded:c.__loaded,total:c.__total,target:c,lengthComputable:!0}),void 0!==b.status&&Object.defineProperty(c,"status",{get:function(){return b.status}}),void 0!==b.statusText&&Object.defineProperty(c,"statusText",{get:function(){return b.statusText}}),Object.defineProperty(c,"readyState",{get:function(){return 4}}),void 0!==b.response&&Object.defineProperty(c,"response",{get:function(){return b.response}}),Object.defineProperty(c,"responseText",{get:function(){return b.responseText}}),Object.defineProperty(c,"response",{get:function(){return b.responseText}}),c.__fileApiXHR=b,c.onreadystatechange()},fileprogress:function(a){a.target=c,c.__listeners.progress&&c.__listeners.progress(a),c.__total=a.total,c.__loaded=a.loaded},headers:c.__requestHeaders};e.data={},e.files={};for(var f=0;f',d=d.firstChild;var e=a.parentNode;e.insertBefore(d,a),e.removeChild(a),d.appendChild(a)}else c.addClass("js-fileapi-wrapper")},e=function(a){return function(b){for(var c=FileAPI.getFiles(b),d=0;d-1){c=f.substring(0,e);break}null==FileAPI.staticPath&&(FileAPI.staticPath=c),g.setAttribute("src",a||c+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(g),FileAPI.hasFlash=b()}}()}window.FileReader||(window.FileReader=function(){function a(a,c){var d={type:a,target:b,loaded:c.loaded,total:c.total,error:c.error};return null!=c.result&&(d.target.result=c.result),d}var b=this,c=!1;this.listeners={},this.addEventListener=function(a,c){b.listeners[a]=b.listeners[a]||[],b.listeners[a].push(c)},this.removeEventListener=function(a,c){b.listeners[a]&&b.listeners[a].splice(b.listeners[a].indexOf(c),1)},this.dispatchEvent=function(a){var c=b.listeners[a.type];if(c)for(var d=0;d - * @version 1.6.1 + * @version 1.6.2 */ (function() { @@ -209,8 +209,8 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f evt.preventDefault(); $timeout.cancel(leaveTimeout); if (!elem[0].__drag_over_class_) { - var dragOverClassFn = $parse(attr['ngFileDragOverClass']); - if (dragOverClassFn instanceof Function) { + if (attr['ngFileDragOverClass'].search(/\) *$/) > -1) { + dragOverClassFn = $parse(attr['ngFileDragOverClass']); var dragOverClass = dragOverClassFn(scope, { $event : evt }); @@ -229,7 +229,7 @@ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', f leaveTimeout = $timeout(function() { elem.removeClass(elem[0].__drag_over_class_); elem[0].__drag_over_class_ = null; - }); + }, attr['ngFileDragOverDelay'] || 1); }, false); var fn = $parse(attr['ngFileDrop']); elem[0].addEventListener("drop", function(evt) { diff --git a/dist/angular-file-upload.min.js b/dist/angular-file-upload.min.js index 2b636a69..a7394dd4 100644 --- a/dist/angular-file-upload.min.js +++ b/dist/angular-file-upload.min.js @@ -1,2 +1,2 @@ -/*! 1.6.1 */ -!function(){var a=angular.module("angularFileUpload",[]);a.service("$upload",["$http","$q","$timeout",function(a,b,c){function d(d){d.method=d.method||"POST",d.headers=d.headers||{},d.transformRequest=d.transformRequest||function(b,c){return window.ArrayBuffer&&b instanceof window.ArrayBuffer?b:a.defaults.transformRequest[0](b,c)};var e=b.defer();window.XMLHttpRequest.__isShim&&(d.headers.__setXHR_=function(){return function(a){a&&(d.__XHR=a,d.xhrFn&&d.xhrFn(a),a.upload.addEventListener("progress",function(a){e.notify(a)},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&e.notify(a)},!1))}}),a(d).then(function(a){e.resolve(a)},function(a){e.reject(a)},function(a){e.notify(a)});var f=e.promise;return f.success=function(a){return f.then(function(b){a(b.data,b.status,b.headers,d)}),f},f.error=function(a){return f.then(null,function(b){a(b.data,b.status,b.headers,d)}),f},f.progress=function(a){return f.then(null,null,function(b){a(b)}),f},f.abort=function(){return d.__XHR&&c(function(){d.__XHR.abort()}),f},f.xhr=function(a){return d.xhrFn=function(b){return function(){b&&b.apply(f,arguments),a.apply(f,arguments)}}(d.xhrFn),f},f}this.upload=function(b){b.headers=b.headers||{},b.headers["Content-Type"]=void 0,b.transformRequest=b.transformRequest||a.defaults.transformRequest;var c=new FormData,e=b.transformRequest,f=b.data;return b.transformRequest=function(a,c){if(f)if(b.formDataAppender)for(var d in f){var g=f[d];b.formDataAppender(a,d,g)}else for(var d in f){var g=f[d];if("function"==typeof e)g=e(g,c);else for(var h=0;h'),h=0;h0&&f[0].webkitGetAsEntry&&"file"!=c.protocol()&&f[0].webkitGetAsEntry().isDirectory)for(var h=0;h'),h=0;h0&&f[0].webkitGetAsEntry&&"file"!=c.protocol()&&f[0].webkitGetAsEntry().isDirectory)for(var h=0;h-1){dragOverClassFn=a(f.ngFileDragOverClass);var g=dragOverClassFn(d,{$event:c});e[0].__drag_over_class_=g}else e[0].__drag_over_class_=f.ngFileDragOverClass||"dragover";e.addClass(e[0].__drag_over_class_)},!1),e[0].addEventListener("dragenter",function(a){a.stopPropagation(),a.preventDefault()},!1),e[0].addEventListener("dragleave",function(){j=b(function(){e.removeClass(e[0].__drag_over_class_),e[0].__drag_over_class_=null},f.ngFileDragOverDelay||1)},!1);var k=a(f.ngFileDrop);e[0].addEventListener("drop",function(a){a.stopPropagation(),a.preventDefault(),e.removeClass(e[0].__drag_over_class_),e[0].__drag_over_class_=null,h(a,function(b){k(d,{$files:b,$event:a})})},!1);var l=0}}}])}(); \ No newline at end of file diff --git a/nuget/Package.nuspec b/nuget/Package.nuspec index e406d2d0..801a2ed0 100644 --- a/nuget/Package.nuspec +++ b/nuget/Package.nuspec @@ -3,7 +3,7 @@ angular-file-upload Angular file upload - 1.6.1 + 1.6.2 Danial Farid, Georgios Diamantopoulos (nuget package) Danial Farid https://github.com/danialfarid/angular-file-upload/blob/master/LICENSE diff --git a/package.json b/package.json index 343f796d..23e36b16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-file-upload", - "version": "1.6.1", + "version": "1.6.2", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-uglify": "~0.2.7",