|
| 1 | +<!-- |
| 2 | +Copyright 2020 Google LLC |
| 3 | + |
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | + |
| 8 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + |
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +--> |
| 16 | +<html lang="en"> |
| 17 | +<head> |
| 18 | + <title>Tabs VS Spaces</title> |
| 19 | + <link rel="stylesheet" |
| 20 | + href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> |
| 21 | + <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> |
| 22 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> |
| 23 | +</head> |
| 24 | +<body> |
| 25 | +<nav class="red lighten-1"> |
| 26 | + <div class="nav-wrapper"> |
| 27 | + <a href="#" class="brand-logo center">Tabs VS Spaces</a> |
| 28 | + </div> |
| 29 | +</nav> |
| 30 | +<div class="section"> |
| 31 | + <div class="center"> |
| 32 | + <h4> |
| 33 | + <?php if ($tab_count == $space_count): ?> |
| 34 | + TABS and SPACES are evenly matched! |
| 35 | + <?php elseif ($tab_count > $space_count): ?> |
| 36 | + TABS are winning by <?=$tab_count - $space_count?> |
| 37 | + <?= $tab_count - $space_count > 1 ? "votes" : "vote" ?>! |
| 38 | + <?php elseif ($space_count > $tab_count): ?> |
| 39 | + SPACES are winning by <?=$space_count - $tab_count?> |
| 40 | + <?= $space_count - $tab_count > 1 ? "votes" : "vote" ?>! |
| 41 | + <?php endif ?> |
| 42 | + </h4> |
| 43 | + </div> |
| 44 | + <div class="row center"> |
| 45 | + <div class="col s6 m5 offset-m1"> |
| 46 | + <div class="card-panel <?= $tab_count > $space_count ?: 'green lighten-3' ?>"> |
| 47 | + <i class="material-icons large">keyboard_tab</i> |
| 48 | + <h3><?=$tab_count?> votes</h3> |
| 49 | + <button id="voteTabs" class="btn green">Vote for TABS</button> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + <div class="col s6 m5"> |
| 53 | + <div class="card-panel <?= $tab_count < $space_count ?: 'blue lighten-3' ?>"> |
| 54 | + <i class="material-icons large">space_bar</i> |
| 55 | + <h3><?=$space_count?> votes</h3> |
| 56 | + <button id="voteSpaces" class="btn blue">Vote for SPACES</button> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + <h4 class="header center">Recent Votes</h4> |
| 61 | + <ul class="container collection center"> |
| 62 | + <?php foreach ($list as $vote): ?> |
| 63 | + <li class="collection-item avatar"> |
| 64 | + <?php if ($vote['candidate'] == "TABS"): ?> |
| 65 | + <i class="material-icons circle green">keyboard_tab</i> |
| 66 | + <?php elseif ($vote['candidate'] == "SPACES"): ?> |
| 67 | + <i class="material-icons circle blue">space_bar</i> |
| 68 | + <?php endif ?> |
| 69 | + <span class="title"> |
| 70 | + A vote for <b><?= $vote['candidate'] ?></b> |
| 71 | + </span> |
| 72 | + <p>was cast at <?= $vote['time_cast'] ?></p> |
| 73 | + </li> |
| 74 | + <?php endforeach ?> |
| 75 | + </ul> |
| 76 | +</div> |
| 77 | +<script> |
| 78 | + function vote(team) { |
| 79 | + var xhr = new XMLHttpRequest(); |
| 80 | + xhr.onreadystatechange = function () { |
| 81 | + if (this.readyState == 4) { |
| 82 | + if (!window.alert(this.responseText)) { |
| 83 | + window.location.reload(); |
| 84 | + } |
| 85 | + } |
| 86 | + }; |
| 87 | + xhr.open("POST", "/", true); |
| 88 | + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
| 89 | + xhr.send("team=" + team); |
| 90 | + } |
| 91 | + document.getElementById("voteTabs").addEventListener("click", function () { |
| 92 | + vote("TABS"); |
| 93 | + }); |
| 94 | + document.getElementById("voteSpaces").addEventListener("click", function () { |
| 95 | + vote("SPACES"); |
| 96 | + }); |
| 97 | +</script> |
| 98 | +</body> |
| 99 | +</html> |
0 commit comments