diff --git a/common/static/js/vendor/CodeMirror/mitx_markdown.js b/common/static/js/vendor/CodeMirror/mitx_markdown.js index b6fe4dd459..da8d095742 100644 --- a/common/static/js/vendor/CodeMirror/mitx_markdown.js +++ b/common/static/js/vendor/CodeMirror/mitx_markdown.js @@ -1,12 +1,15 @@ -var schematic_height = 480; -var schematic_width = 640; +var schematic_height = 220; +var schematic_width = 400; + +var schematic_editor_height = 300; +var schematic_editor_width = 500; $(function(){ $(document).ready(function() { //$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices" $("body").append('
'+ - '' + + '' + '
'); //This is the editor that pops up as a modal diff --git a/lms/djangoapps/course_wiki/editors.py b/lms/djangoapps/course_wiki/editors.py new file mode 100644 index 0000000000..a6583a8d98 --- /dev/null +++ b/lms/djangoapps/course_wiki/editors.py @@ -0,0 +1,54 @@ +from django import forms +from django.forms.util import flatatt +from django.utils.encoding import force_unicode +from django.utils.html import conditional_escape +from django.utils.safestring import mark_safe + +from wiki.editors.base import BaseEditor +from wiki.editors.markitup import MarkItUpAdminWidget + +class CodeMirrorWidget(forms.Widget): + def __init__(self, attrs=None): + # The 'rows' and 'cols' attributes are required for HTML correctness. + default_attrs = {'class': 'markItUp', + 'rows': '10', 'cols': '40',} + if attrs: + default_attrs.update(attrs) + super(CodeMirrorWidget, self).__init__(default_attrs) + + def render(self, name, value, attrs=None): + if value is None: value = '' + final_attrs = self.build_attrs(attrs, name=name) + return mark_safe(u'
%s
' % (flatatt(final_attrs), + conditional_escape(force_unicode(value)))) + + +class CodeMirror(BaseEditor): + editor_id = 'codemirror' + + def get_admin_widget(self, instance=None): + return MarkItUpAdminWidget() + + def get_widget(self, instance=None): + return CodeMirrorWidget() + + class AdminMedia: + css = { + 'all': ("wiki/markitup/skins/simple/style.css", + "wiki/markitup/sets/admin/style.css",) + } + js = ("wiki/markitup/admin.init.js", + "wiki/markitup/jquery.markitup.js", + "wiki/markitup/sets/admin/set.js", + ) + + class Media: + css = { + 'all': ("js/vendor/CodeMirror/codemirror.css",) + } + js = ("js/vendor/CodeMirror/codemirror.js", + "js/vendor/CodeMirror/xml.js", + "js/vendor/CodeMirror/mitx_markdown.js", + "js/wiki/CodeMirror.init.js", + ) + diff --git a/lms/envs/common.py b/lms/envs/common.py index c412a3c8cd..e878767704 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -297,6 +297,7 @@ SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False ################################# WIKI ################################### WIKI_ACCOUNT_HANDLING = False +WIKI_EDITOR = 'course_wiki.editors.CodeMirror' ################################# Jasmine ################################### JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' diff --git a/lms/static/js/wiki/CodeMirror.init.js b/lms/static/js/wiki/CodeMirror.init.js new file mode 100644 index 0000000000..60a4917fc2 --- /dev/null +++ b/lms/static/js/wiki/CodeMirror.init.js @@ -0,0 +1,23 @@ +$(document).ready(function() { + + var editor = CodeMirror.fromTextArea(document.getElementById("id_content"), { + mode: 'mitx_markdown', + matchBrackets: true, + theme: "default", + lineWrapping: true, + }); + + //Store the inital contents so we can compare for unsaved changes + var initial_contents = editor.getValue(); + + window.onbeforeunload = function askConfirm() { //Warn the user before they navigate away + if ( editor.getValue() != initial_contents ) { + return "You have made changes to the article that have not been saved yet."; + } + }; + + $(".btn-primary").click(function() { + initial_contents = editor.getValue(); + }); + +}); \ No newline at end of file diff --git a/lms/templates/main_django.html b/lms/templates/main_django.html index a5c54d259a..5554803d73 100644 --- a/lms/templates/main_django.html +++ b/lms/templates/main_django.html @@ -1,9 +1,9 @@ -{% load compressed %}{% load sekizai_tags i18n %}{% load url from future %} +{% load compressed %}{% load sekizai_tags i18n %}{% load url from future %}{% load staticfiles %} {% block title %}edX{% endblock %} - + {% compressed_css 'application' %} {% compressed_js 'main_vendor' %} diff --git a/lms/templates/wiki/base.html b/lms/templates/wiki/base.html index f2d48db8aa..6c529ef748 100644 --- a/lms/templates/wiki/base.html +++ b/lms/templates/wiki/base.html @@ -1,14 +1,14 @@ {% extends "main_django.html" %} -{% load compressed %}{% load sekizai_tags i18n %}{% load url from future %} +{% load compressed %}{% load sekizai_tags i18n %}{% load url from future %}{% load staticfiles %} {% block title %}{% block pagetitle %}{% endblock %} | edX Wiki{% endblock %} {% block headextra %} {% compressed_css 'course' %} - - - - + + + +