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

Fixes and enhancements. [10] #1574

Merged
merged 12 commits into from
Apr 9, 2017
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ sidebar:
# Automatically scroll page to section which is under <!-- more --> mark.
scroll_to_more: true

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

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

Expand Down
12 changes: 6 additions & 6 deletions languages/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title:
tag: Тэг
schedule: Календарь

author: Author
author: Автор

menu:
home: Главная
Expand Down Expand Up @@ -34,11 +34,11 @@ post:
wordcount: Кол-во слов в статье
min2read: Время чтения в минутах
copyright:
author: Post author
link: Post link
license_title: Copyright Notice
license_content: 'All articles in this blog are licensed under
<a href="%s" rel="external nofollow" target="_blank">%s</a> unless stating additionally.'
author: Автор записи
link: Ссылка на запись
license_title: Информация об авторских правах
license_content: 'Все записи на этом сайте защищены лицензией
<a href="%s" rel="external nofollow" target="_blank">%s</a> если не указано дополнительно.'

page:
totally: Всего
Expand Down
1 change: 1 addition & 0 deletions layout/_layout.swig
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
{% include '_third-party/analytics/lean-analytics.swig' %}
{% include '_third-party/seo/baidu-push.swig' %}
{% include '_third-party/mathjax.swig' %}
{% include '_third-party/scroll-cookie.swig' %}
{% include '_third-party/exturl.swig' %}
</body>
</html>
4 changes: 4 additions & 0 deletions layout/_third-party/scroll-cookie.swig
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 %}
165 changes: 165 additions & 0 deletions source/js/src/js.cookie.js
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'define' is not defined.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'define' is not defined.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'define' is not defined.

define(factory);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'define' is not defined.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'define' is not defined.

Choose a reason for hiding this comment

The 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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'module' is not defined.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'module' is not defined.

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'escape' is not defined.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'escape' is not defined.

Choose a reason for hiding this comment

The 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 () {});
}));
23 changes: 23 additions & 0 deletions source/js/src/scroll-cookie.js
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) {

Choose a reason for hiding this comment

The 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]);
}
}

});
6 changes: 4 additions & 2 deletions source/js/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ NexT.utils = NexT.$u = {
$top.toggleClass('back-to-top-on', window.pageYOffset > THRESHOLD);

var scrollTop = $(window).scrollTop();
var docHeight = $(document).height();
var docHeight = $('#content').height();
var winHeight = $(window).height();
var scrollPercent = (scrollTop) / (docHeight - winHeight);
var scrollPercentRounded = Math.round(scrollPercent*100);
$('#scrollpercent>span').html(scrollPercentRounded);
var scrollPercentMaxed = (scrollPercentRounded > 100) ? 100 : scrollPercentRounded;
$('#scrollpercent>span').html(scrollPercentMaxed);
});
});

$top.on('click', function () {
Expand Down