index.js 2.5 KB

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