Modals Dont Render quickly

There is a mistake in this code. The ToggleModal should always set NextModalState to ShowModal parameter. The first four lines should be:

function ToggleModal(ShowModal) {    // ShowModal Boolean: True mean show
  NextModalState = ShowModal;
  if (! ModalIsRendering) {

The bad code will in most cases remove the modal upon drawing it, as the next mode was not set.

UPDATE WARNING:

For the above to work, you need to disable the close button and the click outside of modal features of the Modal. NOTE: in a later post a better method of removing the close button is shown.