ngx-doc-viewer
Version:
Angular document viewer.
16 lines (14 loc) • 4.13 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/core"),require("@angular/platform-browser"),require("rxjs/operators"),require("rxjs"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-doc-viewer",["exports","@angular/core","@angular/platform-browser","rxjs/operators","rxjs","@angular/common"],r):r((e=e||self)["ngx-doc-viewer"]={},e.ng.core,e.ng.platformBrowser,e.rxjs.operators,e.rxjs,e.ng.common)}(this,(function(e,r,o,t,n,i){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function c(e,r,o,t){var n,i=arguments.length,c=i<3?r:null===t?t=Object.getOwnPropertyDescriptor(r,o):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,r,o,t);else for(var u=e.length-1;u>=0;u--)(n=e[u])&&(c=(i<3?n(c):i>3?n(r,o,c):n(r,o))||c);return i>3&&c&&Object.defineProperty(r,o,c),c}var u=function(){function e(e,o){this.domSanitizer=e,this.ngZone=o,this.fullUrl=null,this.checkIFrameSubscription=null,this.configuredViewer="google",this.loaded=new r.EventEmitter,this.url="",this.googleCheckInterval=3e3}return Object.defineProperty(e.prototype,"viewer",{set:function(e){var r=e.toLowerCase().trim();"google"!==r&&"office"!==r&&console.error("Unsupported viewer: '"+e+"'. Supported viewers: google, office"),this.configuredViewer=r},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){this.checkIFrameSubscription&&this.checkIFrameSubscription.unsubscribe()},e.prototype.ngOnChanges=function(e){var r=this;if(e.url&&e.url.currentValue!==e.url.previousValue||e.viewer&&e.viewer.currentValue!==e.viewer.previousValue){var o=this.url.indexOf("/")?encodeURIComponent(this.url):this.url;this.fullUrl=this.domSanitizer.bypassSecurityTrustResourceUrl("google"===this.configuredViewer?"https://docs.google.com/gview?url="+o+"&embedded=true":"https://view.officeapps.live.com/op/embed.aspx?src="+o),"google"===this.configuredViewer&&this.ngZone.runOutsideAngular((function(){var e=document.querySelector("iframe");r.checkIFrame(e),r.checkIFrameSubscription=n.interval(r.googleCheckInterval).pipe(t.take(Math.round(0===r.googleCheckInterval?0:2e4/r.googleCheckInterval))).subscribe((function(){null==e&&(e=document.querySelector("iframe"),r.checkIFrame(e)),r.reloadIFrame(e)}))}))}},e.prototype.checkIFrame=function(e){var r=this;e&&(e.onload=function(){r.loaded.emit(null),r.checkIFrameSubscription&&r.checkIFrameSubscription.unsubscribe()})},e.prototype.reloadIFrame=function(e){e&&(console.log("reloading.."),e.src=e.src)},e.ctorParameters=function(){return[{type:o.DomSanitizer},{type:r.NgZone}]},c([r.Output()],e.prototype,"loaded",void 0),c([r.Input()],e.prototype,"url",void 0),c([r.Input()],e.prototype,"googleCheckInterval",void 0),c([r.Input()],e.prototype,"viewer",null),e=c([r.Component({selector:"ngx-doc-viewer",template:'<iframe id="iframe" *ngIf="fullUrl" frameBorder="0" [src]="fullUrl"></iframe> ',styles:[":host {\n display: block;\n }\n iframe {\n width: 100%;\n height: 100%;\n }\n "]})],e)}(),l=function(){function e(){}return e=c([r.NgModule({imports:[i.CommonModule],declarations:[u],exports:[u]})],e)}();e.NgxDocViewerComponent=u,e.NgxDocViewerModule=l,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-doc-viewer.umd.min.js.map