Skip to content

Instantly share code, notes, and snippets.

@Basster
Created March 4, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Basster/bc2145f0a0d711870e1c023a1cb7825a to your computer and use it in GitHub Desktop.
Save Basster/bc2145f0a0d711870e1c023a1cb7825a to your computer and use it in GitHub Desktop.
export default class Emptyness {
constructor(editor) {
this.editor = editor;
}
init() {
const doc = this.editor.model.document;
const view = this.editor.ui.view.editable;
if (!view) {
return;
}
view.set( 'isEmpty', !documentHasContent(doc) );
view.listenTo(doc, 'change:data', () => {
view.set( 'isEmpty', !documentHasContent(doc) );
} );
if (view.isRendered === true) {
return;
}
const bind = view.bindTemplate;
view.extendTemplate( {
attributes: {
class: [
bind.if( 'isEmpty', 'ck-editor__is-empty' )
]
}
} );
}
}
function documentHasContent(doc) {
return doc.model.hasContent(doc.getRoot());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment