   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)

  # Emoticons
  addEmojiButton = (name, image) ->
    link = $("<a title=\"#{name}\"><img alt=\"#{name}\" class=\"emoji\" src=\"#{image}\" width=\"16\" height=\"16\"></a>")
    link.click -> replaceSelection("", ":" + name + ": ", "")
    $("<li class=\"button\"></li>").append(link).appendTo(emojiBar)

  # TODO: Get these from the backend


  nextFormat = ->
    setFormat formats[(formats.indexOf(format) + 1) % formats.length]

  setFormat(format, true)

  formatButton.find("a").click -> nextFormat()

  addButton = (name, className, callback) ->
    link = $("<a title=\"#{name}\" class=\"#{className}\"><i class=\"icon-#{className}\"></i></a>")

    link.click ->
      [prefix, replacement, postfix] = callback(getSelection(textarea))
      replaceSelection(textarea, prefix, replacement, postfix)

    $("<li class=\"button\"></li>").append(link).insertBefore(formatButton)

  # Bold button
  addButton "Bold", "bold", (selection) -> decorator().bold(selection)

  # Italic button
  addButton "Italics", "italic", (selection) -> decorator().emphasis(selection)

  # Link button
  addButton "Link", "link", (selection) ->
