Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
大大大太阳yt
driver.js
提交
fa4fbb83
D
driver.js
项目概览
大大大太阳yt
/
driver.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
driver.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fa4fbb83
编写于
3月 10, 2018
作者:
K
Kamran Ahmed
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Positioning the popover by giving position
上级
a2f68832
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
124 addition
and
26 deletion
+124
-26
assets/scripts/src/popover.js
assets/scripts/src/popover.js
+112
-24
index.html
index.html
+12
-2
未找到文件。
assets/scripts/src/popover.js
浏览文件 @
fa4fbb83
...
...
@@ -21,20 +21,21 @@ export default class Popover extends Element {
this
.
window
=
window
;
this
.
document
=
document
;
this
.
node
=
this
.
makeNode
();
this
.
makeNode
();
this
.
hide
();
}
makeNode
()
{
let
popover
=
this
.
document
.
getElementById
(
ID_POPOVER
);
if
(
popover
)
{
return
popover
;
if
(
!
popover
)
{
popover
=
Popover
.
createFromString
(
POPOVER_HTML
);
document
.
body
.
appendChild
(
popover
);
}
popover
=
Popover
.
createFromString
(
POPOVER_HTML
)
;
document
.
body
.
appendChild
(
popover
);
return
popover
;
this
.
node
=
popover
;
this
.
tipNode
=
popover
.
querySelector
(
`.
${
CLASS_POPOVER_TIP
}
`
);
this
.
titleNode
=
popover
.
querySelector
(
`.
${
CLASS_POPOVER_TITLE
}
`
);
this
.
descriptionNode
=
popover
.
querySelector
(
`.
${
CLASS_POPOVER_DESCRIPTION
}
`
)
;
}
/**
...
...
@@ -50,8 +51,11 @@ export default class Popover extends Element {
return
div
.
firstChild
;
}
getHeight
()
{
return
Math
.
max
(
this
.
node
.
scrollHeight
,
this
.
node
.
offsetHeight
);
getSize
()
{
return
{
height
:
Math
.
max
(
this
.
node
.
scrollHeight
,
this
.
node
.
offsetHeight
),
width
:
Math
.
max
(
this
.
node
.
scrollWidth
,
this
.
node
.
offsetWidth
),
};
}
hide
()
{
...
...
@@ -74,29 +78,113 @@ export default class Popover extends Element {
show
(
position
)
{
this
.
reset
();
const
popoverTip
=
this
.
node
.
querySelector
(
`.
${
CLASS_POPOVER_TIP
}
`
);
const
popoverTitle
=
this
.
node
.
querySelector
(
`.
${
CLASS_POPOVER_TITLE
}
`
);
const
popoverDescription
=
this
.
node
.
querySelector
(
`.
${
CLASS_POPOVER_DESCRIPTION
}
`
);
// Set the title and descriptions
this
.
titleNode
.
innerText
=
this
.
options
.
title
;
this
.
descriptionNode
.
innerText
=
this
.
options
.
description
;
// Position the popover around the given position
switch
(
this
.
options
.
position
)
{
case
'
left
'
:
this
.
positionOnLeft
(
position
);
break
;
case
'
right
'
:
this
.
positionOnRight
(
position
);
break
;
case
'
top
'
:
this
.
positionOnTop
(
position
);
break
;
case
'
bottom
'
:
this
.
positionOnBottom
(
position
);
break
;
case
'
auto
'
:
default
:
this
.
autoPosition
(
position
);
break
;
}
}
/**
* Shows the popover on the left of the given position
* @param elementPosition
*/
positionOnLeft
(
elementPosition
)
{
const
popoverWidth
=
this
.
getSize
().
width
;
const
popoverMargin
=
this
.
options
.
padding
+
10
;
// adding 10 to give it a little distance from the element
this
.
node
.
style
.
left
=
`
${
elementPosition
.
left
-
popoverWidth
-
popoverMargin
}
px`
;
this
.
node
.
style
.
top
=
`
${
elementPosition
.
top
-
this
.
options
.
padding
}
px`
;
this
.
node
.
style
.
right
=
''
;
this
.
node
.
style
.
bottom
=
''
;
this
.
tipNode
.
classList
.
add
(
'
right
'
);
}
/**
* Shows the popover on the right of the given position
* @param elementPosition
*/
positionOnRight
(
elementPosition
)
{
const
popoverMargin
=
this
.
options
.
padding
+
10
;
// adding 10 to give it a little distance from the element
this
.
node
.
style
.
left
=
`
${
elementPosition
.
right
+
popoverMargin
}
px`
;
this
.
node
.
style
.
top
=
`
${
elementPosition
.
top
-
this
.
options
.
padding
}
px`
;
this
.
node
.
style
.
right
=
''
;
this
.
node
.
style
.
bottom
=
''
;
this
.
tipNode
.
classList
.
add
(
'
left
'
);
}
/**
* Shows the popover on the top of the given position
* @param elementPosition
*/
positionOnTop
(
elementPosition
)
{
const
popoverHeight
=
this
.
getSize
().
height
;
const
popoverMargin
=
this
.
options
.
padding
+
10
;
// adding 10 to give it a little distance from the element
this
.
node
.
style
.
top
=
`
${
elementPosition
.
top
-
popoverHeight
-
popoverMargin
}
px`
;
this
.
node
.
style
.
left
=
`
${
elementPosition
.
left
-
this
.
options
.
padding
}
px`
;
this
.
node
.
style
.
right
=
''
;
this
.
node
.
style
.
bottom
=
''
;
this
.
tipNode
.
classList
.
add
(
'
bottom
'
);
}
popoverTitle
.
innerText
=
this
.
options
.
title
;
popoverDescription
.
innerText
=
this
.
options
.
description
;
/**
* Shows the popover on the bottom of the given position
* @param elementPosition
*/
positionOnBottom
(
elementPosition
)
{
const
popoverMargin
=
this
.
options
.
padding
+
10
;
// adding 10 to give it a little distance from the element
this
.
node
.
style
.
top
=
`
${
elementPosition
.
bottom
+
popoverMargin
}
px`
;
this
.
node
.
style
.
left
=
`
${
elementPosition
.
left
-
this
.
options
.
padding
}
px`
;
this
.
node
.
style
.
right
=
''
;
this
.
node
.
style
.
bottom
=
''
;
const
pageHeight
=
this
.
getFullPageSize
().
height
;
const
popoverMargin
=
this
.
options
.
padding
+
10
;
const
popoverHeight
=
this
.
getHeight
();
this
.
tipNode
.
classList
.
add
(
'
top
'
);
}
/**
* Automatically positions the popover around the given position
* such that the element and popover remain in view
* @param elementPosition
*/
autoPosition
(
elementPosition
)
{
const
pageSize
=
this
.
getFullPageSize
();
const
popoverSize
=
this
.
getSize
();
this
.
node
.
style
.
left
=
`
${
position
.
left
-
this
.
options
.
padding
}
px`
;
const
pageHeight
=
pageSize
.
height
;
const
popoverHeight
=
popoverSize
.
height
;
const
popoverMargin
=
this
.
options
.
padding
+
10
;
// adding 10 to give it a little distance from the element
// Calculate different dimensions after attaching popover
const
pageHeightAfterPopOver
=
position
.
bottom
+
popoverHeight
+
popoverMargin
;
const
pageHeightAfterPopOver
=
elementPosition
.
bottom
+
popoverHeight
+
popoverMargin
;
// If adding popover would go out of the window height, then show it to the top
if
(
pageHeightAfterPopOver
>=
pageHeight
)
{
this
.
node
.
style
.
top
=
`
${
position
.
top
-
popoverHeight
-
popoverMargin
}
px`
;
popoverTip
.
classList
.
add
(
'
bottom
'
);
this
.
positionOnTop
(
elementPosition
);
}
else
{
this
.
node
.
style
.
top
=
`
${
position
.
bottom
+
popoverMargin
}
px`
;
popoverTip
.
classList
.
add
(
'
top
'
);
this
.
positionOnBottom
(
elementPosition
);
}
}
}
index.html
浏览文件 @
fa4fbb83
...
...
@@ -68,24 +68,34 @@
element
:
'
.section__header
'
,
popover
:
{
title
:
'
Adding Introductions
'
,
description
:
'
You can use it to add popovers on top of the website
'
description
:
'
You can use it to add popovers on top of the website
'
,
position
:
'
left
'
},
},
{
element
:
'
.section__how
'
,
popover
:
{
title
:
'
Just Specify the Item
'
,
description
:
'
All you have to do is provide the query selector of element to highlight
'
description
:
'
All you have to do is provide the query selector of element to highlight
'
,
position
:
'
right
'
},
},
{
element
:
'
.section__purpose
'
,
popover
:
{
title
:
'
Automatically Position
'
,
description
:
'
It can automatically position too if you dont provide
'
}
},
{
element
:
'
.section__examples
'
,
},
{
element
:
'
.section__contributing
'
,
popover
:
{
title
:
'
Automatically Position
'
,
description
:
'
It can automatically position too if you dont provide
'
}
},
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录