       lineWrapping: true
     })
 
-    $(@advanced_editor.getWrapperElement()).addClass(HTMLEditingDescriptor.isInactiveClass)
+    @$advancedEditorWrapper = $(@advanced_editor.getWrapperElement())
+    @$advancedEditorWrapper.addClass(HTMLEditingDescriptor.isInactiveClass)
 
 #   This is a workaround for the fact that tinyMCE's baseURL property is not getting correctly set on AWS
 #   instances (like sandbox). It is not necessary to explicitly set baseURL when running locally.

      command.setActive('wrapAsCode', e.nodeName == 'CODE')
    )

  onSwitchEditor: (e)=>
    e.preventDefault();

    if not $(e.currentTarget).hasClass('current')
      element = e.data.element

      $(e.currentTarget).addClass('current')
      $(element).find('table.mceToolbar').toggleClass(HTMLEditingDescriptor.isInactiveClass)
      $(@advanced_editor.getWrapperElement()).toggleClass(HTMLEditingDescriptor.isInactiveClass)

      visualEditor = @getVisualEditor(element)
      if $(e.currentTarget).attr('data-tab') is 'visual'
        $(element).find('.html-tab').removeClass('current')
        @showVisualEditor(visualEditor)
      else
        $(element).find('.visual-tab').removeClass('current')
        @showAdvancedEditor(visualEditor)

  # Show the Advanced (codemirror) Editor. Pulled out as a helper method for unit testing.

    @focusVisualEditor(visualEditor)
    @showingVisualEditor = true

  focusVisualEditor: (visualEditor) =>
    visualEditor.focus()
    if not @$mceToolbar?
      @$mceToolbar = $(@element).find('table.mceToolbar')

  getVisualEditor: () ->
    ###
    Returns the instance of TinyMCE.
    This is different from the textarea that exists in the HTML template (@tiny_mce_textarea.

    Pulled out as a helper method for unit test.
    ###
    return @visualEditor

  save: ->
    @element.off('click', '.editor-tabs .tab', @onSwitchEditor)
    text = @advanced_editor.getValue()
    visualEditor = @getVisualEditor()
    if @showingVisualEditor and visualEditor.isDirty()
      text = visualEditor.getContent({no_events: 1})
    data: text
