Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
大大大太阳yt
driver.js
提交
5aa283f0
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,发现更多精彩内容 >>
提交
5aa283f0
编写于
3月 08, 2018
作者:
K
Kamran Ahmed
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Buttons in the popover
上级
7e830c64
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
24 deletion
+72
-24
.eslintrc.json
.eslintrc.json
+3
-0
assets/scripts/src/overlay.js
assets/scripts/src/overlay.js
+1
-1
assets/scripts/src/sholo.js
assets/scripts/src/sholo.js
+58
-18
assets/styles/scss/demo.scss
assets/styles/scss/demo.scss
+1
-1
index.html
index.html
+9
-4
未找到文件。
.eslintrc.json
浏览文件 @
5aa283f0
...
...
@@ -3,6 +3,9 @@
"env"
:
{
"browser"
:
true
},
"ecmaFeatures"
:
{
"experimentalObjectRestSpread"
:
true
},
"rules"
:
{
"no-console"
:
"off"
,
"no-underscore-dangle"
:
"off"
,
...
...
assets/scripts/src/overlay.js
浏览文件 @
5aa283f0
...
...
@@ -57,7 +57,7 @@ export default class Overlay {
* @param animate bool
*/
highlight
(
element
,
animate
=
true
)
{
if
(
!
element
)
{
if
(
!
element
||
!
element
.
node
)
{
return
;
}
...
...
assets/scripts/src/sholo.js
浏览文件 @
5aa283f0
...
...
@@ -21,10 +21,13 @@ export default class Sholo {
this
.
document
=
document
;
this
.
window
=
window
;
this
.
steps
=
[];
// steps to be presented if any
this
.
currentStep
=
0
;
// index for the currently highlighted step
this
.
onScroll
=
this
.
onScroll
.
bind
(
this
);
this
.
onResize
=
this
.
onResize
.
bind
(
this
);
this
.
onKeyUp
=
this
.
onKeyUp
.
bind
(
this
);
this
.
on
MouseUp
=
this
.
onMouseUp
.
bind
(
this
);
this
.
on
Click
=
this
.
onClick
.
bind
(
this
);
// Event bindings
this
.
bind
();
...
...
@@ -39,7 +42,7 @@ export default class Sholo {
this
.
document
.
addEventListener
(
'
DOMMouseScroll
'
,
this
.
onScroll
,
false
);
this
.
window
.
addEventListener
(
'
resize
'
,
this
.
onResize
,
false
);
this
.
window
.
addEventListener
(
'
keyup
'
,
this
.
onKeyUp
,
false
);
this
.
window
.
addEventListener
(
'
mouseup
'
,
this
.
onMouseUp
,
false
);
this
.
window
.
addEventListener
(
'
click
'
,
this
.
onClick
,
false
);
}
/**
...
...
@@ -47,23 +50,36 @@ export default class Sholo {
* or outside the
* @param e
*/
onMouseUp
(
e
)
{
const
highlightedElement
=
this
.
overlay
.
getHighlightedElement
();
const
popover
=
document
.
getElementById
(
'
sholo-popover-item
'
);
if
(
!
highlightedElement
||
!
highlightedElement
.
node
)
{
onClick
(
e
)
{
if
(
!
this
.
hasHighlightedElement
())
{
// Has no highlighted element so ignore the click
return
;
}
const
highlightedElement
=
this
.
overlay
.
getHighlightedElement
();
const
popover
=
document
.
getElementById
(
'
sholo-popover-item
'
);
const
clickedHighlightedElement
=
highlightedElement
.
node
.
contains
(
e
.
target
);
const
clickedPopover
=
popover
&&
popover
.
contains
(
e
.
target
);
// Remove the overlay If clicked outside the highlighted element
if
(
!
clickedHighlightedElement
&&
!
clickedPopover
)
{
this
.
overlay
.
clear
();
return
;
}
const
nextClicked
=
e
.
target
.
classList
.
contains
(
'
sholo-next-btn
'
);
if
(
nextClicked
)
{
this
.
currentStep
+=
1
;
this
.
overlay
.
highlight
(
this
.
steps
[
this
.
currentStep
]);
}
}
hasHighlightedElement
()
{
const
highlightedElement
=
this
.
overlay
.
getHighlightedElement
();
return
highlightedElement
&&
highlightedElement
.
node
;
}
/**
* Handler for the onScroll event on document
* Refreshes without animation on scroll to make sure
...
...
@@ -93,26 +109,50 @@ export default class Sholo {
}
}
defineSteps
(
steps
)
{
this
.
steps
=
[];
steps
.
forEach
((
step
,
index
)
=>
{
if
(
!
step
.
element
)
{
throw
new
Error
(
`Element (query selector or a dom element) missing in step
${
index
}
`
);
}
const
domElement
=
Sholo
.
findDomElement
(
step
.
element
);
const
element
=
new
Element
(
domElement
,
Object
.
assign
({},
this
.
options
,
step
));
this
.
steps
.
push
(
element
);
});
}
start
()
{
if
(
!
this
.
steps
||
this
.
steps
.
length
===
0
)
{
throw
new
Error
(
'
There are no steps defined to iterate
'
);
}
this
.
currentStep
=
0
;
this
.
overlay
.
highlight
(
this
.
steps
[
0
]);
}
/**
* Highlights the given selector
* @param selector
*/
highlight
(
selector
)
{
let
domElement
;
const
domElement
=
Sholo
.
findDomElement
(
selector
);
const
element
=
new
Element
(
domElement
,
this
.
options
);
this
.
overlay
.
highlight
(
element
);
}
static
findDomElement
(
selector
)
{
if
(
typeof
selector
===
'
string
'
)
{
domElement
=
document
.
querySelector
(
selector
);
}
else
if
(
typeof
selector
===
'
object
'
)
{
domElement
=
selector
;
}
else
{
throw
new
Error
(
'
Element can only be string or the dom element
'
);
return
document
.
querySelector
(
selector
);
}
if
(
domElement
)
{
const
element
=
new
Element
(
domElement
,
this
.
options
);
this
.
overlay
.
highlight
(
element
);
}
else
{
this
.
overlay
.
clear
();
if
(
typeof
selector
===
'
object
'
)
{
return
selector
;
}
throw
new
Error
(
'
Element can only be string or the dom element
'
);
}
}
assets/styles/scss/demo.scss
浏览文件 @
5aa283f0
...
...
@@ -118,7 +118,7 @@ div#sholo-popover-item {
margin
:
10px
0
0
;
}
.sholo-close
{
.sholo-close
-btn
{
float
:
left
;
}
...
...
index.html
浏览文件 @
5aa283f0
...
...
@@ -14,10 +14,10 @@
<div
class=
"sholo-popover-title"
>
Did you know?
</div>
<div
class=
"sholo-popover-description"
>
You can make step by step introductions with sholo!
</div>
<div
class=
"sholo-popover-footer"
>
<a
href=
"javascript:void(0)"
class=
"sholo-close"
>
Close
</a>
<a
href=
"javascript:void(0)"
class=
"sholo-close
-btn
"
>
Close
</a>
<span
class=
"sholo-btn-group"
>
<a
href=
"javascript:void(0)"
>
←
Previous
</a>
<a
href=
"javascript:void(0)"
>
Next
→
</a>
<a
class=
"sholo-prev-btn"
href=
"javascript:void(0)"
>
←
Previous
</a>
<a
class=
"sholo-next-btn"
href=
"javascript:void(0)"
>
Next
→
</a>
</span>
</div>
</div>
...
...
@@ -75,10 +75,15 @@
padding
:
5
});
sholo
.
defineSteps
([
{
element
:
'
.section__header
'
},
{
element
:
'
.section__examples
'
},
{
element
:
'
.section__contributing
'
},
]);
document
.
querySelector
(
'
.btn__example
'
)
.
addEventListener
(
'
click
'
,
function
()
{
sholo
.
highlight
(
'
.section__header
'
);
sholo
.
start
(
);
});
</script>
</body>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录