Skip to content
Snippets Groups Projects
Commit d645d8fd authored by chris's avatar chris Committed by john
Browse files

move resizable note pane to panes/notes

parent 76e081b5
No related branches found
No related tags found
No related merge requests found
...@@ -22,8 +22,6 @@ class Editor extends ProseEditor { ...@@ -22,8 +22,6 @@ class Editor extends ProseEditor {
constructor (parent, props) { constructor (parent, props) {
super(parent, props) super(parent, props)
this.stopResize = this.stopResize.bind(this)
this.handleActions({ this.handleActions({
'showComments': function () { this.toggleCommentsArea(true) }, 'showComments': function () { this.toggleCommentsArea(true) },
'hideComments': function () { this.toggleCommentsArea(false) }, 'hideComments': function () { this.toggleCommentsArea(false) },
...@@ -56,31 +54,10 @@ class Editor extends ProseEditor { ...@@ -56,31 +54,10 @@ class Editor extends ProseEditor {
this.extendState({ editorReady: true }) this.extendState({ editorReady: true })
} }
initResize (e) {
window.addEventListener('mousemove', this.resize, false)
window.addEventListener('mouseup', this.stopResize, false)
}
resize (e) {
const notesContainer = document.getElementsByClassName('notes-container')
notesContainer[0].style.height = (notesContainer[0].offsetHeight + notesContainer[0].offsetTop - e.clientY) + 'px'
}
stopResize (e) {
window.removeEventListener('mousemove', this.resize, false)
window.removeEventListener('mouseup', this.stopResize, false)
}
render ($$) { render ($$) {
// const { trackChangesView } = this.state // const { trackChangesView } = this.state
// const canToggleTrackChanges = this.canToggleTrackChanges() // const canToggleTrackChanges = this.canToggleTrackChanges()
const resizer = $$('div').addClass('resize-area')
const notesContainer = $$('div')
.addClass('notes-container').append(resizer)
resizer.addEventListener('mousedown', this.initResize, false)
const el = $$('div').addClass('sc-prose-editor') const el = $$('div').addClass('sc-prose-editor')
// left side: editor and toolbar // left side: editor and toolbar
...@@ -108,9 +85,7 @@ class Editor extends ProseEditor { ...@@ -108,9 +85,7 @@ class Editor extends ProseEditor {
var editorWithFooter = $$('div') var editorWithFooter = $$('div')
.append( .append(
editor, editor
footerNotes,
// notesContainer
) )
var commentsPane = this.state.editorReady var commentsPane = this.state.editorReady
...@@ -141,7 +116,7 @@ class Editor extends ProseEditor { ...@@ -141,7 +116,7 @@ class Editor extends ProseEditor {
$$(ContextMenu), $$(ContextMenu),
// $$(Dropzones) // $$(Dropzones)
sideNav, sideNav,
notesContainer footerNotes
) )
.attr('id', 'content-panel') .attr('id', 'content-panel')
.ref('contentPanel') .ref('contentPanel')
......
...@@ -333,24 +333,4 @@ $active-blue: #4a90e2; ...@@ -333,24 +333,4 @@ $active-blue: #4a90e2;
flex-wrap: wrap; flex-wrap: wrap;
margin-left: 8%; margin-left: 8%;
} }
.notes-container {
background-color: $white;
bottom: 0;
height: 95px;
left: 130px;
max-height: 700px;
min-height: 10px;
position: fixed;
width: 67.4%;
z-index: 0;
.resize-area {
background-color: red;
cursor: row-resize;
height: 5px;
position: absolute;
top: 0;
width: 100%;
}
}
} }
import { Component } from 'substance' import { Component } from 'substance'
class Notes extends Component { class Notes extends Component {
constructor (props) {
super(props)
this.resize = this.resize.bind(this)
this.stopResize = this.stopResize.bind(this)
}
// use toc:updated to avoid rewriting TOCProvider's this.handleDocumentChange // use toc:updated to avoid rewriting TOCProvider's this.handleDocumentChange
didMount () { didMount () {
this.context.editorSession.onUpdate('document', this.onNotesUpdated, this) this.context.editorSession.onUpdate('document', this.onNotesUpdated, this)
} }
render ($$) { initResize (e) {
const provider = this.getProvider() window.addEventListener('mousemove', this.resize, false)
const entries = provider.getEntries() window.addEventListener('mouseup', this.stopResize, false)
let self = this
const listItems = entries.map(function (entry, i) {
let extractedElement = ''
if (entry.content) {
extractedElement = self.parseEntryContent($$, entry.content)
return extractedElement
.attr('data-id', entry.id)
.addClass('sc-notes-footer-item')
}
return $$('li')
.attr('data-id', entry.id)
.addClass('sc-notes-footer-item')
.append(extractedElement)
})
if (listItems.length === 0) return $$('div')
return $$('ol')
.addClass('sc-notes-footer')
.append(listItems)
} }
parseEntryContent ($$, content) { resize (e) {
let parser = new DOMParser() this.el.el.style.height = (this.el.el.offsetHeight + this.el.el.offsetTop - e.clientY) + 'px'
let parsedContent = parser.parseFromString(content, 'text/html').body }
let parentElement = parsedContent.childNodes[0]
let children = parentElement.childNodes
let constructedElement = $$('li')
for (let i = 0; i < children.length; i++) {
if (children[i].nodeName === '#text') {
constructedElement.append(children[i].data)
} else {
let contructedChildElement = $$(children[i].nodeName)
// Case of nested styling, first contruct the sub child node
if (children[i].children.length === 1) {
let contructedSubChildElement = $$(children[i].children[0].nodeName)
this.assignVirtualElementClass(children[i].children[0], contructedSubChildElement)
this.assignVirtualElementClass(children[i], contructedChildElement)
contructedSubChildElement.append(children[i].children[0].innerText) stopResize (e) {
contructedChildElement.append(contructedSubChildElement) window.removeEventListener('mousemove', this.resize, false)
} else { window.removeEventListener('mouseup', this.stopResize, false)
this.assignVirtualElementClass(children[i], contructedChildElement) }
contructedChildElement.append(children[i].innerText)
}
constructedElement.append(contructedChildElement) render ($$) {
} const resizer = $$('div').addClass('resize-area')
} const notesContainer = $$('div')
.addClass('notes-container').append(resizer)
return constructedElement resizer.addEventListener('mousedown', this.initResize, false)
}
assignVirtualElementClass (DOMElement, virtualElement) { return notesContainer
switch (DOMElement.nodeName) {
case 'STRONG':
virtualElement.addClass('sc-strong')
break
case 'EM':
virtualElement.addClass('sc-emphasis')
break
}
} }
getProvider () { getProvider () {
......
$gray: #ddd; $white: #fff;
.sc-notes-footer { .notes-container {
border-top: 1px solid $gray; background-color: $white;
counter-reset: note-footer; bottom: 0;
font-size: 14px; height: 95px;
list-style-type: none; left: 130px;
padding-top: 25px; max-height: 700px;
} min-height: 10px;
position: fixed;
width: 67.4%;
z-index: 0;
.sc-notes-footer-item::before { .resize-area {
content: ''counter(note-footer)'. '; background-color: red;
counter-increment: note-footer; cursor: row-resize;
} height: 5px;
position: absolute;
top: 0;
width: 100%;
}
}
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