Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
theme-apachecn
提交
405a33c9
T
theme-apachecn
项目概览
OpenDocCN
/
theme-apachecn
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
theme-apachecn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
405a33c9
编写于
6月 06, 2016
作者:
J
Johan Preynat
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into summary/scrolling
上级
ba352347
d6a12a34
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
67 deletion
+89
-67
_layouts/website/summary.html
_layouts/website/summary.html
+1
-1
package.json
package.json
+1
-1
src/js/theme/navigation.js
src/js/theme/navigation.js
+87
-65
未找到文件。
_layouts/website/summary.html
浏览文件 @
405a33c9
{% macro articles(_articles) %}
{% for article in _articles %}
<li
class=
"chapter {% if article.path == file.path and not article.anchor %}active{% endif %}"
data-level=
"{{ article.level }}"
{%
if
article.path
%}
data-path=
"{{ article.path|resolveFile }}"
{%
endif
%}
>
{% if article.path %}
{% if article.path
and getPageByPath(article.path)
%}
<a
href=
"{{ article.path|resolveFile }}{{ article.anchor }}"
>
{% elif article.url %}
<a
target=
"_blank"
href=
"{{ article.url }}"
>
...
...
package.json
浏览文件 @
405a33c9
...
...
@@ -2,7 +2,7 @@
"name"
:
"gitbook-plugin-theme-default"
,
"description"
:
"Default theme for GitBook"
,
"main"
:
"./index.js"
,
"version"
:
"1.0.
1
"
,
"version"
:
"1.0.
3
"
,
"engines"
:
{
"gitbook"
:
">=3.0.0"
},
...
...
src/js/theme/navigation.js
浏览文件 @
405a33c9
...
...
@@ -194,72 +194,94 @@ function handleNavigation(relativeUrl, push) {
prevUri
=
uri
;
return
loading
.
show
(
$
.
get
(
uri
)
.
then
(
function
(
html
)
{
// Replace html content
html
=
html
.
replace
(
/<
(\/?)(
html|head|body
)([^
>
]
*
)
>/ig
,
function
(
a
,
b
,
c
,
d
){
return
'
<
'
+
b
+
'
div
'
+
(
b
?
''
:
'
data-element="
'
+
c
+
'
"
'
)
+
d
+
'
>
'
;
var
promise
=
$
.
Deferred
(
function
(
deferred
)
{
$
.
ajax
({
type
:
'
GET
'
,
url
:
uri
,
cache
:
true
,
headers
:{
'
Access-Control-Expose-Headers
'
:
'
X-Current-Location
'
},
success
:
function
(
html
,
status
,
xhr
)
{
// For GitBook.com, we handle redirection signaled by the server
var
responseURL
=
xhr
.
getResponseHeader
(
'
X-Current-Location
'
)
||
uri
;
// Replace html content
html
=
html
.
replace
(
/<
(\/?)(
html|head|body
)([^
>
]
*
)
>/ig
,
function
(
a
,
b
,
c
,
d
){
return
'
<
'
+
b
+
'
div
'
+
(
b
?
''
:
'
data-element="
'
+
c
+
'
"
'
)
+
d
+
'
>
'
;
});
var
$page
=
$
(
html
),
$pageBody
=
$page
.
find
(
'
.book
'
),
$pageHead
;
// We only use history.pushState for pages generated with GitBook
if
(
$pageBody
.
length
===
0
)
{
var
err
=
new
Error
(
'
Invalid gitbook page, redirecting...
'
);
return
deferred
.
reject
(
err
);
}
// Push url to history
if
(
push
)
{
history
.
pushState
({
path
:
responseURL
},
null
,
responseURL
);
}
// Force reparsing HTML to prevent wrong URLs in Safari
$page
=
$
(
html
);
$pageHead
=
$page
.
find
(
'
[data-element=head]
'
);
$pageBody
=
$page
.
find
(
'
.book
'
);
// Merge heads
// !! Warning !!: we only update necessary portions to avoid strange behavior (page flickering etc ...)
// Update title
document
.
title
=
$pageHead
.
find
(
'
title
'
).
text
();
// Reference to $('head');
var
$head
=
$
(
'
head
'
);
// Update next & prev <link> tags
// Remove old
$head
.
find
(
'
link[rel=prev]
'
).
remove
();
$head
.
find
(
'
link[rel=next]
'
).
remove
();
// Add new next * prev <link> tags
$head
.
append
(
$pageHead
.
find
(
'
link[rel=prev]
'
));
$head
.
append
(
$pageHead
.
find
(
'
link[rel=next]
'
));
// Merge body
var
bodyClass
=
$
(
'
.book
'
).
attr
(
'
class
'
);
var
scrollPosition
=
$
(
'
.book-summary
'
).
scrollTop
();
$pageBody
.
toggleClass
(
'
with-summary
'
,
$
(
'
.book
'
).
hasClass
(
'
with-summary
'
));
$
(
'
.book
'
).
replaceWith
(
$pageBody
);
$
(
'
.book
'
).
attr
(
'
class
'
,
bodyClass
);
$
(
'
.book-summary
'
).
scrollTop
(
scrollPosition
);
// Update state
gitbook
.
state
.
$book
=
$
(
'
.book
'
);
preparePage
(
!
hash
);
// Scroll to hashtag position
if
(
hash
)
{
scrollToHash
(
hash
);
}
deferred
.
resolve
();
}
});
var
$page
=
$
(
html
);
var
$pageHead
=
$page
.
find
(
'
[data-element=head]
'
);
var
$pageBody
=
$page
.
find
(
'
.book
'
);
// We only use history.pushState for pages generated with GitBook
if
(
$pageBody
.
length
===
0
)
{
return
$
.
Deferred
(
function
(
deferred
)
{
var
err
=
new
Error
(
'
Invalid gitbook page, redirecting...
'
);
deferred
.
reject
(
err
);
}).
promise
();
}
// Push url to history
if
(
push
)
{
history
.
pushState
({
path
:
uri
},
null
,
uri
);
}
// Merge heads
// !! Warning !!: we only update necessary portions to avoid strange behavior (page flickering etc ...)
// Update title
document
.
title
=
$pageHead
.
find
(
'
title
'
).
text
();
// Reference to $('head');
var
$head
=
$
(
'
head
'
);
// Update next & prev <link> tags
// Remove old
$head
.
find
(
'
link[rel=prev]
'
).
remove
();
$head
.
find
(
'
link[rel=next]
'
).
remove
();
// Add new next * prev <link> tags
$head
.
append
(
$pageHead
.
find
(
'
link[rel=prev]
'
));
$head
.
append
(
$pageHead
.
find
(
'
link[rel=next]
'
));
// Merge body
var
bodyClass
=
$
(
'
.book
'
).
attr
(
'
class
'
);
var
scrollPosition
=
$
(
'
.book-summary
'
).
scrollTop
();
$pageBody
.
toggleClass
(
'
with-summary
'
,
$
(
'
.book
'
).
hasClass
(
'
with-summary
'
));
$
(
'
.book
'
).
replaceWith
(
$pageBody
);
$
(
'
.book
'
).
attr
(
'
class
'
,
bodyClass
);
$
(
'
.book-summary
'
).
scrollTop
(
scrollPosition
);
// Update state
gitbook
.
state
.
$book
=
$
(
'
.book
'
);
preparePage
(
!
hash
);
// Scroll to hashtag position
if
(
hash
)
{
scrollToHash
(
hash
);
}
})
.
fail
(
function
(
e
)
{
location
.
href
=
relativeUrl
;
}));
}).
promise
();
return
loading
.
show
(
promise
.
fail
(
function
(
e
)
{
console
.
log
(
e
);
// eslint-disable-line no-console
// location.href = relativeUrl;
})
);
}
function
updateNavigationPosition
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录