Fixed download page (#1811) This makes the download page work on Edge again.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/download.html b/download.html
index 9b802ed..abd58ca 100644
--- a/download.html
+++ b/download.html
@@ -109,6 +109,10 @@ section.download {
height: 20em;
word-wrap: break-word;
}
+ #download .download-button {
+ cursor: pointer;
+ width: 100%;
+ }
#download-js .download-button {
border-top-right-radius: 0;
@@ -154,12 +158,12 @@ section.download {
<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>
@@ -174,6 +178,7 @@ section.download {
<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>
diff --git a/scripts/download.js b/scripts/download.js
index 9c56c89..7be6834 100644
--- a/scripts/download.js
+++ b/scripts/download.js
@@ -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);
}
});
}