Skip to content

Commit 38ac3c9

Browse files
committed
Page JS: Improved block jumping and highlighting
- Updated anchor scroll change to open up details blocks if the target exists within. - Updated highlighting and animation implementation to fix hardly visible highlighting. - Removed old, now unused, handing of CM instances in details blocks. Related to #4637.
1 parent 324e403 commit 38ac3c9

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

resources/js/components/page-display.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export class PageDisplay extends Component {
3737

3838
window.importVersioned('code').then(Code => Code.highlight());
3939
this.setupNavHighlighting();
40-
this.setupDetailsCodeBlockRefresh();
4140

4241
// Check the hash on load
4342
if (window.location.hash) {
@@ -87,14 +86,4 @@ export class PageDisplay extends Component {
8786
}
8887
}
8988

90-
setupDetailsCodeBlockRefresh() {
91-
const onToggle = event => {
92-
const codeMirrors = [...event.target.querySelectorAll('.CodeMirror')];
93-
codeMirrors.forEach(cm => cm.CodeMirror && cm.CodeMirror.refresh());
94-
};
95-
96-
const details = [...this.container.querySelectorAll('details')];
97-
details.forEach(detail => detail.addEventListener('toggle', onToggle));
98-
}
99-
10089
}

resources/js/services/util.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {elem} from './dom';
2+
13
/**
24
* Returns a function, that, as long as it continues to be invoked, will not
35
* be triggered. The function will be called after it stops being called for
@@ -30,19 +32,29 @@ export function debounce(func, waitMs, immediate) {
3032
*/
3133
export function scrollAndHighlightElement(element) {
3234
if (!element) return;
35+
36+
const parentDetails = element.closest('details');
37+
if (parentDetails && !parentDetails.open) {
38+
parentDetails.open = true;
39+
}
40+
3341
element.scrollIntoView({behavior: 'smooth'});
3442

35-
const color = getComputedStyle(document.body).getPropertyValue('--color-primary-light');
36-
const initColor = window.getComputedStyle(element).getPropertyValue('background-color');
37-
element.style.backgroundColor = color;
43+
const highlight = getComputedStyle(document.body).getPropertyValue('--color-link');
44+
element.style.outline = `2px dashed ${highlight}`;
45+
element.style.outlineOffset = '5px';
46+
element.style.transition = null;
3847
setTimeout(() => {
39-
element.classList.add('selectFade');
40-
element.style.backgroundColor = initColor;
41-
}, 10);
42-
setTimeout(() => {
43-
element.classList.remove('selectFade');
44-
element.style.backgroundColor = '';
45-
}, 3000);
48+
element.style.transition = 'outline linear 3s';
49+
element.style.outline = '2px dashed rgba(0, 0, 0, 0)';
50+
const listener = () => {
51+
element.removeEventListener('transitionend', listener);
52+
element.style.transition = null;
53+
element.style.outline = null;
54+
element.style.outlineOffset = null;
55+
};
56+
element.addEventListener('transitionend', listener);
57+
}, 1000);
4658
}
4759

4860
/**

0 commit comments

Comments
 (0)