 $ = jQuery
-
-# Detect CSS Animation Support
 
 animationEndSupport = false
 
 $ ->
+    # Detect CSS Animation Support
+
     s = (document.body || document.documentElement).style
     animationEndSupport = s.animation isnt undefined or s.WebkitAnimation isnt undefined or s.MozAnimation isnt undefined or s.MsAnimation isnt undefined or s.OAnimation isnt undefined
+
+    # Register global handler for ESC
+
+    $(window).bind 'keyup.vex', (event) ->
+        vex.closeByEscape() if event.keyCode is 27
 
 # Vex
 


    close: (id) ->
        if not id
            $lastVexContent = vex.getAllVexes().last()
            return false unless $lastVexContent.length
            id = $lastVexContent.data().vex.id

        return vex.closeByID id


    defaultOptions:
        content: ''
        showCloseButton: true
        escapeButtonCloses: true
        overlayClosesOnClick: true
        appendLocation: 'body'
        className: ''
