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
214d741b
Commit
214d741b
authored
Jan 08, 2019
by
Kushal Pandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for `offset` values in `isInViewport`
parent
e2667b76
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+4
-3
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+25
-0
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
214d741b
...
...
@@ -118,12 +118,13 @@ export const handleLocationHash = () => {
// Check if element scrolled into viewport from above or below
// Courtesy http://stackoverflow.com/a/7557433/414749
export
const
isInViewport
=
el
=>
{
export
const
isInViewport
=
(
el
,
offset
=
{})
=>
{
const
rect
=
el
.
getBoundingClientRect
();
const
{
top
,
left
}
=
offset
;
return
(
rect
.
top
>=
0
&&
rect
.
left
>=
0
&&
rect
.
top
>=
(
top
||
0
)
&&
rect
.
left
>=
(
left
||
0
)
&&
rect
.
bottom
<=
window
.
innerHeight
&&
rect
.
right
<=
window
.
innerWidth
);
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
214d741b
...
...
@@ -716,4 +716,29 @@ describe('common_utils', () => {
expect
(
commonUtils
.
roundOffFloat
(
34567.14159
,
-
5
)).
toBe
(
0
);
});
});
describe
(
'
isInViewport
'
,
()
=>
{
let
el
;
beforeEach
(()
=>
{
el
=
document
.
createElement
(
'
div
'
);
});
afterEach
(()
=>
{
document
.
body
.
removeChild
(
el
);
});
it
(
'
returns true when provided `el` is in viewport
'
,
()
=>
{
document
.
body
.
appendChild
(
el
);
expect
(
commonUtils
.
isInViewport
(
el
)).
toBe
(
true
);
});
it
(
'
returns false when provided `el` is not in viewport
'
,
()
=>
{
el
.
setAttribute
(
'
style
'
,
'
position: absolute; top: -1000px; left: -1000px;
'
);
document
.
body
.
appendChild
(
el
);
expect
(
commonUtils
.
isInViewport
(
el
)).
toBe
(
false
);
});
});
});
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