-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathpageLayoutBehavior.jsx
45 lines (35 loc) · 1.4 KB
/
pageLayoutBehavior.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from 'react'
export default function PageLayoutBehavior() {
const pageLayoutSelector = '.PageLayout.PageLayout--responsive-separateRegions';
const primaryRegionSelector = 'PageLayout--responsive-primary';
const detectPageLayoutHash = () => {
const pageLayout = document.querySelector(pageLayoutSelector);
let dest;
if (location.hash === '') {
dest = pageLayout.getAttribute('data-primary-region');
} else if (location.hash === '#pane') {
dest = 'pane';
} else if (location.hash === '#content') {
dest = 'content';
} else {
return;
}
pageLayout.setAttribute('data-current-region', dest);
if (dest === 'pane') {
pageLayout.classList.replace(primaryRegionSelector + '-content', primaryRegionSelector + '-pane');
} else {
pageLayout.classList.replace(primaryRegionSelector + '-pane', primaryRegionSelector + '-content');
}
};
window.addEventListener("hashchange", () => {
detectPageLayoutHash();
});
document.addEventListener('DOMContentLoaded', (event) => {
const pageLayout = document.querySelector(pageLayoutSelector);
const primaryRegion = pageLayout.classList.contains(primaryRegionSelector + '-pane') ? 'pane' : 'content';
if (pageLayout.getAttribute('data-primary-region') === null) {
pageLayout.setAttribute('data-primary-region', primaryRegion);
}
detectPageLayoutHash();
});
}