Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "Select All" languages checkbox (fix #513) #561

Merged
merged 1 commit into from
Sep 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion download.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
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;
Expand Down
62 changes: 52 additions & 10 deletions download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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'];

Expand All @@ -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);

Expand Down