Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
399e1e83
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
399e1e83
编写于
6月 01, 2018
作者:
P
Paul Slaughter
提交者:
Clement Ho
6月 01, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update position sticky polyfill
上级
eeb73247
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
3 addition
and
128 deletion
+3
-128
app/assets/javascripts/init_changes_dropdown.js
app/assets/javascripts/init_changes_dropdown.js
+3
-3
app/assets/javascripts/job.js
app/assets/javascripts/job.js
+0
-7
app/assets/javascripts/lib/utils/sticky.js
app/assets/javascripts/lib/utils/sticky.js
+0
-39
spec/javascripts/lib/utils/sticky_spec.js
spec/javascripts/lib/utils/sticky_spec.js
+0
-79
未找到文件。
app/assets/javascripts/init_changes_dropdown.js
浏览文件 @
399e1e83
import
$
from
'
jquery
'
;
import
stickyMonitor
from
'
./lib/utils/sticky
'
;
import
StickyFill
from
'
stickyfilljs
'
;
export
default
(
stickyTop
)
=>
{
stickyMonitor
(
document
.
querySelector
(
'
.js-diff-files-changed
'
),
stickyTop
);
export
default
()
=>
{
StickyFill
.
add
(
document
.
querySelector
(
'
.js-diff-files-changed
'
)
);
$
(
'
.js-diff-stats-dropdown
'
).
glDropdown
({
filterable
:
true
,
...
...
app/assets/javascripts/job.js
浏览文件 @
399e1e83
...
...
@@ -80,13 +80,6 @@ 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
);
}
...
...
app/assets/javascripts/lib/utils/sticky.js
已删除
100644 → 0
浏览文件 @
eeb73247
export
const
createPlaceholder
=
()
=>
{
const
placeholder
=
document
.
createElement
(
'
div
'
);
placeholder
.
classList
.
add
(
'
sticky-placeholder
'
);
return
placeholder
;
};
export
const
isSticky
=
(
el
,
scrollY
,
stickyTop
,
insertPlaceholder
)
=>
{
const
top
=
Math
.
floor
(
el
.
offsetTop
-
scrollY
);
if
(
top
<=
stickyTop
&&
!
el
.
classList
.
contains
(
'
is-stuck
'
))
{
const
placeholder
=
insertPlaceholder
?
createPlaceholder
()
:
null
;
const
heightBefore
=
el
.
offsetHeight
;
el
.
classList
.
add
(
'
is-stuck
'
);
if
(
insertPlaceholder
)
{
el
.
parentNode
.
insertBefore
(
placeholder
,
el
.
nextElementSibling
);
placeholder
.
style
.
height
=
`
${
heightBefore
-
el
.
offsetHeight
}
px`
;
}
}
else
if
(
top
>
stickyTop
&&
el
.
classList
.
contains
(
'
is-stuck
'
))
{
el
.
classList
.
remove
(
'
is-stuck
'
);
if
(
insertPlaceholder
&&
el
.
nextElementSibling
&&
el
.
nextElementSibling
.
classList
.
contains
(
'
sticky-placeholder
'
))
{
el
.
nextElementSibling
.
remove
();
}
}
};
export
default
(
el
,
stickyTop
,
insertPlaceholder
=
true
)
=>
{
if
(
!
el
)
return
;
if
(
typeof
CSS
===
'
undefined
'
||
!
(
CSS
.
supports
(
'
(position: -webkit-sticky) or (position: sticky)
'
)))
return
;
document
.
addEventListener
(
'
scroll
'
,
()
=>
isSticky
(
el
,
window
.
scrollY
,
stickyTop
,
insertPlaceholder
),
{
passive
:
true
,
});
};
spec/javascripts/lib/utils/sticky_spec.js
已删除
100644 → 0
浏览文件 @
eeb73247
import
{
isSticky
}
from
'
~/lib/utils/sticky
'
;
describe
(
'
sticky
'
,
()
=>
{
let
el
;
beforeEach
(()
=>
{
document
.
body
.
innerHTML
+=
`
<div class="parent">
<div id="js-sticky"></div>
</div>
`
;
el
=
document
.
getElementById
(
'
js-sticky
'
);
});
afterEach
(()
=>
{
el
.
parentNode
.
remove
();
});
describe
(
'
when stuck
'
,
()
=>
{
it
(
'
does not remove is-stuck class
'
,
()
=>
{
isSticky
(
el
,
0
,
el
.
offsetTop
);
isSticky
(
el
,
0
,
el
.
offsetTop
);
expect
(
el
.
classList
.
contains
(
'
is-stuck
'
),
).
toBeTruthy
();
});
it
(
'
adds is-stuck class
'
,
()
=>
{
isSticky
(
el
,
0
,
el
.
offsetTop
);
expect
(
el
.
classList
.
contains
(
'
is-stuck
'
),
).
toBeTruthy
();
});
it
(
'
inserts placeholder element
'
,
()
=>
{
isSticky
(
el
,
0
,
el
.
offsetTop
,
true
);
expect
(
document
.
querySelector
(
'
.sticky-placeholder
'
),
).
not
.
toBeNull
();
});
});
describe
(
'
when not stuck
'
,
()
=>
{
it
(
'
removes is-stuck class
'
,
()
=>
{
spyOn
(
el
.
classList
,
'
remove
'
).
and
.
callThrough
();
isSticky
(
el
,
0
,
el
.
offsetTop
);
isSticky
(
el
,
0
,
0
);
expect
(
el
.
classList
.
remove
,
).
toHaveBeenCalledWith
(
'
is-stuck
'
);
expect
(
el
.
classList
.
contains
(
'
is-stuck
'
),
).
toBeFalsy
();
});
it
(
'
does not add is-stuck class
'
,
()
=>
{
isSticky
(
el
,
0
,
0
);
expect
(
el
.
classList
.
contains
(
'
is-stuck
'
),
).
toBeFalsy
();
});
it
(
'
removes placeholder
'
,
()
=>
{
isSticky
(
el
,
0
,
el
.
offsetTop
,
true
);
isSticky
(
el
,
0
,
0
,
true
);
expect
(
document
.
querySelector
(
'
.sticky-placeholder
'
),
).
toBeNull
();
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录