Skip to content

Commit

Permalink
Fixed josdejong#309: already loaded version of Ace being overwritten …
Browse files Browse the repository at this point in the history
…by the embedded version of JSONEditor
  • Loading branch information
josdejong committed Jan 6, 2017
1 parent 3117789 commit 717ed48
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions src/js/ace/index.js
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 9 additions & 10 deletions src/js/textmode.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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';
Expand All @@ -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;
Expand Down

0 comments on commit 717ed48

Please sign in to comment.