   if !key
     key = e.keyCode
 
-  ### Opera ###
-
+  # Opera
   if key != Event.KEY_ESC
     return
   @cancel()

  $('post-exists').hide()
  $('post-upload-error').hide()

  ### If the files attribute isn't supported, or we have no file (source upload), use regular
  # form submission. 
  ###

  post_file = $('post_file')
  if !post_file.files? or post_file.files.length == 0
    return
  e.stop()
  @set_progress 0
  @request_starting()
  form_data = new FormData(@form_element)
  onprogress = ((e) ->
    done = e.loaded
    total = e.total
    @set_progress if total then done / total else 1
    return
  ).bind(this)
  @current_request = new (Ajax.Request)('/post/create.json',
    contentType: null
    method: 'post'
    postBody: form_data
    onCreate: (resp) ->
      xhr = resp.request.transport
      xhr.upload.onprogress = onprogress
      return
    onComplete: ((resp) ->
      @current_request = null
      @request_ending()
      json = resp.responseJSON
      if !json
        return
      if !json.success
        if json.location
          a = $('post-exists-link')
          a.setTextContent 'post #' + json.post_id
          a.href = json.location
          $('post-exists').show()
          return
        $('post-upload-error').setTextContent json.reason
        $('post-upload-error').show()
        return

      ### If a post/similar link was given and similar results exists, go to them.  Otherwise,
      # go to the new post. 
      ###

      target = json.location
      if json.similar_location and json.has_similar_hits
        target = json.similar_location
      window.location.href = target
      return
    ).bind(this))
  return

### Cancel the running request, if any. ###

PostUploadForm::cancel = ->
  if !@current_request?
    return

  ### Don't clear this.current_request; it'll be done by the onComplete callback. ###

  @current_request.transport.abort()
  return

###
# When file_field is changed to an image, run an image search and put a summary in
# results.
###

window.UploadSimilarSearch = (file_field, results) ->
  if !ThumbnailUserImage
    return

  return

PostUploadForm::form_submit_event = (e) ->
  # This submit may have been stopped by User.run_login_onsubmit.
  if e.stopped
    return
  if @current_request?
