Skip to content

Commit

Permalink
Window event callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Zack LeBlanc committed Jul 21, 2015
1 parent 704e3dc commit 0e782d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions dist/angular-oauth1-client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*! angular-oauth1-client - v0.1.2 - 2015-07-21
* Copyright (c) 2015 Sean Fisher; Licensed MIT */
/*! angular-oauth1-client - v0.1.2 - 2015-07-09
* Copyright (c) 2015 Sean Fisher; Licensed MIT */
/*! angular-oauth1-client - v0.1.2 - 2015-07-07
Expand Down Expand Up @@ -285,11 +287,16 @@ angular.module('oauth1Client', ['LocalStorageModule'])
return deferred.promise;
}

function getAuthorizationToken(oauth_token, callback_url) {
function getAuthorizationToken(oauth_token, callback_url, afterWindowOpen, beforeWindowClose) {
var deffered = $q.defer();
var auth_window = window.open(authorizeEndpoint + "?oauth_token=" + oauth_token + "&oauth_callback=" + callback_url, '_blank', 'location=no,clearcache=yes');
var urlsVisited = 0;
auth_window.addEventListener('loadstart', function(event) {
urlsVisited += 1;
if((event.url).startsWith(callback_url)) {
if(angular.isFunction(beforeWindowClose)){
beforeWindowClose();
}
auth_window.close();

deffered.resolve({
Expand All @@ -298,6 +305,11 @@ angular.module('oauth1Client', ['LocalStorageModule'])
wp_scope: getURLParameter(event.url, 'wp_scope')
});
}
if(urlsVisited == 1) {
if(angular.isFunction(afterWindowOpen)){
afterWindowOpen();
}
}
});
return deffered.promise;
}
Expand Down Expand Up @@ -342,7 +354,7 @@ angular.module('oauth1Client', ['LocalStorageModule'])
}

return {
authorize: function(storage) {
authorize: function(afterWindowOpen, beforeWindowClose) {
var deffered = $q.defer();

var oauthSigner = getOAuthSigner({
Expand All @@ -355,7 +367,7 @@ angular.module('oauth1Client', ['LocalStorageModule'])

getRequestToken(oauthSigner, oauthCallback)
.then(function(request_data) {
return getAuthorizationToken(request_data.oauth_token, oauthCallback);
return getAuthorizationToken(request_data.oauth_token, oauthCallback, afterWindowOpen, beforeWindowClose);
})
.then(function(authorization_data) {
oauthSigner = getOAuthSigner({
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-oauth1-client.min.js

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

0 comments on commit 0e782d4

Please sign in to comment.