aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAiden Woodruff <aiden.woodruff@gmail.com>2018-04-22 13:25:30 -0500
committerGitHub <noreply@github.com>2018-04-22 13:25:30 -0500
commit0b7110220f9f2a2f886898b6cb95f28d5edacb02 (patch)
treeaf7bc116ec4bf521f58f69a3e71ef73bfcfb816a
parent9aa5b06c3404376fd3af2faeffbecbaa1bf6f55a (diff)
downloadsweeper-0b7110220f9f2a2f886898b6cb95f28d5edacb02.tar.gz
sweeper-0b7110220f9f2a2f886898b6cb95f28d5edacb02.tar.bz2
sweeper-0b7110220f9f2a2f886898b6cb95f28d5edacb02.zip
Fixes <td> width issues (#5)
Updated CSS to insure fixed width and height of <td> elements. Give a nice error when you can't send AJAX. Give an error when the dimensions are probably too big (it's browser-based, so hard to tell). Signed-off-by: Aiden Woodruff <aiden.woodruff@gmail.com>
-rw-r--r--flag.pngbin224 -> 203 bytes
-rw-r--r--styles.css15
-rw-r--r--sweeper.js15
3 files changed, 23 insertions, 7 deletions
diff --git a/flag.png b/flag.png
index be39164..591d210 100644
--- a/flag.png
+++ b/flag.png
Binary files differ
diff --git a/styles.css b/styles.css
index 59b17b2..29e1292 100644
--- a/styles.css
+++ b/styles.css
@@ -1,13 +1,18 @@
1table.board { 1table.board {
2 border-spacing: 0; 2 border-spacing: 0;
3 border-collapse: collapse; 3 outline: 1px solid black;
4}
5
6table.board tr {
7 white-space: nowrap;
4} 8}
5 9
6table.board td { 10table.board td {
11 display: inline-block;
7 text-align: center; 12 text-align: center;
8 width: 20px; 13 width: 20px;
9 height: 20px; 14 height: 20px;
10 border: 2px solid black; 15 border: 1px solid black;
11} 16}
12 17
13td.unrevealed { 18td.unrevealed {
@@ -20,10 +25,12 @@ td.revealed {
20 background-color: #c6c6c6; 25 background-color: #c6c6c6;
21} 26}
22 27
23td.flagged { 28td.flagged, td.correct {
24 cursor: pointer; 29 cursor: pointer;
25 background-color: #c6c6c6; 30 background-color: #c6c6c6;
26 background-image: url("flag.png"); 31 background-image: url("flag.png");
32 background-position: center;
33 background-repeat: no-repeat;
27} 34}
28 35
29td.wrong { 36td.wrong {
@@ -32,8 +39,6 @@ td.wrong {
32} 39}
33 40
34td.correct { 41td.correct {
35 cursor: default;
36 background-image: url("flag.png");
37 background-color: #00ff00; 42 background-color: #00ff00;
38} 43}
39 44
diff --git a/sweeper.js b/sweeper.js
index 9a816c5..5f2a7cc 100644
--- a/sweeper.js
+++ b/sweeper.js
@@ -169,10 +169,16 @@ function flag (e) {
169function update_leaderboard () { 169function update_leaderboard () {
170 var xhttp = new XMLHttpRequest(); 170 var xhttp = new XMLHttpRequest();
171 xhttp.onreadystatechange = function () { 171 xhttp.onreadystatechange = function () {
172 if (this.readyState === 4 && this.status !== 200) { 172 if (this.status === 405) {
173 console.log("Couldn't update leaderboard.");
174 document.getElementById("end").removeChild(document.getElementById("end").getElementsByTagName("input")[0]);
175 var error_msg = document.createElement("p");
176 error_msg.innerHTML = "Leaderboard doesn't work here.";
177 document.getElementById("end").appendChild(error_msg);
178 } else if (this.readyState === 4 && this.status !== 200) {
173 console.log("There was some error updating the leaderboard."); 179 console.log("There was some error updating the leaderboard.");
174 } else if (this.readyState === 4 && this.status === 200) { 180 } else if (this.readyState === 4 && this.status === 200) {
175 var ld = document.createElement('a'); 181 var ld = document.createElement("a");
176 ld.href = "leaders.html"; 182 ld.href = "leaders.html";
177 ld.innerHTML = "Leaderboard"; 183 ld.innerHTML = "Leaderboard";
178 document.getElementById("end").appendChild(ld); 184 document.getElementById("end").appendChild(ld);
@@ -332,6 +338,11 @@ for (var y = 0; y < height; y++) {
332} 338}
333 339
334window.onload = function () { 340window.onload = function () {
341 if (width * height > 5000) {
342 document.body.insertBefore(document.createElement("p").appendChild(document.createTextNode("This probably won't work. Try a size where width * height is less than 5000")), document.getElementById("board"));
343 document.body.removeChild(document.getElementById("board"));
344 return;
345 }
335 document.getElementById("board").innerHTML = table; 346 document.getElementById("board").innerHTML = table;
336 timer = window.setInterval( function () { 347 timer = window.setInterval( function () {
337 time++; 348 time++;