Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Other: Replaced nested editable's .ck-editable class with .ck-editor_…
Browse files Browse the repository at this point in the history
…_editable + .ck-editor__nested-editable combo to disable Grammarly. Closes ckeditor/ckeditor5#578.
  • Loading branch information
oleq committed Mar 21, 2018
1 parent 5eb92af commit ee54894
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function setHighlightHandling( element, writer, add, remove ) {
*
* @param {module:engine/view/element~Element} element
* @param {String|Function} labelOrCreator
* * @param {module:engine/view/writer~Writer} writer
* @param {module:engine/view/writer~Writer} writer
*/
export function setLabel( element, labelOrCreator, writer ) {
writer.setCustomProperty( labelSymbol, labelOrCreator, element );
Expand All @@ -133,16 +133,17 @@ export function getLabel( element ) {

/**
* Adds functionality to provided {module:engine/view/editableelement~EditableElement} to act as a widget's editable:
* * adds `ck-editable` CSS class,
* * adds `ck-editor__editable` and `ck-editor__nested-editable` CSS classes,
* * sets `contenteditable` as `true` when {module:engine/view/editableelement~EditableElement#isReadOnly} is `false`
* otherwise set `false`,
* * adds `ck-editable_focused` CSS class when editable is focused and removes it when it's blurred.
* * adds `ck-editor__nested-editable` CSS class when editable is focused and removes it when it's blurred.
*
* @param {module:engine/view/editableelement~EditableElement} editable
* @param {module:engine/view/writer~Writer} writer
* @returns {module:engine/view/editableelement~EditableElement} Returns same element that was provided in `editable` param.
*/
export function toWidgetEditable( editable, writer ) {
writer.addClass( 'ck-editable', editable );
writer.addClass( [ 'ck-editor__editable', 'ck-editor__nested-editable' ], editable );

// Set initial contenteditable value.
writer.setAttribute( 'contenteditable', editable.isReadOnly ? 'false' : 'true', editable );
Expand All @@ -154,9 +155,9 @@ export function toWidgetEditable( editable, writer ) {

editable.on( 'change:isFocused', ( evt, property, is ) => {
if ( is ) {
writer.addClass( 'ck-editable_focused', editable );
writer.addClass( 'ck-editor__nested-editable_focused', editable );
} else {
writer.removeClass( 'ck-editable_focused', editable );
writer.removeClass( 'ck-editor__nested-editable_focused', editable );
}
} );

Expand Down
6 changes: 3 additions & 3 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe( 'widget utils', () => {
} );

it( 'should add proper class', () => {
expect( element.hasClass( 'ck-editable' ) ).to.be.true;
expect( element.hasClass( 'ck-editor__editable', 'ck-editor__nested-editable' ) ).to.be.true;
} );

it( 'should add proper contenteditable value when element is read-only - initialization', () => {
Expand All @@ -161,10 +161,10 @@ describe( 'widget utils', () => {

it( 'should add proper class when element is focused', () => {
element.isFocused = true;
expect( element.hasClass( 'ck-editable_focused' ) ).to.be.true;
expect( element.hasClass( 'ck-editor__nested-editable_focused' ) ).to.be.true;

element.isFocused = false;
expect( element.hasClass( 'ck-editable_focused' ) ).to.be.false;
expect( element.hasClass( 'ck-editor__nested-editable_focused' ) ).to.be.false;
} );
} );

Expand Down

0 comments on commit ee54894

Please sign in to comment.