Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
f34b20f5
Commit
f34b20f5
authored
Aug 31, 2017
by
Tim Zallmann
Committed by
Jose Ivan Vargas
Sep 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'fly-out-nav-jump-fix' into 'master'
Fixed fly-out nav jumping Closes #36699 See merge request !13690
parent
50dc419b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
33 deletions
+26
-33
app/assets/javascripts/fly_out_nav.js
app/assets/javascripts/fly_out_nav.js
+13
-8
spec/javascripts/fly_out_nav_spec.js
spec/javascripts/fly_out_nav_spec.js
+13
-25
No files found.
app/assets/javascripts/fly_out_nav.js
View file @
f34b20f5
import
Cookies
from
'
js-cookie
'
;
import
bp
from
'
./breakpoints
'
;
import
bp
from
'
./breakpoints
'
;
const
HIDE_INTERVAL_TIMEOUT
=
300
;
const
HIDE_INTERVAL_TIMEOUT
=
300
;
...
@@ -8,18 +7,22 @@ const IS_SHOWING_FLY_OUT_CLASS = 'is-showing-fly-out';
...
@@ -8,18 +7,22 @@ const IS_SHOWING_FLY_OUT_CLASS = 'is-showing-fly-out';
let
currentOpenMenu
=
null
;
let
currentOpenMenu
=
null
;
let
menuCornerLocs
;
let
menuCornerLocs
;
let
timeoutId
;
let
timeoutId
;
let
sidebar
;
export
const
mousePos
=
[];
export
const
mousePos
=
[];
export
const
setSidebar
=
(
el
)
=>
{
sidebar
=
el
;
};
export
const
setOpenMenu
=
(
menu
=
null
)
=>
{
currentOpenMenu
=
menu
;
};
export
const
setOpenMenu
=
(
menu
=
null
)
=>
{
currentOpenMenu
=
menu
;
};
export
const
slope
=
(
a
,
b
)
=>
(
b
.
y
-
a
.
y
)
/
(
b
.
x
-
a
.
x
);
export
const
slope
=
(
a
,
b
)
=>
(
b
.
y
-
a
.
y
)
/
(
b
.
x
-
a
.
x
);
export
const
canShowActiveSubItems
=
(
el
)
=>
{
let
headerHeight
=
50
;
const
isHiddenByMedia
=
bp
.
getBreakpointSize
()
===
'
sm
'
||
bp
.
getBreakpointSize
()
===
'
md
'
;
export
const
getHeaderHeight
=
()
=>
headerHeight
;
if
(
el
.
classList
.
contains
(
'
active
'
)
&&
!
isHiddenByMedia
)
{
export
const
canShowActiveSubItems
=
(
el
)
=>
{
return
Cookies
.
get
(
'
sidebar_collapsed
'
)
===
'
true
'
;
if
(
el
.
classList
.
contains
(
'
active
'
)
&&
(
sidebar
&&
!
sidebar
.
classList
.
contains
(
'
sidebar-icons-only
'
)))
{
return
false
;
}
}
return
true
;
return
true
;
...
@@ -74,7 +77,7 @@ export const moveSubItemsToPosition = (el, subItems) => {
...
@@ -74,7 +77,7 @@ export const moveSubItemsToPosition = (el, subItems) => {
const
isAbove
=
top
<
boundingRect
.
top
;
const
isAbove
=
top
<
boundingRect
.
top
;
subItems
.
classList
.
add
(
'
fly-out-list
'
);
subItems
.
classList
.
add
(
'
fly-out-list
'
);
subItems
.
style
.
transform
=
`translate3d(0,
${
Math
.
floor
(
top
)}
px, 0)`
;
// eslint-disable-line no-param-reassign
subItems
.
style
.
transform
=
`translate3d(0,
${
Math
.
floor
(
top
)
-
headerHeight
}
px, 0)`
;
// eslint-disable-line no-param-reassign
const
subItemsRect
=
subItems
.
getBoundingClientRect
();
const
subItemsRect
=
subItems
.
getBoundingClientRect
();
...
@@ -139,13 +142,13 @@ export const documentMouseMove = (e) => {
...
@@ -139,13 +142,13 @@ export const documentMouseMove = (e) => {
};
};
export
default
()
=>
{
export
default
()
=>
{
const
sidebar
=
document
.
querySelector
(
'
.sidebar-top-level-items
'
);
sidebar
=
document
.
querySelector
(
'
.nav-sidebar
'
);
if
(
!
sidebar
)
return
;
if
(
!
sidebar
)
return
;
const
items
=
[...
sidebar
.
querySelectorAll
(
'
.sidebar-top-level-items > li
'
)];
const
items
=
[...
sidebar
.
querySelectorAll
(
'
.sidebar-top-level-items > li
'
)];
sidebar
.
addEventListener
(
'
mouseleave
'
,
()
=>
{
sidebar
.
querySelector
(
'
.sidebar-top-level-items
'
).
addEventListener
(
'
mouseleave
'
,
()
=>
{
clearTimeout
(
timeoutId
);
clearTimeout
(
timeoutId
);
timeoutId
=
setTimeout
(()
=>
{
timeoutId
=
setTimeout
(()
=>
{
...
@@ -153,6 +156,8 @@ export default () => {
...
@@ -153,6 +156,8 @@ export default () => {
},
getHideSubItemsInterval
());
},
getHideSubItemsInterval
());
});
});
headerHeight
=
document
.
querySelector
(
'
.nav-sidebar
'
).
offsetTop
;
items
.
forEach
((
el
)
=>
{
items
.
forEach
((
el
)
=>
{
const
subItems
=
el
.
querySelector
(
'
.sidebar-sub-level-items
'
);
const
subItems
=
el
.
querySelector
(
'
.sidebar-sub-level-items
'
);
...
...
spec/javascripts/fly_out_nav_spec.js
View file @
f34b20f5
import
Cookies
from
'
js-cookie
'
;
import
{
import
{
calculateTop
,
calculateTop
,
showSubLevelItems
,
showSubLevelItems
,
...
@@ -10,6 +9,8 @@ import {
...
@@ -10,6 +9,8 @@ import {
mousePos
,
mousePos
,
getHideSubItemsInterval
,
getHideSubItemsInterval
,
documentMouseMove
,
documentMouseMove
,
getHeaderHeight
,
setSidebar
,
}
from
'
~/fly_out_nav
'
;
}
from
'
~/fly_out_nav
'
;
import
bp
from
'
~/breakpoints
'
;
import
bp
from
'
~/breakpoints
'
;
...
@@ -59,7 +60,7 @@ describe('Fly out sidebar navigation', () => {
...
@@ -59,7 +60,7 @@ describe('Fly out sidebar navigation', () => {
describe
(
'
getHideSubItemsInterval
'
,
()
=>
{
describe
(
'
getHideSubItemsInterval
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
el
.
innerHTML
=
'
<div class="sidebar-sub-level-items" style="position: fixed; top: 0; left: 100px; height: 50px;"></div>
'
;
el
.
innerHTML
=
'
<div class="sidebar-sub-level-items" style="position: fixed; top: 0; left: 100px; height:
1
50px;"></div>
'
;
});
});
it
(
'
returns 0 if currentOpenMenu is nil
'
,
()
=>
{
it
(
'
returns 0 if currentOpenMenu is nil
'
,
()
=>
{
...
@@ -245,7 +246,7 @@ describe('Fly out sidebar navigation', () => {
...
@@ -245,7 +246,7 @@ describe('Fly out sidebar navigation', () => {
expect
(
expect
(
subItems
.
style
.
transform
,
subItems
.
style
.
transform
,
).
toBe
(
`translate3d(0px,
${
Math
.
floor
(
el
.
getBoundingClientRect
().
top
)}
px, 0px)`
);
).
toBe
(
`translate3d(0px,
${
Math
.
floor
(
el
.
getBoundingClientRect
().
top
)
-
getHeaderHeight
()
}
px, 0px)`
);
});
});
it
(
'
sets is-above when element is above
'
,
()
=>
{
it
(
'
sets is-above when element is above
'
,
()
=>
{
...
@@ -281,7 +282,7 @@ describe('Fly out sidebar navigation', () => {
...
@@ -281,7 +282,7 @@ describe('Fly out sidebar navigation', () => {
describe
(
'
canShowActiveSubItems
'
,
()
=>
{
describe
(
'
canShowActiveSubItems
'
,
()
=>
{
afterEach
(()
=>
{
afterEach
(()
=>
{
Cookies
.
remove
(
'
sidebar_collapsed
'
);
setSidebar
(
null
);
});
});
it
(
'
returns true by default
'
,
()
=>
{
it
(
'
returns true by default
'
,
()
=>
{
...
@@ -290,36 +291,23 @@ describe('Fly out sidebar navigation', () => {
...
@@ -290,36 +291,23 @@ describe('Fly out sidebar navigation', () => {
).
toBeTruthy
();
).
toBeTruthy
();
});
});
it
(
'
returns false when
cookie is false & element is active
'
,
()
=>
{
it
(
'
returns false when
active & expanded sidebar
'
,
()
=>
{
Cookies
.
set
(
'
sidebar_collapsed
'
,
'
false
'
);
const
sidebar
=
document
.
createElement
(
'
div
'
);
el
.
classList
.
add
(
'
active
'
);
el
.
classList
.
add
(
'
active
'
);
expect
(
setSidebar
(
sidebar
);
canShowActiveSubItems
(
el
),
).
toBeFalsy
();
});
it
(
'
returns true when cookie is false & element is active
'
,
()
=>
{
Cookies
.
set
(
'
sidebar_collapsed
'
,
'
true
'
);
el
.
classList
.
add
(
'
active
'
);
expect
(
expect
(
canShowActiveSubItems
(
el
),
canShowActiveSubItems
(
el
),
).
toBe
Truth
y
();
).
toBe
Fals
y
();
});
});
it
(
'
returns true when element is active & breakpoint is sm
'
,
()
=>
{
it
(
'
returns true when active & collapsed sidebar
'
,
()
=>
{
breakpointSize
=
'
sm
'
;
const
sidebar
=
document
.
createElement
(
'
div
'
);
sidebar
.
classList
.
add
(
'
sidebar-icons-only
'
);
el
.
classList
.
add
(
'
active
'
);
el
.
classList
.
add
(
'
active
'
);
expect
(
setSidebar
(
sidebar
);
canShowActiveSubItems
(
el
),
).
toBeTruthy
();
});
it
(
'
returns true when element is active & breakpoint is md
'
,
()
=>
{
breakpointSize
=
'
md
'
;
el
.
classList
.
add
(
'
active
'
);
expect
(
expect
(
canShowActiveSubItems
(
el
),
canShowActiveSubItems
(
el
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment