-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom.min.js
1 lines (1 loc) · 2.73 KB
/
custom.min.js
1
function saveMap(){return JSON.stringify(argumentRender.export())}function toPNG(){const e=document.querySelector("#element canvas");var a=e.getContext("2d");a.globalCompositeOperation="destination-over",a.fillStyle="white",a.fillRect(0,0,e.width,e.height);var t=e.toDataURL("image/png"),o=document.createElement("a");o.download="argument-.png",o.href=t,o.click()}const canvas=document.querySelector("#element"),box=canvas.getBoundingClientRect();let graphInitial=[{id:"p1",text:"Prémisse 1",x:1.5*box.width/3,y:1*box.height/3-125},{id:"p2",text:"Prémisse 2",x:2*box.width/3,y:1*box.height/3-125},{id:"c1",text:"Conclusion",x:box.width/2+150,y:2*box.height/3},{from:["p1","p2"],to:"c1"}];var codageArgument=localStorage.getItem("codageArgument");if(codageArgument&&(graphInitial=JSON.parse(codageArgument)),argumentTest=Reasons.mapper("#element-test"),window.location.hash){var newHash=window.location.hash.substring(1);hashDecode=decodeURI(newHash),JSON.parse(hashDecode)&&(graphInitial=JSON.parse(hashDecode),argumentTestRender=argumentTest.render(graphInitial),argumentTestRender&&hashDecode!=codageArgument&&(localStorage.setItem("codageArgument",hashDecode),location.reload()))}argument=Reasons.mapper("#element"),argumentRender=argument.render(graphInitial);var uri=window.location.href.split("#")[0],autosave=!0,developerMode=!1;setInterval(function(){1==autosave&&(codageArgument=saveMap(),localStorage.setItem("codageArgument",codageArgument))},2e3);var codageArgumentTextArea=document.getElementById("codageArgument"),modal=document.getElementById("myModal"),btnModal=document.getElementById("createLink"),closeModal=document.getElementById("closeModal");btnModal.onclick=function(){autosave=!1,codageArgumentTextArea.value=saveMap(),1==developerMode?modal.classList.add("modal-active"):(codageArgument=codageArgumentTextArea.value,JSON.parse(codageArgument)?(graphInitial=JSON.parse(codageArgument),argumentTestRender=argumentTest.render(graphInitial),argumentTestRender&&(localStorage.setItem("codageArgument",codageArgument),navigator.clipboard.writeText(uri+"#"+codageArgumentTextArea.value),location.replace(uri+"#"+codageArgumentTextArea.value))):location.reload(),autosave=!0)},closeModal.onclick=function(){codageArgument=codageArgumentTextArea.value,JSON.parse(codageArgument)?(graphInitial=JSON.parse(codageArgument),argumentTestRender=argumentTest.render(graphInitial),argumentTestRender&&(localStorage.setItem("codageArgument",codageArgument),navigator.clipboard.writeText(uri+"#"+codageArgumentTextArea.value),location.replace(uri+"#"+codageArgumentTextArea.value))):location.reload(),autosave=!0,1==developerMode&&modal.classList.remove("modal-active")},window.onclick=function(e){e.target==modal&&(autosave=!0,1==developerMode&&modal.classList.remove("modal-active"))};