Use window.opener in popup rather than polling. Fixes #789

This commit is contained in:
Tom MacWright
2013-02-26 20:17:38 -05:00
parent 3f7d78edfb
commit 583ee967a9
2 changed files with 10 additions and 28 deletions

View File

@@ -73,17 +73,13 @@ iD.OAuth = function(context) {
['top', screen.height / 2 - h / 2]].map(function(x) {
return x.join('=');
}).join(','),
popup = window.open("about:blank", 'oauth_window', settings),
locationCheck = window.setInterval(function() {
if (popup.closed) return window.clearInterval(locationCheck);
if (popup.location.search) {
var search = popup.location.search,
oauth_token = ohauth.stringQs(search.slice(1));
popup.close();
get_access_token(oauth_token);
window.clearInterval(locationCheck);
}
}, 100);
popup = window.open("about:blank", 'oauth_window', settings);
window.authComplete = function(token) {
var oauth_token = ohauth.stringQs(token);
get_access_token(oauth_token);
delete window.authComplete;
};
function reqTokenDone(err, xhr) {
if (err) callback(err);

View File

@@ -1,23 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>iD</title>
<style>
body {
font:normal 20px/30px 'Helvetica Neue';
text-align:center;
}
</style>
</head>
<html><head></head>
<body>
<h1 id='land'></h1>
<script>
var i = 2;
window.setInterval(function() {
document.getElementById('land').innerHTML = (new Array(i++)).join('.');
i = (i > 8) ? 2 : i;
}, 200);
opener.authComplete(window.location.search.slice(1));
window.close();
</script>
</body>
</html>