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 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 ## 2017-01-06, version 5.5.11
- Fixed embedded version of jsoneditor ace theme not being loaded in - Fixed embedded version of jsoneditor ace theme not being loaded in

View File

@ -1,8 +1,21 @@
// load brace var ace
var ace = require('brace'); if (window.ace) {
// use the already loaded instance of Ace
ace = window.ace
}
else {
try {
// load brace
ace = require('brace');
// load required ace modules // load required Ace plugins
require('brace/mode/json'); require('brace/mode/json');
require('brace/ext/searchbox'); 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; module.exports = ace;

View File

@ -1,13 +1,6 @@
'use strict'; 'use strict';
var ace; var ace = require('./ace');
try {
ace = require('./ace');
}
catch (err) {
// failed to load ace, no problem, we will fall back to plain text
}
var ModeSwitcher = require('./ModeSwitcher'); var ModeSwitcher = require('./ModeSwitcher');
var util = require('./util'); var util = require('./util');
@ -53,6 +46,7 @@ textmode.create = function (container, options) {
// grab ace from options if provided // grab ace from options if provided
var _ace = options.ace ? options.ace : ace; var _ace = options.ace ? options.ace : ace;
// TODO: make the option options.ace deprecated, it's not needed anymore (see #309)
// determine mode // determine mode
this.mode = (options.mode == 'code') ? 'code' : 'text'; this.mode = (options.mode == 'code') ? 'code' : 'text';
@ -66,8 +60,13 @@ textmode.create = function (container, options) {
// determine theme // determine theme
this.theme = options.theme || DEFAULT_THEME; this.theme = options.theme || DEFAULT_THEME;
if (this.theme === DEFAULT_THEME && window.ace) { if (this.theme === DEFAULT_THEME && _ace) {
require('./ace/theme-jsoneditor'); try {
require('./ace/theme-jsoneditor');
}
catch (err) {
console.error(err);
}
} }
var me = this; var me = this;