This repository has been archived by the owner on Aug 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
angular-google-client.min.js
2 lines (2 loc) · 4.89 KB
/
angular-google-client.min.js
1
2
!function(){"use strict";angular.module("cmGoogleApi",[])}(),function(){"use strict";angular.module("cmGoogleApi").provider("googleClient",function(){var e,t,n,i="",o={},c=0,r=0,a=[],u=[],l=!1,s=!1,d=!1,f=!1,p=!1,g=!1,h=!1,v=function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},k=function(){0===--c&&(f=!0,p=!1,t.resolve())},m=function(){0===--r&&(g=!0,h=!1,n.resolve())},y=function(){var t=!1;if(d){if("undefined"==typeof e)return void n.reject("you need to provide the clientId if you load google auth");if(!o.fetch_basic_profile&&""===v(i))return void n.reject('you need to set "fetch_basic_profile" to true or request at least one scope if you load google auth');t=!0,gapi.load("auth",{callback:m}),gapi.load("auth2",function(){o.scope=i,o.client_id=e,gapi.auth2.init(o),m()})}return l&&(t=!0,gapi.load("client",{callback:m})),s&&("undefined"==typeof e?n.reject("you need to provide the clientId if you load google picker"):(t=!0,gapi.load("picker",{callback:m}))),t},_=function(){var e=!1;return angular.forEach(u,function(t){e=!0,gapi.client.load(t.api,t.version,k,t.baseUrl)}),angular.forEach(a,function(t){e=!0,gapi.client.load(t.api,t.version,k)}),!l||e},A=function(){return l||(l=!0,r++),this};this.loadGoogleAuth=function(e){return d||(d=!0,r+=2,"object"==typeof e&&("undefined"!=typeof e.hosted_domain&&(o.hosted_domain=e.hosted_domain),"undefined"!=typeof e.cookie_policy?o.cookie_policy=e.cookie_policy:o.cookie_policy="single_host_origin","undefined"!=typeof e.fetch_basic_profile?o.fetch_basic_profile=e.fetch_basic_profile:o.fetch_basic_profile=!0,o.fetch_basic_profile&&(this.addScope("profile"),this.addScope("email")))),this},this.loadPickerLibrary=function(){return s||(s=!0,r++),this},this.addApi=function(e,t,n){A();var i={};return i.api=e,i.version=t,c++,"undefined"==typeof n?a.push(i):(i.baseUrl=n,u.push(i)),this},this.addScope=function(e){return i+=" "+e,this},this.setClientId=function(t){return e=t,this},this.$get=["$q","$window","$document",function(o,c,r){return{afterScriptsLoaded:function(){if(!g&&!h){h=!0,n=o.defer(),c._cmGoogleClientInitCallback=function(){y()||n.reject("at least you need to add some api, load picker library or load google auth")};var e=r[0].createElement("script");e.onerror=function(e){n.reject(e)},e.src="https://apis.google.com/js/api.js?onload=_cmGoogleClientInitCallback",r[0].body.appendChild(e)}return n.promise},afterApiLoaded:function(){return f||p||(t=o.defer(),p=!0,this.afterScriptsLoaded().then(function(){_()||t.reject("at least you need to load an Api")},function(e){t.reject(e)})),t.promise},clientId:e,scopes:i.trim()}}]})}(),function(){"use strict";angular.module("cmGoogleApi").service("cmApiService",["$q","googleClient",function(e,t){this.execute=function(n,i){var o=e.defer();return t.afterApiLoaded().then(function(){n=n.split(".");var e=gapi.client;angular.forEach(n,function(t){e=e[t]},e);var t;t="undefined"==typeof i?e():e(i),t.then(function(e){o.resolve(e)},function(e){o.reject(e)})},function(e){o.reject(e)}),o.promise}}])}(),function(){"use strict";angular.module("cmGoogleApi").service("cmAuthService",["$q","googleClient",function(e,t){this.getAuthInstance=function(){var n=e.defer();return t.afterScriptsLoaded().then(function(){var e=gapi.auth2.getAuthInstance();e.then(function(){var t=e.then;e.then=void 0,n.resolve(e),e.then=t},function(e){n.reject(e)})},function(e){n.reject(e)}),n.promise}}])}(),function(){"use strict";angular.module("cmGoogleApi").directive("cmGooglePicker",["googleClient","$q","$window",function(e,t,n){return{restrict:"A",scope:{locale:"@",views:"&",onPicked:"="},link:function(t,i,o){function c(e){t.onPicked&&e.action===google.picker.Action.PICKED&&t.$apply(t.onPicked(e.docs))}function r(){e.afterScriptsLoaded().then(function(){var e=(new google.picker.PickerBuilder).setLocale(t.locale).setOAuthToken(gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().access_token).setOrigin(n.location.protocol+"//"+n.location.host).setCallback(c),i=t.views();angular.forEach(i,function(t){e.addView(t)}),e=e.build(),e.setVisible(!0)})}i.bind("click",function(e){r()})}}}])}(),function(){"use strict";angular.module("cmGoogleApi").directive("cmGoogleSignIn",["$http","googleClient",function(e,t){return{restrict:"E",transclude:!0,replace:!0,scope:{clickHandler:"=?",signInListener:"=?",userListener:"=?"},template:"<ng-transclude></ng-transclude>",link:function(e,n,i){function o(t){e.$apply(e.clickHandler(t))}function c(t){gapi.auth.setToken(t.getAuthResponse()),"undefined"!=typeof e.userListener&&e.$apply(e.userListener(t))}function r(t){e.$apply(e.signInListener(t))}"undefined"==typeof e.clickHandler&&(e.clickHandler=angular.noop),t.afterScriptsLoaded().then(function(){var t=gapi.auth2.getAuthInstance();"undefined"!=typeof e.signInListener&&t.isSignedIn.listen(r),t.currentUser.listen(c),t.attachClickHandler(n[0],{},o,function(e){throw new Error(JSON.stringify(e,void 0,2))})},function(e){})}}}])}();
//# sourceMappingURL=angular-google-client.min.js.map