Commit 77c574465ad1711355d4bd8dc724c527e348af39

Michael Schmidt 2019-03-24T18:42:51

Fixed download page (#1811) This makes the download page work on Edge again.

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);
 		}
 	});
 }