1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-11 11:51:27 +00:00

Wiki bugs fix (#2311)

This commit is contained in:
shanshuirenjia
2018-08-29 12:25:22 +08:00
committed by Daniel Pan
parent 74cfd3cf74
commit 2ab330ab86
5 changed files with 246 additions and 52 deletions

View File

@@ -48,30 +48,43 @@ class MarkdownViewer extends React.Component {
super(props);
this.state = {
renderingContent: true,
renderingOutline: true,
html: '',
outlineTreeRoot: null,
navItems: [],
activeId: 0,
activeId: 0
};
this.activeIdFromOutLine = null;
}
scrollToNode(node) {
let url = new URL(window.location.href);
url.set('hash', 'user-content-' + node.data.id);
window.location.href = url.toString();
}
scrollHandler = (event) => {
var target = event.target || event.srcElement;
var markdownContainer = this.refs.markdownContainer;
var headingList = markdownContainer.querySelectorAll('[id^="user-content"]');
var top = target.scrollTop;
var defaultOffset = markdownContainer.offsetTop;
var currentId = '';
for (let i = 0; i < headingList.length; i++) {
let heading = headingList[i];
if (heading.tagName === 'H1') {
continue;
}
if (top > heading.offsetTop - defaultOffset) {
currentId = '#' + heading.getAttribute('id');
} else {
break;
if (!this.activeIdFromOutLine) {
var target = event.target || event.srcElement;
var markdownContainer = this.refs.markdownContainer;
var headingList = markdownContainer.querySelectorAll('[id^="user-content"]');
var top = target.scrollTop;
var defaultOffset = markdownContainer.offsetTop;
for (let i = 0; i < headingList.length; i++) {
let heading = headingList[i];
if (heading.tagName === 'H1') {
continue;
}
if (top > heading.offsetTop - defaultOffset) {
currentId = '#' + heading.getAttribute('id');
} else {
break;
}
}
} else {
currentId = this.activeIdFromOutLine;
this.activeIdFromOutLine = null;
}
if (currentId !== this.state.activeId) {
@@ -81,6 +94,10 @@ class MarkdownViewer extends React.Component {
}
}
handleNavItemClick = (activeId) => {
this.activeIdFromOutLine = activeId;
}
setContent(markdownContent) {
let that = this;
@@ -122,6 +139,10 @@ class MarkdownViewer extends React.Component {
navItems: navItems,
activeId: currentId
})
}else {
_this.setState({
navItems: []
})
}
});
}