Skip to content

Commit

Permalink
Onload callback and location bar added
Browse files Browse the repository at this point in the history
  • Loading branch information
Zack LeBlanc committed Jul 24, 2015
1 parent 56556cd commit f108a8e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
19 changes: 14 additions & 5 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-24
* Copyright (c) 2015 Sean Fisher; Licensed MIT */
/*! angular-oauth1-client - v0.1.8 - 2015-07-23
* Copyright (c) 2015 Sean Fisher; Licensed MIT */
(function(window, angular, undefined) {'use strict';
Expand Down Expand Up @@ -280,9 +282,10 @@ angular.module('oauth1Client', ['LocalStorageModule'])
return deferred.promise;
}

function getAuthorizationToken(oauth_token, callback_url, afterWindowOpen, beforeWindowClose) {
function getAuthorizationToken(oauth_token, callback_url, afterWindowOpen, beforeWindowClose, onLoad) {
var deffered = $q.defer();
var auth_window = window.open(authorizeEndpoint + "?oauth_token=" + oauth_token + "&oauth_callback=" + callback_url, '_blank', 'location=no,clearcache=yes,hidden=yes');
var auth_window = window.open(authorizeEndpoint + "?oauth_token=" + oauth_token + "&oauth_callback=" + callback_url, '_blank', 'location=yes,clearcache=yes,hidden=yes');
var visible = false;
auth_window.addEventListener('loadstart', function(event) {
if((event.url).startsWith(callback_url)) {
if(angular.isFunction(beforeWindowClose)){
Expand All @@ -298,7 +301,13 @@ angular.module('oauth1Client', ['LocalStorageModule'])
}
});
auth_window.addEventListener('loadstop', function(event) {
auth_window.show();
if(angular.isFunction(onLoad)) {
onLoad(auth_window, event);
}
if(!visible) {
auth_window.show();
visible = true;
}
if(angular.isFunction(afterWindowOpen)){
afterWindowOpen();
}
Expand Down Expand Up @@ -357,7 +366,7 @@ angular.module('oauth1Client', ['LocalStorageModule'])
}));
});
},
authorize: function(afterWindowOpen, beforeWindowClose) {
authorize: function(afterWindowOpen, beforeWindowClose, onLoad) {
var deffered = $q.defer();

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

getRequestToken(oauthSigner, oauthCallback)
.then(function(request_data) {
return getAuthorizationToken(request_data.oauth_token, oauthCallback, afterWindowOpen, beforeWindowClose);
return getAuthorizationToken(request_data.oauth_token, oauthCallback, afterWindowOpen, beforeWindowClose, onLoad);
})
.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.

17 changes: 12 additions & 5 deletions src/angular-oauth1-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,10 @@ angular.module('oauth1Client', ['LocalStorageModule'])
return deferred.promise;
}

function getAuthorizationToken(oauth_token, callback_url, afterWindowOpen, beforeWindowClose) {
function getAuthorizationToken(oauth_token, callback_url, afterWindowOpen, beforeWindowClose, onLoad) {
var deffered = $q.defer();
var auth_window = window.open(authorizeEndpoint + "?oauth_token=" + oauth_token + "&oauth_callback=" + callback_url, '_blank', 'location=no,clearcache=yes,hidden=yes');
var auth_window = window.open(authorizeEndpoint + "?oauth_token=" + oauth_token + "&oauth_callback=" + callback_url, '_blank', 'location=yes,clearcache=yes,hidden=yes');
var visible = false;
auth_window.addEventListener('loadstart', function(event) {
if((event.url).startsWith(callback_url)) {
if(angular.isFunction(beforeWindowClose)){
Expand All @@ -298,7 +299,13 @@ angular.module('oauth1Client', ['LocalStorageModule'])
}
});
auth_window.addEventListener('loadstop', function(event) {
auth_window.show();
if(angular.isFunction(onLoad)) {
onLoad(auth_window, event);
}
if(!visible) {
auth_window.show();
visible = true;
}
if(angular.isFunction(afterWindowOpen)){
afterWindowOpen();
}
Expand Down Expand Up @@ -357,7 +364,7 @@ angular.module('oauth1Client', ['LocalStorageModule'])
}));
});
},
authorize: function(afterWindowOpen, beforeWindowClose) {
authorize: function(afterWindowOpen, beforeWindowClose, onLoad) {
var deffered = $q.defer();

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

getRequestToken(oauthSigner, oauthCallback)
.then(function(request_data) {
return getAuthorizationToken(request_data.oauth_token, oauthCallback, afterWindowOpen, beforeWindowClose);
return getAuthorizationToken(request_data.oauth_token, oauthCallback, afterWindowOpen, beforeWindowClose, onLoad);
})
.then(function(authorization_data) {
oauthSigner = getOAuthSigner({
Expand Down

0 comments on commit f108a8e

Please sign in to comment.