index.js 2.5 KB

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