   addEmojiButton "licking-lips", "/images/emoji/ziggy/licking-lips.gif"
   addEmojiButton "deal-with-it", "/images/emoji/ziggy/deal-with-it.gif"
 
-  # Uploads
-  uploadBanner = (file) -> "[Uploading \"#{file.name}\"...]"
-
-  startUpload = (file) ->
-    replaceSelection("", uploadBanner(file) + "\n", "")
-
-  finishUpload = (file, response) ->
-    replacedText = $(textarea).val().replace(uploadBanner(file), decorator.image(response.url).join(""))
-    $(textarea).val(replacedText)
-
-  if Sugar.Configuration.uploads
-    $(textarea).filedrop
-      allowedfiletypes: ['image/jpeg', 'image/png', 'image/gif']
-      maxfiles: 25
-      maxfilesize: 2
-      paramname: "upload[file]"
-      url: "/uploads.json"
-      headers:
-        "X-CSRF-Token": Sugar.authToken($(textarea).closest("form"))
-      uploadStarted: (i, file, len) ->
-        startUpload file
-      uploadFinished: (i, file, response, time) ->
-        finishUpload file, response
-
-  textarea.richtext = true
-
+  bindUploads(textarea, decorator) if Sugar.Configuration.uploads
 
 $(Sugar).bind 'ready modified', ->
   $('textarea.rich').each -> new Sugar.RichTextArea(this)

    format = newFormat
    if format == "markdown"
      label = "Markdown"
      decorator = markdownDecorator
    else if format == "html"
      label = "HTML"
      decorator = htmlDecorator

    formatButton.find("a").html(label)



  # Quoting
  $(Sugar).on "quote", (event, data) ->
    [prefix, replacement, postfix] = decorator().quote(
      data.text,
      data.html,
      data.username,
      data.permalink
    )
    replaceSelection(textarea, prefix, replacement, postfix)

    # Scroll to the bottom of the textarea
    textarea.scrollTop = textarea.scrollHeight
