1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-30 04:25:47 +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 { class MarkdownViewer extends React.Component {
state = { constructor(props) {
renderingContent: true, super(props);
renderingOutline: true, this.state = {
html: '', renderingContent: true,
outlineTreeRoot: null, html: '',
navItems: [], 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) => { scrollHandler = (event) => {
@ -93,6 +89,14 @@ class MarkdownViewer extends React.Component {
html: String(file), html: String(file),
renderingContent: false 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; const hash = window.location.hash;
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl); let fileUrl = serviceUrl + '/wikis/' + slug + filePath + hash;
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl);
} }
onpopstate = (event) => { onpopstate = (event) => {