index.js 2.5 KB

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