Commit 373c8eb2 by Don Mitchell

Merge branch 'feature/cas/speed-editor' of github.com:MITx/mitx into feature/cas/speed-editor

parents 8245ebac 71ee11bf
......@@ -59,6 +59,9 @@ class CMS.Views.UnitEdit extends Backbone.View
type = $(event.currentTarget).data('type')
@$newComponentTypePicker.slideUp(250)
@$(".new-component-#{type}").slideDown(250)
$('html, body').animate({
scrollTop: @$(".new-component-#{type}").offset().top
}, 500)
closeNewComponent: (event) =>
event.preventDefault()
......
<%include file="metadata-edit.html" />
<section class="problem-editor editor">
<div class="row">
%if markdown != '' or data == '<problem>\n</problem>\n':
<div class="editor-bar">
<ul class="format-buttons">
<li><a href="#" class="multiple-choice-button" data-tooltip="Multiple Choice"><span
......@@ -19,7 +20,6 @@
<li><a href="#" class="cheatsheet-toggle" data-tooltip="Toggle Cheatsheet">?</a></li>
</ul>
</div>
%if markdown != '' or data == '<problem>\n</problem>\n':
<textarea class="markdown-box">${markdown}</textarea>
%endif
<textarea class="xml-box" rows="8" cols="40">${data | h}</textarea>
......
......@@ -119,29 +119,6 @@
}
}
.tiny-link-dialog {
position: fixed;
top: 40px;
left: 50%;
z-index: 99999;
width: 600px;
margin-left: -300px;
background: #fff;
.close-button {
@include white-button;
position: absolute;
top: 0;
right: 15px;
width: 29px;
height: 29px;
padding: 0 !important;
border-radius: 17px !important;
line-height: 29px;
text-align: center;
}
}
.problem-editor-icon {
display: inline-block;
width: 26px;
......
......@@ -7,16 +7,6 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
constructor: (element) ->
@element = element
@element.on('click', '.xml-tab', @showXMLEditor)
@element.on('click', '.format-buttons a', @onToolbarButton);
@element.on('click', '.cheatsheet-toggle', @toggleCheatsheet);
@xml_editor = CodeMirror.fromTextArea($(".xml-box", element)[0], {
mode: "xml"
lineNumbers: true
lineWrapping: true
})
@current_editor = @xml_editor
if $(".markdown-box", @element).length != 0
@markdown_editor = CodeMirror.fromTextArea($(".markdown-box", element)[0], {
......@@ -24,36 +14,51 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
mode: null
})
@setCurrentEditor(@markdown_editor)
# Add listeners for toolbar buttons (only present for markdown editor)
@element.on('click', '.xml-tab', @onShowXMLButton)
@element.on('click', '.format-buttons a', @onToolbarButton)
@element.on('click', '.cheatsheet-toggle', @toggleCheatsheet)
# Hide the XML text area
$(@element.find('.xml-box')).hide()
else
@hideMarkdownElements()
@createXMLEditor()
###
Hides the toolbar buttons, as they only apply to the markdown editor.
Creates the XML Editor and sets it as the current editor. If text is passed in,
it will replace the text present in the HTML template.
text: optional argument to override the text passed in via the HTML template
###
hideMarkdownElements: () ->
$(@element.find('.editor-bar')).hide()
$(@element.find('.editor-tabs')).hide()
createXMLEditor: (text) ->
@xml_editor = CodeMirror.fromTextArea($(".xml-box", @element)[0], {
mode: "xml"
lineNumbers: true
lineWrapping: true
})
if text
@xml_editor.setValue(text)
@setCurrentEditor(@xml_editor)
###
User has clicked to show the XML editor. Before XML editor is swapped in,
the user will need to confirm the one-way conversion.
###
showXMLEditor: (e) =>
onShowXMLButton: (e) =>
e.preventDefault();
if @confirmConversionToXml()
@xml_editor.setValue(MarkdownEditingDescriptor.markdownToXml(@markdown_editor.getValue()))
@setCurrentEditor(@xml_editor)
# Need this to get line numbers to display properly (and put caret position to 0)
@createXMLEditor(MarkdownEditingDescriptor.markdownToXml(@markdown_editor.getValue()))
# Need to refresh to get line numbers to display properly (and put cursor position to 0)
@xml_editor.setCursor(0)
@xml_editor.refresh()
@hideMarkdownElements()
# Hide markdown-specific toolbar buttons
$(@element.find('.editor-bar')).hide()
###
Have the user confirm the one-way conversion to XML.
Returns true if the user clicked OK, else false.
###
confirmConversionToXml: ->
# TODO: use something besides a JavaScript confirm dialog?
# TODO: use something besides a JavaScript confirm dialog?
return confirm("If you convert to the XML source representation, you cannot go back to using markdown.\n\nProceed with conversion to XML?")
###
......@@ -90,7 +95,8 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
Stores the current editor and hides the one that is not displayed.
###
setCurrentEditor: (editor) ->
$(@current_editor.getWrapperElement()).hide()
if @current_editor
$(@current_editor.getWrapperElement()).hide()
@current_editor = editor
$(@current_editor.getWrapperElement()).show()
$(@current_editor).focus();
......
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