From 0658b9aa7f5b84c293f4f5b02fc3c4267a74bb36 Mon Sep 17 00:00:00 2001 From: Code by Ben Date: Sun, 28 Jul 2024 11:05:24 +1000 Subject: [PATCH] use #hash urls to open modals on load. --- assets/js/editor-assets.js | 51 ++++++++++++++++++++++++++++------ public/js/editor-assets.min.js | 2 +- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/assets/js/editor-assets.js b/assets/js/editor-assets.js index eb7e3008..a99c972e 100644 --- a/assets/js/editor-assets.js +++ b/assets/js/editor-assets.js @@ -2,19 +2,52 @@ (() => { "use strict"; - alert(`editor assets script is running`); + //alert(`editor assets script is running`); //const danger = `text-danger`; - const err = `is-invalid`; - const ok = `is-valid`; - const fok = `valid-feedback`; - const ferr = `invalid-feedback`; + // const err = `is-invalid`; + // const ok = `is-valid`; + // const fok = `valid-feedback`; + // const ferr = `invalid-feedback`; - const header = { - "Content-type": "application/json; charset=UTF-8", - }; + // const header = { + // "Content-type": "application/json; charset=UTF-8", + // }; - const saveErr = `server could not save the change`; + // const saveErr = `server could not save the change`; + + const dataEditor = document.getElementById("artifact-editor-modal"); + if (dataEditor == null) { + console.error(`the data editor modal is missing`); + return; + } + const assetEditor = document.getElementById("asset-editor-modal"); + if (assetEditor == null) { + console.error(`the asset editor modal is missing`); + return; + } + const jsdosEditor = document.getElementById("emulate-editor-modal"); + if (jsdosEditor == null) { + console.error(`the emulate editor modal is missing`); + return; + } + const dataModal = new bootstrap.Modal(dataEditor); + const assetModal = new bootstrap.Modal(assetEditor); + const emulateModal = new bootstrap.Modal(jsdosEditor); + + const parsedUrl = new URL(window.location.href); + switch (parsedUrl.hash) { + case `#data-editor`: + dataModal.show(); + break; + case `#file-editor`: + assetModal.show(); + break; + case `#emulate-editor`: + emulateModal.show(); + break; + default: + } // The table record id and key value, used for all fetch requests // It is also used to confirm the existence of the editor modal diff --git a/public/js/editor-assets.min.js b/public/js/editor-assets.min.js index 0eb77c54..a4ab7fbc 100644 --- a/public/js/editor-assets.min.js +++ b/public/js/editor-assets.min.js @@ -1,2 +1,2 @@ /* editor-assets.min.js © Defacto2 2024 */ -(()=>{"use strict";alert("editor assets script is running");const e="is-invalid",s="is-valid",t="valid-feedback",n="invalid-feedback",a={"Content-type":"application/json; charset=UTF-8"},i="server could not save the change"})(); +(()=>{"use strict";const e=document.getElementById("artifact-editor-modal");if(e==null){console.error("the data editor modal is missing");return}const t=document.getElementById("asset-editor-modal");if(t==null){console.error("the asset editor modal is missing");return}const o=document.getElementById("emulate-editor-modal");if(o==null){console.error("the emulate editor modal is missing");return}const a=new bootstrap.Modal(e),s=new bootstrap.Modal(t),r=new bootstrap.Modal(o);switch(new URL(window.location.href).hash){case"#data-editor":a.show();break;case"#file-editor":s.show();break;case"#emulate-editor":r.show();break;default:}})();