highlight edited style on history back in FF
This commit is contained in:
parent
5da1e0fb9b
commit
d8914c38a7
|
@ -73,7 +73,7 @@ function initGlobalEvents() {
|
|||
installed.addEventListener('mouseover', handleEvent.lazyAddEntryTitle);
|
||||
installed.addEventListener('mouseout', handleEvent.lazyAddEntryTitle);
|
||||
|
||||
document.addEventListener('visibilitychange', rememberScrollPosition);
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
|
||||
$$('[data-toggle-on-click]').forEach(el => {
|
||||
// dataset on SVG doesn't work in Chrome 49-??, works in 57+
|
||||
|
@ -115,7 +115,6 @@ function initGlobalEvents() {
|
|||
`));
|
||||
}
|
||||
|
||||
|
||||
function showStyles(styles = [], matchUrlIds) {
|
||||
const sorted = sorter.sort({
|
||||
styles: styles.map(style => ({
|
||||
|
@ -164,14 +163,7 @@ function showStyles(styles = [], matchUrlIds) {
|
|||
if ('scrollY' in (history.state || {}) && !sessionStorage.justEditedStyleId) {
|
||||
setTimeout(window.scrollTo, 0, 0, history.state.scrollY);
|
||||
}
|
||||
if (sessionStorage.justEditedStyleId) {
|
||||
const entry = $(ENTRY_ID_PREFIX + sessionStorage.justEditedStyleId);
|
||||
delete sessionStorage.justEditedStyleId;
|
||||
if (entry) {
|
||||
animateElement(entry);
|
||||
requestAnimationFrame(() => scrollElementIntoView(entry));
|
||||
}
|
||||
}
|
||||
highlightEditedStyle();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,7 +408,7 @@ Object.assign(handleEvent, {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
rememberScrollPosition();
|
||||
onVisibilityChange();
|
||||
getActiveTab().then(tab => {
|
||||
sessionStorageHash('manageStylesHistory').set(tab.id, url);
|
||||
location.href = url;
|
||||
|
@ -687,8 +679,28 @@ function switchUI({styleOnly} = {}) {
|
|||
}
|
||||
|
||||
|
||||
function rememberScrollPosition() {
|
||||
function onVisibilityChange() {
|
||||
switch (document.visibilityState) {
|
||||
// page restored without reloading via history navigation (currently only in FF)
|
||||
case 'visible':
|
||||
highlightEditedStyle();
|
||||
break;
|
||||
// going away
|
||||
case 'hidden':
|
||||
history.replaceState({scrollY: window.scrollY}, document.title);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function highlightEditedStyle() {
|
||||
if (!sessionStorage.justEditedStyleId) return;
|
||||
const entry = $(ENTRY_ID_PREFIX + sessionStorage.justEditedStyleId);
|
||||
delete sessionStorage.justEditedStyleId;
|
||||
if (entry) {
|
||||
animateElement(entry);
|
||||
requestAnimationFrame(() => scrollElementIntoView(entry));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user