]> gitweb.ps.run Git - lolstats/blob - html/script.js
8db21f945033e3b607c7c4a13e2464012ec4dc6b
[lolstats] / html / script.js
1 // Start Screen
2 // ------------
3 function getRegions() {
4   return [ "euw", "na", "kr", "br" ];
5 }
6
7 function getInfo() {
8   app.summoner = $("#nameinput").val();
9   app.region = $("#regionselect").val();
10
11 function setUrl() {
12   window.history.pushState("object or string", "Title",
13     "/?summoner=" +
14     app.summoner +
15     "&region=" +
16     app.region +
17     "&view=" +
18     app.view);
19 }
20
21 function toggleStart(up) {
22   $("#start").removeClass(up ? "down" : "up");
23   $("#start").addClass(up ? "up" : "down");
24 }
25 function slideStart() {
26   $("#start").addClass("slideup");
27 }
28 var app = new Vue({
29   el: '#app',
30   data: {
31     summoner: "",
32     region: "",
33     view: "start",
34     regions: getRegions(),
35   },
36   methods: {
37     submit: function() {
38       getInfo();
39       if (app.view == "start") {
40         app.view = "history";
41         setUrl();
42         slideStart();
43         $("#matchhistory").show("slide", { direction: "down" }, 300);
44       } else {
45         setUrl();
46       }
47     },
48     historyToStats: function() {
49       app.view = "stats";
50       setUrl();
51       $("#stats").show("blind", { direction: "right" });
52       $("#matchhistory").hide("blind", { direction: "left" });
53     },
54     statsToHistory: function() {
55       app.view = "history";
56       setUrl();
57       $("#matchhistory").show("blind", { direction: "left" });
58       $("#stats").hide("blind", { direction: "right" });
59     },
60   },
61 });
62
63 // Check for URL parameters
64 let url = new URL(window.location.href);
65 if (url.searchParams.has("summoner")) {
66   app.summoner = url.searchParams.get("summoner");
67   $("#nameinput").val(app.summoner);
68 }
69 if (url.searchParams.has("region")) {
70   app.region = url.searchParams.get("region");
71   $("#regionselect").val(app.region);
72 }
73 if (url.searchParams.has("view")) {
74   let view = url.searchParams.get("view");
75   if (view == "history") {
76     toggleStart(true);
77     $("#matchhistory").show();
78   }
79   else if (view == "stats") {
80     toggleStart(true);
81     $("#stats").show();
82   }
83 }
84 // ------------