index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. document.addEventListener('DOMContentLoaded', () => {
  2. // Intro
  3. const introVimeo = document.getElementById('introVimeo');
  4. const npmClipboard = new Clipboard('#npmCopy');
  5. introVimeo.addEventListener('load', () => {
  6. introVimeo.parentNode.parentNode.classList.add('has-loaded');
  7. });
  8. npmClipboard.on('success', function(e) {
  9. e.trigger.innerText = 'copied!';
  10. e.trigger.classList.add('is-success');
  11. setTimeout(() => {
  12. e.trigger.innerText = 'copy';
  13. e.trigger.classList.remove('is-success');
  14. }, 500);
  15. e.clearSelection();
  16. });
  17. npmClipboard.on('error', function(e) {
  18. e.trigger.innerText = 'error!';
  19. e.trigger.classList.add('is-error');
  20. setTimeout(() => {
  21. e.trigger.innerText = 'copy';
  22. e.trigger.classList.remove('is-error');
  23. }, 500);
  24. });
  25. // Grid
  26. const $grid = document.getElementById('grid');
  27. const $columns = Array.prototype.slice.call(document.querySelectorAll('#grid > .column'), 0);
  28. const $markup = document.querySelector('#markup code');
  29. const $message = document.getElementById('message');
  30. const $add = document.getElementById('add');
  31. const $remove = document.getElementById('remove');
  32. let showing = 5;
  33. function showColumns() {
  34. if (showing === 13) {
  35. $message.style.display = 'block';
  36. } else {
  37. $message.style.display = 'none';
  38. }
  39. showing = Math.min(Math.max(parseInt(showing), 2), 12);
  40. $columns.forEach($el => {
  41. $el.style.display = 'none';
  42. });
  43. $columns.slice(0, showing).forEach($el => {
  44. $el.style.display = 'block';
  45. });
  46. $markup.innerHTML = '<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;columns&quot;</span><span class="nt">&gt;</span>';
  47. $markup.insertAdjacentHTML('beforeend', '\n');
  48. for(let i = 0; i < showing; i++) {
  49. $markup.insertAdjacentHTML('beforeend', ' <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;column&quot;</span><span class="nt">&gt;</span>');
  50. $markup.insertAdjacentHTML('beforeend', i + 1);
  51. $markup.insertAdjacentHTML('beforeend', '<span class="nt">&lt;/div&gt;</span>');
  52. $markup.insertAdjacentHTML('beforeend', '\n');
  53. }
  54. $markup.insertAdjacentHTML('beforeend', '<span class="nt">&lt;/div&gt;</span>');
  55. }
  56. $add.addEventListener('click', () => {
  57. showing++;
  58. showColumns();
  59. });
  60. $remove.addEventListener('click', () => {
  61. showing--;
  62. showColumns();
  63. });
  64. });