Fixes and enhancements. [10]#1574
Conversation
Update from original.
source/js/src/scroll-cookie.js
Outdated
| @@ -0,0 +1,25 @@ | |||
| /* global NexT: true */ | |||
source/js/src/scroll-cookie.js
Outdated
|
|
||
| // Read position from cookie | ||
| if (Cookies.get('scroll-cookie') !== undefined) { | ||
| var cvalues = Cookies.get('scroll-cookie').split('|'); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| }); | ||
|
|
||
| // Read position from cookie | ||
| if (Cookies.get('scroll-cookie') !== undefined) { |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| $(window).on('scroll', function() { | ||
| clearTimeout(timeout); | ||
| timeout = setTimeout(function () { | ||
| Cookies.set('scroll-cookie', ($(window).scrollTop() + '|' + rpath), { path: '' }); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
|
|
||
| // Write position in cookie | ||
| var timeout; | ||
| $(window).on('scroll', function() { |
|
|
||
| key = encodeURIComponent(String(key)); | ||
| key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); | ||
| key = key.replace(/[\(\)]/g, escape); |
| registeredInModuleLoader = true; | ||
| } | ||
| if (typeof exports === 'object') { | ||
| module.exports = factory(); |
| ;(function (factory) { | ||
| var registeredInModuleLoader = false; | ||
| if (typeof define === 'function' && define.amd) { | ||
| define(factory); |
| */ | ||
| ;(function (factory) { | ||
| var registeredInModuleLoader = false; | ||
| if (typeof define === 'function' && define.amd) { |
| var result = {}; | ||
| for (; i < arguments.length; i++) { | ||
| var attributes = arguments[ i ]; | ||
| for (var key in attributes) { |
There was a problem hiding this comment.
The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
source/js/src/scroll-cookie.js
Outdated
| @@ -0,0 +1,25 @@ | |||
| /* global NexT: true */ | |||
source/js/src/scroll-cookie.js
Outdated
|
|
||
| // Read position from cookie | ||
| if (Cookies.get('scroll-cookie') !== undefined) { | ||
| var cvalues = Cookies.get('scroll-cookie').split('|'); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| }); | ||
|
|
||
| // Read position from cookie | ||
| if (Cookies.get('scroll-cookie') !== undefined) { |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| $(window).on('scroll', function() { | ||
| clearTimeout(timeout); | ||
| timeout = setTimeout(function () { | ||
| Cookies.set('scroll-cookie', ($(window).scrollTop() + '|' + rpath), { path: '' }); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
|
|
||
| // Write position in cookie | ||
| var timeout; | ||
| $(window).on('scroll', function() { |
|
|
||
| key = encodeURIComponent(String(key)); | ||
| key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); | ||
| key = key.replace(/[\(\)]/g, escape); |
| registeredInModuleLoader = true; | ||
| } | ||
| if (typeof exports === 'object') { | ||
| module.exports = factory(); |
| ;(function (factory) { | ||
| var registeredInModuleLoader = false; | ||
| if (typeof define === 'function' && define.amd) { | ||
| define(factory); |
| */ | ||
| ;(function (factory) { | ||
| var registeredInModuleLoader = false; | ||
| if (typeof define === 'function' && define.amd) { |
| var result = {}; | ||
| for (; i < arguments.length; i++) { | ||
| var attributes = arguments[ i ]; | ||
| for (var key in attributes) { |
There was a problem hiding this comment.
The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
source/js/src/scroll-cookie.js
Outdated
| @@ -0,0 +1,25 @@ | |||
| /* global NexT: true */ | |||
source/js/src/scroll-cookie.js
Outdated
|
|
||
| // Read position from cookie | ||
| if (Cookies.get('scroll-cookie') !== undefined) { | ||
| var cvalues = Cookies.get('scroll-cookie').split('|'); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| }); | ||
|
|
||
| // Read position from cookie | ||
| if (Cookies.get('scroll-cookie') !== undefined) { |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| $(window).on('scroll', function() { | ||
| clearTimeout(timeout); | ||
| timeout = setTimeout(function () { | ||
| Cookies.set('scroll-cookie', ($(window).scrollTop() + '|' + rpath), { path: '' }); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
|
|
||
| // Write position in cookie | ||
| var timeout; | ||
| $(window).on('scroll', function() { |
|
|
||
| key = encodeURIComponent(String(key)); | ||
| key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); | ||
| key = key.replace(/[\(\)]/g, escape); |
| registeredInModuleLoader = true; | ||
| } | ||
| if (typeof exports === 'object') { | ||
| module.exports = factory(); |
| ;(function (factory) { | ||
| var registeredInModuleLoader = false; | ||
| if (typeof define === 'function' && define.amd) { | ||
| define(factory); |
| */ | ||
| ;(function (factory) { | ||
| var registeredInModuleLoader = false; | ||
| if (typeof define === 'function' && define.amd) { |
| var result = {}; | ||
| for (; i < arguments.length; i++) { | ||
| var attributes = arguments[ i ]; | ||
| for (var key in attributes) { |
There was a problem hiding this comment.
The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
| }); | ||
|
|
||
| // Read position from cookie | ||
| if (Cookies.get("scroll-cookie") !== undefined) { |
source/js/src/scroll-cookie.js
Outdated
|
|
||
| // Read position from cookie | ||
| if (Cookies.get("scroll-cookie") !== undefined) { | ||
| var cvalues = Cookies.get('scroll-cookie').split('|'); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| $(window).on("scroll", function() { | ||
| clearTimeout(timeout); | ||
| timeout = setTimeout(function () { | ||
| Cookies.set('scroll-cookie', ($(window).scrollTop() + '|' + rpath), { path: '' }); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| @@ -0,0 +1,23 @@ | |||
| $(document).ready(function() { | |||
|
|
|||
| // Set relative link path (without domain): https://stackoverflow.com/questions/3955959/whats-an-easy-way-to-get-the-url-in-the-current-window-minus-the-domain-name | |||
source/js/src/scroll-cookie.js
Outdated
| $(window).on("scroll", function() { | ||
| clearTimeout(timeout); | ||
| timeout = setTimeout(function () { | ||
| Cookies.set("scroll-cookie", ($(window).scrollTop() + '|' + rpath), { path: '' }); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
source/js/src/scroll-cookie.js
Outdated
| $(window).on("scroll", function() { | ||
| clearTimeout(timeout); | ||
| timeout = setTimeout(function () { | ||
| Cookies.set("scroll-cookie", ($(window).scrollTop() + '|' + rpath), { path: '' }); |
There was a problem hiding this comment.
Mixed double and single quotes.
'Cookies' is not defined.
|
Thanks. 👍 |
PART 1. Some small fixes.
Files modified:
What's this?
PART 2. Add
save_scrolloption.Option for saving vertical scroll position on each post/page in cookies.
Files modified:
save_scrolloption in config. 16f97aasave_scrolloption in layout. c858f8esave_scrolloption in third-party. [bridge] 29b94d3save_scrollAPI script (js.cookie v2.1.4). 94287c5save_scrollmain script file. [4] 0070675How to use?
In Next
_config.yml: