Commit 6af8ecef by David Baumgold

mitx_markdown => edx_markdown

parent d1f3e3a6
...@@ -9,7 +9,7 @@ var schematic_editor_width = 500; ...@@ -9,7 +9,7 @@ var schematic_editor_width = 500;
$(function(){ $(function(){
$(document).ready(function() { $(document).ready(function() {
//$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices" //$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices"
$("body").append('\ $("body").append('\
<div id="circuit_editor_modal" class="modal hide fade"> \ <div id="circuit_editor_modal" class="modal hide fade"> \
<div class="modal-body"> \ <div class="modal-body"> \
...@@ -21,39 +21,39 @@ $(function(){ ...@@ -21,39 +21,39 @@ $(function(){
</button> \ </button> \
</div> \ </div> \
</div>'); </div>');
//This is the editor that pops up as a modal //This is the editor that pops up as a modal
var editorCircuit = $("#schematic_editor").get(0); var editorCircuit = $("#schematic_editor").get(0);
//This is the circuit that they last clicked. The one being edited. //This is the circuit that they last clicked. The one being edited.
var editingCircuit = null; var editingCircuit = null;
//Notice we use live, because new circuits can be inserted //Notice we use live, because new circuits can be inserted
$(".schematic_open").live("click", function() { $(".schematic_open").live("click", function() {
//Find the new editingCircuit. Transfer its contents to the editorCircuit //Find the new editingCircuit. Transfer its contents to the editorCircuit
editingCircuit = $(this).children("input.schematic").get(0); editingCircuit = $(this).children("input.schematic").get(0);
editingCircuit.schematic.update_value(); editingCircuit.schematic.update_value();
var circuit_so_far = $(editingCircuit).val(); var circuit_so_far = $(editingCircuit).val();
var n = editorCircuit.schematic.components.length; var n = editorCircuit.schematic.components.length;
for (var i = 0; i < n; i++) for (var i = 0; i < n; i++)
editorCircuit.schematic.components[n - 1 - i].remove(); editorCircuit.schematic.components[n - 1 - i].remove();
editorCircuit.schematic.load_schematic(circuit_so_far, ""); editorCircuit.schematic.load_schematic(circuit_so_far, "");
editorCircuit.schematic.zoomall(); editorCircuit.schematic.zoomall();
}); });
$("#circuit_save_btn").click(function () { $("#circuit_save_btn").click(function () {
//Take the circuit from the editor and put it back into editingCircuit //Take the circuit from the editor and put it back into editingCircuit
editorCircuit.schematic.update_value(); editorCircuit.schematic.update_value();
var saving_circuit = $(editorCircuit).val(); var saving_circuit = $(editorCircuit).val();
var n = editingCircuit.schematic.components.length; var n = editingCircuit.schematic.components.length;
for (var i = 0; i < n; i++) for (var i = 0; i < n; i++)
editingCircuit.schematic.components[n - 1 - i].remove(); editingCircuit.schematic.components[n - 1 - i].remove();
editingCircuit.schematic.load_schematic(saving_circuit, ""); editingCircuit.schematic.load_schematic(saving_circuit, "");
editingCircuit.schematic.zoomall(); editingCircuit.schematic.zoomall();
if (editingCircuit.codeMirrorLine) { if (editingCircuit.codeMirrorLine) {
editingCircuit.codeMirrorLine.replace(0, null, "circuit-schematic:" + saving_circuit); editingCircuit.codeMirrorLine.replace(0, null, "circuit-schematic:" + saving_circuit);
} }
...@@ -62,7 +62,7 @@ $(function(){ ...@@ -62,7 +62,7 @@ $(function(){
}); });
CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { CodeMirror.defineMode("edx_markdown", function(cmCfg, modeCfg) {
var htmlFound = CodeMirror.mimeModes.hasOwnProperty("text/html"); var htmlFound = CodeMirror.mimeModes.hasOwnProperty("text/html");
var htmlMode = CodeMirror.getMode(cmCfg, htmlFound ? "text/html" : "text/plain"); var htmlMode = CodeMirror.getMode(cmCfg, htmlFound ? "text/html" : "text/plain");
...@@ -109,7 +109,7 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -109,7 +109,7 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
} }
return null; return null;
} }
function escapeHtml(unsafe) { function escapeHtml(unsafe) {
return unsafe return unsafe
.replace(/&/g, "&amp;") .replace(/&/g, "&amp;")
...@@ -118,16 +118,16 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -118,16 +118,16 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
.replace(/"/g, "&quot;") .replace(/"/g, "&quot;")
.replace(/'/g, "&#039;"); .replace(/'/g, "&#039;");
} }
var circuit_formatter = { var circuit_formatter = {
creator: function(text) { creator: function(text) {
var circuit_value = text.match(circuitRE)[1] var circuit_value = text.match(circuitRE)[1]
circuit_value = escapeHtml(circuit_value); circuit_value = escapeHtml(circuit_value);
var html = "<div style='display:block;line-height:0;' class='schematic_container'><a href='#circuit_editor_modal' data-toggle='modal' class='schematic_open' style='display:inline-block;'>" + var html = "<div style='display:block;line-height:0;' class='schematic_container'><a href='#circuit_editor_modal' data-toggle='modal' class='schematic_open' style='display:inline-block;'>" +
"<input type='hidden' parts='' value='" + circuit_value + "' width='" + schematic_width + "' height='" + schematic_height + "' analyses='' class='schematic ctrls'/></a></div>"; "<input type='hidden' parts='' value='" + circuit_value + "' width='" + schematic_width + "' height='" + schematic_height + "' analyses='' class='schematic ctrls'/></a></div>";
return html; return html;
}, },
size: function(text) { size: function(text) {
...@@ -144,7 +144,7 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -144,7 +144,7 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
schmInput.schematic.redraw_background(); schmInput.schematic.redraw_background();
} }
} catch (err) { } catch (err) {
console.log("Error in mitx_markdown callback: " + err); console.log("Error in edx_markdown callback: " + err);
} }
} }
...@@ -174,7 +174,7 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -174,7 +174,7 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
state.indentation += match[0].length; state.indentation += match[0].length;
return list; return list;
} }
return switchInline(stream, state, state.inline); return switchInline(stream, state, state.inline);
} }
...@@ -196,10 +196,10 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -196,10 +196,10 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
// Inline // Inline
function getType(state) { function getType(state) {
var styles = []; var styles = [];
if (state.strong) { styles.push(state.em ? emstrong : strong); } if (state.strong) { styles.push(state.em ? emstrong : strong); }
else if (state.em) { styles.push(em); } else if (state.em) { styles.push(em); }
if (state.header) { styles.push(header); } if (state.header) { styles.push(header); }
if (state.quote) { styles.push(quote); } if (state.quote) { styles.push(quote); }
...@@ -210,16 +210,16 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -210,16 +210,16 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
if (stream.match(textRE, true)) { if (stream.match(textRE, true)) {
return getType(state); return getType(state);
} }
return undefined; return undefined;
} }
function inlineNormal(stream, state) { function inlineNormal(stream, state) {
var style = state.text(stream, state) var style = state.text(stream, state)
if (typeof style !== 'undefined') if (typeof style !== 'undefined')
return style; return style;
var ch = stream.next(); var ch = stream.next();
if (ch === '\\') { if (ch === '\\') {
stream.next(); stream.next();
return getType(state); return getType(state);
...@@ -241,12 +241,12 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -241,12 +241,12 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
stream.backUp(1); stream.backUp(1);
return switchBlock(stream, state, htmlBlock); return switchBlock(stream, state, htmlBlock);
} }
if (ch === '<' && stream.match(/^\/\w*?>/)) { if (ch === '<' && stream.match(/^\/\w*?>/)) {
state.md_inside = false; state.md_inside = false;
return "tag"; return "tag";
} }
var t = getType(state); var t = getType(state);
if (ch === '*' || ch === '_') { if (ch === '*' || ch === '_') {
if (stream.eat(ch)) { if (stream.eat(ch)) {
...@@ -254,7 +254,7 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -254,7 +254,7 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
} }
return (state.em = !state.em) ? getType(state) : t; return (state.em = !state.em) ? getType(state) : t;
} }
return getType(state); return getType(state);
} }
...@@ -316,11 +316,11 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -316,11 +316,11 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
startState: function() { startState: function() {
return { return {
f: blockNormal, f: blockNormal,
block: blockNormal, block: blockNormal,
htmlState: CodeMirror.startState(htmlMode), htmlState: CodeMirror.startState(htmlMode),
indentation: 0, indentation: 0,
inline: inlineNormal, inline: inlineNormal,
text: handleText, text: handleText,
em: false, em: false,
...@@ -333,11 +333,11 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) { ...@@ -333,11 +333,11 @@ CodeMirror.defineMode("mitx_markdown", function(cmCfg, modeCfg) {
copyState: function(s) { copyState: function(s) {
return { return {
f: s.f, f: s.f,
block: s.block, block: s.block,
htmlState: CodeMirror.copyState(htmlMode, s.htmlState), htmlState: CodeMirror.copyState(htmlMode, s.htmlState),
indentation: s.indentation, indentation: s.indentation,
inline: s.inline, inline: s.inline,
text: s.text, text: s.text,
em: s.em, em: s.em,
......
...@@ -57,7 +57,7 @@ class CodeMirror(BaseEditor): ...@@ -57,7 +57,7 @@ class CodeMirror(BaseEditor):
} }
js = ("js/vendor/CodeMirror/codemirror.js", js = ("js/vendor/CodeMirror/codemirror.js",
"js/vendor/CodeMirror/xml.js", "js/vendor/CodeMirror/xml.js",
"js/vendor/CodeMirror/mitx_markdown.js", "js/vendor/CodeMirror/edx_markdown.js",
"js/wiki/accessible.js", "js/wiki/accessible.js",
"js/wiki/CodeMirror.init.js", "js/wiki/CodeMirror.init.js",
) )
$(document).ready(function() { $(document).ready(function() {
var editor = CodeMirror.fromTextArea(document.getElementById("id_content"), { var editor = CodeMirror.fromTextArea(document.getElementById("id_content"), {
mode: 'mitx_markdown', mode: 'edx_markdown',
matchBrackets: true, matchBrackets: true,
theme: "default", theme: "default",
lineWrapping: true, lineWrapping: true,
keyMap: "accessible" keyMap: "accessible"
}); });
//Store the inital contents so we can compare for unsaved changes //Store the inital contents so we can compare for unsaved changes
var initial_contents = editor.getValue(); var initial_contents = editor.getValue();
window.onbeforeunload = function askConfirm() { //Warn the user before they navigate away window.onbeforeunload = function askConfirm() { //Warn the user before they navigate away
if ( editor.getValue() != initial_contents ) { if ( editor.getValue() != initial_contents ) {
return "You have made changes to the article that have not been saved yet."; return "You have made changes to the article that have not been saved yet.";
} }
}; };
$(".btn-primary").click(function() { $(".btn-primary").click(function() {
initial_contents = editor.getValue(); initial_contents = editor.getValue();
}); });
}); });
\ No newline at end of file
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