Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract bookmark / save_scroll to plugins #1106

Merged
merged 13 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ chat:
# Automatically scroll page to section which is under <!-- more --> mark.
scroll_to_more: true

# Automatically saving scroll position of each page in the browser.
save_scroll: false

# Automatically excerpt description in homepage as preamble text.
excerpt_description: true

Expand Down Expand Up @@ -586,14 +583,6 @@ quicklink:
# See: https://github.com/GoogleChromeLabs/quicklink#custom-ignore-patterns
ignores:

# Bookmark Support
# Dependencies: https://github.com/theme-next/theme-next-bookmark
bookmark:
enable: false
# If auto, save the reading position when closing the page or clicking the bookmark-icon.
# If manual, only save it by clicking the bookmark-icon.
save: auto


# ---------------------------------------------------------------
# Comments and Widgets
Expand Down Expand Up @@ -1078,11 +1067,6 @@ vendors:
# quicklink: //cdn.jsdelivr.net/npm/quicklink@1/dist/quicklink.umd.js
quicklink:

# Internal version: 1.0.0
# Example:
# bookmark: //cdn.jsdelivr.net/gh/theme-next/theme-next-bookmark@1/bookmark.min.js
bookmark:

# DisqusJS
# Example:
# disqusjs_js: //cdn.jsdelivr.net/npm/disqusjs@1/dist/disqus.js
Expand Down
1 change: 0 additions & 1 deletion layout/_partials/head/head.swig
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
exturl: {{ theme.exturl }},
sidebar: {{ theme.sidebar | json_encode }},
back2top: {{ theme.back2top | json_encode }},
save_scroll: {{ theme.save_scroll }},
copycode: {{ theme.codeblock.copy_button | json_encode }},
fancybox: {{ theme.fancybox }},
mediumzoom: {{ theme.mediumzoom }},
Expand Down
4 changes: 1 addition & 3 deletions layout/_partials/pjax.swig
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ var pjax = new Pjax({
'.sidebar-inner': Pjax.switches.innerHTML
},
analytics: false,
cacheBust: false,
scrollTo: !CONFIG.save_scroll
cacheBust: false
});
window.addEventListener('pjax:send', () => {
$('.sidebar-inner').stop().fadeTo('fast', 0);
CONFIG.save_scroll && clearInterval(NexT.utils.saveScrollTimer);
});
window.addEventListener('pjax:success', () => {
document.querySelectorAll('script[pjax], script#page-configurations, #pjax script').forEach(element => {
Expand Down
11 changes: 0 additions & 11 deletions layout/_third-party/bookmark.swig

This file was deleted.

1 change: 0 additions & 1 deletion layout/_third-party/index.swig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% include 'baidu-push.swig' %}
{% include 'bookmark.swig' %}

{% include 'analytics/analytics-with-jquery.swig' %}
{% include 'facebook-sdk.swig' %}
Expand Down
10 changes: 0 additions & 10 deletions source/js/next-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ window.addEventListener('DOMContentLoaded', () => {

$(document).on('DOMContentLoaded pjax:success', () => {

if (CONFIG.save_scroll) {
// Read position from localStorage
var value = localStorage.getItem('scroll' + location.pathname);
$('html, body').animate({ scrollTop: value || 0 });
// Write position in localStorage
NexT.utils.saveScrollTimer = setInterval(() => {
localStorage.setItem('scroll' + location.pathname, window.scrollY);
}, 1000);
}

/**
* Register JS handlers by condition option.
* Need to add config option in Front-End at 'layout/_partials/head.swig' file.
Expand Down
4 changes: 2 additions & 2 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ NexT.utils = {
return element.innerText;
}).join('\n');
var ta = document.createElement('textarea');
var yPosition = window.pageYOffset || document.documentElement.scrollTop;
var yPosition = window.scrollY;
ta.style.top = yPosition + 'px'; // Prevent page scroll
ta.style.position = 'absolute';
ta.style.opacity = '0';
Expand Down Expand Up @@ -135,7 +135,7 @@ NexT.utils = {
scrollPercent = NexT.utils.getScrollPercent();
}
if (backToTop) {
$(backToTop).toggleClass('back-to-top-on', window.pageYOffset > THRESHOLD);
$(backToTop).toggleClass('back-to-top-on', window.scrollY > THRESHOLD);
document.querySelector('#scrollpercent span').innerText = scrollPercent;
}
if (readingProgressBar) {
Expand Down