diff --git a/www/code/inner.js b/www/code/inner.js index 71aae8ac7..57d154950 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -1,5 +1,8 @@ define([ 'jquery', + + 'cm/lib/codemirror', + 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/code/code.less', 'less!/customize/src/less/toolbar.less', @@ -7,6 +10,28 @@ define([ 'css!cm/addon/dialog/dialog.css', 'css!cm/addon/fold/foldgutter.css', -], function ($) { + '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', +], function ($, CMeditor) { + window.CodeMirror = CMeditor; $('.loading-hidden').removeClass('loading-hidden'); }); diff --git a/www/code/main.js b/www/code/main.js index 1108486eb..f9a6a0c63 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -42,7 +42,7 @@ define([ Cryptpad.errorLoadingScreen(Messages.websocketError); }; - var andThen = function () { + var andThen = function (CMeditor) { var $iframe = $('#pad-iframe').contents(); var $contentContainer = $iframe.find('#editorContainer'); var $previewContainer = $iframe.find('#previewContainer'); @@ -58,7 +58,7 @@ define([ } }); - var CodeMirror = Cryptpad.createCodemirror(ifrw, Cryptpad); + var CodeMirror = Cryptpad.createCodemirror(ifrw, Cryptpad, null, CMeditor); $iframe.find('.CodeMirror').addClass('fullPage'); editor = CodeMirror.editor; @@ -428,9 +428,10 @@ define([ Cryptpad.onLogout(function () { setEditable(false); }); }; - var first = function () { + var interval = 100; + var second = function (CM) { Cryptpad.ready(function () { - andThen(); + andThen(CM); Cryptpad.reportAppUsage(); }); Cryptpad.onError(function (info) { @@ -440,6 +441,15 @@ define([ }); }; + var first = function () { + if (ifrw.CodeMirror) { + second(ifrw.CodeMirror); + } else { + console.log("CodeMirror was not defined. Trying again in %sms", interval); + setTimeout(first, interval); + } + }; + first(); }); }); diff --git a/www/common/common-codemirror.js b/www/common/common-codemirror.js index bdc57db76..333059a1d 100644 --- a/www/common/common-codemirror.js +++ b/www/common/common-codemirror.js @@ -3,36 +3,12 @@ define([ '/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, CMeditor) { +], function ($, Modes, Themes) { var saveAs = window.saveAs; var module = {}; - module.create = function (ifrw, Cryptpad, defaultMode) { + module.create = function (ifrw, Cryptpad, defaultMode, CMeditor) { var exp = {}; var Messages = Cryptpad.Messages; diff --git a/www/slide/inner.js b/www/slide/inner.js index 57f2f3e01..b39f43dbc 100644 --- a/www/slide/inner.js +++ b/www/slide/inner.js @@ -1,5 +1,9 @@ define([ 'jquery', + + 'cm/lib/codemirror', + + 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/customize/src/less/toolbar.less', 'less!/customize/src/less/cryptpad.less', @@ -9,6 +13,29 @@ define([ 'css!cm/addon/dialog/dialog.css', 'css!cm/addon/fold/foldgutter.css', -], function ($) { + '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', + +], function ($, CMeditor) { + window.CodeMirror = CMeditor; $('.loading-hidden').removeClass('loading-hidden'); }); diff --git a/www/slide/main.js b/www/slide/main.js index 9cbe64088..7c2b6d0b4 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -50,10 +50,10 @@ define([ Cryptpad.errorLoadingScreen(Messages.websocketError); }; - var andThen = function () { + var andThen = function (CMeditor) { var $iframe = $('#pad-iframe').contents(); var $contentContainer = $iframe.find('#editorContainer'); - var CodeMirror = Cryptpad.createCodemirror(ifrw, Cryptpad, 'markdown'); + var CodeMirror = Cryptpad.createCodemirror(ifrw, Cryptpad, null, CMeditor); editor = CodeMirror.editor; var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); @@ -697,9 +697,11 @@ define([ Cryptpad.onLogout(function () { setEditable(false); }); }; - var first = function () { + var interval = 100; + + var second = function (CM) { Cryptpad.ready(function () { - andThen(); + andThen(CM); Cryptpad.reportAppUsage(); }); Cryptpad.onError(function (info) { @@ -709,6 +711,17 @@ 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(); }); });