Changing the click event to trigger the beforeClose callback, which will then in turn trigger the close event.