move login window functions into a separate JS file and add debug statements
authorRobert Kaiser <kairo@kairo.at>
Fri, 10 Nov 2017 20:25:51 +0000 (21:25 +0100)
committerRobert Kaiser <kairo@kairo.at>
Fri, 10 Nov 2017 20:25:51 +0000 (21:25 +0100)
js/loginwindow.js [new file with mode: 0644]
js/ui.js
login.html
manifest.appcache

diff --git a/js/loginwindow.js b/js/loginwindow.js
new file mode 100644 (file)
index 0000000..ebbdde4
--- /dev/null
@@ -0,0 +1,19 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+console.log("JS-load");
+
+window.onload = function() {
+  // Complete the login process by calling the main window.
+  console.log("onload");
+  if (window.opener) {
+    console.log("opener");
+    window.opener.finishLogin(getParameterByName("code"), getParameterByName("state"));
+    console.log("finished");
+    window.close();
+  }
+  else {
+    console.log("no-opener");
+    document.getElementById("logininfo").textContent = "You have called this document outside of the login flow, which is not supported.";
+  }
+}
index f451fbe52932ec53f900bcd15943431e99b49d76..7526763ee78e184c467375382ee02881a5dd1e3f 100644 (file)
--- a/js/ui.js
+++ b/js/ui.js
@@ -17,11 +17,6 @@ var gBackendURL = "https://backend.lantea.kairo.at";
 var gAuthClientID = "lantea";
 
 window.onload = function() {
 var gAuthClientID = "lantea";
 
 window.onload = function() {
-  if (/\/login\.html/.test(window.location)) {
-    // If we are in the login window, call a function to complete the process and don't do anything else here.
-    completeLoginWindow();
-    return;
-  }
   gAction = document.getElementById("action");
   gActionLabel = document.getElementById("actionlabel");
 
   gAction = document.getElementById("action");
   gActionLabel = document.getElementById("actionlabel");
 
@@ -175,16 +170,6 @@ function prepareLoginButton(aCallback) {
   );
 }
 
   );
 }
 
-function completeLoginWindow() {
-  if (window.opener) {
-    window.opener.finishLogin(getParameterByName("code"), getParameterByName("state"));
-    window.close();
-  }
-  else {
-    document.getElementById("logininfo").textContent = "You have called this document outside of the login flow, which is not supported.";
-  }
-}
-
 function finishLogin(aCode, aState) {
   if (aState == authData["state"]) {
     fetchBackend("login?code=" + aCode + "&state=" + aState + "&redirect_uri=" + encodeURIComponent(getRedirectURI()), "GET", null,
 function finishLogin(aCode, aState) {
   if (aState == authData["state"]) {
     fetchBackend("login?code=" + aCode + "&state=" + aState + "&redirect_uri=" + encodeURIComponent(getRedirectURI()), "GET", null,
index 8eafcbd625cb8f038f035679c959a4f484a0e20f..b4063494af8c3424497491f250f9377de3f8ee9b 100644 (file)
@@ -10,8 +10,8 @@
        https://developer.mozilla.org/en/Mobile/Viewport_meta_tag -->
   <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=no">
   <title>Lantea Login</title>
        https://developer.mozilla.org/en/Mobile/Viewport_meta_tag -->
   <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=no">
   <title>Lantea Login</title>
-  <script src="js/ui.js"></script>
-  <!-- script src="js/piwik.js" async="" defer=""></script -->
+  <script src="js/loginwindow.js"></script>
+  <script src="js/piwik.js" async="" defer=""></script>
   <link rel="stylesheet" href="style/lantea.css">
   <link rel="shortcut icon" href="style/lanteaIcon16.png" type="image/png">
 </head>
   <link rel="stylesheet" href="style/lantea.css">
   <link rel="shortcut icon" href="style/lanteaIcon16.png" type="image/png">
 </head>
index 67b8bc195f8b1b3e55ef01bf742b164e8abac139..9ead49518d98aff31502e1830085eb5cf7fd119e 100644 (file)
@@ -1,12 +1,13 @@
 CACHE MANIFEST
 
 CACHE MANIFEST
 
-# 2017-10-23
+# 2017-11-10
 index.html
 login.html
 manifest.webapp
 js/map.js
 js/ui.js
 js/library.js
 index.html
 login.html
 manifest.webapp
 js/map.js
 js/ui.js
 js/library.js
+js/loginwindow.js
 style/lantea.css
 style/loading.png
 style/loading_action.png
 style/lantea.css
 style/loading.png
 style/loading_action.png