Skip to content

Commit

Permalink
feat: Add the config of scroll to second screen when pjax enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyib committed Sep 13, 2019
1 parent ebf5d11 commit ec6ac43
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
5 changes: 4 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ sidebar:
# Horizon line.
horizon_line: false
# Suggest: 240px ~ 300px
width: 260px
width: 280px

author:
enable: true
Expand Down Expand Up @@ -620,6 +620,8 @@ quicklink:
# See: https://github.com/MoOx/pjax/
pjax:
enable: false
# Scrolling to the second screen when the page loaded.
scrollTo2screen: false
# ! -----------------------------------------------------
# ! If you don't understand, please ignore the following.
# ! -----------------------------------------------------
Expand All @@ -629,6 +631,7 @@ pjax:
switches:
switchesOptions:
history: true
# If you enable this, you must set `scrollTo2screen: false` firstly.
scrollTo: false
scrollRestoration: false
cacheBust: false
Expand Down
8 changes: 8 additions & 0 deletions layout/_partials/config.pug
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
zoom_image = JSON.stringify(theme.zoom_image);
}
var pjax_config = "undefined";
if (theme.pjax.enable) {
pjax_config = JSON.stringify({
scrollTo2screen: theme.pjax.scrollTo2screen
});
}
var external_link = "undefined";
if (theme.external_link.icon.enable) {
external_link = JSON.stringify({
Expand Down Expand Up @@ -87,6 +94,7 @@ script.
zoom_image: !{ zoom_image },
gallery_waterfall: !{ gallery_waterfall },
lazyload: !{ lazyload },
pjax: !{ pjax_config },
external_link: !{ external_link },
shortcuts: !{ shortcuts },
prompt: !{ prompt }
Expand Down
16 changes: 7 additions & 9 deletions layout/_third-party/pjax.pug
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
-
var pjaxArgs = {
'elements': [
'a:not([target=_blank])'
],
'selectors': [
'head title',
'meta[name=description]',
'#main',
'.pjax-reload'
],
Expand Down Expand Up @@ -48,11 +44,13 @@ script.
document.addEventListener('pjax:send', function () {
$('.header-nav-menu').removeClass('show');

$('html').velocity('scroll', {
duration: 500,
offset: $('#header').height(),
easing: 'easeInOutCubic'
});
if (CONFIG.pjax.scrollTo2screen) {
$('html').velocity('scroll', {
duration: 500,
offset: $('#header').height(),
easing: 'easeInOutCubic'
});
}

var loadingBarWidth = 0;
var MAX_LOADING_WIDTH = 95;
Expand Down

0 comments on commit ec6ac43

Please sign in to comment.