Fixed #309: already loaded version of Ace being overwritten by the embedded version of JSONEditor

This commit is contained in:
jos 2017-01-06 21:46:23 +01:00
parent 3117789ed7
commit 717ed48474
3 changed files with 33 additions and 15 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;