mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 05:17:51 +08:00
added ready and route controller modules. script is gone. its over #495
This commit is contained in:
parent
1f7c2c4df6
commit
ac1759bd56
4 changed files with 56 additions and 48 deletions
|
@ -106,6 +106,8 @@ const refactoredSrc = [
|
|||
"./src/js/simple-popups.js",
|
||||
"./src/js/settings.js",
|
||||
"./src/js/input-controller.js",
|
||||
"./src/js/route-controller.js",
|
||||
"./src/js/ready.js",
|
||||
|
||||
"./src/js/account/all-time-stats.js",
|
||||
"./src/js/account/pb-tables.js",
|
||||
|
@ -162,11 +164,7 @@ const refactoredSrc = [
|
|||
|
||||
//legacy files
|
||||
//the order of files is important
|
||||
const globalSrc = [
|
||||
"./src/js/global-dependencies.js",
|
||||
"./src/js/script.js",
|
||||
"./src/js/exports.js",
|
||||
];
|
||||
const globalSrc = ["./src/js/global-dependencies.js", "./src/js/exports.js"];
|
||||
|
||||
//concatenates and lints legacy js files and writes the output to dist/gen/index.js
|
||||
task("cat", function () {
|
||||
|
|
|
@ -56,3 +56,4 @@ import * as PbTables from "./pb-tables";
|
|||
import * as Account from "./account";
|
||||
import * as VerificationController from "./verification-controller";
|
||||
import "./input-controller";
|
||||
import "./ready";
|
||||
|
|
|
@ -1,52 +1,17 @@
|
|||
(function (history) {
|
||||
var pushState = history.pushState;
|
||||
history.pushState = function (state) {
|
||||
if (Funbox.active === "memory" && state !== "/") {
|
||||
Funbox.resetMemoryTimer();
|
||||
}
|
||||
return pushState.apply(history, arguments);
|
||||
};
|
||||
})(window.history);
|
||||
|
||||
$(window).on("popstate", (e) => {
|
||||
let state = e.originalEvent.state;
|
||||
if (state == "" || state == "/") {
|
||||
// show test
|
||||
UI.changePage("test");
|
||||
} else if (state == "about") {
|
||||
// show about
|
||||
UI.changePage("about");
|
||||
} else if (state == "account" || state == "login") {
|
||||
if (firebase.auth().currentUser) {
|
||||
UI.changePage("account");
|
||||
} else {
|
||||
UI.changePage("login");
|
||||
}
|
||||
}
|
||||
});
|
||||
import * as ManualRestart from "./manual-restart-tracker";
|
||||
import Config, * as UpdateConfig from "./config";
|
||||
import * as Misc from "./misc";
|
||||
import * as VerificationController from "./verification-controller";
|
||||
import * as Settings from "./settings";
|
||||
import * as RouteController from "./route-controller";
|
||||
import * as UI from "./ui";
|
||||
|
||||
ManualRestart.set();
|
||||
UpdateConfig.loadFromCookie();
|
||||
Misc.getReleasesFromGitHub();
|
||||
|
||||
let mappedRoutes = {
|
||||
"/": "pageTest",
|
||||
"/login": "pageLogin",
|
||||
"/settings": "pageSettings",
|
||||
"/about": "pageAbout",
|
||||
"/account": "pageAccount",
|
||||
"/verify": "pageTest",
|
||||
};
|
||||
|
||||
function handleInitialPageClasses(el) {
|
||||
$(el).removeClass("hidden");
|
||||
$(el).addClass("active");
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
handleInitialPageClasses(
|
||||
$(".page." + mappedRoutes[window.location.pathname])
|
||||
);
|
||||
RouteController.handleInitialPageClasses(window.location.pathname);
|
||||
if (window.location.pathname === "/") {
|
||||
$("#top .config").removeClass("hidden");
|
||||
}
|
44
src/js/route-controller.js
Normal file
44
src/js/route-controller.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
import * as Funbox from "./funbox";
|
||||
import * as UI from "./ui";
|
||||
|
||||
let mappedRoutes = {
|
||||
"/": "pageTest",
|
||||
"/login": "pageLogin",
|
||||
"/settings": "pageSettings",
|
||||
"/about": "pageAbout",
|
||||
"/account": "pageAccount",
|
||||
"/verify": "pageTest",
|
||||
};
|
||||
|
||||
export function handleInitialPageClasses(pathname) {
|
||||
let el = $(".page." + mappedRoutes[pathname]);
|
||||
$(el).removeClass("hidden");
|
||||
$(el).addClass("active");
|
||||
}
|
||||
|
||||
(function (history) {
|
||||
var pushState = history.pushState;
|
||||
history.pushState = function (state) {
|
||||
if (Funbox.active === "memory" && state !== "/") {
|
||||
Funbox.resetMemoryTimer();
|
||||
}
|
||||
return pushState.apply(history, arguments);
|
||||
};
|
||||
})(window.history);
|
||||
|
||||
$(window).on("popstate", (e) => {
|
||||
let state = e.originalEvent.state;
|
||||
if (state == "" || state == "/") {
|
||||
// show test
|
||||
UI.changePage("test");
|
||||
} else if (state == "about") {
|
||||
// show about
|
||||
UI.changePage("about");
|
||||
} else if (state == "account" || state == "login") {
|
||||
if (firebase.auth().currentUser) {
|
||||
UI.changePage("account");
|
||||
} else {
|
||||
UI.changePage("login");
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Reference in a new issue