From b03c02a9b912e21b60c0d63727042002ac4ad4b5 Mon Sep 17 00:00:00 2001 From: Golmote Date: Fri, 2 Mar 2018 08:39:24 +0100 Subject: [PATCH] Download page: Use hash instead of query-string for redownload URL. Fix #1263 --- download.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/download.js b/download.js index e9a8007b4c..26132e6b5c 100644 --- a/download.js +++ b/download.js @@ -22,9 +22,9 @@ var treePromise = new Promise(function(resolve) { }); }); -var qstr = window.location.search.match(/(?:languages|plugins)=[-+\w]+|themes=[-\w]+/g); -if (qstr) { - qstr.forEach(function(str) { +var hstr = window.location.hash.match(/(?:languages|plugins)=[-+\w]+|themes=[-\w]+/g); +if (hstr) { + hstr.forEach(function(str) { var kv = str.split('=', 2), category = kv[0], ids = kv[1].split('+'); @@ -52,6 +52,13 @@ if (qstr) { }); } +// Stay compatible with old querystring feature +var qstr = window.location.search.match(/(?:languages|plugins)=[-+\w]+|themes=[-\w]+/g); +if (qstr && !hstr) { + window.location.hash = window.location.search.replace(/^\?/, ''); + window.location.search = ''; +} + for (var category in components) { var all = components[category]; @@ -466,19 +473,22 @@ function generateCode(){ $u.element.contents(error, errors); } - var redownloadUrl = window.location.href.split("?")[0] + "?"; + var redownloadUrl = window.location.href.split("#")[0] + "#"; for (var category in redownload) { redownloadUrl += category + "=" + redownload[category].join('+') + "&"; } - redownloadUrl = "/* PrismJS " + version + "\n" + redownloadUrl.replace(/&$/,"") + " */"; + redownloadUrl = redownloadUrl.replace(/&$/,""); + window.location.replace(redownloadUrl); + + var versionComment = "/* PrismJS " + version + "\n" + redownloadUrl + " */"; for (var type in code) { var codeElement = $('#download-' + type + ' code'); - codeElement.textContent = redownloadUrl + "\n" + code[type]; + codeElement.textContent = versionComment + "\n" + code[type]; Prism.highlightElement(codeElement, true); - $('#download-' + type + ' .download-button').href = 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(redownloadUrl + "\n" + code[type]); + $('#download-' + type + ' .download-button').href = 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(versionComment + "\n" + code[type]); } }); }