Skip to content

Commit

Permalink
Fixed download page (#1811)
Browse files Browse the repository at this point in the history
This makes the download page work on Edge again.
  • Loading branch information
RunDevelopment committed Mar 24, 2019
1 parent 64baec3 commit 77c5744
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 7 additions & 2 deletions download.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
height: 20em;
word-wrap: break-word;
}
#download .download-button {
cursor: pointer;
width: 100%;
}

#download-js .download-button {
border-top-right-radius: 0;
Expand Down Expand Up @@ -154,12 +158,12 @@ <h2>Customize your download</h2>
<div class="error"></div>
<section id="download-js" class="download">
<pre><code class="language-javascript"></code></pre>
<a href="#" class="download-button" download="prism.js" target="_blank">Download JS</a>
<button type="button" class="download-button">Download JS</button>
</section>

<section id="download-css" class="download">
<pre><code class="language-css"></code></pre>
<a href="#" class="download-button" download="prism.css" target="_blank">Download CSS</a>
<button type="button" class="download-button">Download CSS</button>
</section>
</section>

Expand All @@ -174,6 +178,7 @@ <h2>Customize your download</h2>
<script src="components.js"></script>
<script src="scripts/code.js"></script>
<script src="scripts/vendor/promise.js"></script>
<script src="scripts/vendor/FileSaver.min.js"></script>
<script src="scripts/download.js"></script>

</body>
Expand Down
16 changes: 12 additions & 4 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,20 @@ function generateCode(){
var versionComment = "/* PrismJS " + version + "\n" + redownloadUrl + " */";

for (var type in code) {
var codeElement = $('#download-' + type + ' code');
(function (type) {
var text = versionComment + "\n" + code[type];
var fileName = 'prism.' + type;

codeElement.textContent = versionComment + "\n" + code[type];
Prism.highlightElement(codeElement, true);
var codeElement = $('#download-' + type + ' code');

$('#download-' + type + ' .download-button').href = 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(versionComment + "\n" + code[type]);
codeElement.textContent = text;
Prism.highlightElement(codeElement, true);


$('#download-' + type + ' .download-button').onclick = function () {
saveAs(new Blob([text], { type: "application/octet-stream;charset=utf-8" }), fileName);
};
})(type);
}
});
}
Expand Down

0 comments on commit 77c5744

Please sign in to comment.