Commit dff33121 by Chris Dodge

refactor the coffeescript a bit more. Hopefully to resolve Jasmine failures

parent d2f91121
...@@ -48,7 +48,7 @@ class @HTMLEditingDescriptor ...@@ -48,7 +48,7 @@ class @HTMLEditingDescriptor
setup : @setupTinyMCE, setup : @setupTinyMCE,
# Cannot get access to tinyMCE Editor instance (for focusing) until after it is rendered. # Cannot get access to tinyMCE Editor instance (for focusing) until after it is rendered.
# The tinyMCE callback passes in the editor as a paramter. # The tinyMCE callback passes in the editor as a paramter.
init_instance_callback: @focusVisualEditor init_instance_callback: @initInstanceCallback
}) })
@showingVisualEditor = true @showingVisualEditor = true
...@@ -96,29 +96,32 @@ class @HTMLEditingDescriptor ...@@ -96,29 +96,32 @@ class @HTMLEditingDescriptor
# Show the Advanced (codemirror) Editor. Pulled out as a helper method for unit testing. # Show the Advanced (codemirror) Editor. Pulled out as a helper method for unit testing.
showAdvancedEditor: (visualEditor) -> showAdvancedEditor: (visualEditor) ->
if visualEditor.isDirty() if visualEditor.isDirty()
content = visualEditor.getContent({no_events: 1}) content = @rewriteStaticLinks(visualEditor.getContent({no_events: 1}), @base_asset_url, '/static/')
regex = new RegExp(@base_asset_url, 'g')
content = content.replace(regex, '/static/')
@advanced_editor.setValue(content) @advanced_editor.setValue(content)
@advanced_editor.setCursor(0) @advanced_editor.setCursor(0)
@advanced_editor.refresh() @advanced_editor.refresh()
@advanced_editor.focus() @advanced_editor.focus()
@showingVisualEditor = false @showingVisualEditor = false
rewriteStaticLinks: (content, from, to) ->
regex = new RegExp(from, 'g')
return content.replace(regex, to)
# Show the Visual (tinyMCE) Editor. Pulled out as a helper method for unit testing. # Show the Visual (tinyMCE) Editor. Pulled out as a helper method for unit testing.
showVisualEditor: (visualEditor) -> showVisualEditor: (visualEditor) ->
# In order for isDirty() to return true ONLY if edits have been made after setting the text, # In order for isDirty() to return true ONLY if edits have been made after setting the text,
# both the startContent must be sync'ed up and the dirty flag set to false. # both the startContent must be sync'ed up and the dirty flag set to false.
visualEditor.startContent = visualEditor.getContent({format: "raw", no_events: 1}); content = @rewriteStaticLinks(@advanced_editor.getValue(), '/static/', @base_asset_url)
visualEditor.setContent(content)
visualEditor.startContent = content
@focusVisualEditor(visualEditor) @focusVisualEditor(visualEditor)
@showingVisualEditor = true @showingVisualEditor = true
focusVisualEditor: (visualEditor) => initInstanceCallback: (visualEditor) =>
content = @advanced_editor.getValue() visualEditor.setContent(@rewriteStaticLinks(@advanced_editor.getValue(), '/static/', @base_asset_url))
regex = new RegExp('/static/', 'g') @focusVisualEditor(visualEditor)
content = content.replace(regex, @base_asset_url)
visualEditor.setContent(content)
focusVisualEditor: (visualEditor) =>
visualEditor.focus() visualEditor.focus()
# Need to mark editor as not dirty both when it is initially created and when we switch back to it. # Need to mark editor as not dirty both when it is initially created and when we switch back to it.
visualEditor.isNotDirty = true visualEditor.isNotDirty = true
...@@ -139,7 +142,5 @@ class @HTMLEditingDescriptor ...@@ -139,7 +142,5 @@ class @HTMLEditingDescriptor
text = @advanced_editor.getValue() text = @advanced_editor.getValue()
visualEditor = @getVisualEditor() visualEditor = @getVisualEditor()
if @showingVisualEditor and visualEditor.isDirty() if @showingVisualEditor and visualEditor.isDirty()
text = visualEditor.getContent({no_events: 1}) text = @rewriteStaticLinks(visualEditor.getContent({no_events: 1}), @base_asset_url, '/static/')
regex = new RegExp(@base_asset_url, 'g')
text = text.replace(regex, '/static/')
data: text data: text
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment