function getRegions() {
- return [ "euw", "na", "kr", "br" ];
+ $.ajax("/lol/regions")
+ .done((data) => {
+ app.regions = JSON.parse(data);
+ });
}
function getChampions() {
- return [ {name: "Aatrox"}, {name: "Annie"}, {name: "Braum"}, {name: "Not"} ];
+ $.ajax("/lol/champions")
+ .done((data) => {
+ app.champions = JSON.parse(data);
+ });
}
function getMatchProps() {
return [
];
}
function getMatches() {
- return [
- {champ: "Xerath", lane: "Middle"},
- {champ: "Quinn", lane: "Bottom"},
- ];
+ $.ajax("/lol/matches?region=" + app.region + "&summoner=" + app.summoner)
+ .done((data) => {
+ app.matches = JSON.parse(data);
+ });
}
function getInfo() {
app.summoner = $("#nameinput").val();
"&view=" +
app.view);
}
+function toggleStartUp() {
+ $("#start").removeClass("down");
+ $("#start").addClass("up");
+}
+function toggleStartDown() {
+ $("#start").removeClass("up");
+ $("#start").addClass("down");
+}
function slideStartUp() {
$("#start").removeClass("slidedown");
$("#start").addClass("slideup");
$("#start").removeClass("slideup");
$("#start").addClass("slidedown");
}
-function changeView(view) {
- if (view != "start" && view != "history" && view != "stats") {
- setUrl();
- return;
+function setView(view) {
+ console.log("Setting view to " + view);
+ if (view == "history") {
+ toggleStartUp();
+ $("#matchhistory").show();
+ } else if (view == "stats") {
+ toggleStartUp();
+ $("#stats").show();
}
+ app.view = view;
+}
+function changeView(view) {
let oldView = app.view;
+ console.log("changing view from " + oldView + " to " + view);
if (oldView == "start") {
if (view == "history") {
slideStartUp();
- $("#matchhistory").show("slide", { direction: "down" }, 300);
+ $("#matchhistory").show("blind", { direction: "down" }, 300);
} else if (view == "stats") {
slideStartUp();
- $("#stats").show("slide", { direction: "down" }, 300);
+ $("#stats").show("blind", { direction: "down" }, 300);
}
} else if (oldView == "history") {
if (view == "start") {
- $("#matchhistory").hide("slide", { direction: "down" }, 300);
+ $("#matchhistory").hide("blind", { direction: "down" }, 300);
slideStartDown();
} else if (view == "stats") {
$("#stats").show("blind", { direction: "right" });
}
} else if (oldView == "stats") {
if (view == "start") {
- $("#stats").hide("slide", { direction: "down" }, 300);
+ $("#stats").hide("blind", { direction: "down" }, 300);
slideStartDown();
} else if (view == "history") {
$("#matchhistory").show("blind", { direction: "left" });
data: {
summoner: "",
region: "",
- view: "start",
- regions: getRegions(),
- champions: getChampions(),
- matchprops: getMatchProps(),
- matches: getMatches(),
+ view: "",
+ regions: [],
+ champions: [],
+ matchprops: [],
+ matches: [],
},
methods: {
submit: function() {
setUrl();
},
refreshHistory: function() {
+ getMatches();
},
},
});
function parseUrl() {
- console.log("parseUrl");
let url = new URL(window.location.href);
if (url.searchParams.has("summoner")) {
app.summoner = url.searchParams.get("summoner");
}
if (url.searchParams.has("view")) {
let view = url.searchParams.get("view");
- changeView(view);
+ if (view != "start" && view != "history" && view != "stats") {
+ view = "start";
+ }
+ return view;
} else {
- changeView("start");
+ return "start";
}
}
-window.addEventListener('popstate', parseUrl);
-window.addEventListener('load', parseUrl);
+window.addEventListener('popstate', () => {
+ let view = parseUrl();
+ changeView(view);
+});
+window.addEventListener('load', () => {
+ let view = parseUrl();
+ setView(view);
+ getRegions();
+ getChampions();
+});