-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Fixes and enhancements. [10] #1574
Changes from all commits
387bba4
2eee68f
4bd315d
16f97aa
c858f8e
29b94d3
94287c5
a18287d
73ca38e
35b9648
579a788
0070675
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{% if theme.save_scroll %} | ||
<script type="text/javascript" src="{{ url_for(theme.js) }}/src/js.cookie.js?v={{ theme.version }}"></script> | ||
<script type="text/javascript" src="{{ url_for(theme.js) }}/src/scroll-cookie.js?v={{ theme.version }}"></script> | ||
{% endif %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/*! | ||
* JavaScript Cookie v2.1.4 | ||
* https://github.com/js-cookie/js-cookie | ||
* | ||
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack | ||
* Released under the MIT license | ||
*/ | ||
;(function (factory) { | ||
var registeredInModuleLoader = false; | ||
if (typeof define === 'function' && define.amd) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'define' is not defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'define' is not defined. |
||
define(factory); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'define' is not defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'define' is not defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'define' is not defined. |
||
registeredInModuleLoader = true; | ||
} | ||
if (typeof exports === 'object') { | ||
module.exports = factory(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'module' is not defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'module' is not defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'module' is not defined. |
||
registeredInModuleLoader = true; | ||
} | ||
if (!registeredInModuleLoader) { | ||
var OldCookies = window.Cookies; | ||
var api = window.Cookies = factory(); | ||
api.noConflict = function () { | ||
window.Cookies = OldCookies; | ||
return api; | ||
}; | ||
} | ||
}(function () { | ||
function extend () { | ||
var i = 0; | ||
var result = {}; | ||
for (; i < arguments.length; i++) { | ||
var attributes = arguments[ i ]; | ||
for (var key in attributes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. |
||
result[key] = attributes[key]; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
function init (converter) { | ||
function api (key, value, attributes) { | ||
var result; | ||
if (typeof document === 'undefined') { | ||
return; | ||
} | ||
|
||
// Write | ||
|
||
if (arguments.length > 1) { | ||
attributes = extend({ | ||
path: '/' | ||
}, api.defaults, attributes); | ||
|
||
if (typeof attributes.expires === 'number') { | ||
var expires = new Date(); | ||
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5); | ||
attributes.expires = expires; | ||
} | ||
|
||
// We're using "expires" because "max-age" is not supported by IE | ||
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; | ||
|
||
try { | ||
result = JSON.stringify(value); | ||
if (/^[\{\[]/.test(result)) { | ||
value = result; | ||
} | ||
} catch (e) {} | ||
|
||
if (!converter.write) { | ||
value = encodeURIComponent(String(value)) | ||
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); | ||
} else { | ||
value = converter.write(value, key); | ||
} | ||
|
||
key = encodeURIComponent(String(key)); | ||
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); | ||
key = key.replace(/[\(\)]/g, escape); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'escape' is not defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'escape' is not defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'escape' is not defined. |
||
|
||
var stringifiedAttributes = ''; | ||
|
||
for (var attributeName in attributes) { | ||
if (!attributes[attributeName]) { | ||
continue; | ||
} | ||
stringifiedAttributes += '; ' + attributeName; | ||
if (attributes[attributeName] === true) { | ||
continue; | ||
} | ||
stringifiedAttributes += '=' + attributes[attributeName]; | ||
} | ||
return (document.cookie = key + '=' + value + stringifiedAttributes); | ||
} | ||
|
||
// Read | ||
|
||
if (!key) { | ||
result = {}; | ||
} | ||
|
||
// To prevent the for loop in the first place assign an empty array | ||
// in case there are no cookies at all. Also prevents odd result when | ||
// calling "get()" | ||
var cookies = document.cookie ? document.cookie.split('; ') : []; | ||
var rdecode = /(%[0-9A-Z]{2})+/g; | ||
var i = 0; | ||
|
||
for (; i < cookies.length; i++) { | ||
var parts = cookies[i].split('='); | ||
var cookie = parts.slice(1).join('='); | ||
|
||
if (cookie.charAt(0) === '"') { | ||
cookie = cookie.slice(1, -1); | ||
} | ||
|
||
try { | ||
var name = parts[0].replace(rdecode, decodeURIComponent); | ||
cookie = converter.read ? | ||
converter.read(cookie, name) : converter(cookie, name) || | ||
cookie.replace(rdecode, decodeURIComponent); | ||
|
||
if (this.json) { | ||
try { | ||
cookie = JSON.parse(cookie); | ||
} catch (e) {} | ||
} | ||
|
||
if (key === name) { | ||
result = cookie; | ||
break; | ||
} | ||
|
||
if (!key) { | ||
result[name] = cookie; | ||
} | ||
} catch (e) {} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
api.set = api; | ||
api.get = function (key) { | ||
return api.call(api, key); | ||
}; | ||
api.getJSON = function () { | ||
return api.apply({ | ||
json: true | ||
}, [].slice.call(arguments)); | ||
}; | ||
api.defaults = {}; | ||
|
||
api.remove = function (key, attributes) { | ||
api(key, '', extend(attributes, { | ||
expires: -1 | ||
})); | ||
}; | ||
|
||
api.withConverter = init; | ||
|
||
return api; | ||
} | ||
|
||
return init(function () {}); | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
$(document).ready(function() { | ||
|
||
// Set relative link path (without domain) | ||
var rpath = window.location.href.replace(window.location.origin, ""); | ||
|
||
// Write position in cookie | ||
var timeout; | ||
$(window).on("scroll", function() { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(function () { | ||
Cookies.set("scroll-cookie", ($(window).scrollTop() + "|" + rpath), { expires: 365, path: '' }); | ||
}, 250); | ||
}); | ||
|
||
// Read position from cookie | ||
if (Cookies.get("scroll-cookie") !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Cookies' is not defined. |
||
var cvalues = Cookies.get("scroll-cookie").split('|'); | ||
if (cvalues[1] == rpath) { | ||
$(window).scrollTop(cvalues[0]); | ||
} | ||
} | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'define' is not defined.