Skip to content

Commit b043735

Browse files
author
zjtang
committed
add affix toc
1 parent 24881a4 commit b043735

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

Diff for: static/css/myaffix.css

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.sidebar-toc.affix {
2+
position: fixed;
3+
top: 10px;
4+
margin-left: 0;
5+
border-left:1px solid #ddd;
6+
padding-left:0;
7+
margin-top:0;
8+
word-wrap:break-word;
9+
color:#6e7173;
10+
line-height:2.7;
11+
font-size:16px;
12+
display:block;
13+
font-weight:400;
14+
}
15+
16+
.sidebar-toc.affix-top {
17+
border-left: none;
18+
color:#6e7173;
19+
line-height:2.7;
20+
font-size:16px;
21+
display:block;
22+
font-weight:400;
23+
overflow: hidden;
24+
padding-left: 0;
25+
margin-top: 10px;
26+
}
27+
28+
#sidebar-toc{
29+
padding: 0;
30+
margin-bottom: 20px;
31+
}
32+
33+
.markdown-toc.editormd-markdown-toc {
34+
margin: 0;
35+
max-height: inherit;
36+
}
37+
38+
ul.markdown-toc-list {
39+
margin: 0;
40+
max-height: inherit;
41+
}
42+
43+
li, ul, ol{
44+
list-style:none;
45+
margin-left:-5px;
46+
}

Diff for: templates/blogging/base.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
{% block extrastyle %}
2929
{% endblock extrastyle %}
3030
</head>
31-
<body>
32-
<div class="body_container">
31+
<body style="background:#f7f8fa">
32+
<div class="body_container" style="background:white">
3333
<div id="header">
3434
<div class="site-name">
3535
<h1 class="hidden">ezBlog</h1>
@@ -44,7 +44,7 @@ <h1 class="hidden">ezBlog</h1>
4444
{% with messages = get_flashed_messages(with_categories=true) %}
4545
{% if messages %}
4646
{% for category, message in messages %}
47-
<div class="pure-u-1">
47+
<div class="pure-u-1 pure-u-md-3-4">
4848
<div class="content_container">
4949
<div class="alert alert-{{ category }} alert-dismissible" style="text-align:center;margin-left:30%;margin-right:30%">
5050
<button type="button" class="close" data-dismiss="alert">&times;</button>
@@ -62,7 +62,7 @@ <h1 class="hidden">ezBlog</h1>
6262
{% endblock sidebar %}
6363
<div class="pure-u-1">
6464
<br />
65-
<div id="footer">
65+
<div id="footer" class="pure-u-1 pure-u-md-3-4">
6666
Copyright © 2018
6767
<a href="{{url_for("blogging.about")}}" rel="nofollow" style="color:gray">{{config.BLOGGING_AUTHOR}}</a>
6868
| Powered by

Diff for: templates/blogging/login.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{% endblock navmenu %}
2020

2121
{% block post %}
22-
<div class="pure-u-1">
22+
<div class="pure-u-1 pure-u-md-3-4">
2323
<div class="content_container">
2424
<div class="content-wrap">
2525
<div id="content" class="content">

Diff for: templates/blogging/page.html

+23-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
{% block extrastyle %}
1212
<!--link rel="stylesheet" href="/static/libs/editor.md/css/style.css" /-->
1313
<link rel="stylesheet" href="/static/libs/editor.md/css/editormd.preview.css" />
14+
<link rel="stylesheet" href="/static/css/myaffix.css" />
1415
{% endblock extrastyle %}
1516

1617
{% block navmenu %}
@@ -126,12 +127,12 @@ <h1 class="post-title">
126127
<a href="{{link.link}}" title="{{link.name}}" target="_blank">{{link.name}}</a>
127128
{% endfor %}
128129
</div>
129-
<div class="widget" style="margin-bottom:10px">
130+
<div class="sidebar-toc" style="border:1px solid #ddd">
130131
<div class="widget-title">
131132
<i class="fa fa-list">目录</i>
132133
</div>
133-
</div>
134-
<div style="padding:0" class="markdown-body editormd-preview-container" id="sidebar-toc">
134+
<div style="padding-left:0" class="markdown-body editormd-preview-container" id="sidebar-toc">
135+
</div>
135136
</div>
136137
</div>
137138
</div>
@@ -147,6 +148,8 @@ <h1 class="post-title">
147148
<script src="/static/libs/editor.md/lib/flowchart.min.js"></script>
148149
<script src="/static/libs/editor.md/lib/jquery.flowchart.min.js"></script>
149150
<script src="/static/libs/editor.md/js/editormd.min.js"></script>
151+
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js">
152+
</script>
150153
<script type="text/javascript">
151154
var viewEditor;
152155
$(function(){
@@ -166,6 +169,23 @@ <h1 class="post-title">
166169
});
167170
});
168171
</script>
172+
<script type="text/javascript">
173+
var tocTop = $(".sidebar-toc").offset().top;
174+
var sidebarwid = document.getElementsByClassName("widget")[0].clientWidth;
175+
document.getElementById("sidebar-toc").style.width = sidebarwid+'px';
176+
window.addEventListener("resize", winresize);
177+
var docheight = document.documentElement.clientHeight;
178+
document.getElementById("sidebar-toc").style.maxHeight = docheight*0.7+'px';
179+
function winresize(){
180+
var docheight = document.documentElement.clientHeight;
181+
document.getElementById("sidebar-toc").style.maxHeight = docheight*0.7+'px';
182+
}
183+
$('.sidebar-toc').affix({
184+
offset: {
185+
top: tocTop,
186+
}
187+
});
188+
</script>
169189
<script type="text/javascript">
170190
function confirmDelete(url_str){
171191
var url_to_delete = window.location.protocol+'//'+window.location.host+url_str;

0 commit comments

Comments
 (0)