Skip to content

Commit

Permalink
Merge pull request #35 from editor-js/feature/read-only-mode
Browse files Browse the repository at this point in the history
Add read-only mode support
  • Loading branch information
neSpecc authored Sep 29, 2020
2 parents 8b74d1b + dae258e commit 83d2d9d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/code",
"version": "2.5.0",
"version": "2.6.0",
"keywords": [
"codex editor",
"code",
Expand Down
18 changes: 17 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ require('./index.css').toString();
* Code Tool for the Editor.js allows to include code examples in your articles.
*/
class CodeTool {

/**
* Notify core that read-only mode is supported
*
* @returns {boolean}
*/
static get isReadOnlySupported() {
return true;
}

/**
* Allow to press Enter inside the CodeTool textarea
*
Expand All @@ -40,9 +50,11 @@ class CodeTool {
* @param {CodeData} options.data — previously saved plugin code
* @param {object} options.config - user config for Tool
* @param {object} options.api - Editor.js API
* @param {boolean} options.readOnly - read only mode flag
*/
constructor({ data, config, api }) {
constructor({ data, config, api, readOnly }) {
this.api = api;
this.readOnly = readOnly;

this.placeholder = this.api.i18n.t(config.placeholder || CodeTool.DEFAULT_PLACEHOLDER);

Expand Down Expand Up @@ -81,6 +93,10 @@ class CodeTool {

textarea.placeholder = this.placeholder;

if (this.readOnly) {
textarea.disabled = true;
}

wrapper.appendChild(textarea);

this.nodes.textarea = textarea;
Expand Down

0 comments on commit 83d2d9d

Please sign in to comment.