</head>
<body>
+ <script src="/lmno.js"></script>
+
<div id="page">
- <form onsubmit="join_game(this)">
+ <div id="message-area">
+ </div>
+
+ <form onsubmit="lmno_join(this); return false">
<div class="form-field large">
<label for="id">Game ID</label>
--- /dev/null
+function undisplay(element) {
+ element.style.display="none";
+}
+
+function add_message(severity, message) {
+ message = `<div class="message ${severity}" onclick="undisplay(this)">
+<span class="hide-button" onclick="undisplay(this.parentElement)">×</span>
+${message}
+</div>`;
+ const message_area = document.getElementById('message-area');
+ message_area.insertAdjacentHTML('beforeend', message);
+}
+
+function join_loadend(request, game_id) {
+ if (request.status === 404) {
+ add_message("danger", game_id + " is not a valid game ID. Try again.");
+ return;
+ }
+}
+
+function lmno_join(form) {
+ const game_id = form.id.value;
+
+ var request = new XMLHttpRequest();
+ request.addEventListener("loadend", () => join_loadend(request, game_id));
+
+ request.open("GET", "/" + game_id);
+ request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
+ request.send();
+
+ form.reset();
+}
::-moz-focus-inner {
border: 0;
}
+
+/*\
+|*|
+|*| Styling for a message area
+|*|
+\*/
+
+/* Default message severity is "info" but can be overriden. */
+.message {
+ padding: 1em;
+ background-color: #44c7ef;
+ color: white;
+ transition: 0.3s;
+ margin-bottom: 0.5em;
+ font-weight: bold;
+ border-radius: 4px;
+ position: relative;
+}
+
+.success {
+ background-color: #44c7ef;
+}
+
+.warning {
+ background-color: #ffa92a;
+}
+
+.danger {
+ background-color: #f56257
+}
+
+.hide-button {
+ color: white;
+ font-size: 125%;
+ font-weight: bold;
+ cursor: pointer;
+ position: absolute;
+ right: 0.5em;
+ top: 0;
+}
+
+.hide-button:hover {
+ color: #bc2822;
+}