import { stageManager } from "./stage-manager"; import { FileParser } from "../parser/file-parser"; class HeaderMenu { constructor() {} bootstrap() { $("body").on("click", "#save", this.save.bind(this)); $("body").on("click", "#open", this.open.bind(this)); $("body").on("change", "#input-file", this.onFileChanged.bind(this)); } save() { const layer = stageManager.getCurrentLayer(); const file = layer.actionManager.save(); const a = document.createElement("a"), url = URL.createObjectURL(file); a.href = url; a.download = `${layer.name}.geo`; document.body.appendChild(a); a.click(); setTimeout(function() { document.body.removeChild(a); window.URL.revokeObjectURL(url); }, 0); } open() { $("#input-file").click(); } onFileChanged() { const files = $("#input-file")[0].files; if (files == undefined || files.length === 0) return; const reader = new FileReader(); reader.onload = function() { const result = reader.result; const parser = new FileParser(result); const map = parser.parse(); console.info("map", map); }; reader.readAsText(files[0]); } } export const headerMenu = new HeaderMenu();