Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 583ee967a9a44452febe5fe8ceae886908edaf4b 1 parent 3f7d78e
Tom MacWright authored February 26, 2013

Showing 2 changed files with 10 additions and 28 deletions. Show diff stats Hide diff stats

  1. 18  js/id/oauth.js
  2. 20  land.html
18  js/id/oauth.js
@@ -73,17 +73,13 @@ iD.OAuth = function(context) {
73 73
                 ['top', screen.height / 2 - h / 2]].map(function(x) {
74 74
                     return x.join('=');
75 75
                 }).join(','),
76  
-            popup = window.open("about:blank", 'oauth_window', settings),
77  
-            locationCheck = window.setInterval(function() {
78  
-                if (popup.closed) return window.clearInterval(locationCheck);
79  
-                if (popup.location.search) {
80  
-                    var search = popup.location.search,
81  
-                        oauth_token = ohauth.stringQs(search.slice(1));
82  
-                    popup.close();
83  
-                    get_access_token(oauth_token);
84  
-                    window.clearInterval(locationCheck);
85  
-                }
86  
-            }, 100);
  76
+            popup = window.open("about:blank", 'oauth_window', settings);
  77
+
  78
+        window.authComplete = function(token) {
  79
+            var oauth_token = ohauth.stringQs(token);
  80
+            get_access_token(oauth_token);
  81
+            delete window.authComplete;
  82
+        };
87 83
 
88 84
         function reqTokenDone(err, xhr) {
89 85
             if (err) callback(err);
20  land.html
... ...
@@ -1,23 +1,9 @@
1 1
 <!DOCTYPE html>
2  
-<html>
3  
-    <head>
4  
-        <meta charset='utf-8'>
5  
-        <title>iD</title>
6  
-        <style>
7  
-            body {
8  
-                font:normal 20px/30px 'Helvetica Neue';
9  
-                text-align:center;
10  
-            }
11  
-        </style>
12  
-    </head>
  2
+<html><head></head>
13 3
     <body>
14  
-        <h1 id='land'></h1>
15 4
         <script>
16  
-            var i = 2;
17  
-            window.setInterval(function() {
18  
-                document.getElementById('land').innerHTML = (new Array(i++)).join('.');
19  
-                i = (i > 8) ? 2 : i;
20  
-            }, 200);
  5
+            opener.authComplete(window.location.search.slice(1));
  6
+            window.close();
21 7
         </script>
22 8
     </body>
23 9
 </html>

0 notes on commit 583ee96

Please sign in to comment.
Something went wrong with that request. Please try again.