UNPKG

angular-file-picker-fixed

Version:
3 lines (2 loc) 3.89 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common"],t):t(e["angular-file-picker-fixed"]={},e.ng.core,e.ng.common)}(this,function(e,t,r){"use strict";var n=function(){function e(e,t,r,n,i,a){this._lastModifiedDate=e,this._name=t,this._size=r,this._type=n,this._readMode=i,this._content=a}return Object.defineProperty(e.prototype,"lastModifiedDate",{get:function(){return this._lastModifiedDate},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return this._type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readMode",{get:function(){return this._readMode},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"content",{get:function(){return this._content},enumerable:!0,configurable:!0}),e}(),i={};i.arrayBuffer=0,i.binaryString=1,i.dataURL=2,i.text=3,i[i.arrayBuffer]="arrayBuffer",i[i.binaryString]="binaryString",i[i.dataURL]="dataURL",i[i.text]="text";var a=function(){function e(e,r){this.el=e,this.renderer=r,this.accept="",this.filePick=new t.EventEmitter,this.readStart=new t.EventEmitter,this.readEnd=new t.EventEmitter}return Object.defineProperty(e.prototype,"multiple",{get:function(){return this._multiple},set:function(e){this._multiple=function(e){return null!=e&&""+e!="false"}(e)},enumerable:!0,configurable:!0}),e.prototype.ngOnInit=function(){var e=this;this.input=this.renderer.createElement("input"),this.renderer.appendChild(this.el.nativeElement,this.input),this.renderer.setAttribute(this.input,"type","file"),this.renderer.setAttribute(this.input,"accept",this.accept),this.renderer.setStyle(this.input,"display","none"),this.multiple&&this.renderer.setAttribute(this.input,"multiple","multiple"),this.renderer.listen(this.input,"change",function(t){var r=t.target.files.length;e.readStart.emit(t.target.files.length),Promise.all(Array.from(t.target.files).map(function(t){return e.readFile(t)})).then(function(){return e.readEnd.emit(r)})})},e.prototype.reset=function(){this.input?this.input.value=null:console.error("It seems that ngOnInit() has not been executed or that the hidden input element is null. Did you mess with the DOM?")},e.prototype.browse=function(){this.input?this.input.click():console.error("It seems that ngOnInit() has not been executed or that the hidden input element is null. Did you mess with the DOM?")},e.prototype.readFile=function(e){var t=this;return new Promise(function(r,a){var o=new FileReader;switch(o.onload=function(i){var a=i.target,o=new n(e.lastModifiedDate,e.name,e.size,e.type,t.readMode,a.result);t.filePick.emit(o),r()},t.readMode){case i.arrayBuffer:o.readAsArrayBuffer(e);break;case i.binaryString:o.readAsBinaryString(e);break;case i.text:o.readAsText(e);break;case i.dataURL:default:o.readAsDataURL(e)}})},e}();a.decorators=[{type:t.Directive,args:[{selector:"[ngFilePicker]"}]}],a.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Renderer2}]},a.propDecorators={accept:[{type:t.Input}],multiple:[{type:t.Input}],readMode:[{type:t.Input,args:["ngFilePicker"]}],filePick:[{type:t.Output}],readStart:[{type:t.Output}],readEnd:[{type:t.Output}],browse:[{type:t.HostListener,args:["click"]}]};var o=function(){return function(){}}();o.decorators=[{type:t.NgModule,args:[{imports:[r.CommonModule],declarations:[a],exports:[a]}]}],o.ctorParameters=function(){return[]},e.AngularFilePickerModule=o,e.FilePickerDirective=a,e.ReadMode=i,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=angular-file-picker-fixed.umd.min.js.map