Skip to content

Commit

Permalink
Add download button (#45)
Browse files Browse the repository at this point in the history
Resolves #22
  • Loading branch information
hjonin authored May 8, 2024
1 parent 9bf79ad commit 28b7936
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ <h1>CodeMeta generator v3.0</h1>
title="Checks the codemeta.json file below is valid, and displays errors." />
<input type="button" id="importCodemeta" value="Import codemeta.json" disabled
title="Fills the fields above based on the codemeta.json file below." />
<a id="downloadCodemeta"><input type="button" value="Download codemeta.json" disabled
title="Download the codemeta.json file as displayed below." /></a>
</form>

<p id="errorMessage">
Expand Down
9 changes: 9 additions & 0 deletions js/codemeta_generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,12 @@ function loadStateFromStorage() {
importCodemeta();
}
}

function downloadCodemeta() {
const codemetaText = document.querySelector('#codemetaText').innerText;
const blob = new Blob([codemetaText], {type: 'application/json'});
const url = URL.createObjectURL(blob);
document.querySelector('#downloadCodemeta').href = url;
document.querySelector('#downloadCodemeta').download = "codemeta.json";
URL.revokeObjectURL(url);
}
4 changes: 4 additions & 0 deletions js/dynamic_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ function initCallbacks() {
document.querySelector('#importCodemeta')
.addEventListener('click', importCodemeta);

document.querySelector('#downloadCodemeta input').disabled = false;
document.querySelector('#downloadCodemeta input')
.addEventListener('click', downloadCodemeta);

document.querySelector('#inputForm')
.addEventListener('change', () => generateCodemeta());

Expand Down

0 comments on commit 28b7936

Please sign in to comment.