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
bc56f1f5
Commit
bc56f1f5
authored
Jun 05, 2018
by
Paul Slaughter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add polyfill and comments to utils/sticky
parent
81e899ea
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
11 deletions
+25
-11
app/assets/javascripts/init_changes_dropdown.js
app/assets/javascripts/init_changes_dropdown.js
+1
-1
app/assets/javascripts/job.js
app/assets/javascripts/job.js
+2
-9
app/assets/javascripts/lib/utils/sticky.js
app/assets/javascripts/lib/utils/sticky.js
+22
-1
No files found.
app/assets/javascripts/init_changes_dropdown.js
View file @
bc56f1f5
import
$
from
'
jquery
'
;
import
stickyMonitor
from
'
./lib/utils/sticky
'
;
import
{
stickyMonitor
}
from
'
./lib/utils/sticky
'
;
export
default
(
stickyTop
)
=>
{
stickyMonitor
(
document
.
querySelector
(
'
.js-diff-files-changed
'
),
stickyTop
);
...
...
app/assets/javascripts/job.js
View file @
bc56f1f5
import
$
from
'
jquery
'
;
import
_
from
'
underscore
'
;
import
StickyFill
from
'
stickyfilljs
'
;
import
{
polyfillSticky
}
from
'
./lib/utils/sticky
'
;
import
axios
from
'
./lib/utils/axios_utils
'
;
import
{
visitUrl
}
from
'
./lib/utils/url_utility
'
;
import
bp
from
'
./breakpoints
'
;
...
...
@@ -80,14 +80,7 @@ export default class Job {
}
initAffixTopArea
()
{
/**
If the browser does not support position sticky, it returns the position as static.
If the browser does support sticky, then we allow the browser to handle it, if not
then we use a polyfill
*/
if
(
this
.
$topBar
.
css
(
'
position
'
)
!==
'
static
'
)
return
;
StickyFill
.
add
(
this
.
$topBar
);
polyfillSticky
(
this
.
$topBar
);
}
// eslint-disable-next-line class-methods-use-this
...
...
app/assets/javascripts/lib/utils/sticky.js
View file @
bc56f1f5
import
StickyFill
from
'
stickyfilljs
'
;
export
const
createPlaceholder
=
()
=>
{
const
placeholder
=
document
.
createElement
(
'
div
'
);
placeholder
.
classList
.
add
(
'
sticky-placeholder
'
);
...
...
@@ -28,7 +30,16 @@ export const isSticky = (el, scrollY, stickyTop, insertPlaceholder) => {
}
};
export
default
(
el
,
stickyTop
,
insertPlaceholder
=
true
)
=>
{
/**
* Create a listener that will toggle a 'is-stuck' class, based on the current scroll position.
*
* - If the current environment does not support `position: sticky`, do nothing.
*
* @param {HTMLElement} el The `position: sticky` element.
* @param {Number} stickyTop Used to determine when an element is stuck.
* @param {Boolean} insertPlaceholder Should a placeholder element be created when element is stuck?
*/
export
const
stickyMonitor
=
(
el
,
stickyTop
,
insertPlaceholder
=
true
)
=>
{
if
(
!
el
)
return
;
if
(
typeof
CSS
===
'
undefined
'
||
!
(
CSS
.
supports
(
'
(position: -webkit-sticky) or (position: sticky)
'
)))
return
;
...
...
@@ -37,3 +48,13 @@ export default (el, stickyTop, insertPlaceholder = true) => {
passive
:
true
,
});
};
/**
* Polyfill the `position: sticky` behavior.
*
* - If the current environment supports `position: sticky`, do nothing.
* - Can receive an iterable element list (NodeList, jQuery collection, etc.) or single HTMLElement.
*/
export
const
polyfillSticky
=
(
el
)
=>
{
StickyFill
.
add
(
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