Skip to content

Commit

Permalink
Remove the unused chapter-fold, add expandable-chapter plugin.
Browse files Browse the repository at this point in the history
Resolves #112.

Signed-off-by: Tao He <[email protected]>
  • Loading branch information
sighingnow committed Dec 21, 2023
1 parent c00e400 commit 703c478
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 104 deletions.
17 changes: 10 additions & 7 deletions _includes/footer.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<script src="{{site.baseurl}}/assets/gitbook/gitbook.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/theme.js"></script>

<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-expandable-chapters-small2/expandable-chapters-small.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/search.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-splitter/splitter.js"></script>

<!-- <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<!--
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script> -->

<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/search.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
<script src="{{site.baseurl}}/assets/gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
-->

{% if site.extra_footer_js %}
{%- for extra_js in site.extra_header_js -%}
Expand Down
4 changes: 3 additions & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
{%- endif -%}

<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/style.css">
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-back-to-top-button/plugin.css">
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-expandable-chapters-small2/expandable-chapters-small.css">
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-search-pro/search.css">
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-back-to-top-button/plugin.css">
<link rel="stylesheet" href="{{site.baseurl}}/assets/gitbook/gitbook-plugin-splitter/splitter.css">

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

Expand Down
5 changes: 4 additions & 1 deletion _includes/metadata.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"website": "styles/website.css"
},
"pluginsConfig": {
"expandable-chapter-small2": {
"articlesExpand": true,
},
"fontsettings": {
"family": "sans",
"size": 2,
Expand All @@ -34,7 +37,7 @@
"print": "styles/print.css",
"website": "styles/website.css"
}
}
},
},
"theme": "default",
"author": "Tao He",
Expand Down
67 changes: 0 additions & 67 deletions assets/gitbook/gitbook-plugin-chapter-fold/chapter-fold.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
.book .book-summary .chapter > .articles {
overflow: hidden;
max-height: 0px;
}

.book .book-summary .chapter.expanded > .articles {
max-height: 9999px;
}

.book .book-summary .exc-trigger {
position: absolute;
left: 12px;
top: 12px;
}

.book .book-summary ul.summary li a,
.book .book-summary ul.summary li span {
padding-left: 30px;
}

.book .book-summary .exc-trigger:before {
content: "\f105";
}

.book .book-summary .expanded > a .exc-trigger:before,
.book .book-summary .expanded > span .exc-trigger:before {
content: "\f107";
}
/* .book .book-summary .chapter > .articles { */
.book .book-summary .chapter ul {
overflow: hidden;
max-height: 0px;
}

.book .book-summary .chapter li ul {
overflow: hidden;
max-height: 0px !important;
}

/* .book .book-summary .chapter.expanded > .articles { */
.book .book-summary .chapter.expanded ul {
max-height: 9999px;
}

.book .book-summary .chapter.expanded li.expanded ul {
max-height: 9999px !important;
}

.book .book-summary .exc-trigger {
position: absolute;
left: 12px;
top: 12px;
}

.book .book-summary ul.summary li a,
.book .book-summary ul.summary li span {
padding-left: 30px;
}

.book .book-summary .exc-trigger:before {
content: "\f105";
}

.book .book-summary .expanded > a .exc-trigger:before,
.book .book-summary .expanded > span .exc-trigger:before {
content: "\f107";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
require(['gitbook', 'jQuery'], function (gitbook, $) {
var PLUGIN = 'expandable-chapter-small2',
TOGGLE_CLASSNAME = 'expanded',
CHAPTER = '.chapter',
// ARTICLES = '.articles',
ARTICLES = '.chapter ul',
FOLDABLE = '.chapter, .chapter li',
ARTICLE_CHILDREN = 'ul',
TRIGGER_TEMPLATE = '<i class="exc-trigger fa"></i>',
LS_NAMESPACE = 'expChapters';

var init = function () {
// adding the trigger element to each ARTICLES parent and binding the event
var config = gitbook.state.config.pluginsConfig || {};
var articlesExpand = false;
if (config && config[PLUGIN]) {
articlesExpand = config[PLUGIN].articlesExpand || false;
}
if (articlesExpand) {
$(ARTICLES)
.parent(CHAPTER)
.find(ARTICLE_CHILDREN)
.prev()
.css('cursor', 'pointer')
.on('click', function (e) {
e.preventDefault();
e.stopPropagation();
toggle($(e.target).closest(FOLDABLE));
})
.append(TRIGGER_TEMPLATE);
} else {
$(ARTICLES)
.parent(CHAPTER)
.find(ARTICLE_CHILDREN)
.prev()
.append(
$(TRIGGER_TEMPLATE)
.on('click', function (e) {
e.preventDefault();
e.stopPropagation();
toggle($(e.target).closest(FOLDABLE));
})
);
}
expand(lsItem());

// expand current selected chapter with it's parents
var activeChapter = $(CHAPTER + '.active');
expand(activeChapter);

// expand current selected chapter's children
// expand(activeChapter.parents(CHAPTER));
activeChapter.find(ARTICLE_CHILDREN).closest(FOLDABLE).each(function () {
expand($(this));
});
}

var toggle = function ($chapter) {
if ($chapter.hasClass('expanded')) {
collapse($chapter);
} else {
expand($chapter);
}
}

var collapse = function ($chapter) {
if ($chapter.length && $chapter.hasClass(TOGGLE_CLASSNAME)) {
$chapter.removeClass(TOGGLE_CLASSNAME);
lsItem($chapter);
}
}

var expand = function ($chapter) {
if ($chapter.length && !$chapter.hasClass(TOGGLE_CLASSNAME)) {
$chapter.addClass(TOGGLE_CLASSNAME);
lsItem($chapter);
}
}

var lsItem = function () {
var map = JSON.parse(localStorage.getItem(LS_NAMESPACE)) || {}
if (arguments.length) {
var $chapters = arguments[0];
$chapters.each(function (index, element) {
var level = $(this).data('level');
var value = $(this).hasClass(TOGGLE_CLASSNAME);
map[level] = value;
})
localStorage.setItem(LS_NAMESPACE, JSON.stringify(map));
} else {
return $(CHAPTER).map(function (index, element) {
if (map[$(this).data('level')]) {
return this;
}
})
}
}

gitbook.events.bind('page.change', function () {
init()
});
});
24 changes: 24 additions & 0 deletions assets/gitbook/gitbook-plugin-splitter/splitter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.divider-content-summary {
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 5px;
display: table;
cursor: col-resize;
color: #ccc;
-webkit-transition: color 350ms ease;
-moz-transition: color 350ms ease;
-o-transition: color 350ms ease;
transition: color 350ms ease
}

.divider-content-summary:hover {
color: #444;
}

.divider-content-summary__icon {
display: table-cell;
vertical-align: middle;
text-align: center;
}
Loading

0 comments on commit 703c478

Please sign in to comment.