<commit_before>'use strict';
function Modal() {
}

/** Init Modal functions **/
Modal.prototype.init = function () {
  var self = this;

  // init handlers
  self.initHandlers();
};

/** Initialization of handlers on top menu **/
Modal.prototype.initHandlers = function () {
  var self = this;
  var emailBtnsCollection = document.getElementsByClassName('email-btn');
  var overlay = document.getElementById("modal-overlay");
  var contactForm = document.getElementById('contact-form');

  // handle click on send email button and show email form
  for (var i = 0; i < emailBtnsCollection.length; i++) {
    emailBtnsCollection[i].addEventListener("click", function (event) {
      event.preventDefault();
      self.showOverlay(overlay);
      self.showContactForm(contactForm);
    });
  }

  // hide overlay if user clicked on it
  overlay.addEventListener("click", function (e) {
    e.preventDefault();
    self.hideOverlay(overlay);
    self.hideContactForm(contactForm);
  });

  // function to send email and show success window
  document.getElementById('contact-form').addEventListener('submit', function (event) {
    event.preventDefault();
    self.submitEmail();
    self.hideOverlay(overlay);
    self.hideContactForm(contactForm);
  });

  // hide success modal
  document.querySelector('.success-send-close-btn').addEventListener("click", function (e) {
    e.preventDefault();
    self.hideOverlay(overlay);
    self.hideContactForm(contactForm);

    // clear form fields to make available sending new messages
    setTimeout(function (){
      self.resetMailForm();
    }, 400)
  });
};

/** Open modal overlay **/
Modal.prototype.showOverlay = function (overlay) {
  overlay.style.display = "block";
  setTimeout(function () {
    overlay.classList.add('visible');
  }, 100)
};

/** Close modal overlay **/
Modal.prototype.hideOverlay = function (overlay) {
  overlay.classList.remove('visible');
  setTimeout(function () {
    overlay.removeAttribute("style");
  }, 400);
};

/** Show modal contact form with animation **/
Modal.prototype.showContactForm = function (contactForm) {
  contactForm.classList.remove('hidden'); // make contact form being displayed, but still invisible

  // make it visible with certain animations
  setTimeout(function () {
    contactForm.style.opacity = 1;
    contactForm.style.top = '22%';
  }, 100)
};

/** Hide modal contact form with animation **/
Modal.prototype.hideContactForm = function (contactForm) {
  contactForm.removeAttribute('style');

  // make it visible with certain animations
  setTimeout(function () {
    contactForm.classList.add('hidden');
  }, 400)
};

/** Send email message when submit clicked **/
Modal.prototype.submitEmail = function () {
  var self = this;
  var elements = document.getElementsByClassName("form-val");
  var formData = {};
  var xmlHttp = new XMLHttpRequest();

  for (var i = 0; i < elements.length; i++) {
    formData[elements[i].name] = elements[i].value;
  }

  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      self.showSuccessText();
    }
  };

  xmlHttp.open("POST", "https://formspree.io/d.bobrenko@gmail.com");
  xmlHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  xmlHttp.send(JSON.stringify(formData));
};

/** Show success window if email sent was successful **/
Modal.prototype.showSuccessText = function (){
  var self = this;

  // hide form elements
  var elements = document.getElementsByClassName("form-val");
  for (var i = 0; i < elements.length; i++) {elements[i].style.display = 'none'};
  document.querySelector('#contact-form .send-btn').style.display = 'none';

  // show success fields
  document.querySelector('.success-send-msg').style.display = 'block';
  document.querySelector('.success-send-close-btn').style.display = 'block';

  // show modal window
  self.showOverlay(document.getElementById("modal-overlay"));
  self.showContactForm(document.getElementById('contact-form'));
};

/** Show success window if email sent was successful **/
Modal.prototype.resetMailForm = function (){
  var self = this;

  // hide success fields
  document.querySelector('.success-send-msg').style.display = 'none';
  document.querySelector('.success-send-close-btn').style.display = 'none';

  // clear form fields and show them
  var name = document.querySelector('#contact-from input[name="name"]');
  name.value = '';
  name.style.display = 'block';

  var email = document.querySelector('#contact-from input[name="email"]');
  email.value = '';
  email.style.display = 'block';

  var message = document.querySelector('#contact-from input[name="message"]');
  message.value = '';
  message.style.display = 'block';<commit_msg>--\\--<commit_after>'use strict';
function Modal() {
}

/** Init Modal functions **/
Modal.prototype.init = function () {
  var self = this;

  // init handlers
  self.initHandlers();
};

/** Initialization of handlers on top menu **/
Modal.prototype.initHandlers = function () {
  var self = this;
  var emailBtnsCollection = document.getElementsByClassName('email-btn');
  var overlay = document.getElementById("modal-overlay");
  var contactForm = document.getElementById('contact-form');

  // handle click on send email button and show email form
  for (var i = 0; i < emailBtnsCollection.length; i++) {
    emailBtnsCollection[i].addEventListener("click", function (event) {
      event.preventDefault();
      self.showOverlay(overlay);
      self.showContactForm(contactForm);
    });
  }

  // hide overlay if user clicked on it
  overlay.addEventListener("click", function (e) {
    e.preventDefault();
    self.hideOverlay(overlay);
    self.hideContactForm(contactForm);
  });

  // function to send email and show success window
  document.getElementById('contact-form').addEventListener('submit', function (event) {
    event.preventDefault();
    self.submitEmail();
    self.hideOverlay(overlay);
    self.hideContactForm(contactForm);
  });

  // hide success modal
  document.querySelector('.success-send-close-btn').addEventListener("click", function (e) {
    e.preventDefault();
    self.hideOverlay(overlay);
    self.hideContactForm(contactForm);

    // clear form fields to make available sending new messages
    setTimeout(function (){
      self.resetMailForm();
    }, 400)
  });
};

/** Open modal overlay **/
Modal.prototype.showOverlay = function (overlay) {
  overlay.style.display = "block";
  setTimeout(function () {
    overlay.classList.add('visible');
  }, 100)
};

/** Close modal overlay **/
Modal.prototype.hideOverlay = function (overlay) {
  overlay.classList.remove('visible');
  setTimeout(function () {
    overlay.removeAttribute("style");
  }, 400);
};

/** Show modal contact form with animation **/
Modal.prototype.showContactForm = function (contactForm) {
  contactForm.classList.remove('hidden'); // make contact form being displayed, but still invisible

  // make it visible with certain animations
  setTimeout(function () {
    contactForm.style.opacity = 1;
    contactForm.style.top = '22%';
  }, 100)
};

/** Hide modal contact form with animation **/
Modal.prototype.hideContactForm = function (contactForm) {
  contactForm.removeAttribute('style');

  // make it visible with certain animations
  setTimeout(function () {
    contactForm.classList.add('hidden');
  }, 400)
};

/** Send email message when submit clicked **/
Modal.prototype.submitEmail = function () {
  var self = this;
  var elements = document.getElementsByClassName("form-val");
  var formData = {};
  var xmlHttp = new XMLHttpRequest();

  for (var i = 0; i < elements.length; i++) {
    formData[elements[i].name] = elements[i].value;
  }

  xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
      self.showSuccessText();
    }
  };

  xmlHttp.open("POST", "https://formspree.io/d.bobrenko@gmail.com");
  xmlHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  xmlHttp.send(JSON.stringify(formData));
};

/** Show success window if email sent was successful **/
Modal.prototype.showSuccessText = function (){
  var self = this;

  // hide form elements
  var elements = document.getElementsByClassName("form-val");
  for (var i = 0; i < elements.length; i++) {elements[i].style.display = 'none'};
  document.querySelector('#contact-form .send-btn').style.display = 'none';

  // show success fields
  document.querySelector('.success-send-msg').style.display = 'block';
  document.querySelector('.success-send-close-btn').style.display = 'block';

  // show modal window
  self.showOverlay(document.getElementById("modal-overlay"));
  self.showContactForm(document.getElementById('contact-form'));
};

/** Show success window if email sent was successful **/
Modal.prototype.resetMailForm = function (){
  var self = this;

  // hide success fields
  document.querySelector('.success-send-msg').style.display = 'none';
  document.querySelector('.success-send-close-btn').style.display = 'none';

  // clear form fields and show them
  var name = document.querySelector('#contact-form input[name="name"]');
  name.value = '';
  name.style.display = 'block';

  var email = document.querySelector('#contact-form input[name="email"]');
  email.value = '';
  email.style.display = 'block';

  var message = document.querySelector('#contact-form input[name="message"]');
  message.value = '';
  message.style.display = 'block';
{'fraction_non_alphanumeric': 0.15162073698659065, 'fraction_numerical': 0.005490444514834759, 'mean_word_length': 4.089736700698549, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2065134', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2686, 'n_words': 617}