Skip to content

Commit 703c478

Browse files
committed
Remove the unused chapter-fold, add expandable-chapter plugin.
Resolves sighingnow#112. Signed-off-by: Tao He <sighingnow@gmail.com>
1 parent c00e400 commit 703c478

8 files changed

Lines changed: 309 additions & 104 deletions

File tree

_includes/footer.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<script src="{{site.baseurl}}/assets/gitbook/gitbook.js"></script>
22
<script src="{{site.baseurl}}/assets/gitbook/theme.js"></script>
33

4+
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
5+
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
6+
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-expandable-chapters-small2/expandable-chapters-small.js"></script>
47
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
8+
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
9+
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/search.js"></script>
510
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-sharing/buttons.js"></script>
11+
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-splitter/splitter.js"></script>
612

7-
<!-- <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
13+
<!--
14+
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
815
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
916
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
10-
<script src="../gitbook/gitbook-plugin-search/search.js"></script> -->
11-
12-
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
13-
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/search.js"></script>
14-
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
15-
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
17+
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
18+
-->
1619

1720
{% if site.extra_footer_js %}
1821
{%- for extra_js in site.extra_header_js -%}

_includes/head.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
{%- endif -%}
2222

2323
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/style.css">
24+
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-back-to-top-button/plugin.css">
25+
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-expandable-chapters-small2/expandable-chapters-small.css">
2426
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-fontsettings/website.css">
2527
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/search.css">
26-
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-back-to-top-button/plugin.css">
28+
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-splitter/splitter.css">
2729

2830
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/rouge/{{ site.syntax_highlighter_style | default: 'colorful' }}.css">
2931

_includes/metadata.json.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"website": "styles/website.css"
1010
},
1111
"pluginsConfig": {
12+
"expandable-chapter-small2": {
13+
"articlesExpand": true,
14+
},
1215
"fontsettings": {
1316
"family": "sans",
1417
"size": 2,
@@ -34,7 +37,7 @@
3437
"print": "styles/print.css",
3538
"website": "styles/website.css"
3639
}
37-
}
40+
},
3841
},
3942
"theme": "default",
4043
"author": "Tao He",

assets/gitbook/gitbook-plugin-chapter-fold/chapter-fold.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

assets/gitbook/gitbook-plugin-chapter-fold/chapter-fold.css renamed to assets/gitbook/gitbook-plugin-expandable-chapters-small2/expandable-chapters-small.css

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1-
.book .book-summary .chapter > .articles {
2-
overflow: hidden;
3-
max-height: 0px;
4-
}
5-
6-
.book .book-summary .chapter.expanded > .articles {
7-
max-height: 9999px;
8-
}
9-
10-
.book .book-summary .exc-trigger {
11-
position: absolute;
12-
left: 12px;
13-
top: 12px;
14-
}
15-
16-
.book .book-summary ul.summary li a,
17-
.book .book-summary ul.summary li span {
18-
padding-left: 30px;
19-
}
20-
21-
.book .book-summary .exc-trigger:before {
22-
content: "\f105";
23-
}
24-
25-
.book .book-summary .expanded > a .exc-trigger:before,
26-
.book .book-summary .expanded > span .exc-trigger:before {
27-
content: "\f107";
28-
}
1+
/* .book .book-summary .chapter > .articles { */
2+
.book .book-summary .chapter ul {
3+
overflow: hidden;
4+
max-height: 0px;
5+
}
6+
7+
.book .book-summary .chapter li ul {
8+
overflow: hidden;
9+
max-height: 0px !important;
10+
}
11+
12+
/* .book .book-summary .chapter.expanded > .articles { */
13+
.book .book-summary .chapter.expanded ul {
14+
max-height: 9999px;
15+
}
16+
17+
.book .book-summary .chapter.expanded li.expanded ul {
18+
max-height: 9999px !important;
19+
}
20+
21+
.book .book-summary .exc-trigger {
22+
position: absolute;
23+
left: 12px;
24+
top: 12px;
25+
}
26+
27+
.book .book-summary ul.summary li a,
28+
.book .book-summary ul.summary li span {
29+
padding-left: 30px;
30+
}
31+
32+
.book .book-summary .exc-trigger:before {
33+
content: "\f105";
34+
}
35+
36+
.book .book-summary .expanded > a .exc-trigger:before,
37+
.book .book-summary .expanded > span .exc-trigger:before {
38+
content: "\f107";
39+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
require(['gitbook', 'jQuery'], function (gitbook, $) {
2+
var PLUGIN = 'expandable-chapter-small2',
3+
TOGGLE_CLASSNAME = 'expanded',
4+
CHAPTER = '.chapter',
5+
// ARTICLES = '.articles',
6+
ARTICLES = '.chapter ul',
7+
FOLDABLE = '.chapter, .chapter li',
8+
ARTICLE_CHILDREN = 'ul',
9+
TRIGGER_TEMPLATE = '<i class="exc-trigger fa"></i>',
10+
LS_NAMESPACE = 'expChapters';
11+
12+
var init = function () {
13+
// adding the trigger element to each ARTICLES parent and binding the event
14+
var config = gitbook.state.config.pluginsConfig || {};
15+
var articlesExpand = false;
16+
if (config && config[PLUGIN]) {
17+
articlesExpand = config[PLUGIN].articlesExpand || false;
18+
}
19+
if (articlesExpand) {
20+
$(ARTICLES)
21+
.parent(CHAPTER)
22+
.find(ARTICLE_CHILDREN)
23+
.prev()
24+
.css('cursor', 'pointer')
25+
.on('click', function (e) {
26+
e.preventDefault();
27+
e.stopPropagation();
28+
toggle($(e.target).closest(FOLDABLE));
29+
})
30+
.append(TRIGGER_TEMPLATE);
31+
} else {
32+
$(ARTICLES)
33+
.parent(CHAPTER)
34+
.find(ARTICLE_CHILDREN)
35+
.prev()
36+
.append(
37+
$(TRIGGER_TEMPLATE)
38+
.on('click', function (e) {
39+
e.preventDefault();
40+
e.stopPropagation();
41+
toggle($(e.target).closest(FOLDABLE));
42+
})
43+
);
44+
}
45+
expand(lsItem());
46+
47+
// expand current selected chapter with it's parents
48+
var activeChapter = $(CHAPTER + '.active');
49+
expand(activeChapter);
50+
51+
// expand current selected chapter's children
52+
// expand(activeChapter.parents(CHAPTER));
53+
activeChapter.find(ARTICLE_CHILDREN).closest(FOLDABLE).each(function () {
54+
expand($(this));
55+
});
56+
}
57+
58+
var toggle = function ($chapter) {
59+
if ($chapter.hasClass('expanded')) {
60+
collapse($chapter);
61+
} else {
62+
expand($chapter);
63+
}
64+
}
65+
66+
var collapse = function ($chapter) {
67+
if ($chapter.length && $chapter.hasClass(TOGGLE_CLASSNAME)) {
68+
$chapter.removeClass(TOGGLE_CLASSNAME);
69+
lsItem($chapter);
70+
}
71+
}
72+
73+
var expand = function ($chapter) {
74+
if ($chapter.length && !$chapter.hasClass(TOGGLE_CLASSNAME)) {
75+
$chapter.addClass(TOGGLE_CLASSNAME);
76+
lsItem($chapter);
77+
}
78+
}
79+
80+
var lsItem = function () {
81+
var map = JSON.parse(localStorage.getItem(LS_NAMESPACE)) || {}
82+
if (arguments.length) {
83+
var $chapters = arguments[0];
84+
$chapters.each(function (index, element) {
85+
var level = $(this).data('level');
86+
var value = $(this).hasClass(TOGGLE_CLASSNAME);
87+
map[level] = value;
88+
})
89+
localStorage.setItem(LS_NAMESPACE, JSON.stringify(map));
90+
} else {
91+
return $(CHAPTER).map(function (index, element) {
92+
if (map[$(this).data('level')]) {
93+
return this;
94+
}
95+
})
96+
}
97+
}
98+
99+
gitbook.events.bind('page.change', function () {
100+
init()
101+
});
102+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.divider-content-summary {
2+
position: absolute;
3+
top: 0;
4+
right: 0;
5+
height: 100%;
6+
width: 5px;
7+
display: table;
8+
cursor: col-resize;
9+
color: #ccc;
10+
-webkit-transition: color 350ms ease;
11+
-moz-transition: color 350ms ease;
12+
-o-transition: color 350ms ease;
13+
transition: color 350ms ease
14+
}
15+
16+
.divider-content-summary:hover {
17+
color: #444;
18+
}
19+
20+
.divider-content-summary__icon {
21+
display: table-cell;
22+
vertical-align: middle;
23+
text-align: center;
24+
}

0 commit comments

Comments
 (0)