Codemirror activation on opening popup, and removing unscheduled event item from calendar on closing popup. These two event handlers need to be checked for being attached more than once, causing unexpected behaviour.
Removed redundant definition of popup.close()