var Wick = Wick || {};

Wick.ScrollDisable = (function() {
  var $body = $('body');
  var $modal = $('.modal');
  var shouldDisableScroll = Wick.Responsive.isTouchDevice() && $modal.length;
  var currentPosition = 0;

  function disableScroll () {
    currentPosition = $(window).scrollTop();
    $body
      .addClass('scroll-disable')
      .css('margin-top', -currentPosition + 'px');
  }

  function enableScroll () {
    $body
      .removeClass('scroll-disable')
      .css('margin-top', '');
    window.scrollTo(0, currentPosition);
  }

  if (shouldDisableScroll) {
    $modal
      .on('show.bs.modal', disableScroll)
      .on('hide.bs.modal', enableScroll);
  }
})();
