Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.03 KB | None | 0 0
  1. <!--
  2. Style Sheet
  3. -->
  4.  
  5. <style>
  6. #reward-container {
  7. width: 100%;
  8. height: 100%;
  9. background-color: #D3D3D3;
  10. position: relative;
  11. }
  12.  
  13. #reward-header {
  14. width: 100%;
  15. height: 10%;
  16. text-align: center;
  17. line-height: 2.1;
  18. font-size: 30px;
  19. color: white;
  20. background-color: #0094ce;
  21. font-weight: bold;
  22. box-shadow: 0px 3px 5px #404040;
  23. position: relative;
  24. z-index: 3;
  25. }
  26.  
  27. #nav {
  28. list-style: none;
  29. height: 30px;
  30. width: 100%;
  31. position: relative;
  32. z-index: 2;
  33. text-align: center;
  34. }
  35.  
  36. #nav ul {
  37. list-style: none;
  38. display: inline-block;
  39. margin: 0;
  40. padding: 0;
  41. height: 100%;
  42. }
  43.  
  44. #categories {
  45. height: 30px;
  46. width: 100%;
  47. margin: 0;
  48. padding: 0;
  49. display: inline-block;
  50. }
  51.  
  52. #nav ul li {
  53. float: left;
  54. width: 72.5px;
  55. margin: 0;
  56. height: 100%;
  57. }
  58.  
  59. #nav ul li button {
  60. height: 100%;
  61. width: 100%;
  62. outline: none;
  63. border: none;
  64. color: white;
  65. transition: all 0.3s ease 0s;
  66. }
  67.  
  68. #nav, #nav ul li button {
  69. background-color: #939393;
  70. }
  71.  
  72. #nav ul li button:hover {
  73. background-color: #d3d3d3;
  74. color: black;
  75. cursor: pointer;
  76. }
  77.  
  78. .navselected {
  79. background-color: whitesmoke !important;
  80. color: black !important;
  81. }
  82.  
  83. #stats {
  84. height: 500px;
  85. width: 100%;
  86. }
  87.  
  88. #hint {
  89. width: 100%;
  90. height: 23px;
  91. background-color: #a8a8a8;
  92. text-align: center;
  93. color: white;
  94. line-height: 1.5;
  95. position: relative;
  96. z-index: 1;
  97. }
  98.  
  99. .stat-container {
  100. width: 100%;
  101. height: 100%;
  102. display: none;
  103. }
  104.  
  105. .stat-container-show {
  106. display: block;
  107. }
  108.  
  109. .student {
  110. width: 100%;
  111. height: 20px;
  112. background-color: whitesmoke;
  113. text-align: center;
  114. }
  115.  
  116. #timer {
  117. background-color: red;
  118. color: white;
  119. font-weight: bold;
  120. font-size: 16px;
  121. text-align: center;
  122. margin-top: 10px;
  123. }
  124. </style>
  125.  
  126. <!--
  127. HTML
  128. -->
  129.  
  130. <div id="userData" style="display:none; visibility:hidden;" data-users="{{msg.payload}}"></div>
  131.  
  132. <div id="reward-container">
  133. <div id="reward-header">Water Wars</div>
  134. <div id="hint">
  135. View the rankings per category.
  136. </div>
  137. <div id="nav">
  138. <ul>
  139. <li>
  140. <button class="navselected" id="students" onclick="changeTab(this)">Students</button>
  141. </li>
  142.  
  143. <li>
  144. <button id="classes" onclick="changeTab(this)">Classes</button>
  145. </li>
  146.  
  147. <li>
  148. <button id="staff" onclick="changeTab(this)">Staff</button>
  149. </li>
  150.  
  151. <li>
  152. <button id="schools" onclick="changeTab(this)">Schools</button>
  153. </li>
  154. </ul>
  155. </div>
  156. <div id="stats">
  157. <div id="stats-student" class="stat-container stat-container-show">
  158.  
  159. </div>
  160. <div id="stats-classes" class="stat-container">
  161.  
  162. </div>
  163. <div id="stats-staff" class="stat-container">
  164.  
  165. </div>
  166. <div id="stats-school" class="stat-container">
  167.  
  168. </div>
  169. </div>
  170. <div id="timer">
  171. Competition ends in ...
  172. </div>
  173. </div>
  174.  
  175.  
  176.  
  177.  
  178. <!--
  179. JS and JQuery
  180. -->
  181.  
  182. <script>
  183. // LOAD DATA
  184. try {
  185. let data;
  186. } catch (e) {
  187. throw e;
  188. }
  189.  
  190. window.onload = setTimeout(() => {
  191. data = JSON.parse(eById("userData").getAttribute("data-users"));
  192.  
  193. let [students, classes, staff, schools] = [data["students"], data["classes"], data["staff"], data["schools"]];
  194.  
  195. let rankings = [];
  196.  
  197. for (var student in students) {
  198. let points = students[student]["points"];
  199. rankings.push([student, points]);
  200. }
  201.  
  202. rankings.sort(function(a, b) {
  203. return b[1] - a[1];
  204. });
  205.  
  206. for (var p in rankings) {
  207. let user = getStudentById(rankings[p]);
  208. let person = document.createElement("div");
  209. person.setAttribute("id", "student-" + rankings[p][0]);
  210. person.classList.add("student");
  211. person.innerHTML = "#" + (parseInt(p)+1) + " | " + user["firstname"] + " " + user["lastname"] + " | " + user["points"] + " pts.";
  212.  
  213. eById("stats-student").append(person);
  214. }
  215.  
  216. rankings = [];
  217.  
  218. for (var c in classes) {
  219. let points = classes[c]["points"];
  220. rankings.push([c, points]);
  221. }
  222.  
  223. rankings.sort(function(a, b) {
  224. return b[1] - a[1];
  225. });
  226.  
  227. for (var c in rankings) {
  228. let cl = getClassById(rankings[c]);
  229. let classElement = document.createElement("div");
  230. classElement.setAttribute("id", "class-" + rankings[c][0]);
  231. classElement.classList.add("student");
  232. classElement.innerHTML = "#" + (parseInt(c) + 1) + " | " + cl["name"] + " | " + cl["points"] + " pts.";
  233.  
  234. eById("stats-classes").append(classElement);
  235. }
  236.  
  237. rankings = [];
  238.  
  239. for (var s in staff) {
  240. let points = staff[s]["points"];
  241. rankings.push([s, points]);
  242. }
  243.  
  244. rankings.sort(function(a, b) {
  245. return b[1] - a[1];
  246. });
  247.  
  248. for (var s in rankings) {
  249. let st = getStaffById(rankings[s]);
  250. let staffElement = document.createElement("div");
  251. staffElement.setAttribute("id", "class-" + rankings[s][0]);
  252. staffElement.classList.add("student");
  253. staffElement.innerHTML = "#" + (parseInt(s) + 1) + " | " + st["firstname"] + " " + st["lastname"] + " | " + st["points"] + " pts.";
  254.  
  255. eById("stats-staff").append(staffElement);
  256. }
  257.  
  258. // sort schools
  259. rankings = [];
  260.  
  261. for (var s in schools) {
  262. let points = schools[s]["points"];
  263. rankings.push([s, points]);
  264. }
  265.  
  266. rankings.sort(function(a, b) {
  267. return b[1] - a[1];
  268. });
  269.  
  270. for (var s in rankings) {
  271. let sc = getSchoolById(rankings[s]);
  272. let schoolElement = document.createElement("div");
  273. schoolElement.setAttribute("id", "school-" + rankings[s][0]);
  274. schoolElement.classList.add("student");
  275. schoolElement.innerHTML = "#" + (parseInt(s) + 1) + " | " + sc["name"] + " | " + sc["points"] + " pts.";
  276.  
  277. eById("stats-school").append(schoolElement);
  278. }
  279. }, 250);
  280.  
  281. function getStudentById(iden) {
  282. let students = data["students"];
  283. for (var student in students) {
  284. if (iden.includes(student)) {
  285. return students[student];
  286. }
  287. }
  288. return null;
  289. }
  290.  
  291. function getClassById(iden) {
  292. let classes = data["classes"];
  293. for (var c in classes) {
  294. if (iden.includes(c)) {
  295. return classes[c];
  296. }
  297. }
  298. return null;
  299. }
  300.  
  301. function getStaffById(iden) {
  302. let staff = data["staff"];
  303. for (var s in staff) {
  304. if (iden.includes(s)) {
  305. return staff[s];
  306. }
  307. }
  308. return null;
  309. }
  310.  
  311. function getSchoolById(iden) {
  312. let schools = data["schools"];
  313. for (var s in schools) {
  314. if (iden.includes(s)) {
  315. return schools[s];
  316. }
  317. }
  318. return null;
  319. }
  320.  
  321.  
  322. function eById(i) {
  323. return document.getElementById(i);
  324. }
  325.  
  326. function rc(e, c) {
  327. e.classList.remove(c);
  328. }
  329.  
  330. function changeTab(tab) {
  331. let [s, c, sf, sc] = [eById("students"), eById("classes"), eById("staff"), eById("schools")];
  332. let [st, ct, sft, sct] = [eById("stats-student"), eById("stats-classes"), eById("stats-staff"), eById("stats-school")];
  333.  
  334. if (tab.classList.contains("navselected")) {
  335. return;
  336. }
  337.  
  338. //student tab
  339. rc(s, "navselected");
  340. rc(st, "stat-container-show");
  341.  
  342. //class tab
  343. rc(c, "navselected");
  344. rc(ct, "stat-container-show");
  345.  
  346. //staff tab
  347. rc(sf, "navselected");
  348. rc(sft, "stat-container-show");
  349.  
  350. rc(sc, "navselected");
  351. rc(sct, "stat-container-show");
  352.  
  353. switch (tab) {
  354. case s:
  355. st.classList.add("stat-container-show");
  356. break;
  357. case c:
  358. ct.classList.add("stat-container-show");
  359. break;
  360. case sf:
  361. sft.classList.add("stat-container-show");
  362. break;
  363. case sc:
  364. sct.classList.add("stat-container-show");
  365. break;
  366. }
  367.  
  368. tab.classList.add("navselected");
  369. }
  370.  
  371. // COUNTDOWN CLOCK
  372.  
  373. var endDate = new Date("March 31, 2018 23:59:59").getTime();
  374.  
  375. var cd = setInterval(() => {
  376. var current = new Date().getTime();
  377.  
  378. var dist = endDate - current;
  379.  
  380. var d = Math.floor(dist / (1000 * 60 * 60 * 24));
  381. var h = Math.floor((dist % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  382. var m = Math.floor((dist % (1000 * 60 * 60)) / (1000 * 60));
  383. var s = Math.floor((dist % (1000 * 60)) / 1000);
  384.  
  385. eById("timer").innerHTML = " Competition ends in " + d + "d " + h + "h " + m + "m " + s + "s!";
  386.  
  387. }, 1000);
  388.  
  389. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement