Skip to content

Commit ee77282

Browse files
authored
Merge pull request #10 from InfiniteLibrary/toc
Toc
2 parents 2506664 + b6cd9c8 commit ee77282

File tree

4 files changed

+107
-5
lines changed

4 files changed

+107
-5
lines changed

app/app.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
$family-primary: 'Helvetica Neue', 'Lucida Grande', 'Segoe UI', Ubuntu, Cantarell, sans-serif;
22
$super-color: #ffca29;
3+
$link-color: #00d1b2;
4+
$link-hover: darken($link-color, 0.5);
5+
36
@import '~bulma/bulma.sass';
47

58
.input {

app/components/Epub/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class Epub extends Component {
4444
}
4545
});
4646

47+
this.book.loaded.navigation.then((nav) => {
48+
if (this.props.onNavigationReady) this.props.onNavigationReady(nav.toc);
49+
});
50+
4751
this.keyListener = (e) => {
4852
// Left Key
4953
if ((e.keyCode || e.which) === 37) {
@@ -72,6 +76,24 @@ class Epub extends Component {
7276
document.removeEventListener('keyup', this.keyListener, false);
7377
}
7478

79+
componentWillUpdate(nextProps) {
80+
if (nextProps.location !== this.props.location) {
81+
this.rendition.display(nextProps.location);
82+
}
83+
84+
if (nextProps.theme !== this.props.theme) {
85+
this.rendition.themes.apply(nextProps.theme);
86+
}
87+
88+
if (nextProps.fontSize !== this.props.fontSize) {
89+
this.rendition.themes.fontSize(nextProps.fontSize);
90+
}
91+
}
92+
93+
display(what) {
94+
this.rendition && this.rendition.display(what);
95+
}
96+
7597
render() {
7698
return (
7799
<div className="epub__container">

app/components/Reader/Reader.scss

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
@import '../../variables.scss';
2+
3+
$toc-menu-width: 300px;
4+
15
.reader__container {
26
background-color: #fcfcfc;
7+
padding: 25px;
38
}
49

510
.reader__controls {
@@ -10,3 +15,28 @@
1015
width: 100vw;
1116
z-index: 500;
1217
}
18+
19+
.reader__toc {
20+
background-color: $dark-gray;
21+
color: #fff;
22+
height: 100vh;
23+
-webkit-overflow-scrolling: touch;
24+
overflow-y: auto;
25+
padding: $base-spacing $small-spacing;
26+
position: fixed;
27+
top: 0;
28+
left: 0;
29+
bottom: 0;
30+
right: auto;
31+
transform: translateX(-100%);
32+
transition: all 0.1s ease-in-out;
33+
width: $toc-menu-width;
34+
z-index: 600;
35+
36+
&.is-visible { transform: translateX(0%); }
37+
38+
&__item {
39+
a {}
40+
a:hover { color: #fff; }
41+
}
42+
}

app/components/Reader/index.js

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,63 @@ class Reader extends Component {
1111
this.handleReady = this.handleReady.bind(this);
1212
}
1313

14+
_navigationReady(nav) {
15+
this.setState({ ...this.state, nav });
16+
}
17+
18+
_onNavClick(item) {
19+
this.setState({ ...this.state, location: item.href });
20+
}
21+
22+
handleReady() {
23+
this.setState({ ...this.state, isLoading: false });
24+
}
25+
26+
tocToggle() {
27+
let navMenu = document.getElementById('toc-nav');
28+
29+
if (navMenu.classList.contains('is-visible')) {
30+
navMenu.classList.remove('is-visible');
31+
} else {
32+
navMenu.classList.add('is-visible');
33+
}
34+
35+
}
36+
1437
state = {
15-
isLoading: true
38+
isLoading: true,
39+
nav: [],
40+
location : 0
1641
};
1742

1843
handleReady() {
19-
this.setState({ isLoading: false });
44+
this.setState({ ...this.state, isLoading: false });
2045
}
2146

2247
render() {
2348
const { book } = this.props;
2449
const download = encodeURIComponent(book.download);
2550
return (
2651
<div className="reader__container">
52+
<div id="toc-nav" className="reader__toc">
53+
<ul>
54+
<h2>Table of Contents</h2>
55+
{
56+
this.state.nav.map((item, index) =>
57+
<li>
58+
<a key={`navitem_${index}`}
59+
className="reader__toc__item"
60+
onClick={() => {
61+
this._onNavClick(item)
62+
this.tocToggle()
63+
}}>
64+
{item.label}
65+
</a>
66+
</li>
67+
)
68+
}
69+
</ul>
70+
</div>
2771
<nav className="nav is-fixed">
2872
<div className="nav-left">
2973
<Link to="/" className="nav-item">
@@ -38,17 +82,20 @@ class Reader extends Component {
3882
</div>
3983
</div>
4084
<div className="nav-right">
41-
<div className="nav-item">
85+
<a className="nav-item" onClick={() => { this.tocToggle()}}>
4286
<span className="icon">
4387
<i className="fa fa-navicon" />
4488
</span>
45-
</div>
89+
</a>
4690
</div>
4791
</nav>
4892
{this.state.isLoading && <Loader />}
4993
<Epub
50-
onReady={this.handleReady}
5194
src={`${getStreamHost()}/${book.id}/${download}/`}
95+
onNavigationReady={ this._navigationReady.bind(this) }
96+
onLocationChanged={(location) => console.log(location)}
97+
onReady={ this.handleReady.bind(this) }
98+
location={this.state.location}
5299
/>
53100
</div>
54101
);

0 commit comments

Comments
 (0)