//
// No external JavaScript libraries are used or required
// Plugins used are autoprefixer and babel
//
(() => {
  'use strict';

  // Initiate foundation reveal plugin (jQuery is required)
  //$(document).foundation();

  // Create object literal with project variables
  const galleryVariables = {
    galleryAuthor: document.querySelector('.js-modal-author'),
    galleryButton: document.querySelector('.js-close-button'),
    galleryLinks: document.querySelectorAll('a[data-toggle="galleryModal"]'),
    galleryModal: document.querySelector('.js-gallery-reveal'),
    galleryOverlay: document.querySelector('.js-gallery-overlay'),
    galleryPreview: document.querySelector('.js-modal-preview'),
    galleryPreviewAuthor: document.querySelector('.js-modal-author')
  }

  // Fade in fuction
  const fadeIn = (element) => {
    // Create variable with initial opacity
    let elementOpacity = 0.1;

    // Create timer for fadeIn function
    let timer = setInterval(function() {
      if (elementOpacity >= 1) {
        // Reset interval
        clearInterval(timer);
      }

      // Set element opacity to elementOpacity
      element.style.opacity = elementOpacity;

      // Increase value of elementOpacity
      elementOpacity += elementOpacity * 0.1;

      // Show element
      element.style.display = 'block';
    }, 15);
  }

  // Fade out function
  const fadeOut = (element) => {
    // Create variable with initial opacity
    let elementOpacity = 1;

    // Create timer for fadeOut function
    let timer = setInterval(function() {
      if (elementOpacity <= 0.1) {
        // Reset interval
        clearInterval(timer);

        // Hide element
        element.style.display = 'none';
      }

      // Set element opacity to elementOpacity
      element.style.opacity = elementOpacity;

      // Decrease value of elementOpacity
      elementOpacity -= elementOpacity * 0.1;
    }, 15);
  }

  // Handle openning modal by clicking on images
  for (let x = 0, y = galleryVariables.galleryLinks.length; x < y; x++) {
    // Add event listener for image containers
    galleryVariables.galleryLinks[x].addEventListener('click', (e) => {
      e.preventDefault();

      // Get clicked image
      let image = e.target;

      // Get src of the image
      let imageSrc = image.getAttribute('src');

      // Get alt of the image
      let imageAlt = image.getAttribute('alt');

      // Set alt attribute of preview image to clicked image
      galleryVariables.galleryPreview.setAttribute('alt', imageAlt);

      // Set src attribute of preview image to clicked image
      galleryVariables.galleryPreview.setAttribute('src', imageSrc);

      // Set preview headline to alt of clicked phot
      galleryVariables.galleryPreviewAuthor.textContent = imageAlt;
      
      // Avoid openning modal unless its content is loaded
      if (galleryVariables.galleryPreview.getAttribute('src').length > 0 && galleryVariables.galleryPreview.getAttribute('alt').length > 0 && galleryVariables.galleryPreviewAuthor.textContent.length > 0) {
        // Add Foundation class to hide overflow
        document.body.classList.add('is-reveal-open');

        // Show modal dialog
        galleryVariables.galleryModal.style.display = 'block';

        // Show modal overlay (fade it in)
        fadeIn(galleryVariables.galleryOverlay);
      }
    });
  }

  // Handle closing modal
  galleryVariables.galleryButton.addEventListener('click', (e) => {
    e.preventDefault();

    // Hide modal overlay (fade it out)
    fadeOut(galleryVariables.galleryOverlay);
    
    // Wait before overlay fades out
    setTimeout(() => {
      // Hide modal dialog
      galleryVariables.galleryModal.style.display = 'none';
      
      // Reset alt attribute of preview image
      galleryVariables.galleryPreview.setAttribute('alt', '');

      // Reset src attribute of preview image
      galleryVariables.galleryPreview.setAttribute('src', '');

      // Reset text for preview headline
      galleryVariables.galleryPreviewAuthor.textContent = '';

      // Remove Foundation class to hide overflow
      document.body.classList.remove('is-reveal-open');
    }, 250);
  });
})();

@@ -784,16 +784,17 @@
 de in fu
+n
 ction%0A  

Fix typo