diff --git a/InitUiElements.ts b/InitUiElements.ts index f69f7d0..ab9037b 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -34,27 +34,34 @@ import {GeoLocationHandler} from "./Logic/Leaflet/GeoLocationHandler"; import {Layout} from "./Customizations/Layout"; import {LocalStorageSource} from "./Logic/Web/LocalStorageSource"; import {FromJSON} from "./Customizations/JSON/FromJSON"; +import {Utils} from "./Utils"; export class InitUiElements { - static InitAll(layoutToUse: Layout, layoutFromBase64: string, testing: UIEventSource, defaultLayout1: string ) { + static InitAll(layoutToUse: Layout, layoutFromBase64: string, testing: UIEventSource, layoutName: string ) { if (layoutToUse === undefined) { console.log("Incorrect layout") - new FixedUiElement("Error: incorrect layout " + defaultLayout1 + "
Go back").AttachTo("centermessage").onClick(() => { + new FixedUiElement("Error: incorrect layout " + layoutName + "
Go back").AttachTo("centermessage").onClick(() => { }); throw "Incorrect layout" } - console.log("Using layout: ", layoutToUse.id); + const hash = location.hash.substr(1); + console.log("Using layout: ", layoutToUse.id, "LayoutFromBase64 is ", layoutFromBase64); State.state = new State(layoutToUse); + + // This 'leaks' the global state via the window object, useful for debugging + // @ts-ignore + window.mapcomplete_state = State.state; if (layoutToUse.hideFromOverview) { State.state.osmConnection.GetPreference("hidden-theme-" + layoutToUse.id + "-enabled").setData("true"); } if (layoutFromBase64 !== "false") { - State.state.layoutDefinition = location.hash.substr(1); + State.state.layoutDefinition = hash; + console.log("Layout definition:",Utils.EllipsesAfter(State.state.layoutDefinition, 100)) if (testing.data !== "true") { State.state.osmConnection.OnLoggedIn(() => { State.state.osmConnection.GetLongPreference("installed-theme-" + layoutToUse.id).setData(State.state.layoutDefinition); @@ -200,9 +207,7 @@ export class InitUiElements { new GeoLocationHandler().AttachTo("geolocate-button"); State.state.locationControl.ping(); - // This 'leaks' the global state via the window object, useful for debugging - // @ts-ignore - window.mapcomplete_state = State.state; + } diff --git a/index.ts b/index.ts index 92301b9..d547dd0 100644 --- a/index.ts +++ b/index.ts @@ -34,7 +34,6 @@ if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { // ----------------- SELECT THE RIGHT QUESTSET ----------------- let defaultLayout = "bookcases" -let hash = window.location.hash; const path = window.location.pathname.split("/").slice(-1)[0]; if (path !== "index.html" && path !== "") { @@ -68,7 +67,7 @@ if (layoutFromBase64.startsWith("wiki:")) { const themeName = layoutFromBase64.substr("wiki:".length); new FixedUiElement(`Downloading ${themeName} from the wiki...`) .AttachTo("centermessage"); - const cleanUrl = `https://wiki.openstreetmap.org/wiki/${themeName}`; + const cleanUrl = `https://wiki.openstreetmap.org/wiki/${themeName}`; const url = `https://cors-anywhere.herokuapp.com/` + cleanUrl; // VERY SAFE AND HACKER-PROOF! $.ajax({ @@ -82,6 +81,7 @@ if (layoutFromBase64.startsWith("wiki:")) { try { console.log("DOWNLOADED:",layoutJson); const layout = FromJSON.LayoutFromJSON(JSON.parse(layoutJson)); + layout.id = layoutFromBase64; InitUiElements.InitAll(layout, layoutFromBase64, testing, layoutFromBase64); } catch (e) { new FixedUiElement(`${themeName} is invalid:
${e}`) @@ -96,9 +96,9 @@ if (layoutFromBase64.startsWith("wiki:")) { .AttachTo("centermessage"); }); +} else if (layoutFromBase64 !== "false") { + layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam); + InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout); } else { - if (layoutFromBase64 !== "false") { - layoutToUse = InitUiElements.LoadLayoutFromHash(userLayoutParam); - } InitUiElements.InitAll(layoutToUse, layoutFromBase64, testing, defaultLayout); }