Skip to content

Commit

Permalink
disabling content editable works before render
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Aug 25, 2015
1 parent 44f38d8 commit 3a2c416
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ class Editor {
*/
disableEditing() {
this.isEditable = false;
this.element.setAttribute('contentEditable', false);
if (this.element) {
this.element.setAttribute('contentEditable', false);
}
}

/**
Expand All @@ -610,7 +612,9 @@ class Editor {
*/
enableEditing() {
this.isEditable = true;
this.element.setAttribute('contentEditable', true);
if (this.element) {
this.element.setAttribute('contentEditable', true);
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/acceptance/basic-editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ test('sets element as contenteditable', (assert) => {
`editor element has a P as its first child`);
});

test('#disableEditing before render is meaningful', (assert) => {
let innerHTML = `<p>Hello</p>`;
editorElement.innerHTML = innerHTML;
editor = new Editor();
editor.disableEditing();
editor.render(editorElement);

assert.ok(!editorElement.hasAttribute('contenteditable'),
'element is not contenteditable');
editor.enableEditing();
assert.equal(editorElement.getAttribute('contenteditable'),
'true',
'element is contenteditable');
});

test('#disableEditing and #enableEditing toggle contenteditable', (assert) => {
let innerHTML = `<p>Hello</p>`;
editorElement.innerHTML = innerHTML;
Expand Down

0 comments on commit 3a2c416

Please sign in to comment.