     this
 
   close: ->
-    $(window).off 'keyup', @escape
-    $(window).off 'resize', @resize
+    @$window.off 'keyup', @escape
+    @$window.off 'resize', @resize
 
     mediator.off null, null, this
 

      in:   => @updatePosition()

  setWidth: (width) ->
    @$dialog.css { width: width || @width }

  setup: ->
    # Render outer

    'click .modal-close': 'close'
    'click .modal-dialog': '_intercept'

  initialize: (options = {}) ->
    { @width } = _.defaults options, { width: '400px' }

    @templateData ?= {}

    @resize = _.debounce @updatePosition, 100

    @$window = $(window)
    @$window.on 'keyup', @escape
    @$window.on 'resize', @resize

    mediator.on 'modal:close', @close, this
    mediator.on 'modal:opened', @updatePosition, this
