1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-29 20:14:19 +00:00

Chapter jump (#2307)

This commit is contained in:
C_Q 2018-08-28 17:59:24 +08:00 committed by Daniel Pan
parent 61f0c49cd4
commit 0815a90a90
2 changed files with 20 additions and 15 deletions

View File

@ -44,19 +44,15 @@ class MarkdownViewerContent extends React.Component {
class MarkdownViewer extends React.Component {
state = {
renderingContent: true,
renderingOutline: true,
html: '',
outlineTreeRoot: null,
navItems: [],
activeId: 0
}
scrollToNode(node) {
let url = new URL(window.location.href);
url.set('hash', 'user-content-' + node.data.id);
window.location.href = url.toString();
constructor(props) {
super(props);
this.state = {
renderingContent: true,
html: '',
navItems: [],
activeId: 0,
};
this.activeIdFromOutLine = null;
}
scrollHandler = (event) => {
@ -93,6 +89,14 @@ class MarkdownViewer extends React.Component {
html: String(file),
renderingContent: false
});
setTimeout(() => {
// reset the href to jump to the section
var url = new URL(window.location.href);
if (url.hash) {
window.location.href = window.location.href;
}
}, 100);
})
}

View File

@ -142,8 +142,9 @@ class Wiki extends Component {
})
})
let fileUrl = serviceUrl + '/wikis/' + slug + filePath;
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl);
const hash = window.location.hash;
let fileUrl = serviceUrl + '/wikis/' + slug + filePath + hash;
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl);
}
onpopstate = (event) => {