Created
March 4, 2019 11:21
-
-
Save Basster/bc2145f0a0d711870e1c023a1cb7825a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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