Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions dist/google-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
/**
* Load required modules
*/
function instanciate () {
gapi.load('auth', { 'callback': onApiAuthLoad });
function instantiate () {
gapi.load('auth2', { 'callback': onApiAuthLoad });
gapi.load('picker');
}

Expand All @@ -71,17 +71,18 @@
* If user is already logged in, then open the Picker modal
*/
function onApiAuthLoad () {
var authToken = gapi.auth.getToken();

if (authToken) {
handleAuthResult(authToken);
} else {
gapi.auth.authorize({
'client_id' : lkGoogleSettings.clientId,
'scope' : lkGoogleSettings.scopes,
'immediate' : false
}, handleAuthResult);
}
gapi.auth2.init({
'client_id' : lkGoogleSettings.clientId,
'scope' : lkGoogleSettings.scopes
})
.then(function (authInstance) {
return authInstance.signIn();
})
.then(function (guser) {
var response = guser.getAuthResponse();
accessToken = response.access_token;
openDialog();
});
}

/**
Expand Down Expand Up @@ -139,11 +140,9 @@
});
}

gapi.load('auth');
gapi.load('picker');

element.bind('click', function (e) {
instanciate();
/* dynamically load dependencies only on click */
instantiate();
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/google-picker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/google-picker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions src/google-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* Load required modules
*/
function instantiate () {
gapi.load('auth', { 'callback': onApiAuthLoad });
gapi.load('auth2', { 'callback': onApiAuthLoad });
gapi.load('picker');
}

Expand All @@ -71,17 +71,18 @@
* If user is already logged in, then open the Picker modal
*/
function onApiAuthLoad () {
var authToken = gapi.auth.getToken();

if (authToken) {
handleAuthResult(authToken);
} else {
gapi.auth.authorize({
'client_id' : lkGoogleSettings.clientId,
'scope' : lkGoogleSettings.scopes,
'immediate' : false
}, handleAuthResult);
}
gapi.auth2.init({
'client_id' : lkGoogleSettings.clientId,
'scope' : lkGoogleSettings.scopes
})
.then(function (authInstance) {
return authInstance.signIn();
})
.then(function (guser) {
var response = guser.getAuthResponse();
accessToken = response.access_token;
openDialog();
});
}

/**
Expand Down