Scroll to linked status in public status view (fixes #7884) (#8130)

When there is a single detailed status on a public page, scroll to it and
replace the history state to not scroll back on refresh (simulates # anchors).
This commit is contained in:
ThibG 2018-08-06 15:16:02 +02:00 committed by Eugen Rochko
parent c52bcc0331
commit 1ab8b4b8ea
1 changed files with 9 additions and 0 deletions

View File

@ -31,6 +31,7 @@ function main() {
const React = require('react'); const React = require('react');
const ReactDOM = require('react-dom'); const ReactDOM = require('react-dom');
const Rellax = require('rellax'); const Rellax = require('rellax');
const createHistory = require('history').createBrowserHistory;
ready(() => { ready(() => {
const locale = document.documentElement.lang; const locale = document.documentElement.lang;
@ -86,6 +87,14 @@ function main() {
} }
new Rellax('.parallax', { speed: -1 }); new Rellax('.parallax', { speed: -1 });
const history = createHistory();
const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
const location = history.location;
if (detailedStatuses.length === 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
detailedStatuses[0].scrollIntoView();
history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true });
}
}); });
delegate(document, '.webapp-btn', 'click', ({ target, button }) => { delegate(document, '.webapp-btn', 'click', ({ target, button }) => {