Merge pull request #561 from Golmote/prism-check-all Add a "Select All" languages checkbox (fix #513)
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
diff --git a/components.js b/components.js
index 4bc1146..01fd5f9 100644
--- a/components.js
+++ b/components.js
@@ -35,7 +35,8 @@ var components = {
"meta": {
"path": "components/prism-{id}",
"noCSS": true,
- "examplesPath": "examples/prism-{id}"
+ "examplesPath": "examples/prism-{id}",
+ "addCheckAll": true
},
"markup": {
"title": "Markup",
diff --git a/download.html b/download.html
index 103d813..3cb74e2 100644
--- a/download.html
+++ b/download.html
@@ -71,7 +71,8 @@ section.options#category-plugins {
column-span: all;
}
- section.options#category-languages label[data-id="javascript"] {
+ section.options#category-languages label[data-id="javascript"],
+ section.options label[data-id^="check-all-"] {
border-bottom: 1px solid #aaa;
padding-bottom: 1em;
margin-bottom: 1em;
diff --git a/download.js b/download.js
index 742da97..e56e587 100644
--- a/download.js
+++ b/download.js
@@ -64,6 +64,37 @@ for (var category in components) {
},
inside: '#components'
});
+
+ if (all.meta.addCheckAll) {
+ $u.element.create('label', {
+ attributes: {
+ 'data-id': 'check-all-' + category
+ },
+ contents: [
+ {
+ tag: 'input',
+ properties: {
+ type: 'checkbox',
+ name: 'check-all-' + category,
+ value: '',
+ checked: false,
+ onclick: (function(category, all){
+ return function () {
+ var checkAll = this;
+ $$('input[name="download-' + category + '"]').forEach(function(input) {
+ all[input.value].enabled = input.checked = checkAll.checked;
+ });
+
+ update(category);
+ };
+ })(category, all)
+ }
+ },
+ 'Select/unselect all'
+ ],
+ inside: all.meta.section
+ });
+ }
for (var id in all) {
if(id === 'meta') {
@@ -266,10 +297,11 @@ function update(updatedCategory, updatedId){
for (var category in components) {
var all = components[category];
-
+ var allChecked = true;
+
for (var id in all) {
var info = all[id];
-
+
if (info.enabled || id == updatedId) {
var distro = info.files[minified? 'minified' : 'dev'];
@@ -295,18 +327,28 @@ function update(updatedCategory, updatedId){
}
});
}
+ if (id !== 'meta' && !info.enabled) {
+ allChecked = false;
+ }
+ }
+
+ if (all.meta.addCheckAll) {
+ $('input[name="check-all-' + category + '"]').checked = allChecked;
}
}
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' : '')
- });
+
+ if (updatedId) {
+ 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(total.all);