Added ability to pass a function to Nifty.loading("loading").hideAfter() that would hide the modal dialog when the javascript function completes executing. Chances are you good you should be passing a Deferred instead, but I'll let you decide :)