{"size": 1130, "ext": "js", "max_stars_repo_path": "src/js/initialize-elements.js", "max_stars_repo_name": "EinsCMS/eins-modal", "max_stars_repo_stars_event_min_datetime": "2021-06-18T20:39:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T07:43:54.000Z", "max_issues_repo_path": "src/js/initialize-elements.js", "max_issues_repo_name": "EinsCMS/eins-modal", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/js/initialize-elements.js", "max_forks_repo_name": "EinsCMS/eins-modal", "max_forks_repo_forks_event_min_datetime": "2021-07-11T19:27:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-26T07:44:39.000Z"}
{"max_stars_count": 25, "max_issues_count": null, "max_forks_count": 3, "avg_line_length": 20.1785714286, "max_line_length": 61, "alphanum_fraction": 0.6663716814}
import { addFillGapSelector } from 'scroll-lock'

import addModalFunction from './modal-function'
import Elements from './elements'
import Modal from './modal'

/**
 * Hide all modals on page load.
 * To prevent bugs on page reload.
 */
function hideModals() {
  const { modals } = Elements
  if (modals.length === 0) {
    return
  }
  // hide all modals
  for (let i = 0; i < modals.length; i += 1) {
    const modal = modals[i]
    modal.style.display = 'none'
  }
}

/**
 * Add click and touch events to all trigger buttons on page.
 */
function initButtons() {
  Modal.addOpenHandlers(Elements.buttons)
}

/**
 * Add the ".modal()" closure to all modal elements.
 */
function initModalClosures() {
  const { modals } = Elements
  if (modals.length === 0) {
    return
  }
  for (let i = 0; i < modals.length; i += 1) {
    const modal = modals[i]
    addModalFunction(modal)
  }
}

function fillScrollbarGap() {
  addFillGapSelector('.' + Elements.fillScrollbarGapClass)
}

const initializeElements = function() {
  hideModals()
  initButtons()
  initModalClosures()
  fillScrollbarGap()
}

export default initializeElements
