"use strict"; const output = document.querySelector(".output"); var localJsonFile = "data/marti_test_asic.json"; var btn = document.getElementById("loadBtn"); btn.onclick = dataLoadFunction; function dataLoadFunction() { var loadDef = document.getElementById("loaddefinition") if (loadDef.value.startsWith("http://") || loadDef.value.startsWith("https://")) { fetchData(loadDef.value); } else { fetchData("data/"+ loadDef.value); } } var definition_must = ""; var jdata = {}; window.addEventListener("DOMContentLoaded", () => { var urlParams = new URLSearchParams(window.location.search); if (urlParams.has('martilq')) { var loadDef = urlParams.get('martilq'); if (loadDef.startsWith("http://") || loadDef.startsWith("https://")) { fetchData(loadDef); } else { fetchData("data/"+ loadDef); } var ld = document.getElementById("loaddefinition") ld.value = loadDef } else { output.innerHTML = "Please supply a MartiLQ definition to load, such as \"martilq_asic.json\""; } }); function fetchData(dataFile) { output.textContent = "Loading...."; fetch(dataFile) .then((response) => response.json()) .then((data) => { var template = "data/martilq_def.must"; jdata["item"] = data; jdata["describe"] = data.description.replace(/\r\n/g, "
"); if (data["custom"]) { data.custom.forEach((el) => { if (el.extension == "template" && el.renderer == "MartiReference:Mustache") { template = el.url; } }); } // Use the template fetchMust(template); }); } function fetchMust(mustTemplateFile) { fetch(mustTemplateFile) .then((response) => response.text()) .then((data) => { definition_must = data const dMust = document.createElement("div"); dMust.innerHTML = Mustache.render(definition_must, jdata); output.innerHTML = ""; output.append(dMust); }); }