diff --git a/_includes/scripts/lib/affix.js b/_includes/scripts/lib/affix.js
index 899f6003255..a49fcf4b695 100644
--- a/_includes/scripts/lib/affix.js
+++ b/_includes/scripts/lib/affix.js
@@ -1,26 +1,33 @@
(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
- var $window = $(window), $document = $(window.document), $root;
+ var $window = $(window), $root, $scrollTarget, $scroller, $scroll;
var rootTop, rootLeft, rootHeight, scrollBottom, rootBottomTop, lastScrollTop;
- var offsetBottom = 0, disabled = false, hasInit = false;
+ var offsetBottom = 0, disabled = false, scrollTarget = window, scroller = 'html, body', scroll = window.document;
+ var hasInit = false, isOverallScroller = true;
function setOptions(options) {
var _options = options || {};
_options.offsetBottom && (offsetBottom = _options.offsetBottom);
+ _options.scrollTarget && (scrollTarget = _options.scrollTarget);
+ _options.scroller && (scroller = _options.scroller);
+ _options.scroll && (scroll = _options.scroll);
_options.disabled !== undefined && (disabled = _options.disabled);
+ $scrollTarget = $(scrollTarget);
+ $scroller = $(scroller);
+ isOverallScroller = window.isOverallScroller($scroller[0]);
+ $scroll = $(scroll);
calc(true);
}
function initData() {
top();
- var rootOffset = $root.offset();
rootHeight = $root.outerHeight();
- rootTop = rootOffset.top;
- rootLeft = rootOffset.left;
+ rootTop = $root.offset().top + (isOverallScroller ? 0 : $scroller.scrollTop());
+ rootLeft = $root.offset().left;
}
function calc(needInitData) {
needInitData && initData();
- scrollBottom = $document.outerHeight() - offsetBottom - rootHeight;
+ scrollBottom = $scroll.outerHeight() - offsetBottom - rootHeight;
rootBottomTop = scrollBottom - rootTop;
}
function top() {
@@ -43,7 +50,7 @@
}
function setState(force) {
force !== true && (force = false);
- var scrollTop = $window.scrollTop();
+ var scrollTop = $scrollTarget.scrollTop();
if (scrollTop >= rootTop && scrollTop <= scrollBottom) {
(!force && lastScrollTop >= rootTop && lastScrollTop <= scrollBottom) || fixed();
} else if (scrollTop < rootTop) {
@@ -68,7 +75,7 @@
clearInterval(interval);
clearTimeout(timeout);
});
- $window.on('scroll', function() {
+ $scrollTarget.on('scroll', function() {
disabled || setState();
});
$window.on('resize', window.throttle(function() {
diff --git a/_includes/scripts/lib/scroll.js b/_includes/scripts/lib/scroll.js
new file mode 100644
index 00000000000..5970aae7088
--- /dev/null
+++ b/_includes/scripts/lib/scroll.js
@@ -0,0 +1,13 @@
+(function() {
+ var SOURCES = window.TEXT_VARIABLES.sources;
+ window.Lazyload.js(SOURCES.jquery, function() {
+ function scrollToAnchor(anchor, duration, callback) {
+ var $root = this;
+ $root.animate({ scrollTop: $(anchor).position().top }, duration, function() {
+ window.history.replaceState(null, '', window.location.href.split('#')[0] + anchor);
+ callback && callback();
+ });
+ }
+ $.fn.scrollToAnchor = scrollToAnchor;
+ });
+})();
\ No newline at end of file
diff --git a/_includes/scripts/lib/toc.js b/_includes/scripts/lib/toc.js
index 21b8932cef9..2494cb4011d 100644
--- a/_includes/scripts/lib/toc.js
+++ b/_includes/scripts/lib/toc.js
@@ -1,25 +1,29 @@
(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function() {
- var $window = $(window), $root, $tocUl = $('
'), $tocLi, $headings, $activeLast, $activeCur;
- var selectors = 'h1,h2,h3', container = 'body', disabled = false;
+ var $window = $(window), $root, $scrollTarget, $scroller, $tocUl = $(''), $tocLi, $headings, $activeLast, $activeCur;
+ var selectors = 'h1,h2,h3', container = 'body', scrollTarget = window, scroller = 'html, body', disabled = false;
var headingsPos, scrolling = false, rendered = false, hasInit = false;
function setOptions(options) {
var _options = options || {};
_options.selectors && (selectors = _options.selectors);
_options.container && (container = _options.container);
+ _options.scrollTarget && (scrollTarget = _options.scrollTarget);
+ _options.scroller && (scroller = _options.scroller);
_options.disabled !== undefined && (disabled = _options.disabled);
$headings = $(container).find(selectors);
+ $scrollTarget = $(scrollTarget);
+ $scroller = $(scroller);
calc();
}
function calc() {
headingsPos = [];
$headings.each(function() {
- headingsPos.push(Math.floor($(this).offset().top));
+ headingsPos.push(Math.floor($(this).position().top));
});
}
function setState(element, disabled) {
- var scrollTop = $window.scrollTop(), i;
+ var scrollTop = $scroller.scrollTop(), i;
if (disabled || !headingsPos || headingsPos.length < 1) { return; }
if (element) {
$activeCur = element;
@@ -50,7 +54,7 @@
var $this = $(this);
scrolling = true;
setState($this.parent());
- window.scrollTopAnchor($this.attr('href'), function() {
+ $scroller.scrollToAnchor($this.attr('href'), 400, function() {
scrolling = false;
});
});
@@ -72,7 +76,7 @@
clearInterval(interval);
clearTimeout(timeout);
});
- $window.on('scroll', function() {
+ $scrollTarget.on('scroll', function() {
disabled || setState(null, scrolling);
});
$window.on('resize', window.throttle(function() {
diff --git a/_includes/scripts/page-post-common.js b/_includes/scripts/page-post-common.js
index 0e25e3f0b63..fd63522411c 100644
--- a/_includes/scripts/page-post-common.js
+++ b/_includes/scripts/page-post-common.js
@@ -1,18 +1,10 @@
(function() {
var SOURCES = window.TEXT_VARIABLES.sources;
- function scrollAnimateTo(destination, duration, callback) {
- var $body = $('html, body'), bodyScrollTop = $body.scrollTop();
- if(bodyScrollTop === destination) { return; }
- $body.animate({ scrollTop: destination }, duration, callback);
- }
- window.scrollTopAnchor = function(anchor, callback) {
- scrollAnimateTo($(anchor).offset().top, 400, function() {
- window.history.replaceState(null, '', window.location.href.split('#')[0] + anchor);
- callback && callback();
- });
- };
window.Lazyload.js(SOURCES.jquery, function() {
- var $articleContent = $('.article-content'), $this;
+ var $this, $articleContent = $('.article-content'), $scroll;
+ var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
+ var scroll = hasSidebar ? '.js-page-main' : 'html, body';
+ $scroll = $(scroll);
$articleContent.children('.highlight').each(function() {
$this = $(this);
$this.attr('data-lang', $this.find('code').attr('data-lang'));
@@ -23,7 +15,7 @@
$this.append($('').html(''));
});
$articleContent.on('click', '.anchor', function() {
- window.scrollTopAnchor('#' + $(this).parent().attr('id'));
+ $scroll.scrollToAnchor('#' + $(this).parent().attr('id'), 400);
});
});
})();
\ No newline at end of file
diff --git a/_includes/scripts/post.js b/_includes/scripts/post.js
index db1bea3ec55..95aaf789309 100644
--- a/_includes/scripts/post.js
+++ b/_includes/scripts/post.js
@@ -10,6 +10,7 @@
var $tocRoot = $('.js-toc-root');
var $col2 = $('.js-col-2');
var toc, affix;
+ var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
var hasToc = $articleContent.find(TOC_SELECTOR).length > 0;
var tocDisabled = false;
@@ -36,10 +37,15 @@
toc = $tocRoot.toc({
selectors: TOC_SELECTOR,
container: $articleContent,
+ scrollTarget: hasSidebar ? '.js-page-main' : null,
+ scroller: hasSidebar ? '.js-page-main' : null,
disabled: tocDisabled
});
affix = $articleAside.affix({
offsetBottom: $pageFooter.outerHeight(),
+ scrollTarget: hasSidebar ? '.js-page-main' : null,
+ scroller: hasSidebar ? '.js-page-main' : null,
+ scroll: hasSidebar ? $('.js-page-main').children() : null,
disabled: tocDisabled
});
}, 1000);
diff --git a/_includes/scripts/utils.js b/_includes/scripts/utils.js
index 6c9cc724648..368f1d15058 100644
--- a/_includes/scripts/utils.js
+++ b/_includes/scripts/utils.js
@@ -10,10 +10,15 @@
return str ? decodeURIComponent(str.replace(/\+/g, '%20')) : '';
};
+
window.hasEvent = function(event) {
return 'on'.concat(event) in window.document;
};
+ window.isOverallScroller = function(node) {
+ return node === document.documentElement || node === document.body;
+ };
+
window.pageLoad = (function () {
var loaded = false, cbs = [];
window.addEventListener('load', function () {
diff --git a/_layouts/page-1.html b/_layouts/page-1.html
new file mode 100644
index 00000000000..40b22664b4a
--- /dev/null
+++ b/_layouts/page-1.html
@@ -0,0 +1,86 @@
+
+{%- include snippets/get-lang.html -%}
+
+
+ {%- include head.html -%}
+
+ {%- include scripts/variables.html -%}
+
+
+ {%- if page.sidebar -%}
+