treesummaryrefslogcommitdiff
path: root/html/script.js
blob: a19069073401247332a582256e70b7a3617e34fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Start Screen
// ------------
function getRegions() {
  return [ "euw", "na", "kr", "br" ];
}
function getChampions() {
  return [ "Aatrox", "Annie", "Braum" ];
}
function getInfo() {
  app.summoner = $("#nameinput").val();
  app.region = $("#regionselect").val();
} 
function setUrl() {
  window.history.pushState("object or string", "Title",
    "/lol?summoner=" +
    app.summoner +
    "&region=" +
    app.region +
    "&view=" +
    app.view);
}

function toggleStart(up) {
  $("#start").removeClass(up ? "down" : "up");
  $("#start").addClass(up ? "up" : "down");
}
function slideStart() {
  $("#start").addClass("slideup");
}
var app = new Vue({
  el: '#app',
  data: {
    summoner: "",
    region: "",
    view: "start",
    regions: getRegions(),
    champions: getChampions(),
  },
  methods: {
    submit: function() {
      getInfo();
      if (app.view == "start") {
        app.view = "history";
        setUrl();
        slideStart();
        $("#matchhistory").show("slide", { direction: "down" }, 300);
      } else {
        setUrl();
      }
    },
    historyToStats: function() {
      app.view = "stats";
      setUrl();
      $("#stats").show("blind", { direction: "right" });
      $("#matchhistory").hide("blind", { direction: "left" });
    },
    statsToHistory: function() {
      app.view = "history";
      setUrl();
      $("#matchhistory").show("blind", { direction: "left" });
      $("#stats").hide("blind", { direction: "right" });
    },
  },
});

// Check for URL parameters
let url = new URL(window.location.href);
if (url.searchParams.has("summoner")) {
  app.summoner = url.searchParams.get("summoner");
  $("#nameinput").val(app.summoner);
}
if (url.searchParams.has("region")) {
  app.region = url.searchParams.get("region");
  $("#regionselect").val(app.region);
}
if (url.searchParams.has("view")) {
  let view = url.searchParams.get("view");
  if (view == "history") {
    toggleStart(true);
    $("#matchhistory").show();
  }
  else if (view == "stats") {
    toggleStart(true);
    $("#stats").show();
  }
}
// ------------