diff --git a/www/code/inner.html b/www/code/inner.html index e832c026c..6a224ba7d 100644 --- a/www/code/inner.html +++ b/www/code/inner.html @@ -3,33 +3,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/www/code/inner.js b/www/code/inner.js index d2dac0968..71aae8ac7 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -3,6 +3,10 @@ define([ 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/code/code.less', 'less!/customize/src/less/toolbar.less', + 'css!cm/lib/codemirror.css', + 'css!cm/addon/dialog/dialog.css', + 'css!cm/addon/fold/foldgutter.css', + ], function ($) { $('.loading-hidden').removeClass('loading-hidden'); }); diff --git a/www/code/main.js b/www/code/main.js index 226e3a235..1e7210ce3 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -42,7 +42,7 @@ define([ Cryptpad.errorLoadingScreen(Messages.websocketError); }; - var andThen = function (CMeditor) { + var andThen = function () { var $iframe = $('#pad-iframe').contents(); var $contentContainer = $iframe.find('#editorContainer'); var $previewContainer = $iframe.find('#previewContainer'); @@ -58,7 +58,7 @@ define([ } }); - var CodeMirror = Cryptpad.createCodemirror(CMeditor, ifrw, Cryptpad); + var CodeMirror = Cryptpad.createCodemirror(ifrw, Cryptpad); $iframe.find('.CodeMirror').addClass('fullPage'); editor = CodeMirror.editor; @@ -430,9 +430,9 @@ define([ var interval = 100; - var second = function (CM) { + var first = function () { Cryptpad.ready(function () { - andThen(CM); + andThen(); Cryptpad.reportAppUsage(); }); Cryptpad.onError(function (info) { @@ -442,17 +442,6 @@ define([ }); }; - var first = function () { - if (ifrw.CodeMirror) { - // it exists, call your continuation - second(ifrw.CodeMirror); - } else { - console.log("CodeMirror was not defined. Trying again in %sms", interval); - // try again in 'interval' ms - setTimeout(first, interval); - } - }; - first(); }); }); diff --git a/www/common/boot2.js b/www/common/boot2.js index da1ca2bc3..928b57d48 100644 --- a/www/common/boot2.js +++ b/www/common/boot2.js @@ -10,6 +10,7 @@ define([], function () { "json.sortify": "/bower_components/json.sortify/dist/JSON.sortify", //"pdfjs-dist/build/pdf": "/bower_components/pdfjs-dist/build/pdf", //"pdfjs-dist/build/pdf.worker": "/bower_components/pdfjs-dist/build/pdf.worker" + cm: '/bower_components/codemirror' }, map: { '*': { diff --git a/www/common/common-codemirror.js b/www/common/common-codemirror.js index 6202a9ce3..bdc57db76 100644 --- a/www/common/common-codemirror.js +++ b/www/common/common-codemirror.js @@ -2,18 +2,42 @@ define([ 'jquery', '/common/modes.js', '/common/themes.js', + + 'cm/lib/codemirror', + 'cm/mode/javascript/javascript', + 'cm/mode/markdown/markdown', + 'cm/addon/mode/loadmode', + 'cm/mode/meta', + 'cm/addon/mode/overlay', + 'cm/addon/mode/multiplex', + 'cm/addon/mode/simple', + 'cm/addon/edit/closebrackets', + 'cm/addon/edit/matchbrackets', + 'cm/addon/edit/trailingspace', + 'cm/addon/selection/active-line', + 'cm/addon/search/search', + 'cm/addon/search/match-highlighter', + 'cm/addon/search/searchcursor', + 'cm/addon/dialog/dialog', + 'cm/addon/fold/foldcode', + 'cm/addon/fold/foldgutter', + 'cm/addon/fold/brace-fold', + 'cm/addon/fold/xml-fold', + 'cm/addon/fold/markdown-fold', + 'cm/addon/fold/comment-fold', + 'cm/addon/display/placeholder', + '/bower_components/file-saver/FileSaver.min.js' -], function ($, Modes, Themes) { +], function ($, Modes, Themes, CMeditor) { var saveAs = window.saveAs; var module = {}; - module.create = function (CMeditor, ifrw, Cryptpad) { + module.create = function (ifrw, Cryptpad, defaultMode) { var exp = {}; - var Messages = Cryptpad.Messages; var CodeMirror = exp.CodeMirror = CMeditor; - CodeMirror.modeURL = "/bower_components/codemirror/mode/%N/%N.js"; + CodeMirror.modeURL = "cm/mode/%N/%N"; var $pad = $('#pad-iframe'); var $textarea = exp.$textarea = $pad.contents().find('#editor1'); @@ -43,14 +67,16 @@ define([ extraKeys: {"Shift-Ctrl-R": undefined}, foldGutter: true, gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], - mode: "javascript", + mode: defaultMode || "javascript", readOnly: true }); editor.setValue(Messages.codeInitialState); var setMode = exp.setMode = function (mode, cb) { exp.highlightMode = mode; - if (mode !== "text") { CMeditor.autoLoadMode(editor, mode); } + if (mode !== "text") { + CMeditor.autoLoadMode(editor, mode); + } editor.setOption('mode', mode); if (exp.$language) { var name = exp.$language.find('a[data-value="' + mode + '"]').text() || undefined; diff --git a/www/common/modes.js b/www/common/modes.js index 918a804a3..e5d9892fb 100644 --- a/www/common/modes.js +++ b/www/common/modes.js @@ -54,11 +54,9 @@ define(function () { "jsx jsx .jsx", "julia julia", "livescript livescript", - "loadmode.js loadmode.js", "lua lua", "markdown markdown .md", "mathematica mathematica", - "meta.js meta.js", "mirc mirc", "mllike mllike", "modelica modelica", diff --git a/www/slide/inner.html b/www/slide/inner.html index 4a6b4ce9f..e9ececf5e 100644 --- a/www/slide/inner.html +++ b/www/slide/inner.html @@ -6,34 +6,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/www/slide/main.js b/www/slide/main.js index 50dda8a0e..4df790e9a 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -50,10 +50,10 @@ define([ Cryptpad.errorLoadingScreen(Messages.websocketError); }; - var andThen = function (CMeditor) { + var andThen = function () { var $iframe = $('#pad-iframe').contents(); var $contentContainer = $iframe.find('#editorContainer'); - var CodeMirror = Cryptpad.createCodemirror(CMeditor, ifrw, Cryptpad); + var CodeMirror = Cryptpad.createCodemirror(ifrw, Cryptpad, 'slide'); editor = CodeMirror.editor; var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); @@ -697,9 +697,9 @@ define([ var interval = 100; - var second = function (CM) { + var first = function () { Cryptpad.ready(function () { - andThen(CM); + andThen(); Cryptpad.reportAppUsage(); }); Cryptpad.onError(function (info) { @@ -709,17 +709,6 @@ define([ }); }; - var first = function () { - if (ifrw.CodeMirror) { - // it exists, call your continuation - second(ifrw.CodeMirror); - } else { - console.log("CodeMirror was not defined. Trying again in %sms", interval); - // try again in 'interval' ms - setTimeout(first, interval); - } - }; - first(); }); });