mirror of
https://github.com/duguosheng/6.S081-All-in-one.git
synced 2026-07-10 22:46:17 +08:00
修改结构
This commit is contained in:
29
docs/gitbook/gitbook-plugin-chapter-fold/chapter-fold.css
Normal file
29
docs/gitbook/gitbook-plugin-chapter-fold/chapter-fold.css
Normal file
@@ -0,0 +1,29 @@
|
||||
.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";
|
||||
}
|
||||
|
||||
67
docs/gitbook/gitbook-plugin-chapter-fold/chapter-fold.js
Normal file
67
docs/gitbook/gitbook-plugin-chapter-fold/chapter-fold.js
Normal file
@@ -0,0 +1,67 @@
|
||||
require(['gitbook', 'jQuery'], function(gitbook, $) {
|
||||
var TOGGLE_CLASSNAME = 'expanded',
|
||||
CHAPTER = '.chapter',
|
||||
ARTICLES = '.articles',
|
||||
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 chapterLink = $(ARTICLES).parent(CHAPTER).children('a');
|
||||
chapterLink.append($(TRIGGER_TEMPLATE));
|
||||
chapterLink.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
//e.stopPropagation();
|
||||
toggle($(e.target).closest(CHAPTER));
|
||||
});
|
||||
|
||||
expand(lsItem());
|
||||
//expand current selected chapter with it's parents
|
||||
collapse($(CHAPTER));
|
||||
var activeChapter = $(CHAPTER + '.active');
|
||||
expand(activeChapter);
|
||||
expand(activeChapter.parents(CHAPTER));
|
||||
}
|
||||
//on page.change will happend the function.
|
||||
|
||||
var toggle = function ($chapter) {
|
||||
if ($chapter.hasClass('expanded')) {
|
||||
collapse($chapter);
|
||||
} else {
|
||||
expand($chapter);
|
||||
//$chapter.addClass('active').siblings().removeClass('active');
|
||||
}
|
||||
}
|
||||
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()
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user