Skip to content

Commit f56d1e2

Browse files
make search bar fixed
1 parent 1332c29 commit f56d1e2

File tree

7 files changed

+52
-36
lines changed

7 files changed

+52
-36
lines changed

source/_data/navigation-zh-cn.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
home:
3-
- title: 快速开始
3+
- title: 快速上手
44
link: zh-cn/quick-start.html
55
color: purple
66
icon: flash

source/zh-cn/quick-start.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: 快速开始
2+
title: 快速上手
33
lang: zh-cn
44
related_path: en/quick-start.html
55
---
66

7-
# 快速开始
7+
# 快速上手
88

99
Ktorm 已经发布到 maven 中央仓库,因此,如果你使用 maven 的话,只需要在 `pom.xml` 文件里面添加一个依赖:
1010

themes/doc/lib/browser/navigation/components.jsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ class Sidebar extends React.Component {
2929

3030
componentDidUpdate() {
3131
if (this.props.visibleHeaderId) {
32-
setTimeout(function () {
33-
const $sidebar = $('.doc-sidebar');
34-
const $firstItem = $($('.doc-sidebar-list').children('li').get(0));
35-
const $currentItem = $('.doc-sidebar-list__item--current');
32+
if ($(window).width() > 800) {
33+
setTimeout(function () {
34+
const $sidebar = $('.doc-sidebar');
35+
const $firstItem = $($('.doc-sidebar-list').children('.doc-sidebar-list__item--link').get(0));
36+
const $currentItem = $('.doc-sidebar-list__item--current');
3637

37-
if ($currentItem.length > 0) {
38-
$sidebar.animate({scrollTop: $currentItem.position().top - $firstItem.position().top}, 800);
39-
}
40-
}, 100);
38+
if ($currentItem.length > 0) {
39+
const offset = $currentItem.position().top - $firstItem.position().top;
40+
if (offset > 100) {
41+
$sidebar.animate({ scrollTop: offset }, 800);
42+
}
43+
}
44+
}, 100);
45+
}
4146
}
4247
}
4348

themes/doc/lib/browser/navigation/containers.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Navigation extends React.Component {
177177
}
178178

179179
onContentClick () {
180-
if ( this.$body.hasClass(SIDEBAR_IS_VISIBLE_CLASS) ) {
180+
if (this.$body.hasClass(SIDEBAR_IS_VISIBLE_CLASS)) {
181181
this.toggleSidebar();
182182
}
183183
}
@@ -192,7 +192,7 @@ class Navigation extends React.Component {
192192

193193
uncollapseSidebar () {
194194
this.$body.removeClass(NAVIGATION_IS_COLLAPSED_CLASS);
195-
this.$searchFormInput().focus();
195+
this.$searchFormInput()[0].focus();
196196

197197
if (window.localStorage) {
198198
window.localStorage.setItem('navigation_collapsed', 'false');
@@ -201,6 +201,10 @@ class Navigation extends React.Component {
201201

202202
toggleSidebar () {
203203
this.$body.toggleClass(SIDEBAR_IS_VISIBLE_CLASS);
204+
205+
if (this.$body.hasClass(SIDEBAR_IS_VISIBLE_CLASS)) {
206+
this.$searchFormInput()[0].focus();
207+
}
204208
}
205209

206210
hideSidebar () {

themes/doc/lib/browser/support/components.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
const React = require('react');
22

33
module.exports.SupportFooter = function ({page, data, url_for}) {
4-
var navigation = null;
4+
let navigation;
55
if (page.lang === 'zh-cn') {
66
navigation = data['navigation-zh-cn'].main.filter((item) => item.type === 'link');
77
} else {
88
navigation = data['navigation-en'].main.filter((item) => item.type === 'link');
99
}
1010

1111
function renderLinks() {
12-
var links = [];
13-
var currentIndex = navigation.map((item) => item.path).indexOf(page.path.replace('index.html', ''));
12+
const links = [];
13+
const currentIndex = navigation.findIndex((item) => {
14+
const itemPath = (item.path || '').replace(/index\.html$/, '').replace(/\/$/, '');
15+
const pagePath = (page.path || '').replace(/index\.html$/, '').replace(/\/$/, '');
16+
return itemPath === pagePath;
17+
});
1418

1519
if (currentIndex !== -1 && currentIndex !== 0) {
16-
var previous = navigation[currentIndex - 1];
20+
const previous = navigation[currentIndex - 1];
1721
links.push(
1822
<div className="doc-footer-link" key={previous.path}>
1923
{page.lang === 'zh-cn' ? '上一篇:' : 'Prev Article: '}
@@ -25,7 +29,7 @@ module.exports.SupportFooter = function ({page, data, url_for}) {
2529
}
2630

2731
if (currentIndex !== -1 && currentIndex !== navigation.length - 1) {
28-
var next = navigation[currentIndex + 1];
32+
const next = navigation[currentIndex + 1];
2933
links.push(
3034
<div className="doc-footer-link" key={next.path}>
3135
{page.lang === 'zh-cn' ? '下一篇:' : 'Next Article: '}
@@ -50,7 +54,7 @@ module.exports.SupportFooter = function ({page, data, url_for}) {
5054
return (
5155
<div className="doc-support-footer">
5256
{renderLinks()}
53-
Any questions about the document? Try searching again on the left menu or <a href="https://github.com/kotlin-orm/ktorm/issues/new">Raise an issue on Github</a>
57+
Any questions about the document? Try searching again on the left menu or <a href="https://github.com/kotlin-orm/ktorm/issues/new">raise an issue on GitHub</a>
5458
</div>
5559
);
5660
}

themes/doc/source/style/_doc/navigation.scss

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@
2525
width: $doc-sidebar-width;
2626
}
2727

28-
.doc-search-form {
29-
margin-top: 0.7rem;
30-
margin-bottom: 0rem;
31-
margin-left: auto;
32-
33-
@media screen and (min-width: $doc-breakpoint) {
34-
display: none
35-
}
36-
}
37-
3828
&__logo {
3929
flex-grow: 1;
4030
display: flex;
@@ -84,7 +74,7 @@
8474

8575
&__sidebar-toggle {
8676
line-height: $doc-navbar-height;
87-
font-size:2rem;
77+
font-size: 2rem;
8878
height: 100%;
8979
display: inline-block;
9080
vertical-align: middle;
@@ -178,18 +168,31 @@
178168
}
179169

180170
&__search-form {
181-
height: 36px;
182-
width: 100%;
183-
margin: 24px 0 0 22px;
171+
width: $doc-sidebar-width;
172+
background-color: white;
184173

185-
@media screen and (max-width: $doc-breakpoint) {
186-
display: none;
174+
@media screen and (min-width: $doc-breakpoint) {
175+
position: fixed;
176+
left: 0;
177+
top: 50px;
178+
z-index: 3;
179+
}
180+
181+
.doc-search-form {
182+
margin: 15px 22px;
183+
width: 236px;
184+
height: 36px;
187185
}
188186
}
189187
}
190188

191189
.doc-sidebar-list {
192190
padding-left: 0px;
191+
margin-top: -10px;
192+
193+
@media screen and (min-width: $doc-breakpoint) {
194+
margin-top: 66px;
195+
}
193196

194197
&__item {
195198
margin-left: 34px;

themes/doc/source/style/_doc/search.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.doc-search-form {
2-
width: 236px;
2+
max-width: 236px;
33

44
&__input[type="search"] {
55
width: 100%;

0 commit comments

Comments
 (0)