diff --git a/Gruntfile.js b/Gruntfile.js index 0cc9162e..f486da65 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,53 +1,57 @@ module.exports = function(grunt) { + grunt.initConfig({ + pkg : grunt.file.readJSON('package.json'), - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), + copy : { + build : { + options : { + processContent : function(content, srcpath) { + return grunt.template.process(content); + } + }, + files : [ { + expand : true, + cwd : 'demo/war/js/', + src : '<%= pkg.name %>*.js', + dest : 'dist/', + flatten : true, + filter : 'isFile' + }, { + expand : true, + cwd : 'demo/war/js/', + src : 'FileAPI.flash.swf', + dest : 'dist/', + flatten : true, + filter : 'isFile' + }, { + expand : true, + cwd : 'demo/war/js/', + src : 'FileAPI.min.js', + dest : 'dist/', + flatten : true, + filter : 'isFile' + } ] + } + }, + uglify : { + options : { + banner : '/*! <%= pkg.version %> */\n' + }, + build : { + files : [ { + 'dist/<%= pkg.name %>.min.js' : 'dist/<%= pkg.name %>.js', + 'dist/<%= pkg.name %>-shim.min.js' : 'dist/<%= pkg.name %>-shim.js', + 'dist/<%= pkg.name %>-html5-shim.min.js' : 'dist/<%= pkg.name %>-html5-shim.js' + } ] + } + } + }); - copy: { - build: { - files: [{ - expand: true, - cwd: 'demo/war/js/', - src: '<%= pkg.name %>*.js', - dest: 'dist/', - flatten: true, - filter: 'isFile' - }, { - expand: true, - cwd: 'demo/war/js/', - src: 'FileAPI.flash.swf', - dest: 'dist/', - flatten: true, - filter: 'isFile' - }, { - expand: true, - cwd: 'demo/war/js/', - src: 'FileAPI.min.js', - dest: 'dist/', - flatten: true, - filter: 'isFile' - }] - } - }, - uglify: { - options: { - banner: '/*! <%= pkg.version %> */\n' - }, - build: { - files: [{ - 'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js', - 'dist/<%= pkg.name %>-shim.min.js': 'dist/<%= pkg.name %>-shim.js', - 'dist/<%= pkg.name %>-html5-shim.min.js': 'dist/<%= pkg.name %>-html5-shim.js' - }] - } - } - }); + // Load the plugin that provides the "uglify" task. + grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-contrib-uglify'); - // Load the plugin that provides the "uglify" task. - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - - // Default task(s). - grunt.registerTask('default', ['copy', 'uglify']); + // Default task(s). + grunt.registerTask('default', [ 'copy', 'uglify' ]); }; \ No newline at end of file diff --git a/bower.json b/bower.json deleted file mode 100644 index 3b50e862..00000000 --- a/bower.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "angularjs-file-upload", - "main": "angular-file-upload.min.js", - "version": "1.2.1", - "homepage": "https://github.com/danialfarid/angular-file-upload", - "authors": [ - "Danial Farid " - ], - "description": "Light-weight HTML5 and cross-browser AngularJS directives for file upload, progress, abort and drag&drop", - "keywords": [ - "AngularJS.", - "angular", - "angular-js", - "file-upload", - "upload", - "FileAPI", - "ajax-file-upload", - "upload-progress", - "upload-abort", - "file-drag&drop", - "upload-preview" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "demo"], - "dependencies": { - "angular": "~1.0.7" - } -} diff --git a/demo/war/js/angular-file-upload-html5-shim.js b/demo/war/js/angular-file-upload-html5-shim.js index 1a656313..69310aa3 100644 --- a/demo/war/js/angular-file-upload-html5-shim.js +++ b/demo/war/js/angular-file-upload-html5-shim.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload shim for angular XHR HTML5 browsers * @author Danial - * @version 1.2.1 + * @version <%= pkg.version %> */ if (window.XMLHttpRequest) { if (window.FormData) { @@ -25,5 +25,6 @@ if (window.XMLHttpRequest) { return xhr; } })(XMLHttpRequest); + window.XMLHttpRequest.__isShim = true; } } diff --git a/demo/war/js/angular-file-upload-shim.js b/demo/war/js/angular-file-upload-shim.js index b0825143..295d24d5 100644 --- a/demo/war/js/angular-file-upload-shim.js +++ b/demo/war/js/angular-file-upload-shim.js @@ -1,14 +1,14 @@ /**! * AngularJS file upload shim for HTML5 FormData * @author Danial - * @version 1.2.1 + * @version <%= pkg.version %> */ (function() { if (window.XMLHttpRequest) { if (window.FormData) { // allow access to Angular XHR private field: https://github.com/angular/angular.js/issues/1934 - XMLHttpRequest = (function(origXHR) { + window.XMLHttpRequest = (function(origXHR) { return function() { var xhr = new origXHR(); xhr.setRequestHeader = (function(orig) { @@ -26,9 +26,9 @@ if (window.XMLHttpRequest) { })(xhr.setRequestHeader); return xhr; } - })(XMLHttpRequest); + })(window.XMLHttpRequest); } else { - XMLHttpRequest = (function(origXHR) { + window.XMLHttpRequest = (function(origXHR) { return function() { var xhr = new origXHR(); var origSend = xhr.send; @@ -120,8 +120,9 @@ if (window.XMLHttpRequest) { } return xhr; } - })(XMLHttpRequest); + })(window.XMLHttpRequest); } + window.XMLHttpRequest.__isShim = true; } if (!window.FormData) { @@ -234,6 +235,7 @@ if (!window.FormData) { })(); } +/* if (!window.FileReader) { window.FileReader = function() { var _this = this, loadStarted = false; @@ -294,5 +296,5 @@ if (!window.FileReader) { } } } - +*/ })(); \ No newline at end of file diff --git a/demo/war/js/angular-file-upload.js b/demo/war/js/angular-file-upload.js index 72d70d3e..63f7eacb 100644 --- a/demo/war/js/angular-file-upload.js +++ b/demo/war/js/angular-file-upload.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload/drop directive with http post and progress * @author Danial - * @version 1.2.1 + * @version <%= pkg.version %> */ (function() { @@ -18,27 +18,29 @@ angularFileUpload.service('$upload', ['$http', '$rootScope', '$timeout', functio return $http.defaults.transformRequest[0](data); }; - config.headers['__setXHR_'] = function() { - return function(xhr) { - config.__XHR = xhr; - xhr.upload.addEventListener('progress', function(e) { - if (config.progress) { - $timeout(function() { - config.progress(e); - }); - } - }, false); - //fix for firefox not firing upload progress end, also IE8-9 - xhr.upload.addEventListener('load', function(e) { - if (e.lengthComputable) { - $timeout(function() { - config.progress(e); - }); - } - }, false); - } - }; - + if (window.XMLHttpRequest.__isShim) { + config.headers['__setXHR_'] = function() { + return function(xhr) { + config.__XHR = xhr; + xhr.upload.addEventListener('progress', function(e) { + if (config.progress) { + $timeout(function() { + config.progress(e); + }); + } + }, false); + //fix for firefox not firing upload progress end, also IE8-9 + xhr.upload.addEventListener('load', function(e) { + if (e.lengthComputable) { + $timeout(function() { + config.progress(e); + }); + } + }, false); + } + }; + } + var promise = $http(config); promise.progress = function(fn) { diff --git a/dist/FileAPI.flash.swf b/dist/FileAPI.flash.swf index f0e53802..e142b388 100644 Binary files a/dist/FileAPI.flash.swf and b/dist/FileAPI.flash.swf differ diff --git a/dist/FileAPI.min.js b/dist/FileAPI.min.js index 7cc0ff4c..19e43025 100644 --- a/dist/FileAPI.min.js +++ b/dist/FileAPI.min.js @@ -1,5 +1,5 @@ /**! - * FileAPI — a set of tools for working with files + * FileAPI � a set of tools for working with files * * @author RubaXa * @build lib/canvas-to-blob lib/FileAPI.core lib/FileAPI.Image lib/FileAPI.Form lib/FileAPI.XHR lib/FileAPI.Flash diff --git a/dist/angular-file-upload-html5-shim.js b/dist/angular-file-upload-html5-shim.js index 1a656313..12382eda 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.2.1 + * @version 1.2.2 */ if (window.XMLHttpRequest) { if (window.FormData) { @@ -25,5 +25,6 @@ if (window.XMLHttpRequest) { return xhr; } })(XMLHttpRequest); + window.XMLHttpRequest.__isShim = true; } } diff --git a/dist/angular-file-upload-html5-shim.min.js b/dist/angular-file-upload-html5-shim.min.js index 1c70bffb..5ecb39e7 100644 --- a/dist/angular-file-upload-html5-shim.min.js +++ b/dist/angular-file-upload-html5-shim.min.js @@ -1,2 +1,2 @@ -/*! 1.2.1 */ -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)); \ No newline at end of file +/*! 1.2.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 b0825143..83b600b2 100644 --- a/dist/angular-file-upload-shim.js +++ b/dist/angular-file-upload-shim.js @@ -1,14 +1,14 @@ /**! * AngularJS file upload shim for HTML5 FormData * @author Danial - * @version 1.2.1 + * @version 1.2.2 */ (function() { if (window.XMLHttpRequest) { if (window.FormData) { // allow access to Angular XHR private field: https://github.com/angular/angular.js/issues/1934 - XMLHttpRequest = (function(origXHR) { + window.XMLHttpRequest = (function(origXHR) { return function() { var xhr = new origXHR(); xhr.setRequestHeader = (function(orig) { @@ -26,9 +26,9 @@ if (window.XMLHttpRequest) { })(xhr.setRequestHeader); return xhr; } - })(XMLHttpRequest); + })(window.XMLHttpRequest); } else { - XMLHttpRequest = (function(origXHR) { + window.XMLHttpRequest = (function(origXHR) { return function() { var xhr = new origXHR(); var origSend = xhr.send; @@ -120,8 +120,9 @@ if (window.XMLHttpRequest) { } return xhr; } - })(XMLHttpRequest); + })(window.XMLHttpRequest); } + window.XMLHttpRequest.__isShim = true; } if (!window.FormData) { @@ -234,6 +235,7 @@ if (!window.FormData) { })(); } +/* if (!window.FileReader) { window.FileReader = function() { var _this = this, loadStarted = false; @@ -294,5 +296,5 @@ if (!window.FileReader) { } } } - +*/ })(); \ No newline at end of file diff --git a/dist/angular-file-upload-shim.min.js b/dist/angular-file-upload-shim.min.js index 7768cea8..7293a9e3 100644 --- a/dist/angular-file-upload-shim.min.js +++ b/dist/angular-file-upload-shim.min.js @@ -1,2 +1,2 @@ -/*! 1.2.1 */ -!function(){if(window.XMLHttpRequest&&(XMLHttpRequest=window.FormData?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):function(a){return function(){var b=new a,c=b.send;return b.__requestHeaders=[],b.open=function(a){return b.upload={addEventListener:function(a,c){"progress"===a&&(b.__progress=c),"load"===a&&(b.__load=c)}},function(c,d,e){a.apply(b,[c,d,e]),b.__url=d}}(b.open),b.getResponseHeader=function(a){return function(c){return b.__fileApiXHR?b.__fileApiXHR.getResponseHeader(c):a.apply(b,[c])}}(b.getResponseHeader),b.getAllResponseHeaders=function(a){return function(){return b.__fileApiXHR?b.__fileApiXHR.getAllResponseHeaders():a.apply(b)}}(b.getAllResponseHeaders),b.abort=function(a){return function(){return b.__fileApiXHR?b.__fileApiXHR.abort():null==a?null:a.apply(b)}}(b.abort),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.send=function(){if(arguments[0]&&arguments[0].__isShim){var a=arguments[0],d={url:b.__url,complete:function(a,c){b.__load({type:"load",loaded:b.__total,total:b.__total,target:b,lengthComputable:!0}),Object.defineProperty(b,"status",{get:function(){return c.status}}),Object.defineProperty(b,"statusText",{get:function(){return c.statusText}}),Object.defineProperty(b,"readyState",{get:function(){return 4}}),Object.defineProperty(b,"response",{get:function(){return c.response}}),Object.defineProperty(b,"responseText",{get:function(){return c.responseText}}),b.__fileApiXHR=c,b.onreadystatechange()},progress:function(a){a.target=b,b.__progress(a),b.__total=a.total},headers:b.__requestHeaders};d.data={},d.files={};for(var e=0;e',c=c.firstChild;var d=b.parentNode;d.insertBefore(c,b),d.removeChild(b),c.appendChild(b),a||c.appendChild(document.createTextNode("Flash is required")),b.__isWrapped=!0}},e=function(a){return function(b){var c=FileAPI.getFiles(b);b.target||(b.target={}),b.target.files=c,b.target.files.item=function(a){return b.target.files[a]||null},a(b)}},f=function(a,b){return("change"===b.toLowerCase()||"onchange"===b.toLowerCase())&&"file"==a.getAttribute("type")};HTMLInputElement.prototype.addEventListener&&(HTMLInputElement.prototype.addEventListener=function(a){return function(b,c,g,h){f(this,b)?(d(this),a.apply(this,[b,e(c),g,h])):a.apply(this,[b,c,g,h])}}(HTMLInputElement.prototype.addEventListener)),HTMLInputElement.prototype.attachEvent&&(HTMLInputElement.prototype.attachEvent=function(a){return function(b,c){f(this,b)?(d(this),a.apply(this,[b,e(c)])):a.apply(this,[b,c])}}(HTMLInputElement.prototype.attachEvent)),window.FormData=FormData=function(){return{append:function(a,b,c){this.data.push({key:a,val:b,name:c})},data:[],__isShim:!0}},function(){if(!window.FileAPI||!FileAPI.upload){var a,b,c,d="",e=document.createElement("script"),f=document.getElementsByTagName("script");if(window.FileAPI&&window.FileAPI.jsPath)d=window.FileAPI.jsPath;else for(a=0;a-1){d=c.substring(0,b);break}window.FileAPI&&null!=FileAPI.staticPath||(FileAPI={staticPath:d}),e.setAttribute("src",d+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(e)}}()}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',c=c.firstChild;var d=b.parentNode;d.insertBefore(c,b),d.removeChild(b),c.appendChild(b),a||c.appendChild(document.createTextNode("Flash is required")),b.__isWrapped=!0}},e=function(a){return function(b){var c=FileAPI.getFiles(b);b.target||(b.target={}),b.target.files=c,b.target.files.item=function(a){return b.target.files[a]||null},a(b)}},f=function(a,b){return("change"===b.toLowerCase()||"onchange"===b.toLowerCase())&&"file"==a.getAttribute("type")};HTMLInputElement.prototype.addEventListener&&(HTMLInputElement.prototype.addEventListener=function(a){return function(b,c,g,h){f(this,b)?(d(this),a.apply(this,[b,e(c),g,h])):a.apply(this,[b,c,g,h])}}(HTMLInputElement.prototype.addEventListener)),HTMLInputElement.prototype.attachEvent&&(HTMLInputElement.prototype.attachEvent=function(a){return function(b,c){f(this,b)?(d(this),a.apply(this,[b,e(c)])):a.apply(this,[b,c])}}(HTMLInputElement.prototype.attachEvent)),window.FormData=FormData=function(){return{append:function(a,b,c){this.data.push({key:a,val:b,name:c})},data:[],__isShim:!0}},function(){if(!window.FileAPI||!FileAPI.upload){var a,b,c,d="",e=document.createElement("script"),f=document.getElementsByTagName("script");if(window.FileAPI&&window.FileAPI.jsPath)d=window.FileAPI.jsPath;else for(a=0;a-1){d=c.substring(0,b);break}window.FileAPI&&null!=FileAPI.staticPath||(FileAPI={staticPath:d}),e.setAttribute("src",d+"FileAPI.min.js"),document.getElementsByTagName("head")[0].appendChild(e)}}()}}(); \ No newline at end of file diff --git a/dist/angular-file-upload.js b/dist/angular-file-upload.js index 72d70d3e..097c9cdf 100644 --- a/dist/angular-file-upload.js +++ b/dist/angular-file-upload.js @@ -1,7 +1,7 @@ /**! * AngularJS file upload/drop directive with http post and progress * @author Danial - * @version 1.2.1 + * @version 1.2.2 */ (function() { @@ -18,27 +18,29 @@ angularFileUpload.service('$upload', ['$http', '$rootScope', '$timeout', functio return $http.defaults.transformRequest[0](data); }; - config.headers['__setXHR_'] = function() { - return function(xhr) { - config.__XHR = xhr; - xhr.upload.addEventListener('progress', function(e) { - if (config.progress) { - $timeout(function() { - config.progress(e); - }); - } - }, false); - //fix for firefox not firing upload progress end, also IE8-9 - xhr.upload.addEventListener('load', function(e) { - if (e.lengthComputable) { - $timeout(function() { - config.progress(e); - }); - } - }, false); - } - }; - + if (window.XMLHttpRequest.__isShim) { + config.headers['__setXHR_'] = function() { + return function(xhr) { + config.__XHR = xhr; + xhr.upload.addEventListener('progress', function(e) { + if (config.progress) { + $timeout(function() { + config.progress(e); + }); + } + }, false); + //fix for firefox not firing upload progress end, also IE8-9 + xhr.upload.addEventListener('load', function(e) { + if (e.lengthComputable) { + $timeout(function() { + config.progress(e); + }); + } + }, false); + } + }; + } + var promise = $http(config); promise.progress = function(fn) { diff --git a/dist/angular-file-upload.min.js b/dist/angular-file-upload.min.js index a9bfbefb..819f4cab 100644 --- a/dist/angular-file-upload.min.js +++ b/dist/angular-file-upload.min.js @@ -1,2 +1,2 @@ -/*! 1.2.1 */ -!function(){var a=angular.module("angularFileUpload",[]);a.service("$upload",["$http","$rootScope","$timeout",function(a,b,c){function d(b){b.method=b.method||"POST",b.headers=b.headers||{},b.transformRequest=b.transformRequest||function(b){return b instanceof ArrayBuffer?b:a.defaults.transformRequest[0](b)},b.headers.__setXHR_=function(){return function(a){b.__XHR=a,a.upload.addEventListener("progress",function(a){b.progress&&c(function(){b.progress(a)})},!1),a.upload.addEventListener("load",function(a){a.lengthComputable&&c(function(){b.progress(a)})},!1)}};var d=a(b);return d.progress=function(a){return b.progress=a,d},d.abort=function(){return b.__XHR&&c(function(){b.__XHR.abort()}),d},d.then=function(a,c){return function(d,e,f){return b.progress=f||b.progress,c.apply(a,[d,e,f]),a}}(d,d.then),d}this.upload=function(b){b.headers["Content-Type"]=void 0,b.transformRequest=b.transformRequest||a.defaults.transformRequest;var c=new FormData;if(b.data)for(var e in b.data){var f=b.data[e];if(b.formDataAppender)b.formDataAppender(c,e,f);else{if("function"==typeof b.transformRequest)f=b.transformRequest(f);else for(var g=0;g angular-file-upload Angular file upload - 1.2.1 + 1.2.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 e143fca6..7352f0dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-file-upload", - "version": "1.2.1", + "version": "1.2.2", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-uglify": "~0.2.7",