ng-gapi
Version:
Angular 9+ Google api module ng-gapi
16 lines (14 loc) • 3.74 kB
JavaScript
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("ng-gapi",["exports","@angular/core","rxjs","rxjs/operators"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self)["ng-gapi"]={},e.ng.core,e.rxjs,e.rxjs.operators)}(this,(function(e,o,t,n){"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 i(e,o,t,n){var i,r=arguments.length,u=r<3?o:null===n?n=Object.getOwnPropertyDescriptor(o,t):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,o,t,n);else for(var c=e.length-1;c>=0;c--)(i=e[c])&&(u=(r<3?i(u):r>3?i(o,t,u):i(o,t))||u);return r>3&&u&&Object.defineProperty(o,t,u),u}function r(e,o){return function(t,n){o(t,n,e)}}var u,c=function(){function e(e){this.clientConfig=e}return e.prototype.getClientConfig=function(){return this.clientConfig},e}(),p=new o.InjectionToken("ng-gapi.config");e.GoogleApiService=function(){function e(e){this.gapiUrl="https://apis.google.com/js/api.js",this.observers=[],this.config=new c(e),this.loadGapi().subscribe()}return e.prototype.onLoad=function(){return this.loadGapi()},e.prototype.getConfig=function(){return this.config},e.prototype.loadGapi=function(){var e=this;return new t.Observable((function(o){e.gapiLoaded?(o.next(!0),o.complete()):e.node?e.observers.push(o):(e.node=document.createElement("script"),e.node.async=!0,e.node.src=e.gapiUrl,e.node.type="text/javascript",e.node.onload=function(){for(e.gapiLoaded=!0;e.observers.length;){var o=e.observers.shift();o.next(!0),o.complete()}e.node=void 0},e.node.onerror=function(){e.node=void 0},document.getElementsByTagName("head")[0].appendChild(e.node))}))},e}(),e.GoogleApiService=i([o.Injectable(),r(0,o.Inject(p))],e.GoogleApiService),e.GoogleAuthService=function(){function e(e){var o=this;this.googleApi=e,this.GoogleAuth=void 0,this.googleApi.onLoad().subscribe((function(){o.loadGapiAuth().subscribe()}))}return e.prototype.getAuth=function(e){var o=this;return void 0===e&&(e=!1),!this.GoogleAuth||e?this.googleApi.onLoad().pipe(n.mergeMap((function(){return o.loadGapiAuth()}))):t.of(this.GoogleAuth)},e.prototype.loadGapiAuth=function(){var e=this;return new t.Observable((function(o){gapi.load("auth2",(function(){gapi.auth2.init(e.googleApi.getConfig().getClientConfig()).then((function(t){e.GoogleAuth=t,o.next(t),o.complete()})).catch((function(e){return o.error(e)}))}))}))},e}(),e.GoogleAuthService=i([o.Injectable(),r(0,o.Inject(e.GoogleApiService))],e.GoogleAuthService),e.GoogleApiModule=u=function(){function o(){}return o.forRoot=function(o){return{ngModule:u,providers:[o,e.GoogleAuthService,e.GoogleApiService]}},o}(),e.GoogleApiModule=u=i([o.NgModule()],e.GoogleApiModule),e.GoogleApiConfig=c,e.NG_GAPI_CONFIG=p,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-gapi.umd.min.js.map