diff --git a/cms/static/coffee/src/views/unit.coffee b/cms/static/coffee/src/views/unit.coffee index 6b072b208a..91740a2b04 100644 --- a/cms/static/coffee/src/views/unit.coffee +++ b/cms/static/coffee/src/views/unit.coffee @@ -94,6 +94,10 @@ class CMS.Views.UnitEdit extends Backbone.View @$editor = $($('#problem-editor').html()) $preview = $($('#problem-preview').html()) initProblemEditors(@$editor, $preview) + when 'html' + @$editor = $($('#html-editor').html()) + $preview = $('
') + initHTMLEditor(@$editor, $preview) @$editor.find('.save-button, .cancel-button').bind('click', => @$componentItem.removeClass('editing') diff --git a/cms/static/js/html-editor.js b/cms/static/js/html-editor.js new file mode 100644 index 0000000000..9d530b6199 --- /dev/null +++ b/cms/static/js/html-editor.js @@ -0,0 +1,26 @@ +var $body; +var $htmlPreview; +var $htmlEditor; +var htmlEditor; + +function initHTMLEditor($editor, $prev) { + $htmlEditor = $editor; + console.log($editor.find('.edit-box')); + htmlEditor = CodeMirror.fromTextArea($editor.find('.edit-box')[0], { + lineWrapping: true, + mode: 'xml', + lineNumbers: true, + onChange: onHTMLEditorUpdate + }); + + currentEditor = htmlEditor; + + $(htmlEditor.getWrapperElement()).css('background', '#fff'); + + $(htmlEditor.getWrapperElement()).bind('click', setFocus); + $htmlPreview = $prev; +} + +function onHTMLEditorUpdate(e) { + $htmlPreview.html(htmlEditor.getValue()); +} \ No newline at end of file diff --git a/cms/static/sass/_unit.scss b/cms/static/sass/_unit.scss index 0cd09022ec..8fc431694e 100644 --- a/cms/static/sass/_unit.scss +++ b/cms/static/sass/_unit.scss @@ -374,6 +374,10 @@ } } + .html-preview { + padding: 20px 30px; + } + .component-editor { @include edit-box; display: none; diff --git a/cms/templates/unit.html b/cms/templates/unit.html index 51cc51368d..3d5e625caf 100644 --- a/cms/templates/unit.html +++ b/cms/templates/unit.html @@ -15,6 +15,7 @@ + + +