BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
48ec7025
Unverified
Commit
48ec7025
authored
Aug 01, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reverted the JS timeout code
improved specs so that they pass
parent
20bfc4f6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
70 deletions
+13
-70
fly_out_nav.js
app/assets/javascripts/fly_out_nav.js
+5
-41
new_sidebar.scss
app/assets/stylesheets/new_sidebar.scss
+3
-3
fly_out_nav_spec.js
spec/javascripts/fly_out_nav_spec.js
+5
-26
No files found.
app/assets/javascripts/fly_out_nav.js
View file @
48ec7025
let
hideTimeoutInterval
=
0
;
let
hideTimeout
;
let
subitems
;
export
const
getHideTimeoutInterval
=
()
=>
hideTimeoutInterval
;
export
const
hideAllSubItems
=
()
=>
{
subitems
.
forEach
((
el
)
=>
{
el
.
parentNode
.
classList
.
remove
(
'is-over'
);
el
.
style
.
display
=
'none'
;
// eslint-disable-line no-param-reassign
});
};
export
const
calculateTop
=
(
boundingRect
,
outerHeight
)
=>
{
const
windowHeight
=
window
.
innerHeight
;
const
bottomOverflow
=
windowHeight
-
(
boundingRect
.
top
+
outerHeight
);
...
...
@@ -24,14 +11,8 @@ export const showSubLevelItems = (el) => {
if
(
!
$subitems
)
return
;
hideAllSubItems
();
if
(
el
.
classList
.
contains
(
'is-over'
))
{
clearTimeout
(
hideTimeout
);
}
else
{
$subitems
.
style
.
display
=
'block'
;
el
.
classList
.
add
(
'is-over'
);
}
const
boundingRect
=
el
.
getBoundingClientRect
();
const
top
=
calculateTop
(
boundingRect
,
$subitems
.
offsetHeight
);
...
...
@@ -46,37 +27,20 @@ export const showSubLevelItems = (el) => {
export
const
hideSubLevelItems
=
(
el
)
=>
{
const
$subitems
=
el
.
querySelector
(
'.sidebar-sub-level-items'
);
const
hideFn
=
()
=>
{
if
(
!
$subitems
)
return
;
el
.
classList
.
remove
(
'is-over'
);
$subitems
.
style
.
display
=
'none'
;
$subitems
.
classList
.
remove
(
'is-above'
);
hideTimeoutInterval
=
0
;
};
if
(
$subitems
&&
hideTimeoutInterval
)
{
hideTimeout
=
setTimeout
(
hideFn
,
hideTimeoutInterval
);
}
else
if
(
$subitems
)
{
hideFn
();
}
};
export
const
setMouseOutTimeout
=
(
el
)
=>
{
if
(
el
.
closest
(
'.sidebar-sub-level-items'
))
{
hideTimeoutInterval
=
250
;
}
else
{
hideTimeoutInterval
=
0
;
}
};
export
default
()
=>
{
const
items
=
[...
document
.
querySelectorAll
(
'.sidebar-top-level-items > li:not(.active)'
)]
;
subitems
=
[...
document
.
querySelectorAll
(
'.sidebar-top-level-items > li:not(.active) .sidebar-sub-level-items'
)]
;
const
items
=
[...
document
.
querySelectorAll
(
'.sidebar-top-level-items > li:not(.active)'
)]
.
filter
(
el
=>
el
.
querySelector
(
'.sidebar-sub-level-items'
))
;
items
.
forEach
((
el
)
=>
{
el
.
addEventListener
(
'mouseenter'
,
e
=>
showSubLevelItems
(
e
.
currentTarget
));
el
.
addEventListener
(
'mouseleave'
,
e
=>
hideSubLevelItems
(
e
.
currentTarget
));
});
subitems
.
forEach
(
el
=>
el
.
addEventListener
(
'mouseleave'
,
e
=>
setMouseOutTimeout
(
e
.
target
)));
};
app/assets/stylesheets/new_sidebar.scss
View file @
48ec7025
...
...
@@ -226,10 +226,10 @@ $new-sidebar-width: 220px;
&
:
:
before
{
content
:
""
;
position
:
absolute
;
top
:
-
2
0px
;
bottom
:
-
2
0px
;
top
:
-
3
0px
;
bottom
:
-
3
0px
;
left
:
0
;
right
:
-
2
0px
;
right
:
-
3
0px
;
z-index
:
-1
;
}
...
...
spec/javascripts/fly_out_nav_spec.js
View file @
48ec7025
import
{
calculateTop
,
setMouseOutTimeout
,
getHideTimeoutInterval
,
hideSubLevelItems
,
showSubLevelItems
,
}
from
'~/fly_out_nav'
;
...
...
@@ -41,26 +39,6 @@ describe('Fly out sidebar navigation', () => {
});
});
describe
(
'setMouseOutTimeout'
,
()
=>
{
it
(
'sets hideTimeoutInterval to 150 when inside sub items'
,
()
=>
{
el
.
innerHTML
=
'<div class="sidebar-sub-level-items"><div class="js-test"></div></div>'
;
setMouseOutTimeout
(
el
.
querySelector
(
'.js-test'
));
expect
(
getHideTimeoutInterval
(),
).
toBe
(
150
);
});
it
(
'resets hideTimeoutInterval when not inside sub items'
,
()
=>
{
setMouseOutTimeout
(
el
);
expect
(
getHideTimeoutInterval
(),
).
toBe
(
0
);
});
});
describe
(
'hideSubLevelItems'
,
()
=>
{
beforeEach
(()
=>
{
el
.
innerHTML
=
'<div class="sidebar-sub-level-items"></div>'
;
...
...
@@ -142,16 +120,17 @@ describe('Fly out sidebar navigation', () => {
it
(
'sets is-above when element is above'
,
()
=>
{
const
subItems
=
el
.
querySelector
(
'.sidebar-sub-level-items'
);
subItems
.
style
.
height
=
'5000px'
;
subItems
.
style
.
height
=
`
${
window
.
innerHeight
+
el
.
offsetHeight
}
px`
;
subItems
.
style
.
position
=
'absolute'
;
el
.
style
.
position
=
'relative'
;
el
.
style
.
top
=
'1000px'
;
el
.
style
.
top
=
`
${
window
.
innerHeight
-
el
.
offsetHeight
}
px`
;
spyOn
(
el
.
classList
,
'add'
);
spyOn
(
subItems
.
classList
,
'add'
);
showSubLevelItems
(
el
);
expect
(
el
.
classList
.
add
,
subItems
.
classList
.
add
,
).
toHaveBeenCalledWith
(
'is-above'
);
});
});
...
...
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