Rudchyk
8/31/2018 - 11:51 AM

Beforeunload action

ACC.beforeunload = {
  leavePageMsg: 'Navigating away from this page will result in losing the data you have entered!',
  formID: '#formID',
  events: function () {
      $(document)
          .one('change', this.formID, this.enableBeforeUnloadEvent.bind(this))
          .one('submit', this.formID, this.disableBeforeUnloadEvent.bind(this));
  },
  enableBeforeUnloadEvent: function() {
      $(window).on('beforeunload', this.beforeUnloadHandler);
  },
  disableBeforeUnloadEvent: function () {
      $(window).off('beforeunload', this.beforeUnloadHandler);
  },
  beforeUnloadHandler: function () {
      return ACC.beforeunload.leavePageMsg;
  }
}