diff --git a/HISTORY.md b/HISTORY.md index ab4da30..6fd8904 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,12 @@ https://github.com/josdejong/jsoneditor +## not yet released, version 5.5.12 + +- Fixed #309: already loaded version of Ace being overwritten by the embedded + version of JSONEditor. + + ## 2017-01-06, version 5.5.11 - Fixed embedded version of jsoneditor ace theme not being loaded in diff --git a/src/js/ace/index.js b/src/js/ace/index.js index cc41440..ec6541e 100644 --- a/src/js/ace/index.js +++ b/src/js/ace/index.js @@ -1,8 +1,21 @@ -// load brace -var ace = require('brace'); +var ace +if (window.ace) { + // use the already loaded instance of Ace + ace = window.ace +} +else { + try { + // load brace + ace = require('brace'); -// load required ace modules -require('brace/mode/json'); -require('brace/ext/searchbox'); + // load required Ace plugins + require('brace/mode/json'); + require('brace/ext/searchbox'); + } + catch (err) { + // failed to load brace (can be minimalist bundle). + // No worries, the editor will fall back to plain text if needed. + } +} module.exports = ace; diff --git a/src/js/textmode.js b/src/js/textmode.js index e27e88a..f8a3e05 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -1,13 +1,6 @@ 'use strict'; -var ace; -try { - ace = require('./ace'); -} -catch (err) { - // failed to load ace, no problem, we will fall back to plain text -} - +var ace = require('./ace'); var ModeSwitcher = require('./ModeSwitcher'); var util = require('./util'); @@ -53,6 +46,7 @@ textmode.create = function (container, options) { // grab ace from options if provided var _ace = options.ace ? options.ace : ace; + // TODO: make the option options.ace deprecated, it's not needed anymore (see #309) // determine mode this.mode = (options.mode == 'code') ? 'code' : 'text'; @@ -66,8 +60,13 @@ textmode.create = function (container, options) { // determine theme this.theme = options.theme || DEFAULT_THEME; - if (this.theme === DEFAULT_THEME && window.ace) { - require('./ace/theme-jsoneditor'); + if (this.theme === DEFAULT_THEME && _ace) { + try { + require('./ace/theme-jsoneditor'); + } + catch (err) { + console.error(err); + } } var me = this;