Chat.toast.js is included before Chat.ui.js.  Chat.ui.js creates $toast at the topmost scope.  Chat.toast.js needs to raise events on the $(ui) element.  tl;dr circular dependency that needs to be broken at some stage.

I think that there needs to be some extra decoupling but I was planning on refactoring out ui.events from line 722 of Chat.ui.js into its own file along with a couple of other changes in another PR.  I can do it on this PR before you merge it though if you want.