Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
大白技术控
yanglr2010
提交
efbe2c03
Y
yanglr2010
项目概览
大白技术控
/
yanglr2010
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yanglr2010
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
efbe2c03
编写于
8月 28, 2019
作者:
EvanOne(文一)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: Add pjax support
上级
1eef9320
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
177 addition
and
48 deletion
+177
-48
_config.yml
_config.yml
+26
-0
layout/_common/layout.pug
layout/_common/layout.pug
+3
-0
layout/_scripts/common.pug
layout/_scripts/common.pug
+0
-1
layout/_third-party/pjax.pug
layout/_third-party/pjax.pug
+86
-0
source/js/scroll.js
source/js/scroll.js
+15
-10
source/js/sidebar.js
source/js/sidebar.js
+28
-23
source/js/stun-boot.js
source/js/stun-boot.js
+19
-14
未找到文件。
_config.yml
浏览文件 @
efbe2c03
...
...
@@ -627,6 +627,26 @@ quicklink:
# - (uri, el) => el.hasAttribute('nofollow')
ignores
:
# Pjax
# See: https://github.com/MoOx/pjax/
pjax
:
enable
:
true
# ! -----------------------------------------------------
# ! If you don't understand, please ignore the following.
# ! -----------------------------------------------------
# Please see: https://github.com/MoOx/pjax/#options
elements
:
selectors
:
switches
:
switchesOptions
:
history
:
true
scrollTo
:
false
scrollRestoration
:
false
cacheBust
:
false
debug
:
false
currentUrlFullReload
:
false
timeout
:
0
# Google AdSense
google_adsense
:
enable
:
false
...
...
@@ -787,3 +807,9 @@ cdn:
# Example:
# quicklink: //cdn.jsdelivr.net/npm/quicklink@latest/dist/quicklink.umd.js
quicklink
:
# Using version: latest
# See: https://github.com/MoOx/pjax/
# Example:
# pjax: //cdn.jsdelivr.net/npm/pjax@latest/pjax.min.js
pjax
:
layout/_common/layout.pug
浏览文件 @
efbe2c03
...
...
@@ -20,3 +20,6 @@ html(lang=config.language)
include ../_third-party/comments/index.pug
include ../_third-party/math/index.pug
include ../_third-party/search/index.pug
if theme.pjax && theme.pjax.enable
include ../_third-party/pjax.pug
layout/_scripts/common.pug
浏览文件 @
efbe2c03
script(src=`${url_for(theme.js)}/utils.js?v=${stun_env("version")}`)
script(src=`${url_for(theme.js)}/stun-boot.js?v=${stun_env("version")}`)
script(src=`${url_for(theme.js)}/copy.js?v=${stun_env("version")}`)
script(src=`${url_for(theme.js)}/scroll.js?v=${stun_env("version")}`)
script(src=`${url_for(theme.js)}/header.js?v=${stun_env("version")}`)
...
...
layout/_third-party/pjax.pug
0 → 100644
浏览文件 @
efbe2c03
-
var pjaxArgs = {
'elements': [
'a:not([target=_blank])'
],
'selectors': [
'title',
'meta[name=description]',
'#main'
],
'history': theme.pjax.history,
'scrollTo': theme.pjax.scrollTo,
'scrollRestoration': theme.pjax.scrollRestoration,
'cacheBust': theme.pjax.cacheBust,
'debug': theme.pjax.debug,
'currentUrlFullReload': theme.pjax.currentUrlFullReload,
'timeout': theme.pjax.timeout
};
if (theme.pjax.elements) {
pjaxArgs.elements.push(theme.pjax.elements);
}
if (theme.pjax.selectors) {
pjaxArgs.selectors.push(theme.pjax.selectors);
}
if (theme.pjax.selectors) {
pjaxArgs.switches = theme.pjax.selectors;
}
if (theme.pjax.selectors) {
pjaxArgs.switchesOptions = theme.pjax.selectors;
}
pjaxArgs = JSON.stringify(pjaxArgs)
if theme.pjax && theme.pjax.enable
- var pjax_js = "https://cdn.jsdelivr.net/npm/pjax@latest/pjax.min.js"
- if (theme.cdn.pjax) pjax_js = theme.cdn.pjax
script(src=pjax_js)
script.
var header = document.querySelector('#header');
var headerHeight = header.offsetHeight;
var pjax = new Pjax(!{ pjaxArgs });
// 加载进度条的计时器
var loadingTimer = null;
// 重置页面 Y 方向上的滚动偏移量
document.addEventListener('pjax:send', function () {
$('html').velocity('scroll', {
duration: 500,
offset: $('#header').height(),
easing: 'easeInOutCubic'
});
var loadingBarWidth = 0;
var MAX_LOADING_WIDTH = 95;
$('.loading-bar .progress').css('transform', 'translateX(-100%)');
$('.loading-bar').addClass('loading');
clearInterval(loadingTimer);
loadingTimer = setInterval(function () {
loadingBarWidth += 2;
if (loadingBarWidth > MAX_LOADING_WIDTH) {
loadingBarWidth = MAX_LOADING_WIDTH;
}
$('.loading-bar .progress').css(
'transform', 'translateX(' + (loadingBarWidth - 100) + '%)'
);
}, 100);
}, false);
document.addEventListener('pjax:complete', function () {
clearInterval(loadingTimer);
$('.loading-bar .progress').css('transform', 'translateX(0%)');
setTimeout(function () {
$('.loading-bar').removeClass('loading');
$('.loading-bar .progress').css('transform', 'translateX(-100%)');
}, 400);
// 重载失效的函数,使其再执行一次
Stun.utils.pjaxReloadBoot();
Stun.utils.pjaxReloadScroll();
Stun.utils.pjaxReloadSidebar();
}, false);
source/js/scroll.js
浏览文件 @
efbe2c03
...
...
@@ -85,16 +85,21 @@ $(document).ready(function () {
headerNavScroll
();
},
100
));
// Click the heading.
$
(
'
.content
'
)
.
find
(
'
h1,h2,h3,h4,h5,h6
'
)
.
on
(
'
click
'
,
function
()
{
scrollHeadingToTop
(
'
#
'
+
$
(
this
).
attr
(
'
id
'
));
Stun
.
utils
.
pjaxReloadScroll
=
function
()
{
// Click the heading.
$
(
'
.content
'
)
.
find
(
'
h1,h2,h3,h4,h5,h6
'
)
.
on
(
'
click
'
,
function
()
{
scrollHeadingToTop
(
'
#
'
+
$
(
this
).
attr
(
'
id
'
));
});
// Click the post toc.
$
(
'
.toc-link
'
).
on
(
'
click
'
,
function
(
e
)
{
e
.
preventDefault
();
scrollHeadingToTop
(
$
(
this
).
attr
(
'
href
'
));
});
};
// Click the post toc.
$
(
'
.toc-link
'
).
on
(
'
click
'
,
function
(
e
)
{
e
.
preventDefault
();
scrollHeadingToTop
(
$
(
this
).
attr
(
'
href
'
));
});
// Initializaiton
Stun
.
utils
.
pjaxReloadScroll
();
});
source/js/sidebar.js
浏览文件 @
efbe2c03
...
...
@@ -142,28 +142,33 @@ $(document).ready(function () {
readProgress
();
},
150
));
var
$tocWrapper
=
$
(
'
.sidebar-toc
'
);
var
$view
=
$
(
'
.sidebar-overview
'
);
$
(
'
.sidebar-nav-toc
'
).
on
(
'
click
'
,
function
()
{
$
(
'
.sidebar-nav-toc
'
).
toggleClass
(
'
current
'
);
$
(
'
.sidebar-nav-overview
'
).
toggleClass
(
'
current
'
);
$tocWrapper
.
css
(
'
display
'
,
'
block
'
);
$tocWrapper
.
velocity
(
'
fadeIn
'
);
$view
.
css
(
'
display
'
,
'
none
'
);
$view
.
velocity
(
'
fadeOut
'
);
});
$
(
'
.sidebar-nav-overview
'
).
on
(
'
click
'
,
function
()
{
$
(
'
.sidebar-nav-toc
'
).
toggleClass
(
'
current
'
);
$
(
'
.sidebar-nav-overview
'
).
toggleClass
(
'
current
'
);
$tocWrapper
.
css
(
'
display
'
,
'
none
'
);
$tocWrapper
.
velocity
(
'
fadeOut
'
);
Stun
.
utils
.
pjaxReloadSidebar
=
function
()
{
var
$tocWrapper
=
$
(
'
.sidebar-toc
'
);
var
$view
=
$
(
'
.sidebar-overview
'
);
$
(
'
.sidebar-nav-toc
'
).
on
(
'
click
'
,
function
()
{
$
(
'
.sidebar-nav-toc
'
).
toggleClass
(
'
current
'
);
$
(
'
.sidebar-nav-overview
'
).
toggleClass
(
'
current
'
);
$tocWrapper
.
css
(
'
display
'
,
'
block
'
);
$tocWrapper
.
velocity
(
'
fadeIn
'
);
$view
.
css
(
'
display
'
,
'
none
'
);
$view
.
velocity
(
'
fadeOut
'
);
});
$
(
'
.sidebar-nav-overview
'
).
on
(
'
click
'
,
function
()
{
$
(
'
.sidebar-nav-toc
'
).
toggleClass
(
'
current
'
);
$
(
'
.sidebar-nav-overview
'
).
toggleClass
(
'
current
'
);
$tocWrapper
.
css
(
'
display
'
,
'
none
'
);
$tocWrapper
.
velocity
(
'
fadeOut
'
);
$view
.
css
(
'
display
'
,
'
block
'
);
$view
.
velocity
(
'
fadeIn
'
);
});
};
$view
.
css
(
'
display
'
,
'
block
'
);
$view
.
velocity
(
'
fadeIn
'
);
});
// Initialization
Stun
.
utils
.
pjaxReloadSidebar
();
});
source/js/stun-boot.js
浏览文件 @
efbe2c03
...
...
@@ -6,21 +6,26 @@ $(document).ready(function () {
Stun
.
utils
.
addIconToExternalLink
(
'
#footer
'
);
}
Stun
.
utils
.
addCopyButtonToCopyright
();
Stun
.
utils
.
registerCopyEvent
();
CONFIG
.
reward
&&
Stun
.
utils
.
registerShowReward
();
CONFIG
.
gallery_waterfall
&&
Stun
.
utils
.
galleryWaterFall
();
CONFIG
.
lazyload
&&
Stun
.
utils
.
lazyLoadImages
();
Stun
.
utils
.
pjaxReloadBoot
=
function
()
{
this
.
addCopyButtonToCopyright
();
this
.
registerCopyEvent
();
CONFIG
.
reward
&&
this
.
registerShowReward
();
CONFIG
.
gallery_waterfall
&&
this
.
galleryWaterFall
();
CONFIG
.
lazyload
&&
this
.
lazyLoadImages
();
if
(
CONFIG
.
external_link
)
{
var
WRAPPER
=
'
.archive-inner, .post-title
'
;
if
(
CONFIG
.
external_link
)
{
var
WRAPPER
=
'
.archive-inner, .post-title
'
;
Stun
.
util
s
.
addIconToExternalLink
(
WRAPPER
);
}
thi
s
.
addIconToExternalLink
(
WRAPPER
);
}
if
(
CONFIG
.
fancybox
)
{
Stun
.
utils
.
wrapImageWithFancyBox
();
}
else
if
(
CONFIG
.
zoom_image
)
{
Stun
.
utils
.
registerClickToZoomImage
();
}
if
(
CONFIG
.
fancybox
)
{
this
.
wrapImageWithFancyBox
();
}
else
if
(
CONFIG
.
zoom_image
)
{
this
.
registerClickToZoomImage
();
}
};
// Initializaiton
Stun
.
utils
.
pjaxReloadBoot
();
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录