Skip to content
Snippets Groups Projects
Commit 2c4962d8 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

cleanup container editor changes

parent 4fa0fbe2
No related branches found
No related tags found
No related merge requests found
...@@ -10,14 +10,16 @@ import { ...@@ -10,14 +10,16 @@ import {
class ContainerEditor extends SubstanceContainerEditor { class ContainerEditor extends SubstanceContainerEditor {
constructor (...args) { constructor (...args) {
super(...args) super(...args)
this.disableBackButton = this.disableBackButton.bind(this) this.controlBackButton = this.controlBackButton.bind(this)
} }
render ($$) { render ($$) {
let el = super.render($$) let el = super.render($$)
el.addClass('my-custom-class')
// native spellcheck // native spellcheck
el.attr('spellcheck', this.props.spellcheck === 'native') // TODO -- there is a hasNativeSpellcheck fn
const isSpellcheckNative = (this.props.spellcheck === 'native')
el.attr('spellcheck', isSpellcheckNative)
// open for editing // open for editing
// TODO -- should maybe change to isEditable ? // TODO -- should maybe change to isEditable ?
...@@ -32,41 +34,53 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -32,41 +34,53 @@ class ContainerEditor extends SubstanceContainerEditor {
didMount () { didMount () {
super.didMount() super.didMount()
if (this.isEmpty()) this.createText() if (this.isEmpty()) this.createText()
this.el.focus() // TODO notworking
// TODO -- why this and not this.focus ?
this.el.focus()
if (this.isReadOnlyMode()) { if (this.isReadOnlyMode()) {
this.editorSession.onUpdate('', this.disableToolbar, this) this.editorSession.onUpdate('', this.disableToolbar, this)
this.addTargetToLinks() this.addTargetToLinks()
} }
this.props.history.listenBefore((location, callback) => { this.props.history.listenBefore((location, callback) => {
const commandStates = this.getCommandStates() const commandStates = this.getCommandStates()
if (commandStates['save'].disabled === false) { if (commandStates['save'].disabled === false) {
this._owner.send('ChangesNotSaved') const editor = this.getEditor()
this._owner.emit('send:route', location.pathname)
editor.send('ChangesNotSaved')
editor.emit('send:route', location.pathname)
return callback(false) return callback(false)
} else {
return callback()
} }
return callback()
}) })
window.history.pushState(null, null, document.URL) window.history.pushState(null, null, document.URL)
window.addEventListener('popstate', this.disableBackButton) window.addEventListener('popstate', this.controlBackButton)
} }
disableBackButton () { // TODO -- review // messes up browser history
const url = '/books/' + this.props.book.id + '/book-builder' controlBackButton () {
const commandStates = this.getCommandStates() const commandStates = this.getCommandStates()
window.removeEventListener('popstate', this.disableBackButton) const url = '/books/' + this.props.book.id + '/book-builder'
window.removeEventListener('popstate', this.controlBackButton)
if (commandStates['save'].disabled === false) { if (commandStates['save'].disabled === false) {
const editor = this.getEditor()
window.history.pushState(null, null, document.URL) window.history.pushState(null, null, document.URL)
this._owner.send('ChangesNotSaved')
this._owner.emit('send:route', url) editor.send('ChangesNotSaved')
editor.emit('send:route', url)
} else { } else {
this.props.history.push(url) this.props.history.push(url)
} }
return
} }
onTextInput (event) { onTextInput (event) {
...@@ -183,6 +197,7 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -183,6 +197,7 @@ class ContainerEditor extends SubstanceContainerEditor {
newSel = tx.createSelection({ newSel = tx.createSelection({
type: 'property', type: 'property',
// TODO -- both id's ??
containerId: 'body', containerId: 'body',
surfaceId: 'body', surfaceId: 'body',
path: [ node.id, 'content' ], path: [ node.id, 'content' ],
...@@ -190,6 +205,7 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -190,6 +205,7 @@ class ContainerEditor extends SubstanceContainerEditor {
endOffset: 0 endOffset: 0
}) })
}.bind(this)) }.bind(this))
this.rerender() this.rerender()
this.editorSession.setSelection(newSel) this.editorSession.setSelection(newSel)
} }
...@@ -220,6 +236,10 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -220,6 +236,10 @@ class ContainerEditor extends SubstanceContainerEditor {
link.attr('target', '_blank') link.attr('target', '_blank')
) )
} }
getEditor () {
return this.context.editor
}
} }
export default ContainerEditor export default ContainerEditor
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment