Mark chapter as selected as long as the next chapter is not reached Fixes #3817
Also adds a colour to the selected chapter, to make it more clear
This commit is contained in:
parent
db0f1dae86
commit
3fabf9e658
3 changed files with 30 additions and 3 deletions
|
|
@ -17,12 +17,12 @@
|
||||||
} @else {
|
} @else {
|
||||||
@for (chapterGroup of chapters; track chapterGroup.title + chapterGroup.children.length) {
|
@for (chapterGroup of chapters; track chapterGroup.title + chapterGroup.children.length) {
|
||||||
<ul class="chapter-title">
|
<ul class="chapter-title">
|
||||||
<li class="{{chapterGroup.page === pageNum ? 'active': ''}}" (click)="loadChapterPage(chapterGroup.page, '')">
|
<li class="{{isChapterSelected(chapterGroup) ? 'active': ''}}" (click)="loadChapterPage(chapterGroup.page, '')">
|
||||||
{{chapterGroup.title}}
|
{{chapterGroup.title}}
|
||||||
</li>
|
</li>
|
||||||
@for(chapter of chapterGroup.children; track chapter.title + chapter.part) {
|
@for(chapter of chapterGroup.children; track chapter.title + chapter.part) {
|
||||||
<ul>
|
<ul>
|
||||||
<li class="{{cleanIdSelector(chapter.part) === currentPageAnchor ? 'active' : ''}}">
|
<li class="{{isAnchorSelected(chapter) ? 'active' : ''}}">
|
||||||
<a href="javascript:void(0);" (click)="loadChapterPage(chapter.page, chapter.part)">{{chapter.title}}</a>
|
<a href="javascript:void(0);" (click)="loadChapterPage(chapter.page, chapter.part)">{{chapter.title}}</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
color: var(--primary-color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.chapter-title {
|
.chapter-title {
|
||||||
padding-inline-start: 1rem;
|
padding-inline-start: 1rem;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,4 +47,30 @@ export class TableOfContentsComponent implements OnChanges {
|
||||||
loadChapterPage(pageNum: number, part: string) {
|
loadChapterPage(pageNum: number, part: string) {
|
||||||
this.loadChapter.emit({pageNum, part});
|
this.loadChapter.emit({pageNum, part});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isChapterSelected(chapterGroup: BookChapterItem) {
|
||||||
|
if (chapterGroup.page === this.pageNum) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const idx = this.chapters.indexOf(chapterGroup);
|
||||||
|
if (idx < 0) {
|
||||||
|
return false; // should never happen
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextIdx = idx + 1;
|
||||||
|
// Last chapter
|
||||||
|
if (nextIdx >= this.chapters.length) {
|
||||||
|
return chapterGroup.page < this.pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passed chapter, and next chapter has not been reached
|
||||||
|
const next = this.chapters[nextIdx];
|
||||||
|
return chapterGroup.page < this.pageNum && next.page > this.pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
isAnchorSelected(chapter: BookChapterItem) {
|
||||||
|
return this.cleanIdSelector(chapter.part) === this.currentPageAnchor
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue