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
Boxiang Sun
gitlab-ce
Commits
75054174
Commit
75054174
authored
Jul 19, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved JS & only run when new_nav cookie exists
parent
ad633afd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
27 deletions
+78
-27
app/assets/javascripts/fly_out_nav.js
app/assets/javascripts/fly_out_nav.js
+35
-0
app/assets/javascripts/layout_nav.js
app/assets/javascripts/layout_nav.js
+6
-0
app/assets/javascripts/main.js
app/assets/javascripts/main.js
+0
-27
spec/javascripts/fly_out_nav_spec.js
spec/javascripts/fly_out_nav_spec.js
+37
-0
No files found.
app/assets/javascripts/fly_out_nav.js
0 → 100644
View file @
75054174
export
const
calculateTop
=
(
boundingRect
,
outerHeight
)
=>
{
const
windowHeight
=
window
.
innerHeight
;
const
bottomOverflow
=
windowHeight
-
(
boundingRect
.
top
+
outerHeight
);
return
bottomOverflow
<
0
?
boundingRect
.
top
-
Math
.
abs
(
bottomOverflow
)
:
boundingRect
.
top
;
};
export
const
createArrowStyles
=
(
boundingRect
,
top
)
=>
`.sidebar-sub-level-items::before { transform: translate3d(0,
${
boundingRect
.
top
-
top
}
px, 0); }`
;
export
default
()
=>
{
const
style
=
document
.
createElement
(
'
style
'
);
document
.
head
.
appendChild
(
style
);
$
(
'
.sidebar-top-level-items > li:not(.active)
'
).
on
(
'
mouseover
'
,
(
e
)
=>
{
const
$this
=
e
.
currentTarget
;
const
$subitems
=
$
(
'
.sidebar-sub-level-items
'
,
$this
).
show
();
if
(
$subitems
.
length
)
{
const
boundingRect
=
$this
.
getBoundingClientRect
();
const
top
=
calculateTop
(
boundingRect
,
$subitems
.
outerHeight
());
$subitems
.
css
({
transform
:
`translate3d(0,
${
top
}
px, 0)`
,
});
style
.
sheet
.
insertRule
(
createArrowStyles
(
boundingRect
,
top
),
0
);
}
}).
on
(
'
mouseout
'
,
(
e
)
=>
{
$
(
'
.sidebar-sub-level-items
'
,
e
.
currentTarget
).
hide
();
if
(
style
.
sheet
.
rules
.
length
)
{
style
.
sheet
.
deleteRule
(
0
);
}
});
};
app/assets/javascripts/layout_nav.js
View file @
75054174
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, no-unused-vars, one-var, one-var-declaration-per-line, vars-on-top, max-len */
import
Cookies
from
'
js-cookie
'
;
import
_
from
'
underscore
'
;
import
initFlyOutNav
from
'
./fly_out_nav
'
;
(
function
()
{
var
hideEndFade
;
...
...
@@ -54,5 +56,9 @@ import _ from 'underscore';
$
(()
=>
{
$
(
window
).
on
(
'
scroll
'
,
_
.
throttle
(
applyScrollNavClass
,
100
));
if
(
Cookies
.
get
(
'
new_nav
'
)
===
'
true
'
)
{
initFlyOutNav
();
}
});
}).
call
(
window
);
app/assets/javascripts/main.js
View file @
75054174
...
...
@@ -347,31 +347,4 @@ $(function () {
gl
.
utils
.
renderTimeago
();
$
(
document
).
trigger
(
'
init.scrolling-tabs
'
);
const
style
=
document
.
createElement
(
"
style
"
);
document
.
head
.
appendChild
(
style
);
$
(
'
.sidebar-top-level-items > li:not(.active)
'
).
on
(
'
mouseover
'
,
(
e
)
=>
{
const
windowHeight
=
window
.
innerHeight
;
const
$this
=
e
.
currentTarget
;
const
$subitems
=
$
(
'
.sidebar-sub-level-items
'
,
$this
).
show
();
if
(
$subitems
.
length
)
{
const
boundingRect
=
$this
.
getBoundingClientRect
();
const
bottomOverflow
=
windowHeight
-
(
boundingRect
.
top
+
$subitems
.
outerHeight
());
const
top
=
bottomOverflow
<
0
?
boundingRect
.
top
-
Math
.
abs
(
bottomOverflow
)
:
boundingRect
.
top
;
$subitems
.
css
({
transform
:
`translate3d(0,
${
top
}
px, 0)`
,
});
style
.
sheet
.
insertRule
(
`.sidebar-sub-level-items::before { transform: translate3d(0,
${
boundingRect
.
top
-
top
}
px, 0); }`
,
0
);
}
}).
on
(
'
mouseout
'
,
(
e
)
=>
{
$
(
'
.sidebar-sub-level-items
'
,
e
.
currentTarget
).
hide
();
if
(
style
.
sheet
.
rules
.
length
)
{
style
.
sheet
.
deleteRule
(
0
);
}
});
});
spec/javascripts/fly_out_nav_spec.js
0 → 100644
View file @
75054174
import
{
calculateTop
,
createArrowStyles
}
from
'
~/fly_out_nav
'
;
describe
(
'
Fly out sidebar navigation
'
,
()
=>
{
describe
(
'
calculateTop
'
,
()
=>
{
it
(
'
returns boundingRect top
'
,
()
=>
{
const
boundingRect
=
{
top
:
100
,
};
expect
(
calculateTop
(
boundingRect
,
100
),
).
toBe
(
100
);
});
it
(
'
returns boundingRect - bottomOverflow
'
,
()
=>
{
const
boundingRect
=
{
top
:
window
.
innerHeight
,
};
expect
(
calculateTop
(
boundingRect
,
100
),
).
toBe
(
window
.
innerHeight
-
100
);
});
});
describe
(
'
createArrowStyles
'
,
()
=>
{
it
(
'
returns translate3d styles
'
,
()
=>
{
const
boundingRect
=
{
top
:
100
,
};
expect
(
createArrowStyles
(
boundingRect
,
50
),
).
toContain
(
'
translate3d(0, 50px, 0)
'
);
});
});
});
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