 
     onRender: () ->
       # update model after the user has stopped making changes
-      
+
       if @isLoaded
         updateModel = =>
           alohaId = @$el.attr('id')
           alohaEditable = Aloha.getEditableById(alohaId)
-       
+
           if alohaEditable
             editableBody = alohaEditable.getContents()
             editableBody = editableBody.trim() # Trim for idempotence
             # Change the contents but do not update the Aloha editable area
             @model.set(@modelKey, editableBody, {internalAlohaUpdate: true})
-       
+
         @saveInterval = setInterval(updateModel, AUTOSAVE_INTERVAL) if not @saveInterval
-       
+
         # Once Aloha has finished loading enable
         @$el.addClass('disabled')
-       
+
         Aloha.ready =>
           @$el.addClass('aloha-root-editable')
           @$el.mahalo?()
           @$el.aloha()
-       
+
           # Wait until Aloha is started before loading MathJax.
           MathJax?.Hub.Configured()
-       
+
           # reenable everything
           @$el.removeClass('disabled')
 

        @imagesLoaded.resolve()

      @listenTo @model, "change:#{@modelKey}", =>
        @contentLoaded.resolve() if @model.attributes.body.length

      # if content is already present change will never fire
      # so check that and conditionally finish the content loading as well
      @modelLoaded.done =>
        @contentLoaded.resolve() if @model.attributes.body.length
     
      # this is the trigger for actually showing content and enabling editing 
      $.when(@imagesLoaded, @modelLoaded, @contentLoaded, @initalRender).done =>
        @isLoaded = true
        @render()

      return {isLoaded: @isLoaded}

    initialize: () ->
      @isLoaded = @model.isNew()

      # images only have to be loaded the first time
      if @model.get(@modelKey)?.length
        @imagesLoaded = (new $.Deferred()).resolve()
      else
        @imagesLoaded = new $.Deferred()
