From 021581fbb5dead5df8df43f480a812dd91bac9c3 Mon Sep 17 00:00:00 2001 From: dolymood Date: Mon, 21 Aug 2017 23:27:30 +0800 Subject: [PATCH] 0.0.4 --- dist/uploader.js | 24 ++++++++++++++---------- dist/uploader.min.js | 4 ++-- dist/uploader.min.js.map | 2 +- package.json | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/dist/uploader.js b/dist/uploader.js index df4aa4e..e148066 100644 --- a/dist/uploader.js +++ b/dist/uploader.js @@ -1,6 +1,6 @@ /*! * Uploader - Uploader library implements html5 file upload and provides multiple simultaneous, stable, fault tolerant and resumable uploads - * @version v0.0.3 + * @version v0.0.4 * @author dolymood * @link https://github.com/simple-uploader/Uploader * @license MIT @@ -352,7 +352,7 @@ var event = _dereq_('./event') var File = _dereq_('./file') var Chunk = _dereq_('./chunk') -var version = '0.0.3' +var version = '0.0.4' // ie10+ var ie10plus = window.navigator.msPointerEnabled @@ -503,6 +503,12 @@ utils.extend(Uploader.prototype, { this.addFiles([file], evt) }, + cancel: function () { + for (var i = this.fileList.length - 1; i >= 0; i--) { + this.fileList[i].cancel() + } + }, + removeFile: function (file) { File.prototype.removeFile.call(this, file) this._trigger('fileRemoved', file) @@ -814,6 +820,7 @@ function File (uploader, file, parent) { this.fileList = [] this.chunks = [] this._errorFiles = [] + this.id = utils.uid() if (this.isRoot || !file) { this.file = null @@ -990,7 +997,7 @@ utils.extend(File.prototype, { this.averageSpeed = 0 uploader._trigger('fileSuccess', rootFile, this, message, chunk) if (rootFile.isComplete()) { - uploader._trigger('fileComplete', rootFile) + uploader._trigger('fileComplete', rootFile, this) } } else if (!this._progeressId) { triggerProgress() @@ -1092,12 +1099,6 @@ utils.extend(File.prototype, { }, cancel: function () { - if (this.isFolder) { - for (var i = this.files.length - 1; i >= 0; i--) { - this.files[i].cancel() - } - return - } this.uploader.removeFile(this) }, @@ -1337,8 +1338,11 @@ var isPlainObject = function (obj) { return serialize.call(obj) === '[object Object]' && Object.getPrototypeOf(obj) === oproto } +var i = 0 var utils = { - + uid: function () { + return ++i + }, noop: function () {}, bind: function (fn, context) { return function () { diff --git a/dist/uploader.min.js b/dist/uploader.min.js index 832f8e1..3f389fd 100644 --- a/dist/uploader.min.js +++ b/dist/uploader.min.js @@ -1,9 +1,9 @@ /*! * Uploader - Uploader library implements html5 file upload and provides multiple simultaneous, stable, fault tolerant and resumable uploads - * @version v0.0.3 + * @version v0.0.4 * @author dolymood * @link https://github.com/simple-uploader/Uploader * @license MIT */ -!function(t){if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Uploader=t()}}(function(){return function t(e,i,s){function r(a,o){if(!i[a]){if(!e[a]){var h="function"==typeof require&&require;if(!o&&h)return h(a,!0);if(n)return n(a,!0);throw new Error("Cannot find module '"+a+"'")}var u=i[a]={exports:{}};e[a][0].call(u.exports,function(t){var i=e[a][1][t];return r(i||t)},u,u.exports,t,e,i,s)}return i[a].exports}for(var n="function"==typeof require&&require,a=0;a-1?n.SUCCESS:this.uploader.opts.permanentErrors.indexOf(this.xhr.status)>-1||!t&&this.retries>=this.uploader.opts.maxChunkRetries?n.ERROR:(this.abort(),n.PENDING):n.PENDING},message:function(){return this.xhr?this.xhr.responseText:""},progress:function(){if(this.pendingRetry)return 0;var t=this.status();return t===n.SUCCESS||t===n.ERROR?1:t===n.PENDING?0:this.total>0?this.loaded/this.total:0},sizeUploaded:function(){var t=this.endByte-this.startByte;return this.status()!==n.SUCCESS&&(t=this.progress()*t),t},prepareXhrRequest:function(t,e,i,s){var n=r.evalOpts(this.uploader.opts.query,this.file,this,e);n=r.extend(this.getParams(),n);var a=r.evalOpts(this.uploader.opts.target,this.file,this,e),o=null;if("GET"===t||"octet"===i){var h=[];r.each(n,function(t,e){h.push([encodeURIComponent(e),encodeURIComponent(t)].join("="))}),a=this.getTarget(a,h),o=s||null}else o=new FormData,r.each(n,function(t,e){o.append(e,t)}),o.append(this.uploader.opts.fileParameterName,s,this.file.name);return this.xhr.open(t,a,!0),this.xhr.withCredentials=this.uploader.opts.withCredentials,r.each(r.evalOpts(this.uploader.opts.headers,this.file,this,e),function(t,e){this.xhr.setRequestHeader(e,t)},this),o}}),e.exports=s},{"./utils":5}],2:[function(t,e,i){var s=t("./utils").each,r={_eventData:null,on:function(t,e){this._eventData||(this._eventData={}),this._eventData[t]||(this._eventData[t]=[]);var i=!1;s(this._eventData[t],function(t){if(t===e)return i=!0,!1}),i||this._eventData[t].push(e)},off:function(t,e){this._eventData||(this._eventData={}),this._eventData[t]&&this._eventData[t].length&&(e?s(this._eventData[t],function(i,s){if(i===e)return this._eventData[t].splice(s,1),!1},this):this._eventData[t]=[])},trigger:function(t){if(this._eventData||(this._eventData={}),!this._eventData[t])return!0;var e=this._eventData[t].slice.call(arguments,1),i=!1;return s(this._eventData[t],function(t){i=!1===t.apply(this,e)||i},this),!i}};e.exports=r},{"./utils":5}],3:[function(t,e,i){function s(t){this.support=u,this.support&&(this.supportDirectory=l,this.filePaths={},this.opts=r.extend({},s.defaults,t||{}),a.call(this,this))}var r=t("./utils"),n=t("./event"),a=t("./file"),o=t("./chunk"),h=window.navigator.msPointerEnabled,u=function(){var t="slice",e=r.isDefined(window.File)&&r.isDefined(window.Blob)&&r.isDefined(window.FileList),i=null;return e&&(i=window.Blob.prototype,r.each(["slice","webkitSlice","mozSlice"],function(e){if(i[e])return t=e,!1}),e=!!i[t]),e&&(s.sliceName=t),i=null,e}(),l=function(){var t=window.document.createElement("input");t.type="file";var e="webkitdirectory"in t||"directory"in t;return t=null,e}();s.version="0.0.3",s.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,415,500,501],successStatuses:[200,201,202],onDropStopPropagation:!1,initFileFn:null,readFileFn:function(t,e,i,r,n){n.readFinished(t.file[s.sliceName](i,r,e))}},s.utils=r,s.event=n,s.File=a,s.Chunk=o,s.prototype=r.extend({},a.prototype),r.extend(s.prototype,n),r.extend(s.prototype,{constructor:s,_trigger:function(t){var e=r.toArray(arguments),i=!this.trigger.apply(this,arguments);return"catchAll"!==t&&(e.unshift("catchAll"),i=!this.trigger.apply(this,e)||i),!i},_triggerAsync:function(){var t=arguments;r.nextTick(function(){this._trigger.apply(this,t)},this)},addFiles:function(t,e){var i=[],s=this.fileList.length;r.each(t,function(t){if((!h||h&&t.size>0)&&(t.size%4096!=0||"."!==t.name&&"."!==t.fileName)){var s=this.generateUniqueIdentifier(t);if(this.opts.allowDuplicateUploads||!this.getFromUniqueIdentifier(s)){var r=new a(this,t,this);r.uniqueIdentifier=s,this._trigger("fileAdded",r,e)&&i.push(r)}}},this);var n=this.fileList.slice(s);this._trigger("filesAdded",i,n,e)&&(r.each(i,function(t){this.opts.singleFile&&this.files.length>0&&this.removeFile(this.files[0]),this.files.push(t)},this),this._trigger("filesSubmitted",i,n,e))},addFile:function(t,e){this.addFiles([t],e)},removeFile:function(t){a.prototype.removeFile.call(this,t),this._trigger("fileRemoved",t)},generateUniqueIdentifier:function(t){var e=this.opts.generateUniqueIdentifier;if(r.isFunction(e))return e(t);var i=t.relativePath||t.webkitRelativePath||t.fileName||t.name;return t.size+"-"+i.replace(/[^0-9a-zA-Z_-]/gim,"")},getFromUniqueIdentifier:function(t){var e=!1;return r.each(this.files,function(i){if(i.uniqueIdentifier===t)return e=i,!1}),e},uploadNextChunk:function(t){var e=!1,i=o.STATUS.PENDING;if(this.opts.prioritizeFirstAndLastChunk&&(r.each(this.files,function(t){return!t.paused&&t.chunks.length&&t.chunks[0].status()===i?(t.chunks[0].send(),e=!0,!1):!t.paused&&t.chunks.length>1&&t.chunks[t.chunks.length-1].status()===i?(t.chunks[t.chunks.length-1].send(),e=!0,!1):void 0}),e))return e;if(r.each(this.files,function(t){if(t.paused||r.each(t.chunks,function(t){if(t.status()===i)return t.send(),e=!0,!1}),e)return!1}),e)return!0;var s=!1;return r.each(this.files,function(t){if(!t.isComplete())return s=!0,!1}),s||t||this._triggerAsync("complete"),!1},upload:function(){var t=this._shouldUploadNext();if(!1!==t){this._trigger("uploadStart");for(var e=!1,i=1;i<=this.opts.simultaneousUploads-t;i++)e=this.uploadNextChunk(!0)||e;e||this._triggerAsync("complete")}},_shouldUploadNext:function(){var t=0,e=!0,i=this.opts.simultaneousUploads,s=o.STATUS.UPLOADING;return r.each(this.files,function(n){r.each(n.chunks,function(r){if(r.status()===s&&++t>=i)return e=!1,!1})}),e&&t},assignBrowse:function(t,e,i,s){void 0===t.length&&(t=[t]),r.each(t,function(t){var n;"INPUT"===t.tagName&&"file"===t.type?n=t:((n=document.createElement("input")).setAttribute("type","file"),r.extend(n.style,{visibility:"hidden",position:"absolute",width:"1px",height:"1px"}),t.appendChild(n),t.addEventListener("click",function(){n.click()},!1)),this.opts.singleFile||i||n.setAttribute("multiple","multiple"),e&&n.setAttribute("webkitdirectory","webkitdirectory"),s&&r.each(s,function(t,e){n.setAttribute(e,t)});var a=this;n.addEventListener("change",function(t){t.target.value&&(a.addFiles(t.target.files,t),t.target.value="")},!1)},this)},onDrop:function(t){this.opts.onDropStopPropagation&&t.stopPropagation(),t.preventDefault(),this._parseDataTransfer(t.dataTransfer,t)},_parseDataTransfer:function(t,e){t.items&&t.items[0]&&t.items[0].webkitGetAsEntry?this.webkitReadDataTransfer(t,e):this.addFiles(t.files,e)},webkitReadDataTransfer:function(t,e){function i(t){t.readEntries(function(e){e.length?(h+=e.length,r.each(e,function(t){if(t.isFile){var e=t.fullPath;t.file(function(t){s(t,e)},n)}else t.isDirectory&&i(t.createReader())}),i(t)):a()},n)}function s(t,e){t.relativePath=e.substring(1),u.push(t),a()}function n(t){throw t}function a(){0==--h&&o.addFiles(u,e)}var o=this,h=t.items.length,u=[];r.each(t.items,function(t){var e=t.webkitGetAsEntry();e?e.isFile?s(t.getAsFile(),e.fullPath):i(e.createReader()):a()})},_assignHelper:function(t,e,i){void 0===t.length&&(t=[t]);var s=i?"removeEventListener":"addEventListener";r.each(t,function(t){r.each(e,function(e,i){t[s](i,e,!1)},this)},this)},assignDrop:function(t){this._onDrop=r.bind(this.onDrop,this),this._assignHelper(t,{dragover:r.preventEvent,dragenter:r.preventEvent,drop:this._onDrop})},unAssignDrop:function(t){this._assignHelper(t,{dragover:r.preventEvent,dragenter:r.preventEvent,drop:this._onDrop},!0),this._onDrop=null}}),e.exports=s},{"./chunk":1,"./event":2,"./file":4,"./utils":5}],4:[function(t,e,i){function s(t,e,i){this.uploader=t,this.isRoot=this.isFolder=t===this,this.parent=i||null,this.files=[],this.fileList=[],this.chunks=[],this._errorFiles=[],this.isRoot||!e?this.file=null:n.isString(e)?(this.isFolder=!0,this.file=null,this.path=e,this.parent.path&&(e=e.substr(this.parent.path.length)),this.name="/"===e.charAt(e.length-1)?e.substr(0,e.length-1):e):(this.file=e,this.fileType=this.file.type,this.name=e.fileName||e.name,this.size=e.size,this.relativePath=e.relativePath||e.webkitRelativePath||this.name,this._parseFile()),this.paused=!1,this.error=!1,this.allError=!1,this.aborted=!1,this.averageSpeed=0,this.currentSpeed=0,this._lastProgressCallback=Date.now(),this._prevUploadedSize=0,this._prevProgress=0,this.bootstrap()}function r(t){var e=[],i=t.split("/"),s=i.length,r=1;if(i.splice(s-1,1),s--,i.length)for(;r<=s;)e.push(i.slice(0,r++).join("/")+"/");return e}var n=t("./utils"),a=t("./chunk");n.extend(s.prototype,{_parseFile:function(){var t=r(this.relativePath);if(t.length){var e=this.uploader.filePaths;n.each(t,function(i,r){var n=e[i];n||(n=new s(this.uploader,i,this.parent),e[i]=n,this._updateParentFileList(n)),this.parent=n,n.files.push(this),t[r+1]||n.fileList.push(this)},this)}else this._updateParentFileList()},_updateParentFileList:function(t){t||(t=this);var e=this.parent;e&&e.fileList.push(t)},_eachAccess:function(t,e){this.isFolder?n.each(this.files,function(e,i){return t.call(this,e,i)},this):e.call(this,this)},bootstrap:function(){if(!this.isFolder){var t=this.uploader.opts;n.isFunction(t.initFileFn)&&t.initFileFn.call(this,this),this.abort(!0),this._resetError(),this._prevProgress=0;for(var e=t.forceChunkSize?Math.ceil:Math.floor,i=Math.max(e(this.size/t.chunkSize),1),s=0;s=this.uploader.opts.progressCallbacksInterval},_chunkEvent:function(t,e,i){var s=this.uploader,r=a.STATUS,n=this,o=this.getRoot(),h=function(e){n._measureSpeed(e),s._trigger("fileProgress",o,n,t),n._lastProgressCallback=Date.now()};switch(e){case r.PROGRESS:this._checkProgress()&&h();break;case r.ERROR:this._error(),this.abort(!0),s._trigger("fileError",o,this,i,t);break;case r.SUCCESS:if(this.error)return;clearTimeout(this._progeressId),this._progeressId=0;var u=Date.now()-this._lastProgressCallback;u=0;t--)this.files[t].cancel();else this.uploader.removeFile(this)},retry:function(t){t?t.bootstrap():this._eachAccess(function(t){t.error&&t.bootstrap()},function(){this.bootstrap()}),this.uploader.upload()},abort:function(t){if(!this.aborted){this.currentSpeed=0,this.averageSpeed=0,this.aborted=!t;var e=this.chunks;t&&(this.chunks=[]);var i=a.STATUS.UPLOADING;n.each(e,function(t){t.status()===i&&(t.abort(),this.uploader.uploadNextChunk())},this)}},progress:function(){var t=0,e=0,i=0;return this._eachAccess(function(s,r){t+=s.progress()*s.size,e+=s.size,r===this.files.length-1&&(i=e>0?t/e:this.isComplete()?1:0)},function(){if(this.error)i=1;else{if(1===this.chunks.length)return this._prevProgress=Math.max(this._prevProgress,this.chunks[0].progress()),void(i=this._prevProgress);var t=0;n.each(this.chunks,function(e){t+=e.progress()*(e.endByte-e.startByte)});var e=t/this.size;this._prevProgress=Math.max(this._prevProgress,e>.9999?1:e),i=this._prevProgress}}),i},getSize:function(){var t=0;return this._eachAccess(function(e){t+=e.size},function(){t+=this.size}),t},getFormatSize:function(){var t=this.getSize();return n.formatSize(t)},getRoot:function(){if(this.isRoot)return this;for(var t=this.parent;t;){if(t.parent===this.uploader)return t;t=t.parent}return this},sizeUploaded:function(){var t=0;return this._eachAccess(function(e){t+=e.sizeUploaded()},function(){n.each(this.chunks,function(e){t+=e.sizeUploaded()})}),t},timeRemaining:function(){function t(t,e){return t&&!e?Number.POSITIVE_INFINITY:t||e?Math.floor(t/e):0}var e=0,i=0,s=0;return this._eachAccess(function(r,n){r.paused||r.error||(i+=r.size-r.sizeUploaded(),s+=r.averageSpeed),n===this.files.length-1&&(e=t(i,s))},function(){if(this.paused||this.error)e=0;else{var i=this.size-this.sizeUploaded();e=t(i,this.averageSpeed)}}),e},removeFile:function(t){if(t.isFolder)for(;t.files.length;){var e=t.files[t.files.length-1];this._removeFile(e)}this._removeFile(t),this._delFilePath(t)},_delFilePath:function(t){t.path&&this.filePaths&&delete this.filePaths[t.path],n.each(t.fileList,function(t){this._delFilePath(t)},this)},_removeFile:function(t){!t.isFolder&&n.each(this.files,function(e,i){if(e===t){this.files.splice(i,1),t.abort();for(var s=t.parent;s&&s!==this;)s._removeFile(t),s=s.parent;return!1}},this),t.parent===this&&n.each(this.fileList,function(e,i){if(e===t)return this.fileList.splice(i,1),!1},this),t.parent=null},getType:function(){return this.isFolder?"folder":this.file.type&&this.file.type.split("/")[1]},getExtension:function(){return this.isFolder?"":this.name.substr(2+(~-this.name.lastIndexOf(".")>>>0)).toLowerCase()}}),e.exports=s},{"./chunk":1,"./utils":5}],5:[function(t,e,i){var s=Object.prototype,r=Array.prototype,n=s.toString,a=function(t){return"[object Function]"===n.call(t)},o=Array.isArray||function(t){return"[object Array]"===n.call(t)},h=function(t){return"[object Object]"===n.call(t)&&Object.getPrototypeOf(t)===s},u={noop:function(){},bind:function(t,e){return function(){return t.apply(e,arguments)}},preventEvent:function(t){t.preventDefault()},stop:function(t){t.preventDefault(),t.stopPropagation()},nextTick:function(t,e){setTimeout(u.bind(t,e),0)},toArray:function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=t.length),r.slice.call(t,e,i)},isPlainObject:h,isFunction:a,isArray:o,isObject:function(t){return Object(t)===t},isString:function(t){return"string"==typeof t},isUndefined:function(t){return void 0===t},isDefined:function(t){return void 0!==t},each:function(t,e,i){if(u.isDefined(t.length))for(var s=0,r=t.length;s-1?n.SUCCESS:this.uploader.opts.permanentErrors.indexOf(this.xhr.status)>-1||!t&&this.retries>=this.uploader.opts.maxChunkRetries?n.ERROR:(this.abort(),n.PENDING):n.PENDING},message:function(){return this.xhr?this.xhr.responseText:""},progress:function(){if(this.pendingRetry)return 0;var t=this.status();return t===n.SUCCESS||t===n.ERROR?1:t===n.PENDING?0:this.total>0?this.loaded/this.total:0},sizeUploaded:function(){var t=this.endByte-this.startByte;return this.status()!==n.SUCCESS&&(t=this.progress()*t),t},prepareXhrRequest:function(t,e,i,s){var n=r.evalOpts(this.uploader.opts.query,this.file,this,e);n=r.extend(this.getParams(),n);var a=r.evalOpts(this.uploader.opts.target,this.file,this,e),o=null;if("GET"===t||"octet"===i){var h=[];r.each(n,function(t,e){h.push([encodeURIComponent(e),encodeURIComponent(t)].join("="))}),a=this.getTarget(a,h),o=s||null}else o=new FormData,r.each(n,function(t,e){o.append(e,t)}),o.append(this.uploader.opts.fileParameterName,s,this.file.name);return this.xhr.open(t,a,!0),this.xhr.withCredentials=this.uploader.opts.withCredentials,r.each(r.evalOpts(this.uploader.opts.headers,this.file,this,e),function(t,e){this.xhr.setRequestHeader(e,t)},this),o}}),e.exports=s},{"./utils":5}],2:[function(t,e,i){var s=t("./utils").each,r={_eventData:null,on:function(t,e){this._eventData||(this._eventData={}),this._eventData[t]||(this._eventData[t]=[]);var i=!1;s(this._eventData[t],function(t){if(t===e)return i=!0,!1}),i||this._eventData[t].push(e)},off:function(t,e){this._eventData||(this._eventData={}),this._eventData[t]&&this._eventData[t].length&&(e?s(this._eventData[t],function(i,s){if(i===e)return this._eventData[t].splice(s,1),!1},this):this._eventData[t]=[])},trigger:function(t){if(this._eventData||(this._eventData={}),!this._eventData[t])return!0;var e=this._eventData[t].slice.call(arguments,1),i=!1;return s(this._eventData[t],function(t){i=!1===t.apply(this,e)||i},this),!i}};e.exports=r},{"./utils":5}],3:[function(t,e,i){function s(t){this.support=u,this.support&&(this.supportDirectory=l,this.filePaths={},this.opts=r.extend({},s.defaults,t||{}),a.call(this,this))}var r=t("./utils"),n=t("./event"),a=t("./file"),o=t("./chunk"),h=window.navigator.msPointerEnabled,u=function(){var t="slice",e=r.isDefined(window.File)&&r.isDefined(window.Blob)&&r.isDefined(window.FileList),i=null;return e&&(i=window.Blob.prototype,r.each(["slice","webkitSlice","mozSlice"],function(e){if(i[e])return t=e,!1}),e=!!i[t]),e&&(s.sliceName=t),i=null,e}(),l=function(){var t=window.document.createElement("input");t.type="file";var e="webkitdirectory"in t||"directory"in t;return t=null,e}();s.version="0.0.4",s.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,415,500,501],successStatuses:[200,201,202],onDropStopPropagation:!1,initFileFn:null,readFileFn:function(t,e,i,r,n){n.readFinished(t.file[s.sliceName](i,r,e))}},s.utils=r,s.event=n,s.File=a,s.Chunk=o,s.prototype=r.extend({},a.prototype),r.extend(s.prototype,n),r.extend(s.prototype,{constructor:s,_trigger:function(t){var e=r.toArray(arguments),i=!this.trigger.apply(this,arguments);return"catchAll"!==t&&(e.unshift("catchAll"),i=!this.trigger.apply(this,e)||i),!i},_triggerAsync:function(){var t=arguments;r.nextTick(function(){this._trigger.apply(this,t)},this)},addFiles:function(t,e){var i=[],s=this.fileList.length;r.each(t,function(t){if((!h||h&&t.size>0)&&(t.size%4096!=0||"."!==t.name&&"."!==t.fileName)){var s=this.generateUniqueIdentifier(t);if(this.opts.allowDuplicateUploads||!this.getFromUniqueIdentifier(s)){var r=new a(this,t,this);r.uniqueIdentifier=s,this._trigger("fileAdded",r,e)&&i.push(r)}}},this);var n=this.fileList.slice(s);this._trigger("filesAdded",i,n,e)&&(r.each(i,function(t){this.opts.singleFile&&this.files.length>0&&this.removeFile(this.files[0]),this.files.push(t)},this),this._trigger("filesSubmitted",i,n,e))},addFile:function(t,e){this.addFiles([t],e)},cancel:function(){for(var t=this.fileList.length-1;t>=0;t--)this.fileList[t].cancel()},removeFile:function(t){a.prototype.removeFile.call(this,t),this._trigger("fileRemoved",t)},generateUniqueIdentifier:function(t){var e=this.opts.generateUniqueIdentifier;if(r.isFunction(e))return e(t);var i=t.relativePath||t.webkitRelativePath||t.fileName||t.name;return t.size+"-"+i.replace(/[^0-9a-zA-Z_-]/gim,"")},getFromUniqueIdentifier:function(t){var e=!1;return r.each(this.files,function(i){if(i.uniqueIdentifier===t)return e=i,!1}),e},uploadNextChunk:function(t){var e=!1,i=o.STATUS.PENDING;if(this.opts.prioritizeFirstAndLastChunk&&(r.each(this.files,function(t){return!t.paused&&t.chunks.length&&t.chunks[0].status()===i?(t.chunks[0].send(),e=!0,!1):!t.paused&&t.chunks.length>1&&t.chunks[t.chunks.length-1].status()===i?(t.chunks[t.chunks.length-1].send(),e=!0,!1):void 0}),e))return e;if(r.each(this.files,function(t){if(t.paused||r.each(t.chunks,function(t){if(t.status()===i)return t.send(),e=!0,!1}),e)return!1}),e)return!0;var s=!1;return r.each(this.files,function(t){if(!t.isComplete())return s=!0,!1}),s||t||this._triggerAsync("complete"),!1},upload:function(){var t=this._shouldUploadNext();if(!1!==t){this._trigger("uploadStart");for(var e=!1,i=1;i<=this.opts.simultaneousUploads-t;i++)e=this.uploadNextChunk(!0)||e;e||this._triggerAsync("complete")}},_shouldUploadNext:function(){var t=0,e=!0,i=this.opts.simultaneousUploads,s=o.STATUS.UPLOADING;return r.each(this.files,function(n){r.each(n.chunks,function(r){if(r.status()===s&&++t>=i)return e=!1,!1})}),e&&t},assignBrowse:function(t,e,i,s){void 0===t.length&&(t=[t]),r.each(t,function(t){var n;"INPUT"===t.tagName&&"file"===t.type?n=t:((n=document.createElement("input")).setAttribute("type","file"),r.extend(n.style,{visibility:"hidden",position:"absolute",width:"1px",height:"1px"}),t.appendChild(n),t.addEventListener("click",function(){n.click()},!1)),this.opts.singleFile||i||n.setAttribute("multiple","multiple"),e&&n.setAttribute("webkitdirectory","webkitdirectory"),s&&r.each(s,function(t,e){n.setAttribute(e,t)});var a=this;n.addEventListener("change",function(t){t.target.value&&(a.addFiles(t.target.files,t),t.target.value="")},!1)},this)},onDrop:function(t){this.opts.onDropStopPropagation&&t.stopPropagation(),t.preventDefault(),this._parseDataTransfer(t.dataTransfer,t)},_parseDataTransfer:function(t,e){t.items&&t.items[0]&&t.items[0].webkitGetAsEntry?this.webkitReadDataTransfer(t,e):this.addFiles(t.files,e)},webkitReadDataTransfer:function(t,e){function i(t){t.readEntries(function(e){e.length?(h+=e.length,r.each(e,function(t){if(t.isFile){var e=t.fullPath;t.file(function(t){s(t,e)},n)}else t.isDirectory&&i(t.createReader())}),i(t)):a()},n)}function s(t,e){t.relativePath=e.substring(1),u.push(t),a()}function n(t){throw t}function a(){0==--h&&o.addFiles(u,e)}var o=this,h=t.items.length,u=[];r.each(t.items,function(t){var e=t.webkitGetAsEntry();e?e.isFile?s(t.getAsFile(),e.fullPath):i(e.createReader()):a()})},_assignHelper:function(t,e,i){void 0===t.length&&(t=[t]);var s=i?"removeEventListener":"addEventListener";r.each(t,function(t){r.each(e,function(e,i){t[s](i,e,!1)},this)},this)},assignDrop:function(t){this._onDrop=r.bind(this.onDrop,this),this._assignHelper(t,{dragover:r.preventEvent,dragenter:r.preventEvent,drop:this._onDrop})},unAssignDrop:function(t){this._assignHelper(t,{dragover:r.preventEvent,dragenter:r.preventEvent,drop:this._onDrop},!0),this._onDrop=null}}),e.exports=s},{"./chunk":1,"./event":2,"./file":4,"./utils":5}],4:[function(t,e,i){function s(t,e,i){this.uploader=t,this.isRoot=this.isFolder=t===this,this.parent=i||null,this.files=[],this.fileList=[],this.chunks=[],this._errorFiles=[],this.id=n.uid(),this.isRoot||!e?this.file=null:n.isString(e)?(this.isFolder=!0,this.file=null,this.path=e,this.parent.path&&(e=e.substr(this.parent.path.length)),this.name="/"===e.charAt(e.length-1)?e.substr(0,e.length-1):e):(this.file=e,this.fileType=this.file.type,this.name=e.fileName||e.name,this.size=e.size,this.relativePath=e.relativePath||e.webkitRelativePath||this.name,this._parseFile()),this.paused=!1,this.error=!1,this.allError=!1,this.aborted=!1,this.averageSpeed=0,this.currentSpeed=0,this._lastProgressCallback=Date.now(),this._prevUploadedSize=0,this._prevProgress=0,this.bootstrap()}function r(t){var e=[],i=t.split("/"),s=i.length,r=1;if(i.splice(s-1,1),s--,i.length)for(;r<=s;)e.push(i.slice(0,r++).join("/")+"/");return e}var n=t("./utils"),a=t("./chunk");n.extend(s.prototype,{_parseFile:function(){var t=r(this.relativePath);if(t.length){var e=this.uploader.filePaths;n.each(t,function(i,r){var n=e[i];n||(n=new s(this.uploader,i,this.parent),e[i]=n,this._updateParentFileList(n)),this.parent=n,n.files.push(this),t[r+1]||n.fileList.push(this)},this)}else this._updateParentFileList()},_updateParentFileList:function(t){t||(t=this);var e=this.parent;e&&e.fileList.push(t)},_eachAccess:function(t,e){this.isFolder?n.each(this.files,function(e,i){return t.call(this,e,i)},this):e.call(this,this)},bootstrap:function(){if(!this.isFolder){var t=this.uploader.opts;n.isFunction(t.initFileFn)&&t.initFileFn.call(this,this),this.abort(!0),this._resetError(),this._prevProgress=0;for(var e=t.forceChunkSize?Math.ceil:Math.floor,i=Math.max(e(this.size/t.chunkSize),1),s=0;s=this.uploader.opts.progressCallbacksInterval},_chunkEvent:function(t,e,i){var s=this.uploader,r=a.STATUS,n=this,o=this.getRoot(),h=function(e){n._measureSpeed(e),s._trigger("fileProgress",o,n,t),n._lastProgressCallback=Date.now()};switch(e){case r.PROGRESS:this._checkProgress()&&h();break;case r.ERROR:this._error(),this.abort(!0),s._trigger("fileError",o,this,i,t);break;case r.SUCCESS:if(this.error)return;clearTimeout(this._progeressId),this._progeressId=0;var u=Date.now()-this._lastProgressCallback;u0?t/e:this.isComplete()?1:0)},function(){if(this.error)i=1;else{if(1===this.chunks.length)return this._prevProgress=Math.max(this._prevProgress,this.chunks[0].progress()),void(i=this._prevProgress);var t=0;n.each(this.chunks,function(e){t+=e.progress()*(e.endByte-e.startByte)});var e=t/this.size;this._prevProgress=Math.max(this._prevProgress,e>.9999?1:e),i=this._prevProgress}}),i},getSize:function(){var t=0;return this._eachAccess(function(e){t+=e.size},function(){t+=this.size}),t},getFormatSize:function(){var t=this.getSize();return n.formatSize(t)},getRoot:function(){if(this.isRoot)return this;for(var t=this.parent;t;){if(t.parent===this.uploader)return t;t=t.parent}return this},sizeUploaded:function(){var t=0;return this._eachAccess(function(e){t+=e.sizeUploaded()},function(){n.each(this.chunks,function(e){t+=e.sizeUploaded()})}),t},timeRemaining:function(){function t(t,e){return t&&!e?Number.POSITIVE_INFINITY:t||e?Math.floor(t/e):0}var e=0,i=0,s=0;return this._eachAccess(function(r,n){r.paused||r.error||(i+=r.size-r.sizeUploaded(),s+=r.averageSpeed),n===this.files.length-1&&(e=t(i,s))},function(){if(this.paused||this.error)e=0;else{var i=this.size-this.sizeUploaded();e=t(i,this.averageSpeed)}}),e},removeFile:function(t){if(t.isFolder)for(;t.files.length;){var e=t.files[t.files.length-1];this._removeFile(e)}this._removeFile(t),this._delFilePath(t)},_delFilePath:function(t){t.path&&this.filePaths&&delete this.filePaths[t.path],n.each(t.fileList,function(t){this._delFilePath(t)},this)},_removeFile:function(t){!t.isFolder&&n.each(this.files,function(e,i){if(e===t){this.files.splice(i,1),t.abort();for(var s=t.parent;s&&s!==this;)s._removeFile(t),s=s.parent;return!1}},this),t.parent===this&&n.each(this.fileList,function(e,i){if(e===t)return this.fileList.splice(i,1),!1},this),t.parent=null},getType:function(){return this.isFolder?"folder":this.file.type&&this.file.type.split("/")[1]},getExtension:function(){return this.isFolder?"":this.name.substr(2+(~-this.name.lastIndexOf(".")>>>0)).toLowerCase()}}),e.exports=s},{"./chunk":1,"./utils":5}],5:[function(t,e,i){var s=Object.prototype,r=Array.prototype,n=s.toString,a=function(t){return"[object Function]"===n.call(t)},o=Array.isArray||function(t){return"[object Array]"===n.call(t)},h=function(t){return"[object Object]"===n.call(t)&&Object.getPrototypeOf(t)===s},u=0,l={uid:function(){return++u},noop:function(){},bind:function(t,e){return function(){return t.apply(e,arguments)}},preventEvent:function(t){t.preventDefault()},stop:function(t){t.preventDefault(),t.stopPropagation()},nextTick:function(t,e){setTimeout(l.bind(t,e),0)},toArray:function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=t.length),r.slice.call(t,e,i)},isPlainObject:h,isFunction:a,isArray:o,isObject:function(t){return Object(t)===t},isString:function(t){return"string"==typeof t},isUndefined:function(t){return void 0===t},isDefined:function(t){return void 0!==t},each:function(t,e,i){if(l.isDefined(t.length))for(var s=0,r=t.length;s", "license": "MIT", "description": "Uploader library implements html5 file upload and provides multiple simultaneous, stable, fault tolerant and resumable uploads",