]> gitweb.ps.run Git - lolstats/blobdiff - html/script.js
changes
[lolstats] / html / script.js
index cee77f6f1d5a8f9586fb18847239319e4806c199..25f1565c26f2f69cc3f5805cd2cc4c7f0054bfae 100644 (file)
@@ -29,6 +29,14 @@ function setUrl() {
     "&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");
@@ -37,23 +45,31 @@ function slideStartDown() {
   $("#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" });
@@ -61,7 +77,7 @@ function changeView(view) {
     }
   } 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" });
@@ -75,7 +91,7 @@ let app = new Vue({
   data: {
     summoner: "",
     region: "",
-    view: "start",
+    view: "",
     regions: getRegions(),
     champions: getChampions(),
     matchprops: getMatchProps(),
@@ -102,7 +118,6 @@ let app = new Vue({
 });
 
 function parseUrl() {
-  console.log("parseUrl");
   let url = new URL(window.location.href);
   if (url.searchParams.has("summoner")) {
     app.summoner = url.searchParams.get("summoner");
@@ -114,11 +129,20 @@ function parseUrl() {
   }
   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);
+});