Add error message in red above the code if a file fails to download
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
diff --git a/download.html b/download.html
index 29ea909..7efa7de 100644
--- a/download.html
+++ b/download.html
@@ -87,6 +87,10 @@ section.download {
padding: .3em;
}
+ #download .error {
+ color: #B61500;
+ display: none;
+ }
#download pre {
height: 20em;
word-wrap: break-word;
@@ -133,6 +137,7 @@ section.download {
<p><strong>Note:</strong> The filesizes displayed refer to non-gizipped files and include any CSS code required. The CSS code is not minified.</p>
<section id="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>
diff --git a/download.js b/download.js
index 44a7299..7b4d99e 100644
--- a/download.js
+++ b/download.js
@@ -33,7 +33,7 @@ if (qstr) {
if (components[category][id].option) {
delete components[category][id].option;
}
- };
+ }
ids.forEach(function(id) {
if (id !== 'meta') {
if (components[category][id]) {
@@ -187,7 +187,7 @@ form.elements.compression[1].onclick = function() {
minified = !!+this.value;
getFilesSizes();
-}
+};
function getFileSize(filepath) {
return treePromise.then(function(tree) {
@@ -242,7 +242,7 @@ function getFileContents(filepath) {
$u.xhr({
url: filepath,
callback: function(xhr) {
- if (xhr.status < 400) {
+ if (xhr.status < 400 && xhr.responseText) {
resolve(xhr.responseText);
} else {
reject();
@@ -361,7 +361,19 @@ function generateCode(){
}
}
- buildCode(promises).then(function(code) {
+ // Hide error message if visible
+ var error = $('#download .error');
+ error.style.display = '';
+
+ buildCode(promises).then(function(res) {
+ var code = res.code;
+ var errors = res.errors;
+
+ if(errors.length) {
+ error.style.display = 'block';
+ error.innerHTML = '';
+ $u.element.contents(error, errors);
+ }
var redownloadUrl = window.location.href.split("?")[0] + "?";
for (var category in redownload) {
@@ -384,6 +396,8 @@ function buildCode(promises) {
var i = 0,
l = promises.length;
var code = {js: '', css: ''};
+ var errors = [];
+
var f = function(resolve) {
if(i < l) {
var p = promises[i];
@@ -393,12 +407,17 @@ function buildCode(promises) {
f(resolve);
});
p.contentsPromise['catch'](function() {
- code[p.type] += '/* Error downloading file '+p.path+' */' + '\n';
+ errors.push($u.element.create({
+ tag: 'p',
+ prop: {
+ textContent: 'An error occurred while fetching the file "' + p.path + '".'
+ }
+ }));
i++;
f(resolve);
});
} else {
- resolve(code);
+ resolve({code: code, errors: errors});
}
};