diff --git a/download.html b/download.html index 9b802edd7c..abd58cabac 100644 --- a/download.html +++ b/download.html @@ -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; @@ -154,12 +158,12 @@

Customize your download

- Download JS +
- Download CSS +
@@ -174,6 +178,7 @@

Customize your download

+ diff --git a/scripts/download.js b/scripts/download.js index 9c56c891e6..7be6834b74 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); } }); }