<script type="text/javascript">
  jQuery(function($){
    var deactivateLink = $('#the-list').find('[data-slug="mailpoet"] span.deactivate a');
    var overlay = $('#mailpoet-deactivate-survey');
    var closeButton = $('#mailpoet-deactivate-survey-close');
    var formOpen = false;

    deactivateLink.on('click', function(event) {
      event.preventDefault();
      overlay.css('display', 'table');
      formOpen = true;
    });

    closeButton.on('click', function(event) {
      event.preventDefault();
      overlay.css('display', 'none');
      formOpen = false;
      location.href = deactivateLink.attr('href');
    });

    $(document).keyup(function(event) {
      if ((event.keyCode === 27) && formOpen) {
        location.href = deactivateLink.attr('href');
      }
    });
  });
</script>
