Resolve #41 - Changed all links to avoid 'href="#"'.

This commit is contained in:
Gareth Latty
2015-12-14 18:41:46 +00:00
parent 7b30e057b5
commit 3278b42fa7
9 changed files with 118 additions and 86 deletions
+66 -2
View File
@@ -21,10 +21,74 @@ jQuery(function($) {
function inviteOverlay(event) {
mui.overlay('on', $('#invite')[0].cloneNode(true));
event.preventDefault();
}
function aboutOverlay(event) {
mui.overlay('on', $('#about')[0].cloneNode(true));
event.preventDefault();
}
function start(url) {
var socket = null;
var gameCode = window.location.hash.substr(1);
var existingGame = localStorage.getItem("existingGame");
if (existingGame != null) {
try {
existingGame = JSON.parse(existingGame);
} catch (error) {
existingGame = null;
}
}
var initialState = {
url: url,
gameCode: gameCode == "" ? null : gameCode,
existingGame: existingGame,
seed: new Date().getTime()
};
var game = Elm.fullscreen(Elm.MassiveDecks.Main, { notifications: "", initialState: initialState });
game.ports.initialState.send(initialState);
function openWebSocket(lobbyId, secret) {
var loc = window.location, new_uri;
if (loc.protocol === "https:") {
new_uri = "wss:";
} else {
new_uri = "ws:";
}
new_uri += "//" + loc.host;
new_uri += loc.pathname + "lobbies/" + lobbyId + "/notifications";
if (socket != null) {
socket.close();
}
socket = new WebSocket(new_uri);
socket.onopen = function (event) {
socket.send(JSON.stringify(secret));
}
socket.onmessage = function (event) {
game.ports.notifications.send(event.data);
}
socket.onclose = function (event) {
if (socket != null) {
openWebSocket(lobbyId, secret);
}
}
}
game.ports.subscription.subscribe(function (lobbyIdAndSecret) {
console.log(lobbyIdAndSecret);
if (lobbyIdAndSecret != null) {
localStorage.setItem("existingGame", JSON.stringify(lobbyIdAndSecret))
openWebSocket(lobbyIdAndSecret.lobbyId, lobbyIdAndSecret.secret);
window.location = "#" + lobbyIdAndSecret.lobbyId;
} else {
if (socket != null) {
window.location = "#";
localStorage.removeItem("existingGame");
var oldSocket = socket;
socket = null;
oldSocket.close();
}
}
});
}