Instead of unbinding everything off document, it might be better to namespace your modal event listeners? e.g.

    $document.on('keyup.moz-modal' foo);

And then unbind:

    $document.of('.moz-modal');