From 8002ce96d651ac9a867b92d0728725b37dd4943a Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 7 Apr 2016 01:30:07 +0000 Subject: [PATCH] Retain URL #hash through login. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3189 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/client.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/core/client.js b/core/client.js index bbd52fbc..1aa2b6e3 100644 --- a/core/client.js +++ b/core/client.js @@ -29,10 +29,22 @@ function enter(event) { function url() { var hash = window.location.href.indexOf('#'); var question = window.location.href.indexOf('?'); - var end = hash != -1 ? hash : question; + var end = -1; + if (hash != -1 && (hash < end || end == -1)) + { + end = hash; + } + if (question != -1 && (question < end || end == -1)) + { + end = question; + } return end != -1 ? window.location.href.substring(0, end) : window.location.href; } +function hash() { + return window.location.hash != "#" ? window.location.hash : ""; +} + function storeTarget(target) { $("#target").text(target || ""); } @@ -280,19 +292,19 @@ function updateLogin() { a.setAttribute("onclick", "logoutGoogle()"); a.setAttribute("href", "#"); } else { - a.setAttribute("href", "/login/logout?return=" + encodeURIComponent(url())); + a.setAttribute("href", "/login/logout?return=" + encodeURIComponent(url() + hash())); } } else if (window.location.href.indexOf("?guest=1") != -1) { - window.location.href = "/login?submit=Proceed+as+Guest&return=" + encodeURIComponent(url()); + window.location.href = "/login?submit=Proceed+as+Guest&return=" + encodeURIComponent(url() + hash()); } else { - window.location.href = "/login?return=" + encodeURIComponent(url()); + window.location.href = "/login?return=" + encodeURIComponent(url() + hash()); } login.appendChild(a); } function logoutGoogle() { gapi.auth2.getAuthInstance().signOut().then(function() { - window.location.href = "/login/logout?return=" + encodeURIComponent(url()); + window.location.href = "/login/logout?return=" + encodeURIComponent(url() + hash()); }); }