提交 e0038f5c 编写于 作者: S Samy Pessé 提交者: GitHub

Merge pull request #32 from GitbookIO/fix-anchors

Fix anchors scrolling
......@@ -8,17 +8,17 @@
},
"dependencies": {},
"devDependencies": {
"browserify": "13.0.0",
"eslint": "2.7.0",
"font-awesome": "4.5.0",
"browserify": "13.1.0",
"eslint": "3.6.1",
"font-awesome": "4.6.3",
"preboot": "git+https://github.com/mdo/preboot.git#4aab4edd85f076d50609cbe28e4fe66cc0771701",
"gitbook-logos": "git+https://github.com/GitbookIO/logos.git#2.0.2",
"gitbook-markdown-css": "1.0.1",
"jquery": "2.1.4",
"less": "2.6.0",
"jquery": "3.1.1",
"less": "2.7.1",
"less-plugin-clean-css": "1.5.1",
"mousetrap": "1.5.3",
"uglify-js": "2.6.1"
"mousetrap": "1.6.0",
"uglify-js": "2.7.3"
},
"scripts": {
"prepublish": "./src/build.sh"
......
......@@ -98,10 +98,17 @@ function setChapterActive($chapter, hash) {
// If hash is provided, set as active chapter
if (!!hash) {
$chapter = $chapters.filter(function() {
var titleId = getChapterHash($(this));
return titleId == hash;
}).first();
// Multiple chapters for this file
if ($chapters.length > 1) {
$chapter = $chapters.filter(function() {
var titleId = getChapterHash($(this));
return titleId == hash;
}).first();
}
// Only one chapter, no need to search
else {
$chapter = $chapters.first();
}
}
// Don't update current chapter
......@@ -324,9 +331,13 @@ function preparePage(resetScroll) {
// Focus on content
$pageWrapper.focus();
// Get scroller
var $scroller = getScroller();
// Reset scroll
if (resetScroll !== false) $bookInner.scrollTop(0);
$bookBody.scrollTop(0);
if (resetScroll !== false) {
$scroller.scrollTop(0);
}
// Get current page summary chapters
$chapters = $('.book-summary .summary .chapter')
......@@ -347,10 +358,13 @@ function preparePage(resetScroll) {
});
// Bind scrolling if summary contains more than one link to this page
var $scroller = getScroller();
if ($chapters.length > 1) {
$scroller.scroll(handleScrolling);
}
// Else, set only chapter in summary as active
else {
$activeChapter = $chapters.first();
}
}
function isLeftClickEvent(e) {
......@@ -417,7 +431,7 @@ function init() {
$(window).resize(updateNavigationPosition);
// Prepare current page
preparePage();
preparePage(false);
}
module.exports = {
......
......@@ -13,7 +13,7 @@ function generateId() {
// Insert a jquery element at a specific position
function insertAt(parent, selector, index, element) {
var lastIndex = parent.children(selector).size();
var lastIndex = parent.children(selector).length;
if (index < 0) {
index = Math.max(0, lastIndex + 1 + index);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册