Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
theme-apachecn
提交
b8ff8daa
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 搜索 >>
提交
b8ff8daa
编写于
4月 12, 2016
作者:
S
Samy Pessé
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Separate core and theme js
上级
e3b5d3eb
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
148 addition
and
131 deletion
+148
-131
_layouts/website/page.html
_layouts/website/page.html
+11
-6
src/build.sh
src/build.sh
+2
-1
src/js/core/index.js
src/js/core/index.js
+44
-5
src/js/core/page.js
src/js/core/page.js
+75
-0
src/js/core/state.js
src/js/core/state.js
+0
-38
src/js/main.js
src/js/main.js
+0
-59
src/js/theme/index.js
src/js/theme/index.js
+10
-7
src/js/theme/loading.js
src/js/theme/loading.js
+1
-1
src/js/theme/navigation.js
src/js/theme/navigation.js
+2
-11
src/js/theme/sidebar.js
src/js/theme/sidebar.js
+2
-2
src/js/theme/toolbar.js
src/js/theme/toolbar.js
+1
-1
未找到文件。
_layouts/website/page.html
浏览文件 @
b8ff8daa
...
...
@@ -15,7 +15,8 @@
{% endblock %}
{% block javascript %}
<script
src=
"{{ "
app.js
"|
resolveAsset
}}"
></script>
<script
src=
"{{ "
gitbook.js
"|
resolveAsset
}}"
></script>
<script
src=
"{{ "
theme.js
"|
resolveAsset
}}"
></script>
{% for resource in plugins.resources.js %}
{% if resource.url %}
<script
src=
"{{ resource.url }}"
></script>
...
...
@@ -23,11 +24,6 @@
<script
src=
"{{ resource.path|resolveAsset }}"
></script>
{% endif %}
{% endfor %}
<script>
require
([
"
gitbook
"
],
function
(
gitbook
)
{
gitbook
.
start
({{
config
.
pluginsConfig
|
dump
|
safe
}});
});
</script>
{% endblock %}
{% block body %}
...
...
@@ -108,6 +104,15 @@
{% endblock %}
{% endblock %}
</div>
<script>
(
function
()
{
gitbook
.
page
.
hasChanged
({
page
:
{{
page
|
dump
|
safe
}},
config
:
{{
config
|
dump
|
safe
}},
})
})();
</script>
</div>
{% endblock %}
...
...
src/build.sh
浏览文件 @
b8ff8daa
...
...
@@ -8,7 +8,8 @@ mkdir -p _assets/website/
mkdir
-p
_assets/ebook/
# Compile JS
browserify src/js/main.js | uglifyjs
-mc
>
_assets/website/app.js
browserify src/js/core/index.js | uglifyjs
-mc
>
_assets/website/gitbook.js
browserify src/js/theme/index.js | uglifyjs
-mc
>
_assets/website/theme.js
# Compile Website CSS
lessc
-clean-css
src/less/website.less _assets/website/style.css
...
...
src/js/core/index.js
浏览文件 @
b8ff8daa
module
.
exports
=
{
events
:
require
(
'
./events
'
),
state
:
require
(
'
./state
'
),
storage
:
require
(
'
./storage
'
)
};
\ No newline at end of file
var
$
=
require
(
'
jquery
'
);
var
events
=
require
(
'
./events
'
);
var
storage
=
require
(
'
./storage
'
);
var
page
=
require
(
'
./page
'
);
console
.
log
(
'
GitBook is starting...
'
);
// Export APIs for plugins
var
gitbook
=
{
events
:
events
,
page
:
page
,
// Deprecated
state
:
page
.
getState
(),
// Read/Write the localstorage
storage
:
storage
};
// Modules mapping for plugins
var
MODULES
=
{
'
gitbook
'
:
gitbook
,
'
jquery
'
:
$
};
window
.
gitbook
=
gitbook
;
window
.
$
=
$
;
window
.
jQuery
=
$
;
window
.
require
=
function
(
mods
,
fn
)
{
mods
=
mods
.
map
(
function
(
mod
)
{
mod
=
mod
.
toLowerCase
();
if
(
!
MODULES
[
mod
])
{
throw
new
Error
(
'
GitBook module
'
+
mod
+
'
doesn
\'
t exist
'
);
}
return
MODULES
[
mod
];
});
fn
.
apply
(
null
,
mods
);
};
console
.
log
(
'
GitBook is started
'
);
src/js/core/page.js
0 → 100644
浏览文件 @
b8ff8daa
var
$
=
require
(
'
jquery
'
);
var
url
=
require
(
'
url
'
);
var
path
=
require
(
'
path
'
);
var
events
=
require
(
'
./events
'
);
var
started
=
false
;
var
state
=
{};
/*
Signal that page has changed, this function must be called by
themes after page is loaded and when navigation changed
*/
function
hasChanged
(
ctx
)
{
console
.
log
(
'
page has changed
'
,
ctx
);
setState
(
ctx
);
if
(
!
started
)
{
// Notify that gitbook is ready
started
=
true
;
events
.
trigger
(
'
start
'
,
ctx
.
config
);
}
events
.
trigger
(
'
page.change
'
);
}
/*
Update current state
data-level="{{ page.level }}"
data-chapter-title="{{ page.title }}"
data-filepath="{{ file.path }}"
data-basepath="{{ './'|resolveFile }}"
data-revision="{{ gitbook.time }}"
data-innerlanguage="{{ innerlanguage }}">
*/
function
setState
(
newState
)
{
// API since GitBook v3
state
.
page
=
newState
.
page
;
state
.
file
=
newState
.
file
;
state
.
gitbook
=
newState
.
gitbook
;
state
.
config
=
newState
.
config
;
state
.
basePath
=
newState
.
basePath
;
// Deprecated
state
.
$book
=
$
(
'
.book
'
);
state
.
innerLanguage
=
''
;
// todo
state
.
revision
=
state
.
gitbook
.
time
;
state
.
level
=
state
.
page
.
level
;
state
.
filepath
=
state
.
file
.
path
;
state
.
chapterTitle
=
state
.
page
.
title
;
// Absolute url to the root of the book (inner book)
state
.
root
=
url
.
resolve
(
location
.
protocol
+
'
//
'
+
location
.
host
,
path
.
dirname
(
path
.
resolve
(
location
.
pathname
.
replace
(
/
\/
$/
,
'
/index.html
'
),
state
.
basePath
))
).
replace
(
/
\/?
$/
,
'
/
'
);
// Absolute root to the language (for multilingual book)
state
.
bookRoot
=
state
.
innerLanguage
?
url
.
resolve
(
state
.
root
,
'
..
'
)
:
state
.
root
;
}
/*
Return state of current page
*/
function
getState
()
{
return
state
;
}
module
.
exports
=
{
hasChanged
:
hasChanged
,
setState
:
setState
,
getState
:
getState
};
src/js/core/state.js
已删除
100644 → 0
浏览文件 @
e3b5d3eb
var
$
=
require
(
'
jquery
'
);
var
url
=
require
(
'
url
'
);
var
path
=
require
(
'
path
'
);
var
state
=
{};
state
.
update
=
function
(
dom
)
{
var
$book
=
$
(
dom
.
find
(
'
.book
'
));
state
.
$book
=
$book
;
state
.
level
=
$book
.
data
(
'
level
'
);
state
.
basePath
=
$book
.
data
(
'
basepath
'
);
// If book is multilingual, language of this book
state
.
innerLanguage
=
$book
.
data
(
'
innerlanguage
'
);
// Date of build
state
.
revision
=
$book
.
data
(
'
revision
'
);
// Original path of the file
state
.
filepath
=
$book
.
data
(
'
filepath
'
);
// Title of the chapter
state
.
chapterTitle
=
$book
.
data
(
'
chapter-title
'
);
// Absolute url to the root of the book (inner book)
state
.
root
=
url
.
resolve
(
location
.
protocol
+
'
//
'
+
location
.
host
,
path
.
dirname
(
path
.
resolve
(
location
.
pathname
.
replace
(
/
\/
$/
,
'
/index.html
'
),
state
.
basePath
))
).
replace
(
/
\/?
$/
,
'
/
'
);
// Absolute root to the language (for multilingual book)
state
.
bookRoot
=
state
.
innerLanguage
?
url
.
resolve
(
state
.
root
,
'
..
'
)
:
state
.
root
;
};
state
.
update
(
$
);
module
.
exports
=
state
;
src/js/main.js
已删除
100755 → 0
浏览文件 @
e3b5d3eb
var
$
=
require
(
'
jquery
'
);
var
events
=
require
(
'
./core
'
).
events
;
var
state
=
require
(
'
./core
'
).
state
;
var
storage
=
require
(
'
./core
'
).
storage
;
var
theme
=
require
(
'
./theme
'
);
function
start
(
config
)
{
// Init theme
theme
.
init
();
// Notify that gitbook is ready
events
.
trigger
(
'
start
'
,
config
);
theme
.
navigation
.
notify
();
}
// Export APIs for plugins
var
gitbook
=
{
start
:
start
,
events
:
events
,
state
:
state
,
// Read/Write the localstorage
storage
:
storage
,
// UI sections
toolbar
:
theme
.
toolbar
,
sidebar
:
theme
.
sidebar
,
// Create keyboard shortcuts
keyboard
:
theme
.
keyboard
};
// Modules mapping for plugins
var
MODULES
=
{
'
gitbook
'
:
gitbook
,
'
jquery
'
:
$
};
window
.
gitbook
=
gitbook
;
window
.
$
=
$
;
window
.
jQuery
=
$
;
window
.
require
=
function
(
mods
,
fn
)
{
mods
=
mods
.
map
(
function
(
mod
)
{
mod
=
mod
.
toLowerCase
();
if
(
!
MODULES
[
mod
])
{
throw
new
Error
(
'
GitBook module
'
+
mod
+
'
doesn
\'
t exist
'
);
}
return
MODULES
[
mod
];
});
fn
.
apply
(
null
,
mods
);
};
module
.
exports
=
{};
src/js/theme/index.js
浏览文件 @
b8ff8daa
...
...
@@ -4,6 +4,8 @@ var navigation = require('./navigation');
var
sidebar
=
require
(
'
./sidebar
'
);
var
toolbar
=
require
(
'
./toolbar
'
);
var
gitbook
=
window
.
gitbook
;
function
init
()
{
// Init sidebar
sidebar
.
init
();
...
...
@@ -26,12 +28,13 @@ function init() {
sidebar
.
toggle
();
}
});
navigation
.
notify
();
}
module
.
exports
=
{
init
:
init
,
keyboard
:
require
(
'
./keyboard
'
),
navigation
:
require
(
'
./navigation
'
),
sidebar
:
require
(
'
./sidebar
'
),
toolbar
:
require
(
'
./toolbar
'
)
};
\ No newline at end of file
gitbook
.
events
.
on
(
'
start
'
,
init
);
gitbook
.
keyboard
=
keyboard
;
gitbook
.
navigation
=
navigation
;
gitbook
.
sidebar
=
sidebar
;
gitbook
.
toolbar
=
toolbar
;
src/js/theme/loading.js
浏览文件 @
b8ff8daa
var
state
=
require
(
'
../core
'
)
.
state
;
var
state
=
gitbook
.
state
;
function
showLoading
(
p
)
{
state
.
$book
.
addClass
(
'
is-loading
'
);
...
...
src/js/theme/navigation.js
浏览文件 @
b8ff8daa
var
$
=
require
(
'
jquery
'
);
var
url
=
require
(
'
url
'
);
var
events
=
require
(
'
../core
'
).
events
;
var
state
=
require
(
'
../core
'
).
state
;
var
loading
=
require
(
'
./loading
'
);
var
state
=
gitbook
.
state
;
var
usePushState
=
(
typeof
history
.
pushState
!==
'
undefined
'
);
...
...
@@ -75,10 +74,6 @@ function updateNavigationPosition() {
$
(
'
.navigation-next
'
).
css
(
'
margin-right
'
,
(
bodyInnerWidth
-
pageWrapperWidth
)
+
'
px
'
);
}
function
notifyPageChange
()
{
events
.
trigger
(
'
page.change
'
);
}
function
preparePage
(
notify
)
{
var
$bookBody
=
$
(
'
.book-body
'
);
var
$bookInner
=
$bookBody
.
find
(
'
.body-inner
'
);
...
...
@@ -93,9 +88,6 @@ function preparePage(notify) {
// Reset scroll
$bookInner
.
scrollTop
(
0
);
$bookBody
.
scrollTop
(
0
);
// Notify
if
(
notify
!==
false
)
notifyPageChange
();
}
function
isLeftClickEvent
(
e
)
{
...
...
@@ -160,6 +152,5 @@ function init() {
module
.
exports
=
{
init
:
init
,
goNext
:
goNext
,
goPrev
:
goPrev
,
notify
:
notifyPageChange
goPrev
:
goPrev
};
src/js/theme/sidebar.js
浏览文件 @
b8ff8daa
var
$
=
require
(
'
jquery
'
);
var
storage
=
require
(
'
../core
'
)
.
storage
;
var
state
=
require
(
'
../core
'
)
.
state
;
var
storage
=
gitbook
.
storage
;
var
state
=
gitbook
.
state
;
var
platform
=
require
(
'
./platform
'
);
...
...
src/js/theme/toolbar.js
浏览文件 @
b8ff8daa
var
$
=
require
(
'
jquery
'
);
var
events
=
require
(
'
../core
'
)
.
events
;
var
events
=
gitbook
.
events
;
// List of created buttons
var
buttons
=
[];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录