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