Fixed download script bugs
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
diff --git a/download.html b/download.html
index 2ef1e2a..44b3647 100644
--- a/download.html
+++ b/download.html
@@ -99,7 +99,7 @@ section.download {
<section id="components"></section>
<p>
- Total filesize: <strong id="filesize">Please, select a compression level first</strong>
+ Total filesize: <strong id="filesize"></strong> (<strong id="percent-js"></strong> JavaScript + <strong id="percent-css"></strong> CSS)
</p>
<p><strong>Note:</strong> The filesizes displayed refer to non-gizipped files and include any CSS code required.</p>
diff --git a/download.js b/download.js
index a946b96..0db2e06 100644
--- a/download.js
+++ b/download.js
@@ -167,21 +167,58 @@ function prettySize(size) {
return Math.round(100 * size / 1024)/100 + 'KB';
}
-function update(category, id){
- var distro = components[category][id].files[minified? 'minified' : 'dev'];
-
- $('label[data-id="' + id + '"] .filesize').textContent = prettySize(distro.size);
-
+function update(updatedCategory, updatedId){
// Update total size
- var totalSize = 0;
+ var total = {js: 0, css: 0}, updated = {js: 0, css: 0};
- forId(function (id, category, info) {
- if(info.enabled) {
- totalSize += info.files[minified? 'minified' : 'dev'].size;
+ for (var category in components) {
+ var all = components[category];
+
+ for (var id in all) {
+ var info = all[id];
+
+ if (info.enabled || id == updatedId) {
+ var distro = info.files[minified? 'minified' : 'dev'];
+
+ distro.paths.forEach(function(path) {
+ if (cache[path]) {
+ var type = path.match(/\.(\w+)$/)[1],
+ size = cache[path].size || 0;
+
+ if (info.enabled) {
+ total[type] += size;
+ }
+
+ if (id == updatedId) {
+ updated[type] += size;
+ }
+ }
+ });
+ }
}
+ }
+
+ total.all = total.js + total.css;
+ updated.all = updated.js + updated.css;
+
+ $u.element.prop($('label[data-id="' + updatedId + '"] .filesize'), {
+ textContent: prettySize(updated.all),
+ title: (updated.js? Math.round(100 * updated.js / updated.all) + '% JavaScript' : '') +
+ (updated.js && updated.css? ' + ' : '') +
+ (updated.css? Math.round(100 * updated.css / updated.all) + '% CSS' : '')
});
- $('#filesize').textContent = prettySize(totalSize);
+ $('#filesize').textContent = prettySize(total.all);
+
+ $u.element.prop($('#percent-js'), {
+ textContent: Math.round(100 * total.js / total.all) + '%',
+ title: prettySize(total.js)
+ });
+
+ $u.element.prop($('#percent-css'), {
+ textContent: Math.round(100 * total.css / total.all) + '%',
+ title: prettySize(total.css)
+ });
generateCode();
}