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