UNPKG

5.59 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/core"),require("ngx-window-token"),require("rxjs")):"function"==typeof define&&define.amd?define("ngx-clipboard",["exports","@angular/common","@angular/core","ngx-window-token","rxjs"],e):e((t=t||self)["ngx-clipboard"]={},t.ng.common,t.ng.core,t.i2,t.rxjs)}(this,(function(t,e,o,r,n){"use strict";var i=function(){function t(t,e){this.document=t,this.window=e,this.copySubject=new n.Subject,this.copyResponse$=this.copySubject.asObservable(),this.config={}}return t.prototype.configure=function(t){this.config=t},t.prototype.copy=function(t){if(!this.isSupported||!t)return this.pushCopyResponse({isSuccess:!1,content:t});var e=this.copyFromContent(t);return e?this.pushCopyResponse({content:t,isSuccess:e}):this.pushCopyResponse({isSuccess:!1,content:t})},Object.defineProperty(t.prototype,"isSupported",{get:function(){return!!this.document.queryCommandSupported&&!!this.document.queryCommandSupported("copy")&&!!this.window},enumerable:!1,configurable:!0}),t.prototype.isTargetValid=function(t){if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement){if(t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');return!0}throw new Error("Target should be input or textarea")},t.prototype.copyFromInputElement=function(t,e){void 0===e&&(e=!0);try{this.selectTarget(t);var o=this.copyText();return this.clearSelection(e?t:void 0,this.window),o&&this.isCopySuccessInIE11()}catch(t){return!1}},t.prototype.isCopySuccessInIE11=function(){var t=this.window.clipboardData;return!(t&&t.getData&&!t.getData("Text"))},t.prototype.copyFromContent=function(t,e){if(void 0===e&&(e=this.document.body),this.tempTextArea&&!e.contains(this.tempTextArea)&&this.destroy(this.tempTextArea.parentElement||void 0),!this.tempTextArea){this.tempTextArea=this.createTempTextArea(this.document,this.window);try{e.appendChild(this.tempTextArea)}catch(t){throw new Error("Container should be a Dom element")}}this.tempTextArea.value=t;var o=this.copyFromInputElement(this.tempTextArea,!1);return this.config.cleanUpAfterCopy&&this.destroy(this.tempTextArea.parentElement||void 0),o},t.prototype.destroy=function(t){void 0===t&&(t=this.document.body),this.tempTextArea&&(t.removeChild(this.tempTextArea),this.tempTextArea=void 0)},t.prototype.selectTarget=function(t){return t.select(),t.setSelectionRange(0,t.value.length),t.value.length},t.prototype.copyText=function(){return this.document.execCommand("copy")},t.prototype.clearSelection=function(t,e){var o;t&&t.focus(),null===(o=e.getSelection())||void 0===o||o.removeAllRanges()},t.prototype.createTempTextArea=function(t,e){var o,r="rtl"===t.documentElement.getAttribute("dir");(o=t.createElement("textarea")).style.fontSize="12pt",o.style.border="0",o.style.padding="0",o.style.margin="0",o.style.position="absolute",o.style[r?"right":"left"]="-9999px";var n=e.pageYOffset||t.documentElement.scrollTop;return o.style.top=n+"px",o.setAttribute("readonly",""),o},t.prototype.pushCopyResponse=function(t){this.copySubject.next(t)},t.prototype.pushCopyReponse=function(t){this.pushCopyResponse(t)},t}();i.ɵprov=o.ɵɵdefineInjectable({factory:function(){return new i(o.ɵɵinject(e.DOCUMENT),o.ɵɵinject(r.WINDOW,8))},token:i,providedIn:"root"}),i.decorators=[{type:o.Injectable,args:[{providedIn:"root"}]}],i.ctorParameters=function(){return[{type:void 0,decorators:[{type:o.Inject,args:[e.DOCUMENT]}]},{type:void 0,decorators:[{type:o.Optional},{type:o.Inject,args:[r.WINDOW]}]}]};var s=function(){function t(t){this.clipboardSrv=t,this.cbOnSuccess=new o.EventEmitter,this.cbOnError=new o.EventEmitter}return t.prototype.ngOnInit=function(){},t.prototype.ngOnDestroy=function(){this.clipboardSrv.destroy(this.container)},t.prototype.onClick=function(t){this.clipboardSrv.isSupported?this.targetElm&&this.clipboardSrv.isTargetValid(this.targetElm)?this.handleResult(this.clipboardSrv.copyFromInputElement(this.targetElm),this.targetElm.value,t):this.cbContent&&this.handleResult(this.clipboardSrv.copyFromContent(this.cbContent,this.container),this.cbContent,t):this.handleResult(!1,void 0,t)},t.prototype.handleResult=function(t,e,o){var r={isSuccess:t,event:o};t?(r=Object.assign(r,{content:e,successMessage:this.cbSuccessMsg}),this.cbOnSuccess.emit(r)):this.cbOnError.emit(r),this.clipboardSrv.pushCopyResponse(r)},t}();s.decorators=[{type:o.Directive,args:[{selector:"[ngxClipboard]"}]}],s.ctorParameters=function(){return[{type:i}]},s.propDecorators={targetElm:[{type:o.Input,args:["ngxClipboard"]}],container:[{type:o.Input}],cbContent:[{type:o.Input}],cbSuccessMsg:[{type:o.Input}],cbOnSuccess:[{type:o.Output}],cbOnError:[{type:o.Output}],onClick:[{type:o.HostListener,args:["click",["$event.target"]]}]};var p=function(){function t(t,e,o){this._clipboardService=t,this._viewContainerRef=e,this._templateRef=o}return t.prototype.ngOnInit=function(){this._clipboardService.isSupported&&this._viewContainerRef.createEmbeddedView(this._templateRef)},t}();p.decorators=[{type:o.Directive,args:[{selector:"[ngxClipboardIfSupported]"}]}],p.ctorParameters=function(){return[{type:i},{type:o.ViewContainerRef},{type:o.TemplateRef}]};var c=function(){};c.decorators=[{type:o.NgModule,args:[{imports:[e.CommonModule],declarations:[s,p],exports:[s,p]}]}],t.ClipboardDirective=s,t.ClipboardIfSupportedDirective=p,t.ClipboardModule=c,t.ClipboardService=i,Object.defineProperty(t,"__esModule",{value:!0})}));
2//# sourceMappingURL=ngx-clipboard.umd.min.js.map
\No newline at end of file