summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-08-19 22:23:15 +0100
committerPhil Hughes <me@iamphill.com>2017-08-19 22:23:15 +0100
commit150e8b30f9b80c3f207a60d93d875dd6933c5064 (patch)
treec655f62f1b4073e6ef616105b33271151ffb54b5
parent5a12fa150833e8f9aabb23bd64aa0244b344d921 (diff)
downloadgitlab-ce-150e8b30f9b80c3f207a60d93d875dd6933c5064.tar.gz
fixes for sidebar jumpingfly-out-update-for-stable
-rw-r--r--app/assets/javascripts/fly_out_nav.js24
-rw-r--r--spec/javascripts/fly_out_nav_spec.js33
2 files changed, 24 insertions, 33 deletions
diff --git a/app/assets/javascripts/fly_out_nav.js b/app/assets/javascripts/fly_out_nav.js
index 0be44a27215..adf397ca0fe 100644
--- a/app/assets/javascripts/fly_out_nav.js
+++ b/app/assets/javascripts/fly_out_nav.js
@@ -1,15 +1,15 @@
-import Cookies from 'js-cookie';
import bp from './breakpoints';
let headerHeight = 50;
+let sidebar;
+
+export const setSidebar = (el) => { sidebar = el; };
export const getHeaderHeight = () => headerHeight;
export const canShowActiveSubItems = (el) => {
- const isHiddenByMedia = bp.getBreakpointSize() === 'sm' || bp.getBreakpointSize() === 'md';
-
- if (el.classList.contains('active') && !isHiddenByMedia) {
- return Cookies.get('sidebar_collapsed') === 'true';
+ if (el.classList.contains('active') && (sidebar && !sidebar.classList.contains('sidebar-icons-only'))) {
+ return false;
}
return true;
@@ -61,10 +61,14 @@ export default () => {
const items = [...document.querySelectorAll('.sidebar-top-level-items > li')]
.filter(el => el.querySelector('.sidebar-sub-level-items'));
- headerHeight = document.querySelector('.nav-sidebar').offsetTop;
+ sidebar = document.querySelector('.nav-sidebar');
- items.forEach((el) => {
- el.addEventListener('mouseenter', e => showSubLevelItems(e.currentTarget));
- el.addEventListener('mouseleave', e => hideSubLevelItems(e.currentTarget));
- });
+ if (sidebar) {
+ headerHeight = sidebar.offsetTop;
+
+ items.forEach((el) => {
+ el.addEventListener('mouseenter', e => showSubLevelItems(e.currentTarget));
+ el.addEventListener('mouseleave', e => hideSubLevelItems(e.currentTarget));
+ });
+ }
};
diff --git a/spec/javascripts/fly_out_nav_spec.js b/spec/javascripts/fly_out_nav_spec.js
index 08803478bef..e13c4629214 100644
--- a/spec/javascripts/fly_out_nav_spec.js
+++ b/spec/javascripts/fly_out_nav_spec.js
@@ -1,4 +1,3 @@
-import Cookies from 'js-cookie';
import {
calculateTop,
hideSubLevelItems,
@@ -6,6 +5,7 @@ import {
canShowSubItems,
canShowActiveSubItems,
getHeaderHeight,
+ setSidebar,
} from '~/fly_out_nav';
import bp from '~/breakpoints';
@@ -183,7 +183,7 @@ describe('Fly out sidebar navigation', () => {
describe('canShowActiveSubItems', () => {
afterEach(() => {
- Cookies.remove('sidebar_collapsed');
+ setSidebar(null);
});
it('returns true by default', () => {
@@ -192,36 +192,23 @@ describe('Fly out sidebar navigation', () => {
).toBeTruthy();
});
- it('returns false when cookie is false & element is active', () => {
- Cookies.set('sidebar_collapsed', 'false');
+ it('returns false when active & expanded sidebar', () => {
+ const sidebar = document.createElement('div');
el.classList.add('active');
- expect(
- canShowActiveSubItems(el),
- ).toBeFalsy();
- });
-
- it('returns true when cookie is false & element is active', () => {
- Cookies.set('sidebar_collapsed', 'true');
- el.classList.add('active');
+ setSidebar(sidebar);
expect(
canShowActiveSubItems(el),
- ).toBeTruthy();
+ ).toBeFalsy();
});
- it('returns true when element is active & breakpoint is sm', () => {
- breakpointSize = 'sm';
+ it('returns true when active & collapsed sidebar', () => {
+ const sidebar = document.createElement('div');
+ sidebar.classList.add('sidebar-icons-only');
el.classList.add('active');
- expect(
- canShowActiveSubItems(el),
- ).toBeTruthy();
- });
-
- it('returns true when element is active & breakpoint is md', () => {
- breakpointSize = 'md';
- el.classList.add('active');
+ setSidebar(sidebar);
expect(
canShowActiveSubItems(el),