|
@@ -66,22 +66,34 @@ class SideNav {
|
|
|
toggler.addEventListener('click', event => this.onMobileToggle(event));
|
|
toggler.addEventListener('click', event => this.onMobileToggle(event));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (window.matchMedia(SIDENAV_DESKTOP_MEDIA).matches) {
|
|
|
|
|
- if (this.state.get('pinned')) {
|
|
|
|
|
- this.pin();
|
|
|
|
|
- } else {
|
|
|
|
|
- this.unpin();
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- this.bodyRemove('hide');
|
|
|
|
|
- this.bodyAdd('hidden');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const desktopMedia = window.matchMedia(SIDENAV_DESKTOP_MEDIA);
|
|
|
|
|
+ this.setResponsiveState(desktopMedia.matches);
|
|
|
|
|
+ desktopMedia.addEventListener('change', event => {
|
|
|
|
|
+ this.setResponsiveState(event.matches);
|
|
|
|
|
+ this.initLinks();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
window.addEventListener('resize', () => this.onResize());
|
|
window.addEventListener('resize', () => this.onResize());
|
|
|
|
|
|
|
|
this.base.addEventListener('mouseenter', () => this.onEnter());
|
|
this.base.addEventListener('mouseenter', () => this.onEnter());
|
|
|
this.base.addEventListener('mouseleave', () => this.onLeave());
|
|
this.base.addEventListener('mouseleave', () => this.onLeave());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Apply the appropriate sidenav state for the current responsive layout.
|
|
|
|
|
+ */
|
|
|
|
|
+ private setResponsiveState(isDesktop: boolean): void {
|
|
|
|
|
+ this.bodyRemove('hide');
|
|
|
|
|
+
|
|
|
|
|
+ if (isDesktop && this.state.get('pinned')) {
|
|
|
|
|
+ this.bodyRemove('hidden');
|
|
|
|
|
+ this.bodyAdd('show', 'pinned');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.bodyRemove('show', 'pinned');
|
|
|
|
|
+ this.bodyAdd('hidden');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* If the sidenav is shown, expand active nav links. Otherwise, collapse them.
|
|
* If the sidenav is shown, expand active nav links. Otherwise, collapse them.
|
|
|
*/
|
|
*/
|
|
@@ -153,12 +165,14 @@ class SideNav {
|
|
|
switch (action) {
|
|
switch (action) {
|
|
|
case 'expand':
|
|
case 'expand':
|
|
|
groupLink.setAttribute('aria-expanded', 'true');
|
|
groupLink.setAttribute('aria-expanded', 'true');
|
|
|
|
|
+ groupLink.classList.add('show');
|
|
|
groupItem.classList.add('active');
|
|
groupItem.classList.add('active');
|
|
|
dropdownMenu.classList.add('show');
|
|
dropdownMenu.classList.add('show');
|
|
|
link.classList.add('active');
|
|
link.classList.add('active');
|
|
|
break;
|
|
break;
|
|
|
case 'collapse':
|
|
case 'collapse':
|
|
|
groupLink.setAttribute('aria-expanded', 'false');
|
|
groupLink.setAttribute('aria-expanded', 'false');
|
|
|
|
|
+ groupLink.classList.remove('show');
|
|
|
groupItem.classList.remove('active');
|
|
groupItem.classList.remove('active');
|
|
|
dropdownMenu.classList.remove('show');
|
|
dropdownMenu.classList.remove('show');
|
|
|
link.classList.remove('active');
|
|
link.classList.remove('active');
|