Update with PR feedback

This commit is contained in:
Ramon Gebben 2016-11-29 09:49:58 +01:00 committed by GitHub
parent 79825dfa1d
commit e5ce080fd3

View file

@ -26,11 +26,11 @@
if (!cookie) { if (!cookie) {
callback('changed'); callback('changed');
} else if (!init) { } else if (!init) {
var req = new XMLHttpRequest(), var req = new XMLHttpRequest();
url = location.href + '/init';
url += '?client_id=' + encodeURIComponent(clientId); var url = location.href + "/init";
url += '&origin=' + encodeURIComponent(origin); url += "?client_id=" + encodeURIComponent(clientId);
url += "&origin=" + encodeURIComponent(origin);
req.open('GET', url, true); req.open('GET', url, true);
@ -64,36 +64,35 @@
} }
} }
function getCookie() { function getCookie()
var name = 'KEYCLOAK_SESSION=', {
ca = document.cookie.split(';'), var name = 'KEYCLOAK_SESSION=';
i = 0, var ca = document.cookie.split(';');
length = ca.length, for(var i=0; i<ca.length; i++)
c = null; {
var c = ca[i].trim();
for (; i < length; i++) {
c = ca[i].trim();
if (c.indexOf(name)===0) return c.substring(name.length,c.length); if (c.indexOf(name)===0) return c.substring(name.length,c.length);
} }
return null; return null;
} }
function receiveMessage(event) { function receiveMessage(event)
var origin = event.origin, {
data = event.data.split(' '), var origin = event.origin;
clientId = data[0], var data = event.data.split(' ');
sessionState = data[1]; if (data.length != 2) {
if (data.length !== 2) {
event.source.postMessage('error', origin); event.source.postMessage('error', origin);
} }
var clientId = data[0];
var sessionState = data[1];
checkState(clientId, event.origin, sessionState, function(result) { checkState(clientId, event.origin, sessionState, function(result) {
event.source.postMessage(result, origin); event.source.postMessage(result, origin);
}); });
} }
window.addEventListener('message', receiveMessage, false); window.addEventListener("message", receiveMessage, false);
</script> </script>
</body> </body>
</html> </html>