Skip to content

Commit b495e6c

Browse files
committed
Add read-only mode support
1 parent 8b74d1b commit b495e6c

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

dist/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ require('./index.css').toString();
1818
* Code Tool for the Editor.js allows to include code examples in your articles.
1919
*/
2020
class CodeTool {
21+
22+
/**
23+
* Notify core that read-only mode is supported
24+
*
25+
* @returns {boolean}
26+
*/
27+
static get isReadOnlySupported() {
28+
return true;
29+
}
30+
2131
/**
2232
* Allow to press Enter inside the CodeTool textarea
2333
*
@@ -40,9 +50,11 @@ class CodeTool {
4050
* @param {CodeData} options.data — previously saved plugin code
4151
* @param {object} options.config - user config for Tool
4252
* @param {object} options.api - Editor.js API
53+
* @param {boolean} options.readOnly - read only mode flag
4354
*/
44-
constructor({ data, config, api }) {
55+
constructor({ data, config, api, readOnly }) {
4556
this.api = api;
57+
this.readOnly = readOnly;
4658

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

@@ -81,6 +93,10 @@ class CodeTool {
8193

8294
textarea.placeholder = this.placeholder;
8395

96+
if (this.readOnly) {
97+
textarea.disabled = true;
98+
}
99+
84100
wrapper.appendChild(textarea);
85101

86102
this.nodes.textarea = textarea;

0 commit comments

Comments
 (0)