Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added save js button #23

Merged
merged 2 commits into from
Feb 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions visualizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<button id="reload">Reload</button>
<button id="compile">Run/Show</button>
<button id="save" onclick="saveKnitout();">Save Knitout</button>
<button id="save" onclick="saveJavascript();">Save Javascript</button>
<label for="showKnitout"><input type="checkbox" name="showKnitout" id="showKnitout" onchange="toggleKnitout()">Show Knitout</label>
<span class="infoLink"><a href="https://github.com/textiles-lab/knitout-live-visualizer" target="_blank">github page</a>;</span>
<span class="infoLink"><a href="https://github.com/textiles-lab/knitout-live-visualizer/issues" target="_blank">report a bug</a></span>
Expand Down Expand Up @@ -555,6 +556,24 @@
}
fileSave(commentFreeKnitout, "knitoutFile.k");
}

function saveJavascript(){
fileSaveJavaScript(editor.getValue(), "knitoutFile.js");

}
function fileSaveJavaScript(sourceText, fileIdentity){
himalinig marked this conversation as resolved.
Show resolved Hide resolved
var workElement = document.createElement("a");
if ('download' in workElement) {
workElement.href = "data:" + 'text/plain' + "charset=utf-8," + escape(sourceText);
workElement.setAttribute("download", fileIdentity);
document.body.appendChild(workElement);
var eventMouse = document.createEvent("MouseEvents");
eventMouse.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
workElement.dispatchEvent(eventMouse);
document.body.removeChild(workElement);
} else throw 'File saving not supported for this browser';

}
function fileSave(sourceText, fileIdentity) {
var workElement = document.createElement("a");
if ('download' in workElement) {
Expand All @@ -568,6 +587,7 @@
} else throw 'File saving not supported for this browser';
}


var file = document.getElementById("file");
file.addEventListener('change', function(evt){
try {
Expand Down