From a4c5190135c2f520d7d0318d8aa7c1dd623da889 Mon Sep 17 00:00:00 2001 From: jos Date: Fri, 25 Dec 2015 15:07:00 +0100 Subject: [PATCH] Renamed `.editor` to `.aceEditor` --- docs/api.md | 3 +-- src/js/textmode.js | 60 +++++++++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/docs/api.md b/docs/api.md index 06bbd66..0455820 100644 --- a/docs/api.md +++ b/docs/api.md @@ -28,8 +28,7 @@ Constructs a new JSONEditor. Set a callback function triggered right after the mode is changed by the user. Only applicable when the mode can be changed by the user (i.e. when option `modes` is set). - `{boolean} escapeUnicode` - If true, unicode characters are escaped and displayed as their code instead - of the character. False by default. + If true, unicode characters are escaped and displayed as their hexadecimal code (like `\u260E`) instead of of the character itself (like `☎`). False by default. - `{boolean} history` Enables history, adds a button Undo and Redo to the menu of the JSONEditor. True by default. Only applicable when `mode` is 'tree' or 'form'. - `{String} mode` diff --git a/src/js/textmode.js b/src/js/textmode.js index c0b4e6a..9e2d390 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -65,7 +65,7 @@ textmode.create = function (container, options) { var me = this; this.container = container; this.dom = {}; - this.editor = undefined; // ace code editor + this.aceEditor = undefined; // ace code editor this.textarea = undefined; // plain text editor (fallback when Ace is not available) this.width = container.clientWidth; @@ -133,18 +133,30 @@ textmode.create = function (container, options) { this.editorDom.style.width = '100%'; // TODO: move to css this.content.appendChild(this.editorDom); - var editor = _ace.edit(this.editorDom); - editor.$blockScrolling = Infinity; - editor.setTheme(this.theme); - editor.setShowPrintMargin(false); - editor.setFontSize(13); - editor.getSession().setMode('ace/mode/json'); - editor.getSession().setTabSize(this.indentation); - editor.getSession().setUseSoftTabs(true); - editor.getSession().setUseWrapMode(true); - editor.commands.bindKey('Ctrl-L', null); // disable Ctrl+L (is used by the browser to select the address bar) - editor.commands.bindKey('Command-L', null); // disable Ctrl+L (is used by the browser to select the address bar) - this.editor = editor; + var aceEditor = _ace.edit(this.editorDom); + aceEditor.$blockScrolling = Infinity; + aceEditor.setTheme(this.theme); + aceEditor.setShowPrintMargin(false); + aceEditor.setFontSize(13); + aceEditor.getSession().setMode('ace/mode/json'); + aceEditor.getSession().setTabSize(this.indentation); + aceEditor.getSession().setUseSoftTabs(true); + aceEditor.getSession().setUseWrapMode(true); + aceEditor.commands.bindKey('Ctrl-L', null); // disable Ctrl+L (is used by the browser to select the address bar) + aceEditor.commands.bindKey('Command-L', null); // disable Ctrl+L (is used by the browser to select the address bar) + this.aceEditor = aceEditor; + + // TODO: deprecated since v5.0.0. Cleanup backward compatibility some day + Object.defineProperty(this, 'editor', { + get: function () { + console.warn('Property "editor" has been renamed to "aceEditor".'); + return me.aceEditor; + }, + set: function (aceEditor) { + console.warn('Property "editor" has been renamed to "aceEditor".'); + me.aceEditor = aceEditor; + } + }); var poweredBy = document.createElement('a'); poweredBy.appendChild(document.createTextNode('powered by ace')); @@ -161,7 +173,7 @@ textmode.create = function (container, options) { if (options.onChange) { // register onchange event - editor.on('change', options.onChange); + aceEditor.on('change', options.onChange); } } else { @@ -216,8 +228,8 @@ textmode._onKeyDown = function (event) { */ textmode._delete = function () { // remove old ace editor - if (this.editor) { - this.editor.destroy(); + if (this.aceEditor) { + this.aceEditor.destroy(); } if (this.frame && this.container && this.frame.parentNode == this.container) { @@ -250,8 +262,8 @@ textmode.focus = function () { if (this.textarea) { this.textarea.focus(); } - if (this.editor) { - this.editor.focus(); + if (this.aceEditor) { + this.aceEditor.focus(); } }; @@ -259,9 +271,9 @@ textmode.focus = function () { * Resize the formatter */ textmode.resize = function () { - if (this.editor) { + if (this.aceEditor) { var force = false; - this.editor.resize(force); + this.aceEditor.resize(force); } }; @@ -303,8 +315,8 @@ textmode.getText = function() { if (this.textarea) { return this.textarea.value; } - if (this.editor) { - return this.editor.getValue(); + if (this.aceEditor) { + return this.aceEditor.getValue(); } return ''; }; @@ -324,8 +336,8 @@ textmode.setText = function(jsonText) { if (this.textarea) { this.textarea.value = text; } - if (this.editor) { - this.editor.setValue(text, -1); + if (this.aceEditor) { + this.aceEditor.setValue(text, -1); } };