diff --git a/bower.json b/bower.json index 59a0037..0e169a0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ember-droplet", - "version": "1.0.1", + "version": "2.0.0", "homepage": "https://github.com/Wildhoney/EmberDroplet", "authors": [ "Adam Timberlake " diff --git a/dist/ember-droplet.js b/dist/ember-droplet.js index 08edc64..330655e 100644 --- a/dist/ember-droplet.js +++ b/dist/ember-droplet.js @@ -1,5 +1,7 @@ 'use strict'; +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } (function main($window, $Ember, $FileReader) { @@ -8,7 +10,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr // Extract the commonly accessed Ember methods. - var _computed, _computed2, _computed3, _computed4; + var _computed, _computed2, _computed3, _computed4, _computed5; var Mixin = $Ember.Mixin; var String = $Ember.String; @@ -247,7 +249,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr * @property options * @type {Object} */ - options: {}, + options: _extends({}, DEFAULT_OPTIONS), /** * @property hooks @@ -275,16 +277,19 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr var _this = this; set(this, 'files', []); - set(this, 'hooks', {}); - - Object.keys(DEFAULT_OPTIONS).forEach(function (key) { - // Copy across all of the options into the options map. - set(_this, 'options.' + key, DEFAULT_OPTIONS[key]); - }); - - set(this, 'options.requestHeaders', {}); - set(this, 'options.requestPostData', {}); + //set(this, 'hooks', {}); + // + //Object.keys(DEFAULT_OPTIONS).forEach(key => { + // + // // Copy across all of the options into the options map. + // set(this, `options.${key}`, DEFAULT_OPTIONS[key]); + // + //}); + // + //set(this, 'options.requestHeaders', {}); + //set(this, 'options.requestPostData', {}); + // this.DropletEventBus && this.DropletEventBus.subscribe(EVENT_NAME, this, function () { for (var _len = arguments.length, files = Array(_len), _key = 0; _key < _len; _key++) { @@ -375,11 +380,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr * @property requestSize * @return {Array} */ - requestSize: computed(function () { + requestSize: (_computed5 = computed(function () { return get(this, 'validFiles').reduce(function (size, model) { return size + model.getFileSize(); }, 0); - }).property(COMPUTED_OBSERVER), + })).property.apply(_computed5, _toConsumableArray(COMPUTED_OBSERVER)), /** * @method getFiles @@ -933,6 +938,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr * @type {Array} */ attributeBindings: ['disabled', 'name', 'type', 'multiple'], + attributeBindings: ['disabled', 'name', 'type', 'multiple'], /** * @property file diff --git a/dist/ember-droplet.min.js b/dist/ember-droplet.min.js index 735f2cf..8d8d3cc 100644 --- a/dist/ember-droplet.min.js +++ b/dist/ember-droplet.min.js @@ -1 +1 @@ -"use strict";function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);ti;i++)r[i]=arguments[i];e.send.apply(e,["prepareFiles"].concat(r))}),this._super()},willDestroy:function(){this._super();var e=this.get("lastRequest");e&&(delete e.upload.onprogress,delete e.upload.onload,delete e.upload.onerror,this.send("abortUpload"))},invokeHook:function(e){for(var t=p(this,"hooks")[e]||function(){},r=arguments.length,i=Array(r>1?r-1:0),n=1;r>n;n++)i[n-1]=arguments[n];t.apply(void 0,i)},uploadStatus:l(function(){return{uploading:!1,percentComplete:0,error:!1}}),validFiles:(i=l(function(){return this.getFiles(f.VALID)})).property.apply(i,_toConsumableArray(D)),invalidFiles:(n=l(function(){return this.getFiles(f.INVALID)})).property.apply(n,_toConsumableArray(D)),uploadedFiles:(s=l(function(){return this.getFiles(f.UPLOADED)})).property.apply(s,_toConsumableArray(D)),deletedFiles:(o=l(function(){return this.getFiles(f.DELETED)})).property.apply(o,_toConsumableArray(D)),requestSize:l(function(){return p(this,"validFiles").reduce(function(e,t){return e+t.getFileSize()},0)}).property(D),getFiles:function(e){return e?this.files.filter(function(t){return t.statusType&e}):this.files},isValid:function F(e){var r=this;if(!(e instanceof t.Object))return!1;var i=function(e){return function(){var t=r.get("options.mimeTypes").some(function(e){return e instanceof RegExp}),i=p(r,"options.mimeTypes");return t?i.some(function(t){var r=t===e,i=!!e.match(t);return r||i}):!!~i.indexOf(e)}},n=function(e){return function(){return e<=Number(p(r,"options.maximumSize"))}},s=function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];return function(e){return t.reverse().every(function(t){return t(e)})}},F=s(i(e.getMIMEType()),n(e.getFileSize()));return F(e)},getFormData:function(){var t=new e.FormData,r=this.get("options.useArray")?"file[]":"file",i=this.get("options.requestPostData"),n=p(this,"validFiles").map(function(e){return e.file});return n.forEach(function(e){t.append(r,e)}),Object.keys(i).forEach(function(e){t.append(e,i[e])}),t},addProgressListener:function(e){var t=this;e.addEventListener("progress",function(e){if(e.lengthComputable){var r=e.loaded/p(t,"requestSize")*100;c(t,"uploadStatus.percentComplete",Math.round(r))}})},getRequest:function(){var e=this,r=function(e){return"function"==typeof e},i=r(p(this,"url"))?p(this,"url").apply(this):p(this,"url"),n=p(this,"options.requestMethod")||"POST",s=this.getFormData(),o=this.get("options.requestHeaders");p(this,"options.includeXFileSize")&&(o["X-File-Size"]=this.get("requestSize"));var a=t.$.ajax({url:i,method:n,headers:o,data:s,processData:!1,contentType:!1,xhr:function u(){var u=t.$.ajaxSettings.xhr();return e.addProgressListener(u.upload),c(e,"lastRequest",u),u}});return c(this,"lastResolver",a),a},actions:{uploadFiles:function(){var e=this,r=p(this,"files").filter(function(e){return e.statusType&f.VALID}),i=this.getRequest();c(this,"abortedUpload",!1),c(this,"uploadStatus.percentComplete",0),c(this,"uploadStatus.uploading",!0),c(this,"uploadStatus.error",!1);var n=function(t,n){e.invokeHook("promiseResolver",t,n,r),i.done(t).fail(n)},s=function(t){e.invokeHook.apply(e,["didUpload"].concat(_toConsumableArray(t.files))),r.map(function(e){return e.setStatusType(f.UPLOADED)})},o=function(t){var r=t.request,i=t.textStatus,n=t.errorThrown;p(e,"abortedUpload")!==!0&&c(e,"uploadStatus.error",{request:r,textStatus:i,errorThrown:n})},a=function(){c(e,"uploadStatus.uploading",!1),e.invokeHook("didComplete")};return new t.RSVP.Promise(n).then(s,o)["finally"](a)},abortUpload:function(){var e=p(this,"lastResolver");e&&p(this,"uploadStatus.uploading")&&(c(this,"abortedUpload",!0),e.abort(),c(this,"uploadStatus.uploading",!1))},mimeTypes:function(e){var t=arguments.length<=1||void 0===arguments[1]?v.PUSH:arguments[1];t===v.SET&&c(this,"options.mimeTypes",[]),e=Array.isArray(e)?e:[e];var r=[].concat(_toConsumableArray(p(this,"options.mimeTypes")),_toConsumableArray(e));c(this,"options.mimeTypes",r)},addFiles:function(){for(var e=this,r=arguments.length,i=Array(r),n=0;r>n;n++)i[n]=arguments[n];var s=i.map(function(r){var i=e.get("validFiles.length")===e.get("options.maximumValidFiles");if(r instanceof t.Object){var n=function(){var t=e.isValid(r)&&!i?f.VALID:f.INVALID;return d(function(){return r.setStatusType(t)}),p(e,"files").pushObject(r),{v:r}}();if("object"==typeof n)return n.v}}).filter(function(e){return"undefined"!=typeof e});s.length&&this.invokeHook.apply(this,["didAdd"].concat(_toConsumableArray(s))),this.get("options.uploadImmediately")&&this.send.apply(this,["uploadFiles"].concat(_toConsumableArray(s)))},prepareFiles:function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];t=m(t);var i=t.reduce(function(e,t){var r=y.create({file:t});return e.push(r),e},[]);return this.send.apply(this,["addFiles"].concat(_toConsumableArray(i))),i},deleteFiles:function(){for(var e=this,t=arguments.length,r=Array(t),i=0;t>i;i++)r[i]=arguments[i];var n=r.map(function(t){var r=!!~p(e,"files").indexOf(t);return r?(t.setStatusType(f.DELETED),t):void 0}).filter(function(e){return"undefined"!=typeof e});n.length&&this.invokeHook.apply(this,["didDelete"].concat(_toConsumableArray(n)))},clearFiles:function(){var e=this,t=[].concat(_toConsumableArray(this.get("validFiles")),_toConsumableArray(this.get("invalidFiles")));t.forEach(function(t){return e.send("deleteFiles",t)})}}});var E=function(e){e.preventDefault(),e.stopPropagation()};e.Droplet.Area=a.create({classNames:["droppable"],drop:function(e){return E(e),this.handleFiles(e.dataTransfer.files)},handleFiles:function(e){var t;return this.DropletEventBus&&(t=this.DropletEventBus).publish.apply(t,[h].concat(_toConsumableArray(m(e)))),e},dragEnter:E,dragOver:E,dragLeave:E}),e.Droplet.Preview=a.create({tagName:"img",attributeBindings:["src"],reader:r,image:{file:{type:""}},isImage:function(e){return!!e.type.match(/^image\//i)},didInsertElement:function(){var e=this,t=this.get("reader"),r=new t,i=p(this,"image.file");return this.isImage(i)?(r.addEventListener("load",d.bind(this,function(t){e.get("isDestroyed")!==!0&&c(e,"src",t.target.result)})),void r.readAsDataURL(i)):void this.destroy()}}),e.Droplet.MultipleInput=a.create({tagName:"input",classNames:"files",attributeBindings:["disabled","name","type","multiple"],type:"file",multiple:"multiple",change:function(){var e=this.get("element").files;this.handleFiles(e)},handleFiles:function(e){var t;this.DropletEventBus&&(t=this.DropletEventBus).publish.apply(t,[h].concat(_toConsumableArray(m(e))))}}),e.Droplet.SingleInput=a.create(e.Droplet.MultipleInput,{multiple:!1})}(window,window.Ember,window.FileReader); \ No newline at end of file +"use strict";function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);tn;n++)r[n]=arguments[n];e.send.apply(e,["prepareFiles"].concat(r))}),this._super()},willDestroy:function(){this._super();var e=this.get("lastRequest");e&&(delete e.upload.onprogress,delete e.upload.onload,delete e.upload.onerror,this.send("abortUpload"))},invokeHook:function(e){for(var t=c(this,"hooks")[e]||function(){},r=arguments.length,n=Array(r>1?r-1:0),i=1;r>i;i++)n[i-1]=arguments[i];t.apply(void 0,n)},uploadStatus:p(function(){return{uploading:!1,percentComplete:0,error:!1}}),validFiles:(n=p(function(){return this.getFiles(h.VALID)})).property.apply(n,_toConsumableArray(D)),invalidFiles:(i=p(function(){return this.getFiles(h.INVALID)})).property.apply(i,_toConsumableArray(D)),uploadedFiles:(s=p(function(){return this.getFiles(h.UPLOADED)})).property.apply(s,_toConsumableArray(D)),deletedFiles:(a=p(function(){return this.getFiles(h.DELETED)})).property.apply(a,_toConsumableArray(D)),requestSize:(o=p(function(){return c(this,"validFiles").reduce(function(e,t){return e+t.getFileSize()},0)})).property.apply(o,_toConsumableArray(D)),getFiles:function(e){return e?this.files.filter(function(t){return t.statusType&e}):this.files},isValid:function S(e){var r=this;if(!(e instanceof t.Object))return!1;var n=function(e){return function(){var t=r.get("options.mimeTypes").some(function(e){return e instanceof RegExp}),n=c(r,"options.mimeTypes");return t?n.some(function(t){var r=t===e,n=!!e.match(t);return r||n}):!!~n.indexOf(e)}},i=function(e){return function(){return e<=Number(c(r,"options.maximumSize"))}},s=function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];return function(e){return t.reverse().every(function(t){return t(e)})}},S=s(n(e.getMIMEType()),i(e.getFileSize()));return S(e)},getFormData:function(){var t=new e.FormData,r=this.get("options.useArray")?"file[]":"file",n=this.get("options.requestPostData"),i=c(this,"validFiles").map(function(e){return e.file});return i.forEach(function(e){t.append(r,e)}),Object.keys(n).forEach(function(e){t.append(e,n[e])}),t},addProgressListener:function(e){var t=this;e.addEventListener("progress",function(e){if(e.lengthComputable){var r=e.loaded/c(t,"requestSize")*100;d(t,"uploadStatus.percentComplete",Math.round(r))}})},getRequest:function(){var e=this,r=function(e){return"function"==typeof e},n=r(c(this,"url"))?c(this,"url").apply(this):c(this,"url"),i=c(this,"options.requestMethod")||"POST",s=this.getFormData(),a=this.get("options.requestHeaders");c(this,"options.includeXFileSize")&&(a["X-File-Size"]=this.get("requestSize"));var o=t.$.ajax({url:n,method:i,headers:a,data:s,processData:!1,contentType:!1,xhr:function u(){var u=t.$.ajaxSettings.xhr();return e.addProgressListener(u.upload),d(e,"lastRequest",u),u}});return d(this,"lastResolver",o),o},actions:{uploadFiles:function(){var e=this,r=c(this,"files").filter(function(e){return e.statusType&h.VALID}),n=this.getRequest();d(this,"abortedUpload",!1),d(this,"uploadStatus.percentComplete",0),d(this,"uploadStatus.uploading",!0),d(this,"uploadStatus.error",!1);var i=function(t,i){e.invokeHook("promiseResolver",t,i,r),n.done(t).fail(i)},s=function(t){e.invokeHook.apply(e,["didUpload"].concat(_toConsumableArray(t.files))),r.map(function(e){return e.setStatusType(h.UPLOADED)})},a=function(t){var r=t.request,n=t.textStatus,i=t.errorThrown;c(e,"abortedUpload")!==!0&&d(e,"uploadStatus.error",{request:r,textStatus:n,errorThrown:i})},o=function(){d(e,"uploadStatus.uploading",!1),e.invokeHook("didComplete")};return new t.RSVP.Promise(i).then(s,a)["finally"](o)},abortUpload:function(){var e=c(this,"lastResolver");e&&c(this,"uploadStatus.uploading")&&(d(this,"abortedUpload",!0),e.abort(),d(this,"uploadStatus.uploading",!1))},mimeTypes:function(e){var t=arguments.length<=1||void 0===arguments[1]?b.PUSH:arguments[1];t===b.SET&&d(this,"options.mimeTypes",[]),e=Array.isArray(e)?e:[e];var r=[].concat(_toConsumableArray(c(this,"options.mimeTypes")),_toConsumableArray(e));d(this,"options.mimeTypes",r)},addFiles:function(){for(var e=this,r=arguments.length,n=Array(r),i=0;r>i;i++)n[i]=arguments[i];var s=n.map(function(r){var n=e.get("validFiles.length")===e.get("options.maximumValidFiles");if(r instanceof t.Object){var i=function(){var t=e.isValid(r)&&!n?h.VALID:h.INVALID;return f(function(){return r.setStatusType(t)}),c(e,"files").pushObject(r),{v:r}}();if("object"==typeof i)return i.v}}).filter(function(e){return"undefined"!=typeof e});s.length&&this.invokeHook.apply(this,["didAdd"].concat(_toConsumableArray(s))),this.get("options.uploadImmediately")&&this.send.apply(this,["uploadFiles"].concat(_toConsumableArray(s)))},prepareFiles:function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];t=g(t);var n=t.reduce(function(e,t){var r=v.create({file:t});return e.push(r),e},[]);return this.send.apply(this,["addFiles"].concat(_toConsumableArray(n))),n},deleteFiles:function(){for(var e=this,t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];var i=r.map(function(t){var r=!!~c(e,"files").indexOf(t);return r?(t.setStatusType(h.DELETED),t):void 0}).filter(function(e){return"undefined"!=typeof e});i.length&&this.invokeHook.apply(this,["didDelete"].concat(_toConsumableArray(i)))},clearFiles:function(){var e=this,t=[].concat(_toConsumableArray(this.get("validFiles")),_toConsumableArray(this.get("invalidFiles")));t.forEach(function(t){return e.send("deleteFiles",t)})}}});var F=function(e){e.preventDefault(),e.stopPropagation()};e.Droplet.Area=u.create({classNames:["droppable"],drop:function(e){return F(e),this.handleFiles(e.dataTransfer.files)},handleFiles:function(e){var t;return this.DropletEventBus&&(t=this.DropletEventBus).publish.apply(t,[m].concat(_toConsumableArray(g(e)))),e},dragEnter:F,dragOver:F,dragLeave:F}),e.Droplet.Preview=u.create({tagName:"img",attributeBindings:["src"],reader:r,image:{file:{type:""}},isImage:function(e){return!!e.type.match(/^image\//i)},didInsertElement:function(){var e=this,t=this.get("reader"),r=new t,n=c(this,"image.file");return this.isImage(n)?(r.addEventListener("load",f.bind(this,function(t){e.get("isDestroyed")!==!0&&d(e,"src",t.target.result)})),void r.readAsDataURL(n)):void this.destroy()}}),e.Droplet.MultipleInput=u.create({tagName:"input",classNames:"files",attributeBindings:["disabled","name","type","multiple"],attributeBindings:["disabled","name","type","multiple"],type:"file",multiple:"multiple",change:function(){var e=this.get("element").files;this.handleFiles(e)},handleFiles:function(e){var t;this.DropletEventBus&&(t=this.DropletEventBus).publish.apply(t,[m].concat(_toConsumableArray(g(e))))}}),e.Droplet.SingleInput=u.create(e.Droplet.MultipleInput,{multiple:!1})}(window,window.Ember,window.FileReader); \ No newline at end of file diff --git a/package.json b/package.json index ef88833..1dffa81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-droplet", - "version": "1.0.1", + "version": "2.0.0", "author": "Adam Timberlake", "dependencies": {}, "devDependencies": {