diff --git a/Gruntfile.js b/Gruntfile.js
index 47b2b37..e4cb1b2 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -19,16 +19,10 @@ module.exports = function(grunt) {
flow: {
files: {
'dist/ng-flow.js': [
- 'src/provider.js',
- 'src/directives/init.js',
- 'src/directives/*.js',
'src/*.js'
],
'dist/ng-flow-standalone.js': [
'bower_components/flow.js/dist/flow.js',
- 'src/provider.js',
- 'src/directives/init.js',
- 'src/directives/*.js',
'src/*.js'
]
}
diff --git a/README.md b/README.md
index 10853ea..5444a69 100644
--- a/README.md
+++ b/README.md
@@ -10,15 +10,15 @@ How can I install it?
============
1) Get the library:
+**npm**
+
+ npm install angular @flowjs/ng-flow
+
**Direct Download**
Download a latest build from https://github.com/flowjs/ng-flow/releases
it contains development and minified production files in `dist/` directory,
they are also concatenated with core flow.js library.
-**Using Bower**
-
- bower install ng-flow#~2
-
**Git Clone**
git clone https://github.com/flowjs/ng-flow
@@ -28,11 +28,20 @@ they are also concatenated with core flow.js library.
bower install "ng-flow#~2" --save
grunt bower-install
-2) Add the module to your app as a dependency:
+2) Add the module to a module in your app as a dependency:
+
+ import angular from 'angular';
+ import ngFlow from '@flowjs/ng-flow';
+
+ const MODULE_NAME = 'appName.moduleName';
+ angular.module(MODULE_NAME, [ngFlow]);
- angular.module('app', ['flow'])
+ export default MODULE_NAME;
3) Include the files in your project
+See https://www.npmjs.com/package/webpack or https://www.npmjs.com/package/browserify
+
+or for legacy applications:
```html
@@ -253,6 +262,17 @@ var app = angular.module('app', ['flow'])
}]);
````
+Bower
+=====
+
+Bower has been deprecated in favour of yarn/webpack, however it is still
+supported by ng-flow for legacy applications.
+
+**Using Bower**
+
+ bower install ng-flow#~2
+
+
Contribution
============
To ensure consistency throughout the source code, keep these rules in mind as you are working:
diff --git a/dist/ng-flow-standalone.js b/dist/ng-flow-standalone.js
index c80610c..c9247c9 100644
--- a/dist/ng-flow-standalone.js
+++ b/dist/ng-flow-standalone.js
@@ -1634,6 +1634,17 @@
}
})(window, document);
+(function (root, factory) {
+ if (typeof define === 'function' && define.amd) {
+ define(['angular', '@flowjs/flow.js'], factory);
+ } else if (typeof exports === 'object') {
+ // Node, CommonJS-like
+ module.exports = factory(require('angular'), require('@flowjs/flow.js'));
+ } else {
+ // Browser globals (root is window)
+ root.ngFlow = factory(root.angular, root.Flow);
+ }
+}(this, function (angular, Flow) {
/**
* @description
* var app = angular.module('App', ['flow.provider'], function(flowFactoryProvider){
@@ -1922,4 +1933,7 @@ angular.module('flow.transfers', ['flow.init'])
};
}]);
angular.module('flow', ['flow.provider', 'flow.init', 'flow.events', 'flow.btn',
- 'flow.drop', 'flow.transfers', 'flow.img', 'flow.dragEvents']);
\ No newline at end of file
+ 'flow.drop', 'flow.transfers', 'flow.img', 'flow.dragEvents']);
+
+return 'flow';
+}));
diff --git a/dist/ng-flow-standalone.min.js b/dist/ng-flow-standalone.min.js
index 8c09055..6c7507d 100644
--- a/dist/ng-flow-standalone.min.js
+++ b/dist/ng-flow-standalone.min.js
@@ -1,2 +1,2 @@
/*! @flowjs/ng-flow 2.7.7 */
-!function(a,b,c){"use strict";function d(b){if(this.support=!("undefined"==typeof File||"undefined"==typeof Blob||"undefined"==typeof FileList||!Blob.prototype.slice&&!Blob.prototype.webkitSlice&&!Blob.prototype.mozSlice),this.support){this.supportDirectory=/Chrome/.test(a.navigator.userAgent)||/Firefox/.test(a.navigator.userAgent)||/Edge/.test(a.navigator.userAgent),this.files=[],this.defaults={chunkSize:1048576,forceChunkSize:!1,simultaneousUploads:3,singleFile:!1,fileParameterName:"file",progressCallbacksInterval:500,speedSmoothingFactor:.1,query:{},headers:{},withCredentials:!1,preprocess:null,method:"multipart",testMethod:"GET",uploadMethod:"POST",prioritizeFirstAndLastChunk:!1,allowDuplicateUploads:!1,target:"/",testChunks:!0,generateUniqueIdentifier:null,maxChunkRetries:0,chunkRetryInterval:null,permanentErrors:[404,413,415,500,501],successStatuses:[200,201,202],onDropStopPropagation:!1,initFileFn:null,readFileFn:f},this.opts={},this.events={};var c=this;this.onDrop=function(a){c.opts.onDropStopPropagation&&a.stopPropagation(),a.preventDefault();var b=a.dataTransfer;b.items&&b.items[0]&&b.items[0].webkitGetAsEntry?c.webkitReadDataTransfer(a):c.addFiles(b.files,a)},this.preventEvent=function(a){a.preventDefault()},this.opts=d.extend({},this.defaults,b||{})}}function e(a,b,d){this.flowObj=a,this.bytes=null,this.file=b,this.name=b.fileName||b.name,this.size=b.size,this.relativePath=b.relativePath||b.webkitRelativePath||this.name,this.uniqueIdentifier=d===c?a.generateUniqueIdentifier(b):d,this.chunks=[],this.paused=!1,this.error=!1,this.averageSpeed=0,this.currentSpeed=0,this._lastProgressCallback=Date.now(),this._prevUploadedSize=0,this._prevProgress=0,this.bootstrap()}function f(a,b,c,d,e){var f="slice";a.file.slice?f="slice":a.file.mozSlice?f="mozSlice":a.file.webkitSlice&&(f="webkitSlice"),e.readFinished(a.file[f](b,c,d))}function g(a,b,c){this.flowObj=a,this.fileObj=b,this.offset=c,this.tested=!1,this.retries=0,this.pendingRetry=!1,this.preprocessState=0,this.readState=0,this.loaded=0,this.total=0,this.chunkSize=this.flowObj.opts.chunkSize,this.startByte=this.offset*this.chunkSize,this.computeEndByte=function(){var a=Math.min(this.fileObj.size,(this.offset+1)*this.chunkSize);return this.fileObj.size-a-1&&a.splice(c,1)}function i(a,b){return"function"==typeof a&&(b=Array.prototype.slice.call(arguments),a=a.apply(null,b.slice(1))),a}function j(a,b){setTimeout(a.bind(b),0)}function k(a,b){return l(arguments,function(b){b!==a&&l(b,function(b,c){a[c]=b})}),a}function l(a,b,c){if(a){var d;if("undefined"!=typeof a.length){for(d=0;d1&&"pending"===a.chunks[a.chunks.length-1].status()?(a.chunks[a.chunks.length-1].send(),b=!0,!1):void 0}),b))return b;if(l(this.files,function(a){return a.paused||l(a.chunks,function(a){return"pending"===a.status()?(a.send(),b=!0,!1):void 0}),b?!1:void 0}),b)return!0;var c=!1;return l(this.files,function(a){return a.isComplete()?void 0:(c=!0,!1)}),c||a||j(function(){this.fire("complete")},this),!1},assignBrowse:function(a,c,d,e){a instanceof Element&&(a=[a]),l(a,function(a){var f;"INPUT"===a.tagName&&"file"===a.type?f=a:(f=b.createElement("input"),f.setAttribute("type","file"),k(f.style,{visibility:"hidden",position:"absolute",width:"1px",height:"1px"}),a.appendChild(f),a.addEventListener("click",function(){f.click()},!1)),this.opts.singleFile||d||f.setAttribute("multiple","multiple"),c&&f.setAttribute("webkitdirectory","webkitdirectory"),l(e,function(a,b){f.setAttribute(b,a)});var g=this;f.addEventListener("change",function(a){a.target.value&&(g.addFiles(a.target.files,a),a.target.value="")},!1)},this)},assignDrop:function(a){"undefined"==typeof a.length&&(a=[a]),l(a,function(a){a.addEventListener("dragover",this.preventEvent,!1),a.addEventListener("dragenter",this.preventEvent,!1),a.addEventListener("drop",this.onDrop,!1)},this)},unAssignDrop:function(a){"undefined"==typeof a.length&&(a=[a]),l(a,function(a){a.removeEventListener("dragover",this.preventEvent),a.removeEventListener("dragenter",this.preventEvent),a.removeEventListener("drop",this.onDrop)},this)},isUploading:function(){var a=!1;return l(this.files,function(b){return b.isUploading()?(a=!0,!1):void 0}),a},_shouldUploadNext:function(){var a=0,b=!0,c=this.opts.simultaneousUploads;return l(this.files,function(d){l(d.chunks,function(d){return"uploading"===d.status()&&(a++,a>=c)?(b=!1,!1):void 0})}),b&&a},upload:function(){var a=this._shouldUploadNext();if(a!==!1){this.fire("uploadStart");for(var b=!1,c=1;c<=this.opts.simultaneousUploads-a;c++)b=this.uploadNextChunk(!0)||b;b||j(function(){this.fire("complete")},this)}},resume:function(){l(this.files,function(a){a.isComplete()||a.resume()})},pause:function(){l(this.files,function(a){a.pause()})},cancel:function(){for(var a=this.files.length-1;a>=0;a--)this.files[a].cancel()},progress:function(){var a=0,b=0;return l(this.files,function(c){a+=c.progress()*c.size,b+=c.size}),b>0?a/b:0},addFile:function(a,b){this.addFiles([a],b)},addFiles:function(a,b){var c=[];l(a,function(a){if((!m||m&&a.size>0)&&(a.size%4096!==0||"."!==a.name&&"."!==a.fileName)){var d=this.generateUniqueIdentifier(a);if(this.opts.allowDuplicateUploads||!this.getFromUniqueIdentifier(d)){var f=new e(this,a,d);this.fire("fileAdded",f,b)&&c.push(f)}}},this),this.fire("filesAdded",c,b)&&(l(c,function(a){this.opts.singleFile&&this.files.length>0&&this.removeFile(this.files[0]),this.files.push(a)},this),this.fire("filesSubmitted",c,b))},removeFile:function(a){for(var b=this.files.length-1;b>=0;b--)this.files[b]===a&&(this.files.splice(b,1),a.abort(),this.fire("fileRemoved",a))},getFromUniqueIdentifier:function(a){var b=!1;return l(this.files,function(c){c.uniqueIdentifier===a&&(b=c)}),b},getSize:function(){var a=0;return l(this.files,function(b){a+=b.size}),a},sizeUploaded:function(){var a=0;return l(this.files,function(b){a+=b.sizeUploaded()}),a},timeRemaining:function(){var a=0,b=0;return l(this.files,function(c){c.paused||c.error||(a+=c.size-c.sizeUploaded(),b+=c.averageSpeed)}),a&&!b?Number.POSITIVE_INFINITY:a||b?Math.floor(a/b):0}},e.prototype={measureSpeed:function(){var a=Date.now()-this._lastProgressCallback;if(a){var b=this.flowObj.opts.speedSmoothingFactor,c=this.sizeUploaded();this.currentSpeed=Math.max((c-this._prevUploadedSize)/a*1e3,0),this.averageSpeed=b*this.currentSpeed+(1-b)*this.averageSpeed,this._prevUploadedSize=c}},chunkEvent:function(a,b,c){switch(b){case"progress":if(Date.now()-this._lastProgressCallbackc;c++)this.chunks.push(new g(this.flowObj,this,c))},progress:function(){if(this.error)return 1;if(1===this.chunks.length)return this._prevProgress=Math.max(this._prevProgress,this.chunks[0].progress()),this._prevProgress;var a=0;l(this.chunks,function(b){a+=b.progress()*(b.endByte-b.startByte)});var b=a/this.size;return this._prevProgress=Math.max(this._prevProgress,b>.9999?1:b),this._prevProgress},isUploading:function(){var a=!1;return l(this.chunks,function(b){return"uploading"===b.status()?(a=!0,!1):void 0}),a},isComplete:function(){var a=!1;return l(this.chunks,function(b){var c=b.status();return"pending"===c||"uploading"===c||"reading"===c||1===b.preprocessState||1===b.readState?(a=!0,!1):void 0}),!a},sizeUploaded:function(){var a=0;return l(this.chunks,function(b){a+=b.sizeUploaded()}),a},timeRemaining:function(){if(this.paused||this.error)return 0;var a=this.size-this.sizeUploaded();return a&&!this.averageSpeed?Number.POSITIVE_INFINITY:a||this.averageSpeed?Math.floor(a/this.averageSpeed):0},getType:function(){return this.file.type&&this.file.type.split("/")[1]},getExtension:function(){return this.name.substr((~-this.name.lastIndexOf(".")>>>0)+2).toLowerCase()}},g.prototype={getParams:function(){return{flowChunkNumber:this.offset+1,flowChunkSize:this.flowObj.opts.chunkSize,flowCurrentChunkSize:this.endByte-this.startByte,flowTotalSize:this.fileObj.size,flowIdentifier:this.fileObj.uniqueIdentifier,flowFilename:this.fileObj.name,flowRelativePath:this.fileObj.relativePath,flowTotalChunks:this.fileObj.chunks.length}},getTarget:function(a,b){return a+=a.indexOf("?")<0?"?":"&",a+b.join("&")},test:function(){this.xhr=new XMLHttpRequest,this.xhr.addEventListener("load",this.testHandler,!1),this.xhr.addEventListener("error",this.testHandler,!1);var a=i(this.flowObj.opts.testMethod,this.fileObj,this),b=this.prepareXhrRequest(a,!0);this.xhr.send(b)},preprocessFinished:function(){this.endByte=this.computeEndByte(),this.preprocessState=2,this.send()},readFinished:function(a){this.readState=2,this.bytes=a,this.send()},send:function(){var a=this.flowObj.opts.preprocess,b=this.flowObj.opts.readFileFn;if("function"==typeof a)switch(this.preprocessState){case 0:return this.preprocessState=1,void a(this);case 1:return}switch(this.readState){case 0:return this.readState=1,void b(this.fileObj,this.startByte,this.endByte,this.fileObj.file.type,this);case 1:return}if(this.flowObj.opts.testChunks&&!this.tested)return void this.test();this.loaded=0,this.total=0,this.pendingRetry=!1,this.xhr=new XMLHttpRequest,this.xhr.upload.addEventListener("progress",this.progressHandler,!1),this.xhr.addEventListener("load",this.doneHandler,!1),this.xhr.addEventListener("error",this.doneHandler,!1);var c=i(this.flowObj.opts.uploadMethod,this.fileObj,this),d=this.prepareXhrRequest(c,!1,this.flowObj.opts.method,this.bytes);this.xhr.send(d)},abort:function(){var a=this.xhr;this.xhr=null,a&&a.abort()},status:function(a){return 1===this.readState?"reading":this.pendingRetry||1===this.preprocessState?"uploading":this.xhr?this.xhr.readyState<4?"uploading":this.flowObj.opts.successStatuses.indexOf(this.xhr.status)>-1?"success":this.flowObj.opts.permanentErrors.indexOf(this.xhr.status)>-1||!a&&this.retries>=this.flowObj.opts.maxChunkRetries?"error":(this.abort(),"pending"):"pending"},message:function(){return this.xhr?this.xhr.responseText:""},progress:function(){if(this.pendingRetry)return 0;var a=this.status();return"success"===a||"error"===a?1:"pending"===a?0:this.total>0?this.loaded/this.total:0},sizeUploaded:function(){var a=this.endByte-this.startByte;return"success"!==this.status()&&(a=this.progress()*a),a},prepareXhrRequest:function(a,b,c,d){var e=i(this.flowObj.opts.query,this.fileObj,this,b);e=k(e,this.getParams());var f=i(this.flowObj.opts.target,this.fileObj,this,b),g=null;if("GET"===a||"octet"===c){var h=[];l(e,function(a,b){h.push([encodeURIComponent(b),encodeURIComponent(a)].join("="))}),f=this.getTarget(f,h),g=d||null}else g=new FormData,l(e,function(a,b){g.append(b,a)}),"undefined"!=typeof d&&g.append(this.flowObj.opts.fileParameterName,d,this.fileObj.file.name);return this.xhr.open(a,f,!0),this.xhr.withCredentials=this.flowObj.opts.withCredentials,l(i(this.flowObj.opts.headers,this.fileObj,this,b),function(a,b){this.xhr.setRequestHeader(b,a)},this),g}},d.evalOpts=i,d.extend=k,d.each=l,d.FlowFile=e,d.FlowChunk=g,d.version="2.13.0","object"==typeof module&&module&&"object"==typeof module.exports?module.exports=d:(a.Flow=d,"function"==typeof define&&define.amd&&define("flow",[],function(){return d}))}(window,document),angular.module("flow.provider",[]).provider("flowFactory",function(){"use strict";this.defaults={},this.factory=function(a){return new Flow(a)},this.events=[],this.on=function(a,b){this.events.push([a,b])},this.$get=function(){var a=this.factory,b=this.defaults,c=this.events;return{create:function(d){var e=a(angular.extend({},b,d));return angular.forEach(c,function(a){e.on(a[0],a[1])}),e}}}}),angular.module("flow.init",["flow.provider"]).controller("flowCtrl",["$scope","$attrs","$parse","flowFactory",function(a,b,c,d){var e=angular.extend({},a.$eval(b.flowInit)),f=a.$eval(b.flowObject)||d.create(e),g=function(b){var c=Array.prototype.slice.call(arguments);c.shift();var d=a.$broadcast.apply(a,["flow::"+b,f].concat(c));return{progress:1,filesSubmitted:1,fileSuccess:1,fileError:1,complete:1}[b]&&a.$apply(),d.defaultPrevented?!1:void 0};f.on("catchAll",g),a.$on("$destroy",function(){f.off("catchAll",g)}),a.$flow=f,b.hasOwnProperty("flowName")&&(c(b.flowName).assign(a,f),a.$on("$destroy",function(){c(b.flowName).assign(a)}))}]).directive("flowInit",[function(){return{scope:!0,controller:"flowCtrl"}}]),angular.module("flow.btn",["flow.init"]).directive("flowBtn",[function(){return{restrict:"EA",scope:!1,require:"^flowInit",link:function(a,b,c){var d=c.hasOwnProperty("flowDirectory"),e=c.hasOwnProperty("flowSingleFile"),f=c.hasOwnProperty("flowAttrs")&&a.$eval(c.flowAttrs);a.$flow.assignBrowse(b,d,e,f)}}}]),angular.module("flow.dragEvents",["flow.init"]).directive("flowPreventDrop",function(){return{scope:!1,link:function(a,b,c){b.bind("drop dragover",function(a){a.preventDefault()})}}}).directive("flowDragEnter",["$timeout",function(a){return{scope:!1,link:function(b,c,d){function e(a){var b=!1,c=a.dataTransfer||a.originalEvent.dataTransfer;return angular.forEach(c&&c.types,function(a){"Files"===a&&(b=!0)}),b}var f,g=!1;c.bind("dragover",function(c){e(c)&&(g||(b.$apply(d.flowDragEnter),g=!0),a.cancel(f),c.preventDefault())}),c.bind("dragleave drop",function(c){a.cancel(f),f=a(function(){b.$eval(d.flowDragLeave),f=null,g=!1},100)})}}}]),angular.module("flow.drop",["flow.init"]).directive("flowDrop",function(){return{scope:!1,require:"^flowInit",link:function(a,b,c){function d(){a.$flow.assignDrop(b)}function e(){a.$flow.unAssignDrop(b)}c.flowDropEnabled?a.$watch(c.flowDropEnabled,function(a){a?d():e()}):d()}}}),!function(a){"use strict";function b(a){return a.charAt(0).toUpperCase()+a.slice(1)}var c=a.module("flow.events",["flow.init"]),d={fileSuccess:["$file","$message"],fileProgress:["$file"],fileAdded:["$file","$event"],filesAdded:["$files","$event"],filesSubmitted:["$files","$event"],fileRetry:["$file"],fileRemoved:["$file"],fileError:["$file","$message"],uploadStart:[],complete:[],progress:[],error:["$message","$file"]};a.forEach(d,function(d,e){var f="flow"+b(e);"flowUploadStart"==f&&(f="flowUploadStarted"),c.directive(f,[function(){return{require:"^flowInit",controller:["$scope","$attrs",function(b,c){b.$on("flow::"+e,function(){var e=Array.prototype.slice.call(arguments),g=e.shift();if(b.$flow===e.shift()){var h={};a.forEach(d,function(a,b){h[a]=e[b]}),b.$eval(c[f],h)===!1&&g.preventDefault()}})}]}}])})}(angular),angular.module("flow.img",["flow.init"]).directive("flowImg",[function(){return{scope:!1,require:"^flowInit",link:function(a,b,c){var d=c.flowImg;a.$watch(d,function(b){if(b){var d=new FileReader;d.readAsDataURL(b.file),d.onload=function(b){a.$apply(function(){c.$set("src",b.target.result)})}}})}}}]),angular.module("flow.transfers",["flow.init"]).directive("flowTransfers",[function(){return{scope:!0,require:"^flowInit",link:function(a){a.transfers=a.$flow.files}}}]),angular.module("flow",["flow.provider","flow.init","flow.events","flow.btn","flow.drop","flow.transfers","flow.img","flow.dragEvents"]);
\ No newline at end of file
+!function(a,b,c){"use strict";function d(b){if(this.support=!("undefined"==typeof File||"undefined"==typeof Blob||"undefined"==typeof FileList||!Blob.prototype.slice&&!Blob.prototype.webkitSlice&&!Blob.prototype.mozSlice),this.support){this.supportDirectory=/Chrome/.test(a.navigator.userAgent)||/Firefox/.test(a.navigator.userAgent)||/Edge/.test(a.navigator.userAgent),this.files=[],this.defaults={chunkSize:1048576,forceChunkSize:!1,simultaneousUploads:3,singleFile:!1,fileParameterName:"file",progressCallbacksInterval:500,speedSmoothingFactor:.1,query:{},headers:{},withCredentials:!1,preprocess:null,method:"multipart",testMethod:"GET",uploadMethod:"POST",prioritizeFirstAndLastChunk:!1,allowDuplicateUploads:!1,target:"/",testChunks:!0,generateUniqueIdentifier:null,maxChunkRetries:0,chunkRetryInterval:null,permanentErrors:[404,413,415,500,501],successStatuses:[200,201,202],onDropStopPropagation:!1,initFileFn:null,readFileFn:f},this.opts={},this.events={};var c=this;this.onDrop=function(a){c.opts.onDropStopPropagation&&a.stopPropagation(),a.preventDefault();var b=a.dataTransfer;b.items&&b.items[0]&&b.items[0].webkitGetAsEntry?c.webkitReadDataTransfer(a):c.addFiles(b.files,a)},this.preventEvent=function(a){a.preventDefault()},this.opts=d.extend({},this.defaults,b||{})}}function e(a,b,d){this.flowObj=a,this.bytes=null,this.file=b,this.name=b.fileName||b.name,this.size=b.size,this.relativePath=b.relativePath||b.webkitRelativePath||this.name,this.uniqueIdentifier=d===c?a.generateUniqueIdentifier(b):d,this.chunks=[],this.paused=!1,this.error=!1,this.averageSpeed=0,this.currentSpeed=0,this._lastProgressCallback=Date.now(),this._prevUploadedSize=0,this._prevProgress=0,this.bootstrap()}function f(a,b,c,d,e){var f="slice";a.file.slice?f="slice":a.file.mozSlice?f="mozSlice":a.file.webkitSlice&&(f="webkitSlice"),e.readFinished(a.file[f](b,c,d))}function g(a,b,c){this.flowObj=a,this.fileObj=b,this.offset=c,this.tested=!1,this.retries=0,this.pendingRetry=!1,this.preprocessState=0,this.readState=0,this.loaded=0,this.total=0,this.chunkSize=this.flowObj.opts.chunkSize,this.startByte=this.offset*this.chunkSize,this.computeEndByte=function(){var a=Math.min(this.fileObj.size,(this.offset+1)*this.chunkSize);return this.fileObj.size-a-1&&a.splice(c,1)}function i(a,b){return"function"==typeof a&&(b=Array.prototype.slice.call(arguments),a=a.apply(null,b.slice(1))),a}function j(a,b){setTimeout(a.bind(b),0)}function k(a,b){return l(arguments,function(b){b!==a&&l(b,function(b,c){a[c]=b})}),a}function l(a,b,c){if(a){var d;if("undefined"!=typeof a.length){for(d=0;d1&&"pending"===a.chunks[a.chunks.length-1].status()?(a.chunks[a.chunks.length-1].send(),b=!0,!1):void 0}),b))return b;if(l(this.files,function(a){if(a.paused||l(a.chunks,function(a){if("pending"===a.status())return a.send(),b=!0,!1}),b)return!1}),b)return!0;var c=!1;return l(this.files,function(a){if(!a.isComplete())return c=!0,!1}),c||a||j(function(){this.fire("complete")},this),!1},assignBrowse:function(a,c,d,e){a instanceof Element&&(a=[a]),l(a,function(a){var f;"INPUT"===a.tagName&&"file"===a.type?f=a:(f=b.createElement("input"),f.setAttribute("type","file"),k(f.style,{visibility:"hidden",position:"absolute",width:"1px",height:"1px"}),a.appendChild(f),a.addEventListener("click",function(){f.click()},!1)),this.opts.singleFile||d||f.setAttribute("multiple","multiple"),c&&f.setAttribute("webkitdirectory","webkitdirectory"),l(e,function(a,b){f.setAttribute(b,a)});var g=this;f.addEventListener("change",function(a){a.target.value&&(g.addFiles(a.target.files,a),a.target.value="")},!1)},this)},assignDrop:function(a){"undefined"==typeof a.length&&(a=[a]),l(a,function(a){a.addEventListener("dragover",this.preventEvent,!1),a.addEventListener("dragenter",this.preventEvent,!1),a.addEventListener("drop",this.onDrop,!1)},this)},unAssignDrop:function(a){"undefined"==typeof a.length&&(a=[a]),l(a,function(a){a.removeEventListener("dragover",this.preventEvent),a.removeEventListener("dragenter",this.preventEvent),a.removeEventListener("drop",this.onDrop)},this)},isUploading:function(){var a=!1;return l(this.files,function(b){if(b.isUploading())return a=!0,!1}),a},_shouldUploadNext:function(){var a=0,b=!0,c=this.opts.simultaneousUploads;return l(this.files,function(d){l(d.chunks,function(d){if("uploading"===d.status()&&(a++,a>=c))return b=!1,!1})}),b&&a},upload:function(){var a=this._shouldUploadNext();if(a!==!1){this.fire("uploadStart");for(var b=!1,c=1;c<=this.opts.simultaneousUploads-a;c++)b=this.uploadNextChunk(!0)||b;b||j(function(){this.fire("complete")},this)}},resume:function(){l(this.files,function(a){a.isComplete()||a.resume()})},pause:function(){l(this.files,function(a){a.pause()})},cancel:function(){for(var a=this.files.length-1;a>=0;a--)this.files[a].cancel()},progress:function(){var a=0,b=0;return l(this.files,function(c){a+=c.progress()*c.size,b+=c.size}),b>0?a/b:0},addFile:function(a,b){this.addFiles([a],b)},addFiles:function(a,b){var c=[];l(a,function(a){if((!m||m&&a.size>0)&&(a.size%4096!==0||"."!==a.name&&"."!==a.fileName)){var d=this.generateUniqueIdentifier(a);if(this.opts.allowDuplicateUploads||!this.getFromUniqueIdentifier(d)){var f=new e(this,a,d);this.fire("fileAdded",f,b)&&c.push(f)}}},this),this.fire("filesAdded",c,b)&&(l(c,function(a){this.opts.singleFile&&this.files.length>0&&this.removeFile(this.files[0]),this.files.push(a)},this),this.fire("filesSubmitted",c,b))},removeFile:function(a){for(var b=this.files.length-1;b>=0;b--)this.files[b]===a&&(this.files.splice(b,1),a.abort(),this.fire("fileRemoved",a))},getFromUniqueIdentifier:function(a){var b=!1;return l(this.files,function(c){c.uniqueIdentifier===a&&(b=c)}),b},getSize:function(){var a=0;return l(this.files,function(b){a+=b.size}),a},sizeUploaded:function(){var a=0;return l(this.files,function(b){a+=b.sizeUploaded()}),a},timeRemaining:function(){var a=0,b=0;return l(this.files,function(c){c.paused||c.error||(a+=c.size-c.sizeUploaded(),b+=c.averageSpeed)}),a&&!b?Number.POSITIVE_INFINITY:a||b?Math.floor(a/b):0}},e.prototype={measureSpeed:function(){var a=Date.now()-this._lastProgressCallback;if(a){var b=this.flowObj.opts.speedSmoothingFactor,c=this.sizeUploaded();this.currentSpeed=Math.max((c-this._prevUploadedSize)/a*1e3,0),this.averageSpeed=b*this.currentSpeed+(1-b)*this.averageSpeed,this._prevUploadedSize=c}},chunkEvent:function(a,b,c){switch(b){case"progress":if(Date.now()-this._lastProgressCallback.9999?1:b),this._prevProgress},isUploading:function(){var a=!1;return l(this.chunks,function(b){if("uploading"===b.status())return a=!0,!1}),a},isComplete:function(){var a=!1;return l(this.chunks,function(b){var c=b.status();if("pending"===c||"uploading"===c||"reading"===c||1===b.preprocessState||1===b.readState)return a=!0,!1}),!a},sizeUploaded:function(){var a=0;return l(this.chunks,function(b){a+=b.sizeUploaded()}),a},timeRemaining:function(){if(this.paused||this.error)return 0;var a=this.size-this.sizeUploaded();return a&&!this.averageSpeed?Number.POSITIVE_INFINITY:a||this.averageSpeed?Math.floor(a/this.averageSpeed):0},getType:function(){return this.file.type&&this.file.type.split("/")[1]},getExtension:function(){return this.name.substr((~-this.name.lastIndexOf(".")>>>0)+2).toLowerCase()}},g.prototype={getParams:function(){return{flowChunkNumber:this.offset+1,flowChunkSize:this.flowObj.opts.chunkSize,flowCurrentChunkSize:this.endByte-this.startByte,flowTotalSize:this.fileObj.size,flowIdentifier:this.fileObj.uniqueIdentifier,flowFilename:this.fileObj.name,flowRelativePath:this.fileObj.relativePath,flowTotalChunks:this.fileObj.chunks.length}},getTarget:function(a,b){return a+=a.indexOf("?")<0?"?":"&",a+b.join("&")},test:function(){this.xhr=new XMLHttpRequest,this.xhr.addEventListener("load",this.testHandler,!1),this.xhr.addEventListener("error",this.testHandler,!1);var a=i(this.flowObj.opts.testMethod,this.fileObj,this),b=this.prepareXhrRequest(a,!0);this.xhr.send(b)},preprocessFinished:function(){this.endByte=this.computeEndByte(),this.preprocessState=2,this.send()},readFinished:function(a){this.readState=2,this.bytes=a,this.send()},send:function(){var a=this.flowObj.opts.preprocess,b=this.flowObj.opts.readFileFn;if("function"==typeof a)switch(this.preprocessState){case 0:return this.preprocessState=1,void a(this);case 1:return}switch(this.readState){case 0:return this.readState=1,void b(this.fileObj,this.startByte,this.endByte,this.fileObj.file.type,this);case 1:return}if(this.flowObj.opts.testChunks&&!this.tested)return void this.test();this.loaded=0,this.total=0,this.pendingRetry=!1,this.xhr=new XMLHttpRequest,this.xhr.upload.addEventListener("progress",this.progressHandler,!1),this.xhr.addEventListener("load",this.doneHandler,!1),this.xhr.addEventListener("error",this.doneHandler,!1);var c=i(this.flowObj.opts.uploadMethod,this.fileObj,this),d=this.prepareXhrRequest(c,!1,this.flowObj.opts.method,this.bytes);this.xhr.send(d)},abort:function(){var a=this.xhr;this.xhr=null,a&&a.abort()},status:function(a){return 1===this.readState?"reading":this.pendingRetry||1===this.preprocessState?"uploading":this.xhr?this.xhr.readyState<4?"uploading":this.flowObj.opts.successStatuses.indexOf(this.xhr.status)>-1?"success":this.flowObj.opts.permanentErrors.indexOf(this.xhr.status)>-1||!a&&this.retries>=this.flowObj.opts.maxChunkRetries?"error":(this.abort(),"pending"):"pending"},message:function(){return this.xhr?this.xhr.responseText:""},progress:function(){if(this.pendingRetry)return 0;var a=this.status();return"success"===a||"error"===a?1:"pending"===a?0:this.total>0?this.loaded/this.total:0},sizeUploaded:function(){var a=this.endByte-this.startByte;return"success"!==this.status()&&(a=this.progress()*a),a},prepareXhrRequest:function(a,b,c,d){var e=i(this.flowObj.opts.query,this.fileObj,this,b);e=k(e,this.getParams());var f=i(this.flowObj.opts.target,this.fileObj,this,b),g=null;if("GET"===a||"octet"===c){var h=[];l(e,function(a,b){h.push([encodeURIComponent(b),encodeURIComponent(a)].join("="))}),f=this.getTarget(f,h),g=d||null}else g=new FormData,l(e,function(a,b){g.append(b,a)}),"undefined"!=typeof d&&g.append(this.flowObj.opts.fileParameterName,d,this.fileObj.file.name);return this.xhr.open(a,f,!0),this.xhr.withCredentials=this.flowObj.opts.withCredentials,l(i(this.flowObj.opts.headers,this.fileObj,this,b),function(a,b){this.xhr.setRequestHeader(b,a)},this),g}},d.evalOpts=i,d.extend=k,d.each=l,d.FlowFile=e,d.FlowChunk=g,d.version="2.13.0","object"==typeof module&&module&&"object"==typeof module.exports?module.exports=d:(a.Flow=d,"function"==typeof define&&define.amd&&define("flow",[],function(){return d}))}(window,document),function(a,b){"function"==typeof define&&define.amd?define(["angular","@flowjs/flow.js"],b):"object"==typeof exports?module.exports=b(require("angular"),require("@flowjs/flow.js")):a.ngFlow=b(a.angular,a.Flow)}(this,function(a,b){return a.module("flow.provider",[]).provider("flowFactory",function(){"use strict";this.defaults={},this.factory=function(a){return new b(a)},this.events=[],this.on=function(a,b){this.events.push([a,b])},this.$get=function(){var b=this.factory,c=this.defaults,d=this.events;return{create:function(e){var f=b(a.extend({},c,e));return a.forEach(d,function(a){f.on(a[0],a[1])}),f}}}}),a.module("flow.init",["flow.provider"]).controller("flowCtrl",["$scope","$attrs","$parse","flowFactory",function(b,c,d,e){var f=a.extend({},b.$eval(c.flowInit)),g=b.$eval(c.flowObject)||e.create(f),h=function(a){var c=Array.prototype.slice.call(arguments);c.shift();var d=b.$broadcast.apply(b,["flow::"+a,g].concat(c));if({progress:1,filesSubmitted:1,fileSuccess:1,fileError:1,complete:1}[a]&&b.$apply(),d.defaultPrevented)return!1};g.on("catchAll",h),b.$on("$destroy",function(){g.off("catchAll",h)}),b.$flow=g,c.hasOwnProperty("flowName")&&(d(c.flowName).assign(b,g),b.$on("$destroy",function(){d(c.flowName).assign(b)}))}]).directive("flowInit",[function(){return{scope:!0,controller:"flowCtrl"}}]),a.module("flow.btn",["flow.init"]).directive("flowBtn",[function(){return{restrict:"EA",scope:!1,require:"^flowInit",link:function(a,b,c){var d=c.hasOwnProperty("flowDirectory"),e=c.hasOwnProperty("flowSingleFile"),f=c.hasOwnProperty("flowAttrs")&&a.$eval(c.flowAttrs);a.$flow.assignBrowse(b,d,e,f)}}}]),a.module("flow.dragEvents",["flow.init"]).directive("flowPreventDrop",function(){return{scope:!1,link:function(a,b,c){b.bind("drop dragover",function(a){a.preventDefault()})}}}).directive("flowDragEnter",["$timeout",function(b){return{scope:!1,link:function(c,d,e){function f(b){var c=!1,d=b.dataTransfer||b.originalEvent.dataTransfer;return a.forEach(d&&d.types,function(a){"Files"===a&&(c=!0)}),c}var g,h=!1;d.bind("dragover",function(a){f(a)&&(h||(c.$apply(e.flowDragEnter),h=!0),b.cancel(g),a.preventDefault())}),d.bind("dragleave drop",function(a){b.cancel(g),g=b(function(){c.$eval(e.flowDragLeave),g=null,h=!1},100)})}}}]),a.module("flow.drop",["flow.init"]).directive("flowDrop",function(){return{scope:!1,require:"^flowInit",link:function(a,b,c){function d(){a.$flow.assignDrop(b)}function e(){a.$flow.unAssignDrop(b)}c.flowDropEnabled?a.$watch(c.flowDropEnabled,function(a){a?d():e()}):d()}}}),!function(a){"use strict";function b(a){return a.charAt(0).toUpperCase()+a.slice(1)}var c=a.module("flow.events",["flow.init"]),d={fileSuccess:["$file","$message"],fileProgress:["$file"],fileAdded:["$file","$event"],filesAdded:["$files","$event"],filesSubmitted:["$files","$event"],fileRetry:["$file"],fileRemoved:["$file"],fileError:["$file","$message"],uploadStart:[],complete:[],progress:[],error:["$message","$file"]};a.forEach(d,function(d,e){var f="flow"+b(e);"flowUploadStart"==f&&(f="flowUploadStarted"),c.directive(f,[function(){return{require:"^flowInit",controller:["$scope","$attrs",function(b,c){b.$on("flow::"+e,function(){var e=Array.prototype.slice.call(arguments),g=e.shift();if(b.$flow===e.shift()){var h={};a.forEach(d,function(a,b){h[a]=e[b]}),b.$eval(c[f],h)===!1&&g.preventDefault()}})}]}}])})}(a),a.module("flow.img",["flow.init"]).directive("flowImg",[function(){return{scope:!1,require:"^flowInit",link:function(a,b,c){var d=c.flowImg;a.$watch(d,function(b){if(b){var d=new FileReader;d.readAsDataURL(b.file),d.onload=function(b){a.$apply(function(){c.$set("src",b.target.result)})}}})}}}]),a.module("flow.transfers",["flow.init"]).directive("flowTransfers",[function(){return{scope:!0,require:"^flowInit",link:function(a){a.transfers=a.$flow.files}}}]),a.module("flow",["flow.provider","flow.init","flow.events","flow.btn","flow.drop","flow.transfers","flow.img","flow.dragEvents"]),"flow"});
\ No newline at end of file
diff --git a/dist/ng-flow.js b/dist/ng-flow.js
index e38ae54..cfae5ff 100644
--- a/dist/ng-flow.js
+++ b/dist/ng-flow.js
@@ -1,3 +1,14 @@
+(function (root, factory) {
+ if (typeof define === 'function' && define.amd) {
+ define(['angular', '@flowjs/flow.js'], factory);
+ } else if (typeof exports === 'object') {
+ // Node, CommonJS-like
+ module.exports = factory(require('angular'), require('@flowjs/flow.js'));
+ } else {
+ // Browser globals (root is window)
+ root.ngFlow = factory(root.angular, root.Flow);
+ }
+}(this, function (angular, Flow) {
/**
* @description
* var app = angular.module('App', ['flow.provider'], function(flowFactoryProvider){
@@ -286,4 +297,7 @@ angular.module('flow.transfers', ['flow.init'])
};
}]);
angular.module('flow', ['flow.provider', 'flow.init', 'flow.events', 'flow.btn',
- 'flow.drop', 'flow.transfers', 'flow.img', 'flow.dragEvents']);
\ No newline at end of file
+ 'flow.drop', 'flow.transfers', 'flow.img', 'flow.dragEvents']);
+
+return 'flow';
+}));
diff --git a/dist/ng-flow.min.js b/dist/ng-flow.min.js
index 77f93c9..d40db0b 100644
--- a/dist/ng-flow.min.js
+++ b/dist/ng-flow.min.js
@@ -1,2 +1,2 @@
/*! @flowjs/ng-flow 2.7.7 */
-angular.module("flow.provider",[]).provider("flowFactory",function(){"use strict";this.defaults={},this.factory=function(a){return new Flow(a)},this.events=[],this.on=function(a,b){this.events.push([a,b])},this.$get=function(){var a=this.factory,b=this.defaults,c=this.events;return{create:function(d){var e=a(angular.extend({},b,d));return angular.forEach(c,function(a){e.on(a[0],a[1])}),e}}}}),angular.module("flow.init",["flow.provider"]).controller("flowCtrl",["$scope","$attrs","$parse","flowFactory",function(a,b,c,d){var e=angular.extend({},a.$eval(b.flowInit)),f=a.$eval(b.flowObject)||d.create(e),g=function(b){var c=Array.prototype.slice.call(arguments);c.shift();var d=a.$broadcast.apply(a,["flow::"+b,f].concat(c));return{progress:1,filesSubmitted:1,fileSuccess:1,fileError:1,complete:1}[b]&&a.$apply(),d.defaultPrevented?!1:void 0};f.on("catchAll",g),a.$on("$destroy",function(){f.off("catchAll",g)}),a.$flow=f,b.hasOwnProperty("flowName")&&(c(b.flowName).assign(a,f),a.$on("$destroy",function(){c(b.flowName).assign(a)}))}]).directive("flowInit",[function(){return{scope:!0,controller:"flowCtrl"}}]),angular.module("flow.btn",["flow.init"]).directive("flowBtn",[function(){return{restrict:"EA",scope:!1,require:"^flowInit",link:function(a,b,c){var d=c.hasOwnProperty("flowDirectory"),e=c.hasOwnProperty("flowSingleFile"),f=c.hasOwnProperty("flowAttrs")&&a.$eval(c.flowAttrs);a.$flow.assignBrowse(b,d,e,f)}}}]),angular.module("flow.dragEvents",["flow.init"]).directive("flowPreventDrop",function(){return{scope:!1,link:function(a,b,c){b.bind("drop dragover",function(a){a.preventDefault()})}}}).directive("flowDragEnter",["$timeout",function(a){return{scope:!1,link:function(b,c,d){function e(a){var b=!1,c=a.dataTransfer||a.originalEvent.dataTransfer;return angular.forEach(c&&c.types,function(a){"Files"===a&&(b=!0)}),b}var f,g=!1;c.bind("dragover",function(c){e(c)&&(g||(b.$apply(d.flowDragEnter),g=!0),a.cancel(f),c.preventDefault())}),c.bind("dragleave drop",function(c){a.cancel(f),f=a(function(){b.$eval(d.flowDragLeave),f=null,g=!1},100)})}}}]),angular.module("flow.drop",["flow.init"]).directive("flowDrop",function(){return{scope:!1,require:"^flowInit",link:function(a,b,c){function d(){a.$flow.assignDrop(b)}function e(){a.$flow.unAssignDrop(b)}c.flowDropEnabled?a.$watch(c.flowDropEnabled,function(a){a?d():e()}):d()}}}),!function(a){"use strict";function b(a){return a.charAt(0).toUpperCase()+a.slice(1)}var c=a.module("flow.events",["flow.init"]),d={fileSuccess:["$file","$message"],fileProgress:["$file"],fileAdded:["$file","$event"],filesAdded:["$files","$event"],filesSubmitted:["$files","$event"],fileRetry:["$file"],fileRemoved:["$file"],fileError:["$file","$message"],uploadStart:[],complete:[],progress:[],error:["$message","$file"]};a.forEach(d,function(d,e){var f="flow"+b(e);"flowUploadStart"==f&&(f="flowUploadStarted"),c.directive(f,[function(){return{require:"^flowInit",controller:["$scope","$attrs",function(b,c){b.$on("flow::"+e,function(){var e=Array.prototype.slice.call(arguments),g=e.shift();if(b.$flow===e.shift()){var h={};a.forEach(d,function(a,b){h[a]=e[b]}),b.$eval(c[f],h)===!1&&g.preventDefault()}})}]}}])})}(angular),angular.module("flow.img",["flow.init"]).directive("flowImg",[function(){return{scope:!1,require:"^flowInit",link:function(a,b,c){var d=c.flowImg;a.$watch(d,function(b){if(b){var d=new FileReader;d.readAsDataURL(b.file),d.onload=function(b){a.$apply(function(){c.$set("src",b.target.result)})}}})}}}]),angular.module("flow.transfers",["flow.init"]).directive("flowTransfers",[function(){return{scope:!0,require:"^flowInit",link:function(a){a.transfers=a.$flow.files}}}]),angular.module("flow",["flow.provider","flow.init","flow.events","flow.btn","flow.drop","flow.transfers","flow.img","flow.dragEvents"]);
\ No newline at end of file
+!function(a,b){"function"==typeof define&&define.amd?define(["angular","@flowjs/flow.js"],b):"object"==typeof exports?module.exports=b(require("angular"),require("@flowjs/flow.js")):a.ngFlow=b(a.angular,a.Flow)}(this,function(a,b){return a.module("flow.provider",[]).provider("flowFactory",function(){"use strict";this.defaults={},this.factory=function(a){return new b(a)},this.events=[],this.on=function(a,b){this.events.push([a,b])},this.$get=function(){var b=this.factory,c=this.defaults,d=this.events;return{create:function(e){var f=b(a.extend({},c,e));return a.forEach(d,function(a){f.on(a[0],a[1])}),f}}}}),a.module("flow.init",["flow.provider"]).controller("flowCtrl",["$scope","$attrs","$parse","flowFactory",function(b,c,d,e){var f=a.extend({},b.$eval(c.flowInit)),g=b.$eval(c.flowObject)||e.create(f),h=function(a){var c=Array.prototype.slice.call(arguments);c.shift();var d=b.$broadcast.apply(b,["flow::"+a,g].concat(c));if({progress:1,filesSubmitted:1,fileSuccess:1,fileError:1,complete:1}[a]&&b.$apply(),d.defaultPrevented)return!1};g.on("catchAll",h),b.$on("$destroy",function(){g.off("catchAll",h)}),b.$flow=g,c.hasOwnProperty("flowName")&&(d(c.flowName).assign(b,g),b.$on("$destroy",function(){d(c.flowName).assign(b)}))}]).directive("flowInit",[function(){return{scope:!0,controller:"flowCtrl"}}]),a.module("flow.btn",["flow.init"]).directive("flowBtn",[function(){return{restrict:"EA",scope:!1,require:"^flowInit",link:function(a,b,c){var d=c.hasOwnProperty("flowDirectory"),e=c.hasOwnProperty("flowSingleFile"),f=c.hasOwnProperty("flowAttrs")&&a.$eval(c.flowAttrs);a.$flow.assignBrowse(b,d,e,f)}}}]),a.module("flow.dragEvents",["flow.init"]).directive("flowPreventDrop",function(){return{scope:!1,link:function(a,b,c){b.bind("drop dragover",function(a){a.preventDefault()})}}}).directive("flowDragEnter",["$timeout",function(b){return{scope:!1,link:function(c,d,e){function f(b){var c=!1,d=b.dataTransfer||b.originalEvent.dataTransfer;return a.forEach(d&&d.types,function(a){"Files"===a&&(c=!0)}),c}var g,h=!1;d.bind("dragover",function(a){f(a)&&(h||(c.$apply(e.flowDragEnter),h=!0),b.cancel(g),a.preventDefault())}),d.bind("dragleave drop",function(a){b.cancel(g),g=b(function(){c.$eval(e.flowDragLeave),g=null,h=!1},100)})}}}]),a.module("flow.drop",["flow.init"]).directive("flowDrop",function(){return{scope:!1,require:"^flowInit",link:function(a,b,c){function d(){a.$flow.assignDrop(b)}function e(){a.$flow.unAssignDrop(b)}c.flowDropEnabled?a.$watch(c.flowDropEnabled,function(a){a?d():e()}):d()}}}),!function(a){"use strict";function b(a){return a.charAt(0).toUpperCase()+a.slice(1)}var c=a.module("flow.events",["flow.init"]),d={fileSuccess:["$file","$message"],fileProgress:["$file"],fileAdded:["$file","$event"],filesAdded:["$files","$event"],filesSubmitted:["$files","$event"],fileRetry:["$file"],fileRemoved:["$file"],fileError:["$file","$message"],uploadStart:[],complete:[],progress:[],error:["$message","$file"]};a.forEach(d,function(d,e){var f="flow"+b(e);"flowUploadStart"==f&&(f="flowUploadStarted"),c.directive(f,[function(){return{require:"^flowInit",controller:["$scope","$attrs",function(b,c){b.$on("flow::"+e,function(){var e=Array.prototype.slice.call(arguments),g=e.shift();if(b.$flow===e.shift()){var h={};a.forEach(d,function(a,b){h[a]=e[b]}),b.$eval(c[f],h)===!1&&g.preventDefault()}})}]}}])})}(a),a.module("flow.img",["flow.init"]).directive("flowImg",[function(){return{scope:!1,require:"^flowInit",link:function(a,b,c){var d=c.flowImg;a.$watch(d,function(b){if(b){var d=new FileReader;d.readAsDataURL(b.file),d.onload=function(b){a.$apply(function(){c.$set("src",b.target.result)})}}})}}}]),a.module("flow.transfers",["flow.init"]).directive("flowTransfers",[function(){return{scope:!0,require:"^flowInit",link:function(a){a.transfers=a.$flow.files}}}]),a.module("flow",["flow.provider","flow.init","flow.events","flow.btn","flow.drop","flow.transfers","flow.img","flow.dragEvents"]),"flow"});
\ No newline at end of file
diff --git a/index.js b/index.js
index aa3d332..d577815 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,11 @@
-/* for module loading using webpack or similar package bundlers */
-window.Flow = require('./dist/ng-flow-standalone');
-module.exports = 'flow';
+/* backwards compatable with deprecated index.js*/
+try {
+ console.warn(new Error("use const ngFlow = require('@flowjs/ng-flow');"));
+} catch (e) {
+ // do nothing
+}
+
+if (typeof window === 'object') {
+ window.Flow = require('@flowjs/flow.js');
+}
+module.exports = require('./src/ng-flow');
diff --git a/package.json b/package.json
index 41960da..af35bda 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
"scripts": {
"test": "grunt test"
},
- "main": "dist/ng-flow.js",
+ "main": "src/ng-flow.js",
"repository": {
"type": "git",
"url": "git://github.com/flowjs/ng-flow.git"
@@ -36,5 +36,11 @@
"karma-firefox-launcher": "0.1.7",
"karma-jasmine": "^0.3.6",
"karma-sauce-launcher": "0.3.1"
+ },
+ "dependencies": {
+ "@flowjs/flow.js": "^2.13.0"
+ },
+ "peerDependencies": {
+ "angular": "^1.2"
}
}
diff --git a/src/angular-flow.js b/src/angular-flow.js
deleted file mode 100644
index f6dd22d..0000000
--- a/src/angular-flow.js
+++ /dev/null
@@ -1,2 +0,0 @@
-angular.module('flow', ['flow.provider', 'flow.init', 'flow.events', 'flow.btn',
- 'flow.drop', 'flow.transfers', 'flow.img', 'flow.dragEvents']);
\ No newline at end of file
diff --git a/src/directives/btn.js b/src/directives/btn.js
deleted file mode 100644
index bdbafff..0000000
--- a/src/directives/btn.js
+++ /dev/null
@@ -1,14 +0,0 @@
-angular.module('flow.btn', ['flow.init'])
-.directive('flowBtn', [function() {
- return {
- 'restrict': 'EA',
- 'scope': false,
- 'require': '^flowInit',
- 'link': function(scope, element, attrs) {
- var isDirectory = attrs.hasOwnProperty('flowDirectory');
- var isSingleFile = attrs.hasOwnProperty('flowSingleFile');
- var inputAttrs = attrs.hasOwnProperty('flowAttrs') && scope.$eval(attrs.flowAttrs);
- scope.$flow.assignBrowse(element, isDirectory, isSingleFile, inputAttrs);
- }
- };
-}]);
\ No newline at end of file
diff --git a/src/directives/drag-events.js b/src/directives/drag-events.js
deleted file mode 100644
index fda5517..0000000
--- a/src/directives/drag-events.js
+++ /dev/null
@@ -1,57 +0,0 @@
-angular.module('flow.dragEvents', ['flow.init'])
-/**
- * @name flowPreventDrop
- * Prevent loading files then dropped on element
- */
- .directive('flowPreventDrop', function() {
- return {
- 'scope': false,
- 'link': function(scope, element, attrs) {
- element.bind('drop dragover', function (event) {
- event.preventDefault();
- });
- }
- };
- })
-/**
- * @name flowDragEnter
- * executes `flowDragEnter` and `flowDragLeave` events
- */
- .directive('flowDragEnter', ['$timeout', function($timeout) {
- return {
- 'scope': false,
- 'link': function(scope, element, attrs) {
- var promise;
- var enter = false;
- element.bind('dragover', function (event) {
- if (!isFileDrag(event)) {
- return ;
- }
- if (!enter) {
- scope.$apply(attrs.flowDragEnter);
- enter = true;
- }
- $timeout.cancel(promise);
- event.preventDefault();
- });
- element.bind('dragleave drop', function (event) {
- $timeout.cancel(promise);
- promise = $timeout(function () {
- scope.$eval(attrs.flowDragLeave);
- promise = null;
- enter = false;
- }, 100);
- });
- function isFileDrag(dragEvent) {
- var fileDrag = false;
- var dataTransfer = dragEvent.dataTransfer || dragEvent.originalEvent.dataTransfer;
- angular.forEach(dataTransfer && dataTransfer.types, function(val) {
- if (val === 'Files') {
- fileDrag = true;
- }
- });
- return fileDrag;
- }
- }
- };
- }]);
diff --git a/src/directives/drop.js b/src/directives/drop.js
deleted file mode 100644
index b028ec0..0000000
--- a/src/directives/drop.js
+++ /dev/null
@@ -1,26 +0,0 @@
-angular.module('flow.drop', ['flow.init'])
-.directive('flowDrop', function() {
- return {
- 'scope': false,
- 'require': '^flowInit',
- 'link': function(scope, element, attrs) {
- if (attrs.flowDropEnabled) {
- scope.$watch(attrs.flowDropEnabled, function (value) {
- if (value) {
- assignDrop();
- } else {
- unAssignDrop();
- }
- });
- } else {
- assignDrop();
- }
- function assignDrop() {
- scope.$flow.assignDrop(element);
- }
- function unAssignDrop() {
- scope.$flow.unAssignDrop(element);
- }
- }
- };
-});
diff --git a/src/directives/events.js b/src/directives/events.js
deleted file mode 100644
index 9c4d8d8..0000000
--- a/src/directives/events.js
+++ /dev/null
@@ -1,50 +0,0 @@
-!function (angular) {'use strict';
- var module = angular.module('flow.events', ['flow.init']);
- var events = {
- fileSuccess: ['$file', '$message'],
- fileProgress: ['$file'],
- fileAdded: ['$file', '$event'],
- filesAdded: ['$files', '$event'],
- filesSubmitted: ['$files', '$event'],
- fileRetry: ['$file'],
- fileRemoved: ['$file'],
- fileError: ['$file', '$message'],
- uploadStart: [],
- complete: [],
- progress: [],
- error: ['$message', '$file']
- };
-
- angular.forEach(events, function (eventArgs, eventName) {
- var name = 'flow' + capitaliseFirstLetter(eventName);
- if (name == 'flowUploadStart') {
- name = 'flowUploadStarted';// event alias
- }
- module.directive(name, [function() {
- return {
- require: '^flowInit',
- controller: ['$scope', '$attrs', function ($scope, $attrs) {
- $scope.$on('flow::' + eventName, function () {
- var funcArgs = Array.prototype.slice.call(arguments);
- var event = funcArgs.shift();// remove angular event
- // remove flow object and ignore event if it is from parent directive
- if ($scope.$flow !== funcArgs.shift()) {
- return ;
- }
- var args = {};
- angular.forEach(eventArgs, function(value, key) {
- args[value] = funcArgs[key];
- });
- if ($scope.$eval($attrs[name], args) === false) {
- event.preventDefault();
- }
- });
- }]
- };
- }]);
- });
-
- function capitaliseFirstLetter(string) {
- return string.charAt(0).toUpperCase() + string.slice(1);
- }
-}(angular);
diff --git a/src/directives/img.js b/src/directives/img.js
deleted file mode 100644
index cf15f1b..0000000
--- a/src/directives/img.js
+++ /dev/null
@@ -1,22 +0,0 @@
-angular.module('flow.img', ['flow.init'])
-.directive('flowImg', [function() {
- return {
- 'scope': false,
- 'require': '^flowInit',
- 'link': function(scope, element, attrs) {
- var file = attrs.flowImg;
- scope.$watch(file, function (file) {
- if (!file) {
- return ;
- }
- var fileReader = new FileReader();
- fileReader.readAsDataURL(file.file);
- fileReader.onload = function (event) {
- scope.$apply(function () {
- attrs.$set('src', event.target.result);
- });
- };
- });
- }
- };
-}]);
\ No newline at end of file
diff --git a/src/directives/init.js b/src/directives/init.js
deleted file mode 100644
index fcc3f13..0000000
--- a/src/directives/init.js
+++ /dev/null
@@ -1,43 +0,0 @@
-angular.module('flow.init', ['flow.provider'])
- .controller('flowCtrl', ['$scope', '$attrs', '$parse', 'flowFactory',
- function ($scope, $attrs, $parse, flowFactory) {
-
- var options = angular.extend({}, $scope.$eval($attrs.flowInit));
-
- // use existing flow object or create a new one
- var flow = $scope.$eval($attrs.flowObject) || flowFactory.create(options);
-
- var catchAllHandler = function(eventName){
- var args = Array.prototype.slice.call(arguments);
- args.shift();
- var event = $scope.$broadcast.apply($scope, ['flow::' + eventName, flow].concat(args));
- if ({
- 'progress':1, 'filesSubmitted':1, 'fileSuccess': 1, 'fileError': 1, 'complete': 1
- }[eventName]) {
- $scope.$apply();
- }
- if (event.defaultPrevented) {
- return false;
- }
- };
-
- flow.on('catchAll', catchAllHandler);
- $scope.$on('$destroy', function(){
- flow.off('catchAll', catchAllHandler);
- });
-
- $scope.$flow = flow;
-
- if ($attrs.hasOwnProperty('flowName')) {
- $parse($attrs.flowName).assign($scope, flow);
- $scope.$on('$destroy', function () {
- $parse($attrs.flowName).assign($scope);
- });
- }
- }])
- .directive('flowInit', [function() {
- return {
- scope: true,
- controller: 'flowCtrl'
- };
- }]);
\ No newline at end of file
diff --git a/src/directives/transfers.js b/src/directives/transfers.js
deleted file mode 100644
index c295a24..0000000
--- a/src/directives/transfers.js
+++ /dev/null
@@ -1,10 +0,0 @@
-angular.module('flow.transfers', ['flow.init'])
-.directive('flowTransfers', [function() {
- return {
- 'scope': true,
- 'require': '^flowInit',
- 'link': function(scope) {
- scope.transfers = scope.$flow.files;
- }
- };
-}]);
\ No newline at end of file
diff --git a/src/ng-flow.js b/src/ng-flow.js
new file mode 100644
index 0000000..cfae5ff
--- /dev/null
+++ b/src/ng-flow.js
@@ -0,0 +1,303 @@
+(function (root, factory) {
+ if (typeof define === 'function' && define.amd) {
+ define(['angular', '@flowjs/flow.js'], factory);
+ } else if (typeof exports === 'object') {
+ // Node, CommonJS-like
+ module.exports = factory(require('angular'), require('@flowjs/flow.js'));
+ } else {
+ // Browser globals (root is window)
+ root.ngFlow = factory(root.angular, root.Flow);
+ }
+}(this, function (angular, Flow) {
+/**
+ * @description
+ * var app = angular.module('App', ['flow.provider'], function(flowFactoryProvider){
+ * flowFactoryProvider.defaults = {target: '/'};
+ * });
+ * @name flowFactoryProvider
+ */
+angular.module('flow.provider', [])
+.provider('flowFactory', function() {
+ 'use strict';
+ /**
+ * Define the default properties for flow.js
+ * @name flowFactoryProvider.defaults
+ * @type {Object}
+ */
+ this.defaults = {};
+
+ /**
+ * Flow, MaybeFlow or NotFlow
+ * @name flowFactoryProvider.factory
+ * @type {function}
+ * @return {Flow}
+ */
+ this.factory = function (options) {
+ return new Flow(options);
+ };
+
+ /**
+ * Define the default events
+ * @name flowFactoryProvider.events
+ * @type {Array}
+ * @private
+ */
+ this.events = [];
+
+ /**
+ * Add default events
+ * @name flowFactoryProvider.on
+ * @function
+ * @param {string} event
+ * @param {Function} callback
+ */
+ this.on = function (event, callback) {
+ this.events.push([event, callback]);
+ };
+
+ this.$get = function() {
+ var fn = this.factory;
+ var defaults = this.defaults;
+ var events = this.events;
+ return {
+ 'create': function(opts) {
+ // combine default options with global options and options
+ var flow = fn(angular.extend({}, defaults, opts));
+ angular.forEach(events, function (event) {
+ flow.on(event[0], event[1]);
+ });
+ return flow;
+ }
+ };
+ };
+});
+angular.module('flow.init', ['flow.provider'])
+ .controller('flowCtrl', ['$scope', '$attrs', '$parse', 'flowFactory',
+ function ($scope, $attrs, $parse, flowFactory) {
+
+ var options = angular.extend({}, $scope.$eval($attrs.flowInit));
+
+ // use existing flow object or create a new one
+ var flow = $scope.$eval($attrs.flowObject) || flowFactory.create(options);
+
+ var catchAllHandler = function(eventName){
+ var args = Array.prototype.slice.call(arguments);
+ args.shift();
+ var event = $scope.$broadcast.apply($scope, ['flow::' + eventName, flow].concat(args));
+ if ({
+ 'progress':1, 'filesSubmitted':1, 'fileSuccess': 1, 'fileError': 1, 'complete': 1
+ }[eventName]) {
+ $scope.$apply();
+ }
+ if (event.defaultPrevented) {
+ return false;
+ }
+ };
+
+ flow.on('catchAll', catchAllHandler);
+ $scope.$on('$destroy', function(){
+ flow.off('catchAll', catchAllHandler);
+ });
+
+ $scope.$flow = flow;
+
+ if ($attrs.hasOwnProperty('flowName')) {
+ $parse($attrs.flowName).assign($scope, flow);
+ $scope.$on('$destroy', function () {
+ $parse($attrs.flowName).assign($scope);
+ });
+ }
+ }])
+ .directive('flowInit', [function() {
+ return {
+ scope: true,
+ controller: 'flowCtrl'
+ };
+ }]);
+angular.module('flow.btn', ['flow.init'])
+.directive('flowBtn', [function() {
+ return {
+ 'restrict': 'EA',
+ 'scope': false,
+ 'require': '^flowInit',
+ 'link': function(scope, element, attrs) {
+ var isDirectory = attrs.hasOwnProperty('flowDirectory');
+ var isSingleFile = attrs.hasOwnProperty('flowSingleFile');
+ var inputAttrs = attrs.hasOwnProperty('flowAttrs') && scope.$eval(attrs.flowAttrs);
+ scope.$flow.assignBrowse(element, isDirectory, isSingleFile, inputAttrs);
+ }
+ };
+}]);
+angular.module('flow.dragEvents', ['flow.init'])
+/**
+ * @name flowPreventDrop
+ * Prevent loading files then dropped on element
+ */
+ .directive('flowPreventDrop', function() {
+ return {
+ 'scope': false,
+ 'link': function(scope, element, attrs) {
+ element.bind('drop dragover', function (event) {
+ event.preventDefault();
+ });
+ }
+ };
+ })
+/**
+ * @name flowDragEnter
+ * executes `flowDragEnter` and `flowDragLeave` events
+ */
+ .directive('flowDragEnter', ['$timeout', function($timeout) {
+ return {
+ 'scope': false,
+ 'link': function(scope, element, attrs) {
+ var promise;
+ var enter = false;
+ element.bind('dragover', function (event) {
+ if (!isFileDrag(event)) {
+ return ;
+ }
+ if (!enter) {
+ scope.$apply(attrs.flowDragEnter);
+ enter = true;
+ }
+ $timeout.cancel(promise);
+ event.preventDefault();
+ });
+ element.bind('dragleave drop', function (event) {
+ $timeout.cancel(promise);
+ promise = $timeout(function () {
+ scope.$eval(attrs.flowDragLeave);
+ promise = null;
+ enter = false;
+ }, 100);
+ });
+ function isFileDrag(dragEvent) {
+ var fileDrag = false;
+ var dataTransfer = dragEvent.dataTransfer || dragEvent.originalEvent.dataTransfer;
+ angular.forEach(dataTransfer && dataTransfer.types, function(val) {
+ if (val === 'Files') {
+ fileDrag = true;
+ }
+ });
+ return fileDrag;
+ }
+ }
+ };
+ }]);
+
+angular.module('flow.drop', ['flow.init'])
+.directive('flowDrop', function() {
+ return {
+ 'scope': false,
+ 'require': '^flowInit',
+ 'link': function(scope, element, attrs) {
+ if (attrs.flowDropEnabled) {
+ scope.$watch(attrs.flowDropEnabled, function (value) {
+ if (value) {
+ assignDrop();
+ } else {
+ unAssignDrop();
+ }
+ });
+ } else {
+ assignDrop();
+ }
+ function assignDrop() {
+ scope.$flow.assignDrop(element);
+ }
+ function unAssignDrop() {
+ scope.$flow.unAssignDrop(element);
+ }
+ }
+ };
+});
+
+!function (angular) {'use strict';
+ var module = angular.module('flow.events', ['flow.init']);
+ var events = {
+ fileSuccess: ['$file', '$message'],
+ fileProgress: ['$file'],
+ fileAdded: ['$file', '$event'],
+ filesAdded: ['$files', '$event'],
+ filesSubmitted: ['$files', '$event'],
+ fileRetry: ['$file'],
+ fileRemoved: ['$file'],
+ fileError: ['$file', '$message'],
+ uploadStart: [],
+ complete: [],
+ progress: [],
+ error: ['$message', '$file']
+ };
+
+ angular.forEach(events, function (eventArgs, eventName) {
+ var name = 'flow' + capitaliseFirstLetter(eventName);
+ if (name == 'flowUploadStart') {
+ name = 'flowUploadStarted';// event alias
+ }
+ module.directive(name, [function() {
+ return {
+ require: '^flowInit',
+ controller: ['$scope', '$attrs', function ($scope, $attrs) {
+ $scope.$on('flow::' + eventName, function () {
+ var funcArgs = Array.prototype.slice.call(arguments);
+ var event = funcArgs.shift();// remove angular event
+ // remove flow object and ignore event if it is from parent directive
+ if ($scope.$flow !== funcArgs.shift()) {
+ return ;
+ }
+ var args = {};
+ angular.forEach(eventArgs, function(value, key) {
+ args[value] = funcArgs[key];
+ });
+ if ($scope.$eval($attrs[name], args) === false) {
+ event.preventDefault();
+ }
+ });
+ }]
+ };
+ }]);
+ });
+
+ function capitaliseFirstLetter(string) {
+ return string.charAt(0).toUpperCase() + string.slice(1);
+ }
+}(angular);
+
+angular.module('flow.img', ['flow.init'])
+.directive('flowImg', [function() {
+ return {
+ 'scope': false,
+ 'require': '^flowInit',
+ 'link': function(scope, element, attrs) {
+ var file = attrs.flowImg;
+ scope.$watch(file, function (file) {
+ if (!file) {
+ return ;
+ }
+ var fileReader = new FileReader();
+ fileReader.readAsDataURL(file.file);
+ fileReader.onload = function (event) {
+ scope.$apply(function () {
+ attrs.$set('src', event.target.result);
+ });
+ };
+ });
+ }
+ };
+}]);
+angular.module('flow.transfers', ['flow.init'])
+.directive('flowTransfers', [function() {
+ return {
+ 'scope': true,
+ 'require': '^flowInit',
+ 'link': function(scope) {
+ scope.transfers = scope.$flow.files;
+ }
+ };
+}]);
+angular.module('flow', ['flow.provider', 'flow.init', 'flow.events', 'flow.btn',
+ 'flow.drop', 'flow.transfers', 'flow.img', 'flow.dragEvents']);
+
+return 'flow';
+}));
diff --git a/src/provider.js b/src/provider.js
deleted file mode 100644
index b024ab8..0000000
--- a/src/provider.js
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * @description
- * var app = angular.module('App', ['flow.provider'], function(flowFactoryProvider){
- * flowFactoryProvider.defaults = {target: '/'};
- * });
- * @name flowFactoryProvider
- */
-angular.module('flow.provider', [])
-.provider('flowFactory', function() {
- 'use strict';
- /**
- * Define the default properties for flow.js
- * @name flowFactoryProvider.defaults
- * @type {Object}
- */
- this.defaults = {};
-
- /**
- * Flow, MaybeFlow or NotFlow
- * @name flowFactoryProvider.factory
- * @type {function}
- * @return {Flow}
- */
- this.factory = function (options) {
- return new Flow(options);
- };
-
- /**
- * Define the default events
- * @name flowFactoryProvider.events
- * @type {Array}
- * @private
- */
- this.events = [];
-
- /**
- * Add default events
- * @name flowFactoryProvider.on
- * @function
- * @param {string} event
- * @param {Function} callback
- */
- this.on = function (event, callback) {
- this.events.push([event, callback]);
- };
-
- this.$get = function() {
- var fn = this.factory;
- var defaults = this.defaults;
- var events = this.events;
- return {
- 'create': function(opts) {
- // combine default options with global options and options
- var flow = fn(angular.extend({}, defaults, opts));
- angular.forEach(events, function (event) {
- flow.on(event[0], event[1]);
- });
- return flow;
- }
- };
- };
-});
\ No newline at end of file