mirror of
https://github.com/jgthms/bulma.git
synced 2024-11-14 11:14:24 +00:00
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
|
document.addEventListener('DOMContentLoaded', () => {
|
||
|
|
||
|
const $grid = document.getElementById('grid');
|
||
|
const $columns = Array.prototype.slice.call(document.querySelectorAll('#grid > .column'), 0);
|
||
|
const $markup = document.querySelector('#markup code');
|
||
|
const $message = document.getElementById('message');
|
||
|
const $add = document.getElementById('add');
|
||
|
const $remove = document.getElementById('remove');
|
||
|
let showing = 5;
|
||
|
|
||
|
function showColumns() {
|
||
|
if (showing === 13) {
|
||
|
$message.style.display = 'block';
|
||
|
} else {
|
||
|
$message.style.display = 'none';
|
||
|
}
|
||
|
|
||
|
showing = Math.min(Math.max(parseInt(showing), 2), 12);
|
||
|
|
||
|
$columns.forEach($el => {
|
||
|
$el.style.display = 'none';
|
||
|
});
|
||
|
$columns.slice(0, showing).forEach($el => {
|
||
|
$el.style.display = 'block';
|
||
|
});
|
||
|
|
||
|
$markup.innerHTML = '<span class="nt"><div</span> <span class="na">class=</span><span class="s">"columns"</span><span class="nt">></span>';
|
||
|
$markup.insertAdjacentHTML('beforeend', '\n');
|
||
|
|
||
|
for(let i = 0; i < showing; i++) {
|
||
|
$markup.insertAdjacentHTML('beforeend', ' <span class="nt"><div</span> <span class="na">class=</span><span class="s">"column"</span><span class="nt">></span>');
|
||
|
$markup.insertAdjacentHTML('beforeend', i + 1);
|
||
|
$markup.insertAdjacentHTML('beforeend', '<span class="nt"></div></span>');
|
||
|
$markup.insertAdjacentHTML('beforeend', '\n');
|
||
|
}
|
||
|
|
||
|
$markup.insertAdjacentHTML('beforeend', '<span class="nt"></div></span>');
|
||
|
}
|
||
|
|
||
|
$add.addEventListener('click', () => {
|
||
|
showing++;
|
||
|
showColumns();
|
||
|
});
|
||
|
|
||
|
$remove.addEventListener('click', () => {
|
||
|
showing--;
|
||
|
showColumns();
|
||
|
});
|
||
|
|
||
|
});
|