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

Refactor save_scroll #1049

Merged
merged 4 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ chat:
# Automatically scroll page to section which is under <!-- more --> mark.
scroll_to_more: true

# Automatically saving scroll position on each post / page in cookies.
# Automatically saving scroll position of each page in the browser.
save_scroll: false

# Automatically excerpt description in homepage as preamble text.
Expand Down
1 change: 0 additions & 1 deletion layout/_layout.swig
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
{% block script_extra %}{% endblock %}

{% include '_scripts/next-boot.swig' %}
{% include '_scripts/scroll-cookie.swig' %}
{% include '_scripts/exturl.swig' %}
{% include '_scripts/three.swig' %}

Expand Down
1 change: 1 addition & 0 deletions layout/_partials/head/head.swig
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
version: '{{ version }}',
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: 0 additions & 4 deletions layout/_scripts/scroll-cookie.swig

This file was deleted.

168 changes: 0 additions & 168 deletions source/js/js.cookie.js

This file was deleted.

1 change: 1 addition & 0 deletions source/js/next-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $(document).ready(function() {
CONFIG.lazyload && window.lozad('.post-body img').observe();
CONFIG.pangu && window.pangu.spacingPage();

CONFIG.save_scroll && NexT.utils.saveScroll();
CONFIG.copycode.enable && NexT.utils.registerCopyCode();
CONFIG.back2top.enable && NexT.utils.registerBackToTop();
CONFIG.tabs && NexT.utils.registerTabsTag();
Expand Down
25 changes: 0 additions & 25 deletions source/js/scroll-cookie.js

This file was deleted.

20 changes: 20 additions & 0 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ NexT.utils = {
});
},

saveScroll: function() {
// Set relative link path (without domain)
var rpath = window.location.pathname;

// Read position from localStorage
if (localStorage.getItem('scroll' + rpath) !== null) {
var cvalues = localStorage.getItem('scroll' + rpath);
$(window).scrollTop(cvalues);
}

// Write position in localStorage
var timeout;
$(window).on('scroll', function() {
clearTimeout(timeout);
timeout = setTimeout(function() {
localStorage.setItem('scroll' + rpath, $(window).scrollTop());
}, 250);
});
},

/**
* One-click copy code support.
*/
Expand Down