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 {
class ContainerEditor extends SubstanceContainerEditor {
constructor (...args) {
super(...args)
this.disableBackButton = this.disableBackButton.bind(this)
this.controlBackButton = this.controlBackButton.bind(this)
}
render ($$) {
let el = super.render($$)
el.addClass('my-custom-class')
// 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
// TODO -- should maybe change to isEditable ?
......@@ -32,41 +34,53 @@ class ContainerEditor extends SubstanceContainerEditor {
didMount () {
super.didMount()
if (this.isEmpty()) this.createText()
this.el.focus() // TODO notworking
// TODO -- why this and not this.focus ?
this.el.focus()
if (this.isReadOnlyMode()) {
this.editorSession.onUpdate('', this.disableToolbar, this)
this.addTargetToLinks()
}
this.props.history.listenBefore((location, callback) => {
const commandStates = this.getCommandStates()
if (commandStates['save'].disabled === false) {
this._owner.send('ChangesNotSaved')
this._owner.emit('send:route', location.pathname)
const editor = this.getEditor()
editor.send('ChangesNotSaved')
editor.emit('send:route', location.pathname)
return callback(false)
} else {
return callback()
}
return callback()
})
window.history.pushState(null, null, document.URL)
window.addEventListener('popstate', this.disableBackButton)
window.addEventListener('popstate', this.controlBackButton)
}
disableBackButton () {
const url = '/books/' + this.props.book.id + '/book-builder'
// TODO -- review // messes up browser history
controlBackButton () {
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) {
const editor = this.getEditor()
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 {
this.props.history.push(url)
}
return
}
onTextInput (event) {
......@@ -183,6 +197,7 @@ class ContainerEditor extends SubstanceContainerEditor {
newSel = tx.createSelection({
type: 'property',
// TODO -- both id's ??
containerId: 'body',
surfaceId: 'body',
path: [ node.id, 'content' ],
......@@ -190,6 +205,7 @@ class ContainerEditor extends SubstanceContainerEditor {
endOffset: 0
})
}.bind(this))
this.rerender()
this.editorSession.setSelection(newSel)
}
......@@ -220,6 +236,10 @@ class ContainerEditor extends SubstanceContainerEditor {
link.attr('target', '_blank')
)
}
getEditor () {
return this.context.editor
}
}
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